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

View File

@ -6,7 +6,7 @@ import {
Query, Query,
Transaction, Transaction,
} from 'firebase-admin/firestore' } 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 { APIError, newEndpoint, validate } from './api'
import { Contract, CPMM_MIN_POOL_QTY } from '../../common/contract' 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()) const unfilledBets = unfilledBetsSnap.docs.map((doc) => doc.data())
// Get balance of all users with open limit orders. // 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 = const userDocs =
userIds.length === 0 userIds.length === 0
? [] ? []