Revert "Range bet executes both bets immediately."
This reverts commit 30b95d75d9
.
This commit is contained in:
parent
00dd88c9fb
commit
529165147c
|
@ -265,53 +265,6 @@ export const getBinaryBetStats = (
|
||||||
return { currentPayout, currentReturn, totalFees, newBet }
|
return { currentPayout, currentReturn, totalFees, newBet }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getBinaryRangeBetInfo = (
|
|
||||||
betAmount: number,
|
|
||||||
contract: CPMMBinaryContract | PseudoNumericContract,
|
|
||||||
lowLimitProb: number,
|
|
||||||
highLimitProb: number,
|
|
||||||
unfilledBets: LimitBet[]
|
|
||||||
) => {
|
|
||||||
const shares = Math.min(
|
|
||||||
betAmount / lowLimitProb,
|
|
||||||
betAmount / (1 - highLimitProb)
|
|
||||||
)
|
|
||||||
const yesAmount = shares * lowLimitProb
|
|
||||||
const noAmount = shares * (1 - highLimitProb)
|
|
||||||
|
|
||||||
const yesResult = getBinaryCpmmBetInfo(
|
|
||||||
'YES',
|
|
||||||
yesAmount,
|
|
||||||
contract,
|
|
||||||
lowLimitProb,
|
|
||||||
unfilledBets
|
|
||||||
)
|
|
||||||
const noResult = getBinaryCpmmBetInfo(
|
|
||||||
'NO',
|
|
||||||
noAmount,
|
|
||||||
{
|
|
||||||
...contract,
|
|
||||||
pool: yesResult.newPool,
|
|
||||||
p: yesResult.newP,
|
|
||||||
totalLiquidity: yesResult.newTotalLiquidity,
|
|
||||||
},
|
|
||||||
highLimitProb,
|
|
||||||
unfilledBets
|
|
||||||
)
|
|
||||||
|
|
||||||
const { newP, newPool, newTotalLiquidity } = noResult
|
|
||||||
const makers = [...yesResult.makers, ...noResult.makers]
|
|
||||||
|
|
||||||
return {
|
|
||||||
yesBet: yesResult.newBet,
|
|
||||||
noBet: noResult.newBet,
|
|
||||||
newP,
|
|
||||||
newPool,
|
|
||||||
newTotalLiquidity,
|
|
||||||
makers,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getNewBinaryDpmBetInfo = (
|
export const getNewBinaryDpmBetInfo = (
|
||||||
outcome: 'YES' | 'NO',
|
outcome: 'YES' | 'NO',
|
||||||
amount: number,
|
amount: number,
|
||||||
|
|
|
@ -14,7 +14,6 @@ import { User } from '../../common/user'
|
||||||
import {
|
import {
|
||||||
BetInfo,
|
BetInfo,
|
||||||
getBinaryCpmmBetInfo,
|
getBinaryCpmmBetInfo,
|
||||||
getBinaryRangeBetInfo,
|
|
||||||
getNewMultiBetInfo,
|
getNewMultiBetInfo,
|
||||||
getNumericBetsInfo,
|
getNumericBetsInfo,
|
||||||
} from '../../common/new-bet'
|
} from '../../common/new-bet'
|
||||||
|
@ -29,16 +28,10 @@ const bodySchema = z.object({
|
||||||
amount: z.number().gte(1),
|
amount: z.number().gte(1),
|
||||||
})
|
})
|
||||||
|
|
||||||
const binarySchema = z.union([
|
const binarySchema = z.object({
|
||||||
z.object({
|
outcome: z.enum(['YES', 'NO']),
|
||||||
outcome: z.enum(['YES', 'NO']),
|
limitProb: z.number().gte(0.001).lte(0.999).optional(),
|
||||||
limitProb: z.number().gte(0.001).lte(0.999).optional(),
|
})
|
||||||
}),
|
|
||||||
z.object({
|
|
||||||
lowLimitProb: z.number().gte(0.001).lte(0.999),
|
|
||||||
highLimitProb: z.number().gte(0.001).lte(0.999),
|
|
||||||
}),
|
|
||||||
])
|
|
||||||
|
|
||||||
const freeResponseSchema = z.object({
|
const freeResponseSchema = z.object({
|
||||||
outcome: z.string(),
|
outcome: z.string(),
|
||||||
|
@ -89,32 +82,20 @@ export const placebet = newEndpoint({}, async (req, auth) => {
|
||||||
(outcomeType == 'BINARY' || outcomeType === 'PSEUDO_NUMERIC') &&
|
(outcomeType == 'BINARY' || outcomeType === 'PSEUDO_NUMERIC') &&
|
||||||
mechanism == 'cpmm-1'
|
mechanism == 'cpmm-1'
|
||||||
) {
|
) {
|
||||||
|
const { outcome, limitProb } = validate(binarySchema, req.body)
|
||||||
|
|
||||||
const unfilledBetsSnap = await trans.get(
|
const unfilledBetsSnap = await trans.get(
|
||||||
getUnfilledBetsQuery(contractDoc)
|
getUnfilledBetsQuery(contractDoc)
|
||||||
)
|
)
|
||||||
const unfilledBets = unfilledBetsSnap.docs.map((doc) => doc.data())
|
const unfilledBets = unfilledBetsSnap.docs.map((doc) => doc.data())
|
||||||
const data = validate(binarySchema, req.body)
|
|
||||||
if ('outcome' in data) {
|
|
||||||
const { outcome, limitProb } = data
|
|
||||||
|
|
||||||
return getBinaryCpmmBetInfo(
|
return getBinaryCpmmBetInfo(
|
||||||
outcome,
|
outcome,
|
||||||
amount,
|
amount,
|
||||||
contract,
|
contract,
|
||||||
limitProb,
|
limitProb,
|
||||||
unfilledBets
|
unfilledBets
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
const { lowLimitProb, highLimitProb } = data
|
|
||||||
const result = getBinaryRangeBetInfo(
|
|
||||||
amount,
|
|
||||||
contract,
|
|
||||||
lowLimitProb,
|
|
||||||
highLimitProb,
|
|
||||||
unfilledBets
|
|
||||||
)
|
|
||||||
return { newBet: result.yesBet, ...result }
|
|
||||||
}
|
|
||||||
} 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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user