Remove some old loan code
This commit is contained in:
parent
1e904f567a
commit
b2091ea659
|
@ -34,5 +34,3 @@ export type NumericBet = Bet & {
|
||||||
allOutcomeShares: { [outcome: string]: number }
|
allOutcomeShares: { [outcome: string]: number }
|
||||||
allBetAmounts: { [outcome: string]: number }
|
allBetAmounts: { [outcome: string]: number }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MAX_LOAN_PER_CONTRACT = 20
|
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import { sumBy } from 'lodash'
|
import { Bet, NumericBet } from './bet'
|
||||||
|
|
||||||
import { Bet, MAX_LOAN_PER_CONTRACT, NumericBet } from './bet'
|
|
||||||
import {
|
import {
|
||||||
calculateDpmShares,
|
calculateDpmShares,
|
||||||
getDpmProbability,
|
getDpmProbability,
|
||||||
|
@ -32,8 +30,7 @@ export type BetInfo = {
|
||||||
export const getNewBinaryCpmmBetInfo = (
|
export const getNewBinaryCpmmBetInfo = (
|
||||||
outcome: 'YES' | 'NO',
|
outcome: 'YES' | 'NO',
|
||||||
amount: number,
|
amount: number,
|
||||||
contract: CPMMBinaryContract,
|
contract: CPMMBinaryContract
|
||||||
loanAmount: number
|
|
||||||
) => {
|
) => {
|
||||||
const { shares, newPool, newP, fees } = calculateCpmmPurchase(
|
const { shares, newPool, newP, fees } = calculateCpmmPurchase(
|
||||||
contract,
|
contract,
|
||||||
|
@ -51,7 +48,7 @@ export const getNewBinaryCpmmBetInfo = (
|
||||||
shares,
|
shares,
|
||||||
outcome,
|
outcome,
|
||||||
fees,
|
fees,
|
||||||
loanAmount,
|
loanAmount: 0,
|
||||||
probBefore,
|
probBefore,
|
||||||
probAfter,
|
probAfter,
|
||||||
createdTime: Date.now(),
|
createdTime: Date.now(),
|
||||||
|
@ -66,8 +63,7 @@ export const getNewBinaryCpmmBetInfo = (
|
||||||
export const getNewBinaryDpmBetInfo = (
|
export const getNewBinaryDpmBetInfo = (
|
||||||
outcome: 'YES' | 'NO',
|
outcome: 'YES' | 'NO',
|
||||||
amount: number,
|
amount: number,
|
||||||
contract: DPMBinaryContract,
|
contract: DPMBinaryContract
|
||||||
loanAmount: number
|
|
||||||
) => {
|
) => {
|
||||||
const { YES: yesPool, NO: noPool } = contract.pool
|
const { YES: yesPool, NO: noPool } = contract.pool
|
||||||
|
|
||||||
|
@ -98,7 +94,7 @@ export const getNewBinaryDpmBetInfo = (
|
||||||
const newBet: CandidateBet<Bet> = {
|
const newBet: CandidateBet<Bet> = {
|
||||||
contractId: contract.id,
|
contractId: contract.id,
|
||||||
amount,
|
amount,
|
||||||
loanAmount,
|
loanAmount: 0,
|
||||||
shares,
|
shares,
|
||||||
outcome,
|
outcome,
|
||||||
probBefore,
|
probBefore,
|
||||||
|
@ -113,8 +109,7 @@ export const getNewBinaryDpmBetInfo = (
|
||||||
export const getNewMultiBetInfo = (
|
export const getNewMultiBetInfo = (
|
||||||
outcome: string,
|
outcome: string,
|
||||||
amount: number,
|
amount: number,
|
||||||
contract: FreeResponseContract,
|
contract: FreeResponseContract
|
||||||
loanAmount: number
|
|
||||||
) => {
|
) => {
|
||||||
const { pool, totalShares, totalBets } = contract
|
const { pool, totalShares, totalBets } = contract
|
||||||
|
|
||||||
|
@ -135,7 +130,7 @@ export const getNewMultiBetInfo = (
|
||||||
const newBet: CandidateBet<Bet> = {
|
const newBet: CandidateBet<Bet> = {
|
||||||
contractId: contract.id,
|
contractId: contract.id,
|
||||||
amount,
|
amount,
|
||||||
loanAmount,
|
loanAmount: 0,
|
||||||
shares,
|
shares,
|
||||||
outcome,
|
outcome,
|
||||||
probBefore,
|
probBefore,
|
||||||
|
@ -189,13 +184,3 @@ export const getNumericBetsInfo = (
|
||||||
|
|
||||||
return { newBet, newPool, newTotalShares, newTotalBets }
|
return { newBet, newPool, newTotalShares, newTotalBets }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getLoanAmount = (yourBets: Bet[], newBetAmount: number) => {
|
|
||||||
const openBets = yourBets.filter((bet) => !bet.isSold && !bet.sale)
|
|
||||||
const prevLoanAmount = sumBy(openBets, (bet) => bet.loanAmount ?? 0)
|
|
||||||
const loanAmount = Math.min(
|
|
||||||
newBetAmount,
|
|
||||||
MAX_LOAN_PER_CONTRACT - prevLoanAmount
|
|
||||||
)
|
|
||||||
return loanAmount
|
|
||||||
}
|
|
||||||
|
|
|
@ -90,10 +90,8 @@ export const createAnswer = functions
|
||||||
}
|
}
|
||||||
transaction.create(newAnswerDoc, answer)
|
transaction.create(newAnswerDoc, answer)
|
||||||
|
|
||||||
const loanAmount = 0
|
|
||||||
|
|
||||||
const { newBet, newPool, newTotalShares, newTotalBets } =
|
const { newBet, newPool, newTotalShares, newTotalBets } =
|
||||||
getNewMultiBetInfo(answerId, amount, contract, loanAmount)
|
getNewMultiBetInfo(answerId, amount, contract)
|
||||||
|
|
||||||
const newBalance = user.balance - amount
|
const newBalance = user.balance - amount
|
||||||
const betDoc = firestore
|
const betDoc = firestore
|
||||||
|
|
|
@ -53,7 +53,6 @@ export const placebet = newEndpoint(['POST'], async (req, auth) => {
|
||||||
const user = userSnap.data() as User
|
const user = userSnap.data() as User
|
||||||
if (user.balance < amount) throw new APIError(400, 'Insufficient balance.')
|
if (user.balance < amount) throw new APIError(400, 'Insufficient balance.')
|
||||||
|
|
||||||
const loanAmount = 0
|
|
||||||
const { closeTime, outcomeType, mechanism, collectedFees, volume } =
|
const { closeTime, outcomeType, mechanism, collectedFees, volume } =
|
||||||
contract
|
contract
|
||||||
if (closeTime && Date.now() > closeTime)
|
if (closeTime && Date.now() > closeTime)
|
||||||
|
@ -69,16 +68,16 @@ export const placebet = newEndpoint(['POST'], async (req, auth) => {
|
||||||
} = await (async (): Promise<BetInfo> => {
|
} = await (async (): Promise<BetInfo> => {
|
||||||
if (outcomeType == 'BINARY' && mechanism == 'dpm-2') {
|
if (outcomeType == 'BINARY' && mechanism == 'dpm-2') {
|
||||||
const { outcome } = validate(binarySchema, req.body)
|
const { outcome } = validate(binarySchema, req.body)
|
||||||
return getNewBinaryDpmBetInfo(outcome, amount, contract, loanAmount)
|
return getNewBinaryDpmBetInfo(outcome, amount, contract)
|
||||||
} else if (outcomeType == 'BINARY' && mechanism == 'cpmm-1') {
|
} else if (outcomeType == 'BINARY' && mechanism == 'cpmm-1') {
|
||||||
const { outcome } = validate(binarySchema, req.body)
|
const { outcome } = validate(binarySchema, req.body)
|
||||||
return getNewBinaryCpmmBetInfo(outcome, amount, contract, loanAmount)
|
return getNewBinaryCpmmBetInfo(outcome, amount, contract)
|
||||||
} else if (outcomeType == 'FREE_RESPONSE' && mechanism == 'dpm-2') {
|
} else if (outcomeType == 'FREE_RESPONSE' && mechanism == 'dpm-2') {
|
||||||
const { outcome } = validate(freeResponseSchema, req.body)
|
const { outcome } = validate(freeResponseSchema, req.body)
|
||||||
const answerDoc = contractDoc.collection('answers').doc(outcome)
|
const answerDoc = contractDoc.collection('answers').doc(outcome)
|
||||||
const answerSnap = await trans.get(answerDoc)
|
const answerSnap = await trans.get(answerDoc)
|
||||||
if (!answerSnap.exists) throw new APIError(400, 'Invalid answer')
|
if (!answerSnap.exists) throw new APIError(400, 'Invalid answer')
|
||||||
return getNewMultiBetInfo(outcome, amount, contract, loanAmount)
|
return getNewMultiBetInfo(outcome, amount, contract)
|
||||||
} else if (outcomeType == 'NUMERIC' && mechanism == 'dpm-2') {
|
} else if (outcomeType == 'NUMERIC' && mechanism == 'dpm-2') {
|
||||||
const { outcome, value } = validate(numericSchema, req.body)
|
const { outcome, value } = validate(numericSchema, req.body)
|
||||||
return getNumericBetsInfo(value, outcome, amount, contract)
|
return getNumericBetsInfo(value, outcome, amount, contract)
|
||||||
|
@ -97,7 +96,7 @@ export const placebet = newEndpoint(['POST'], async (req, auth) => {
|
||||||
throw new APIError(400, 'Bet too large for current liquidity pool.')
|
throw new APIError(400, 'Bet too large for current liquidity pool.')
|
||||||
}
|
}
|
||||||
|
|
||||||
const newBalance = user.balance - amount - loanAmount
|
const newBalance = user.balance - amount
|
||||||
const betDoc = contractDoc.collection('bets').doc()
|
const betDoc = contractDoc.collection('bets').doc()
|
||||||
trans.create(betDoc, { id: betDoc.id, userId: user.id, ...newBet })
|
trans.create(betDoc, { id: betDoc.id, userId: user.id, ...newBet })
|
||||||
log('Created new bet document.')
|
log('Created new bet document.')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user