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 }
|
||||
allBetAmounts: { [outcome: string]: number }
|
||||
}
|
||||
|
||||
export const MAX_LOAN_PER_CONTRACT = 20
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import { sumBy } from 'lodash'
|
||||
|
||||
import { Bet, MAX_LOAN_PER_CONTRACT, NumericBet } from './bet'
|
||||
import { Bet, NumericBet } from './bet'
|
||||
import {
|
||||
calculateDpmShares,
|
||||
getDpmProbability,
|
||||
|
@ -32,8 +30,7 @@ export type BetInfo = {
|
|||
export const getNewBinaryCpmmBetInfo = (
|
||||
outcome: 'YES' | 'NO',
|
||||
amount: number,
|
||||
contract: CPMMBinaryContract,
|
||||
loanAmount: number
|
||||
contract: CPMMBinaryContract
|
||||
) => {
|
||||
const { shares, newPool, newP, fees } = calculateCpmmPurchase(
|
||||
contract,
|
||||
|
@ -51,7 +48,7 @@ export const getNewBinaryCpmmBetInfo = (
|
|||
shares,
|
||||
outcome,
|
||||
fees,
|
||||
loanAmount,
|
||||
loanAmount: 0,
|
||||
probBefore,
|
||||
probAfter,
|
||||
createdTime: Date.now(),
|
||||
|
@ -66,8 +63,7 @@ export const getNewBinaryCpmmBetInfo = (
|
|||
export const getNewBinaryDpmBetInfo = (
|
||||
outcome: 'YES' | 'NO',
|
||||
amount: number,
|
||||
contract: DPMBinaryContract,
|
||||
loanAmount: number
|
||||
contract: DPMBinaryContract
|
||||
) => {
|
||||
const { YES: yesPool, NO: noPool } = contract.pool
|
||||
|
||||
|
@ -98,7 +94,7 @@ export const getNewBinaryDpmBetInfo = (
|
|||
const newBet: CandidateBet<Bet> = {
|
||||
contractId: contract.id,
|
||||
amount,
|
||||
loanAmount,
|
||||
loanAmount: 0,
|
||||
shares,
|
||||
outcome,
|
||||
probBefore,
|
||||
|
@ -113,8 +109,7 @@ export const getNewBinaryDpmBetInfo = (
|
|||
export const getNewMultiBetInfo = (
|
||||
outcome: string,
|
||||
amount: number,
|
||||
contract: FreeResponseContract,
|
||||
loanAmount: number
|
||||
contract: FreeResponseContract
|
||||
) => {
|
||||
const { pool, totalShares, totalBets } = contract
|
||||
|
||||
|
@ -135,7 +130,7 @@ export const getNewMultiBetInfo = (
|
|||
const newBet: CandidateBet<Bet> = {
|
||||
contractId: contract.id,
|
||||
amount,
|
||||
loanAmount,
|
||||
loanAmount: 0,
|
||||
shares,
|
||||
outcome,
|
||||
probBefore,
|
||||
|
@ -189,13 +184,3 @@ export const getNumericBetsInfo = (
|
|||
|
||||
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)
|
||||
|
||||
const loanAmount = 0
|
||||
|
||||
const { newBet, newPool, newTotalShares, newTotalBets } =
|
||||
getNewMultiBetInfo(answerId, amount, contract, loanAmount)
|
||||
getNewMultiBetInfo(answerId, amount, contract)
|
||||
|
||||
const newBalance = user.balance - amount
|
||||
const betDoc = firestore
|
||||
|
|
|
@ -53,7 +53,6 @@ export const placebet = newEndpoint(['POST'], async (req, auth) => {
|
|||
const user = userSnap.data() as User
|
||||
if (user.balance < amount) throw new APIError(400, 'Insufficient balance.')
|
||||
|
||||
const loanAmount = 0
|
||||
const { closeTime, outcomeType, mechanism, collectedFees, volume } =
|
||||
contract
|
||||
if (closeTime && Date.now() > closeTime)
|
||||
|
@ -69,16 +68,16 @@ export const placebet = newEndpoint(['POST'], async (req, auth) => {
|
|||
} = await (async (): Promise<BetInfo> => {
|
||||
if (outcomeType == 'BINARY' && mechanism == 'dpm-2') {
|
||||
const { outcome } = validate(binarySchema, req.body)
|
||||
return getNewBinaryDpmBetInfo(outcome, amount, contract, loanAmount)
|
||||
return getNewBinaryDpmBetInfo(outcome, amount, contract)
|
||||
} else if (outcomeType == 'BINARY' && mechanism == 'cpmm-1') {
|
||||
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') {
|
||||
const { outcome } = validate(freeResponseSchema, req.body)
|
||||
const answerDoc = contractDoc.collection('answers').doc(outcome)
|
||||
const answerSnap = await trans.get(answerDoc)
|
||||
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') {
|
||||
const { outcome, value } = validate(numericSchema, req.body)
|
||||
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.')
|
||||
}
|
||||
|
||||
const newBalance = user.balance - amount - loanAmount
|
||||
const newBalance = user.balance - amount
|
||||
const betDoc = contractDoc.collection('bets').doc()
|
||||
trans.create(betDoc, { id: betDoc.id, userId: user.id, ...newBet })
|
||||
log('Created new bet document.')
|
||||
|
|
Loading…
Reference in New Issue
Block a user