From f40a65cc88fd8f1915d4054d9b1c212773e94dca Mon Sep 17 00:00:00 2001 From: mantikoros Date: Thu, 3 Mar 2022 11:56:21 -0500 Subject: [PATCH] new bet: use calculateCpmmPurchase --- common/new-bet.ts | 16 ++++------------ functions/src/place-bet.ts | 1 - 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/common/new-bet.ts b/common/new-bet.ts index f1df7f70..b9d362cd 100644 --- a/common/new-bet.ts +++ b/common/new-bet.ts @@ -1,11 +1,12 @@ import * as _ from 'lodash' + import { Bet, MAX_LOAN_PER_CONTRACT } from './bet' import { calculateDpmShares, getDpmProbability, getDpmOutcomeProbability, } from './calculate-dpm' -import { calculateCpmmShares, getCpmmProbability } from './calculate-cpmm' +import { calculateCpmmPurchase, getCpmmProbability } from './calculate-cpmm' import { Binary, CPMM, @@ -24,20 +25,11 @@ export const getNewBinaryCpmmBetInfo = ( loanAmount: number, newBetId: string ) => { - const { pool, k } = contract - - const shares = calculateCpmmShares(pool, k, amount, outcome) - const { YES: y, NO: n } = pool - - const [newY, newN] = - outcome === 'YES' - ? [y - shares + amount, amount] - : [amount, n - shares + amount] + const { shares, newPool } = calculateCpmmPurchase(contract, amount, outcome) const newBalance = user.balance - (amount - loanAmount) - const probBefore = getCpmmProbability(pool) - const newPool = { YES: newY, NO: newN } + const probBefore = getCpmmProbability(contract.pool) const probAfter = getCpmmProbability(newPool) const newBet: Bet = { diff --git a/functions/src/place-bet.ts b/functions/src/place-bet.ts index de018de0..41ad8141 100644 --- a/functions/src/place-bet.ts +++ b/functions/src/place-bet.ts @@ -11,7 +11,6 @@ import { } from '../../common/new-bet' import { removeUndefinedProps } from '../../common/util/object' import { Bet } from '../../common/bet' -import { getValues } from './utils' export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall( async (