Fix a bug

This commit is contained in:
James Grugett 2022-10-06 21:43:14 -05:00
parent cfc8cdfa1c
commit b3f7b87ef8
2 changed files with 6 additions and 6 deletions

View File

@ -172,7 +172,7 @@ export const computeFills = (
let amount = betAmount
let cpmmState = { pool: state.pool, p: state.p }
let totalFees = noFees
const makerBalanceByUserId = { ...balanceByUserId }
const currentBalanceByUserId = { ...balanceByUserId }
let i = 0
while (true) {
@ -191,17 +191,17 @@ export const computeFills = (
// Matched against bet.
i++
const { userId } = maker.bet
const makerBalance = makerBalanceByUserId[userId]
const makerBalance = currentBalanceByUserId[userId]
if (floatingGreaterEqual(makerBalance, maker.amount)) {
makerBalanceByUserId[userId] = makerBalance - maker.amount
currentBalanceByUserId[userId] = makerBalance - maker.amount
} else {
// Insufficient balance. Cancel maker bet.
ordersToCancel.push(maker.bet)
continue
}
if (userId) takers.push(taker)
takers.push(taker)
makers.push(maker)
}

View File

@ -6,7 +6,7 @@ import {
Query,
Transaction,
} from 'firebase-admin/firestore'
import { groupBy, mapValues, sumBy, uniq, uniqBy } from 'lodash'
import { groupBy, mapValues, sumBy, uniq } from 'lodash'
import { APIError, newEndpoint, validate } from './api'
import { Contract, CPMM_MIN_POOL_QTY } from '../../common/contract'
@ -217,7 +217,7 @@ export const getUnfilledBetsAndUserBalances = async (
const unfilledBets = unfilledBetsSnap.docs.map((doc) => doc.data())
// Get balance of all users with open limit orders.
const userIds = uniqBy(unfilledBets, (bet) => bet.userId)
const userIds = uniq(unfilledBets.map((bet) => bet.userId))
const userDocs =
userIds.length === 0
? []