migrate cfmm: use sale amount as shares for sold bets

This commit is contained in:
mantikoros 2022-04-18 00:22:56 -05:00
parent c68cdc6f3e
commit dc9af1c5b0
2 changed files with 9 additions and 5 deletions

View File

@ -48,10 +48,11 @@ async function recalculateContract(contractRef: DocRef, isCommit = false) {
)
for (let bet of bets) {
const shares =
bet.isSold || bet.sale
? 0
: calculateStandardDpmPayout(contract, bet, bet.outcome)
const shares = bet.sale
? -bet.sale.amount
: bet.isSold
? bets.find((b) => b.sale?.betId === bet.id)?.sale?.amount ?? 0
: calculateStandardDpmPayout(contract, bet, bet.outcome)
console.log(
'converting',

View File

@ -397,7 +397,10 @@ export function ContractBetsTable(props: {
sales.map((sale) => [sale.sale?.betId ?? '', sale])
)
const [redemptions, normalBets] = _.partition(buys, (b) => b.isRedemption)
const [redemptions, normalBets] = _.partition(
contract.mechanism === 'cpmm-1' ? bets : buys,
(b) => b.isRedemption
)
const amountRedeemed = Math.floor(
-0.5 * _.sumBy(redemptions, (b) => b.shares)
)