resolve market cancel uses only pool to pay out

This commit is contained in:
mantikoros 2021-12-29 00:49:10 -05:00
parent a902dfebca
commit b06d41e31a

View File

@ -54,10 +54,7 @@ export const resolveMarket = functions
const payouts = const payouts =
outcome === 'CANCEL' outcome === 'CANCEL'
? bets.map((bet) => ({ ? getCancelPayouts(contract, bets)
userId: bet.userId,
payout: bet.amount,
}))
: getPayouts(outcome, contract, bets) : getPayouts(outcome, contract, bets)
console.log('payouts:', payouts) console.log('payouts:', payouts)
@ -77,6 +74,20 @@ export const resolveMarket = functions
const firestore = admin.firestore() 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 getPayouts = (outcome: string, contract: Contract, bets: Bet[]) => {
const openBets = bets.filter((b) => !b.isSold && !b.sale) const openBets = bets.filter((b) => !b.isSold && !b.sale)
const [yesBets, noBets] = _.partition( const [yesBets, noBets] = _.partition(