Fix bugs
This commit is contained in:
parent
f001eda823
commit
cfc8cdfa1c
|
@ -172,6 +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 }
|
||||||
|
|
||||||
let i = 0
|
let i = 0
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -190,10 +191,10 @@ export const computeFills = (
|
||||||
// Matched against bet.
|
// Matched against bet.
|
||||||
i++
|
i++
|
||||||
const { userId } = maker.bet
|
const { userId } = maker.bet
|
||||||
const makerBalance = balanceByUserId[userId]
|
const makerBalance = makerBalanceByUserId[userId]
|
||||||
|
|
||||||
if (floatingGreaterEqual(makerBalance, maker.amount)) {
|
if (floatingGreaterEqual(makerBalance, maker.amount)) {
|
||||||
balanceByUserId[userId] = makerBalance - maker.amount
|
makerBalanceByUserId[userId] = makerBalance - maker.amount
|
||||||
} else {
|
} else {
|
||||||
// Insufficient balance. Cancel maker bet.
|
// Insufficient balance. Cancel maker bet.
|
||||||
ordersToCancel.push(maker.bet)
|
ordersToCancel.push(maker.bet)
|
||||||
|
@ -272,7 +273,7 @@ export const getBinaryBetStats = (
|
||||||
contract: CPMMBinaryContract | PseudoNumericContract,
|
contract: CPMMBinaryContract | PseudoNumericContract,
|
||||||
limitProb: number,
|
limitProb: number,
|
||||||
unfilledBets: LimitBet[],
|
unfilledBets: LimitBet[],
|
||||||
balanceByUserId: { [userId: string]: number },
|
balanceByUserId: { [userId: string]: number }
|
||||||
) => {
|
) => {
|
||||||
const { newBet } = getBinaryCpmmBetInfo(
|
const { newBet } = getBinaryCpmmBetInfo(
|
||||||
outcome,
|
outcome,
|
||||||
|
@ -280,7 +281,7 @@ export const getBinaryBetStats = (
|
||||||
contract,
|
contract,
|
||||||
limitProb,
|
limitProb,
|
||||||
unfilledBets as LimitBet[],
|
unfilledBets as LimitBet[],
|
||||||
balanceByUserId,
|
balanceByUserId
|
||||||
)
|
)
|
||||||
const remainingMatched =
|
const remainingMatched =
|
||||||
((newBet.orderAmount ?? 0) - newBet.amount) /
|
((newBet.orderAmount ?? 0) - newBet.amount) /
|
||||||
|
|
|
@ -218,9 +218,12 @@ export const getUnfilledBetsAndUserBalances = async (
|
||||||
|
|
||||||
// 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 = uniqBy(unfilledBets, (bet) => bet.userId)
|
||||||
const userDocs = await trans.getAll(
|
const userDocs =
|
||||||
...userIds.map((userId) => firestore.doc(`users/${userId}`))
|
userIds.length === 0
|
||||||
)
|
? []
|
||||||
|
: await trans.getAll(
|
||||||
|
...userIds.map((userId) => firestore.doc(`users/${userId}`))
|
||||||
|
)
|
||||||
const users = filterDefined(userDocs.map((doc) => doc.data() as User))
|
const users = filterDefined(userDocs.map((doc) => doc.data() as User))
|
||||||
const balanceByUserId = Object.fromEntries(
|
const balanceByUserId = Object.fromEntries(
|
||||||
users.map((user) => [user.id, user.balance])
|
users.map((user) => [user.id, user.balance])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user