From 70ad6f6cc598079065ce37e796acfbcf92d9d4d3 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Thu, 6 Oct 2022 22:06:39 -0500 Subject: [PATCH] Fix merge error --- common/calculate-metrics.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/common/calculate-metrics.ts b/common/calculate-metrics.ts index bf588345..6cfb0421 100644 --- a/common/calculate-metrics.ts +++ b/common/calculate-metrics.ts @@ -1,4 +1,4 @@ -import { last, sortBy, sum, sumBy } from 'lodash' +import { last, sortBy, sum, sumBy, uniq } from 'lodash' import { calculatePayout } from './calculate' import { Bet, LimitBet } from './bet' import { Contract, CPMMContract, DPMContract } from './contract' @@ -62,16 +62,28 @@ export const computeBinaryCpmmElasticity = ( const limitBets = bets .filter( (b) => - !b.isFilled && !b.isSold && !b.isRedemption && !b.sale && !b.isCancelled + !b.isFilled && + !b.isSold && + !b.isRedemption && + !b.sale && + !b.isCancelled && + b.limitProb !== undefined ) - .sort((a, b) => a.createdTime - b.createdTime) + .sort((a, b) => a.createdTime - b.createdTime) as LimitBet[] + + const userIds = uniq(limitBets.map((b) => b.userId)) + // Assume all limit orders are good. + const userBalances = Object.fromEntries( + userIds.map((id) => [id, Number.MAX_SAFE_INTEGER]) + ) const { newPool: poolY, newP: pY } = getBinaryCpmmBetInfo( 'YES', betAmount, contract, undefined, - limitBets as LimitBet[] + limitBets, + userBalances ) const resultYes = getCpmmProbability(poolY, pY) @@ -80,7 +92,8 @@ export const computeBinaryCpmmElasticity = ( betAmount, contract, undefined, - limitBets as LimitBet[] + limitBets, + userBalances ) const resultNo = getCpmmProbability(poolN, pN)