From b06d41e31a39fef3b33775021fd23815a0d7d757 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Wed, 29 Dec 2021 00:49:10 -0500 Subject: [PATCH] resolve market cancel uses only pool to pay out --- functions/src/resolve-market.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/functions/src/resolve-market.ts b/functions/src/resolve-market.ts index 280af022..ec6cd3bf 100644 --- a/functions/src/resolve-market.ts +++ b/functions/src/resolve-market.ts @@ -54,10 +54,7 @@ export const resolveMarket = functions const payouts = outcome === 'CANCEL' - ? bets.map((bet) => ({ - userId: bet.userId, - payout: bet.amount, - })) + ? getCancelPayouts(contract, bets) : getPayouts(outcome, contract, bets) console.log('payouts:', payouts) @@ -77,6 +74,20 @@ export const resolveMarket = functions const firestore = admin.firestore() +const getCancelPayouts = (contract: Contract, bets: Bet[]) => { + const startPool = contract.startPool.YES + contract.startPool.NO + const truePool = contract.pool.YES + contract.pool.NO - startPool + + const openBets = bets.filter((b) => !b.isSold && !b.sale) + + const betSum = _.sumBy(openBets, (b) => b.amount) + + return openBets.map((bet) => ({ + userId: bet.userId, + payout: (bet.amount / betSum) * truePool, + })) +} + const getPayouts = (outcome: string, contract: Contract, bets: Bet[]) => { const openBets = bets.filter((b) => !b.isSold && !b.sale) const [yesBets, noBets] = _.partition(