Fix free response mkt payout to default to last probabilities if resolutions not specified
This commit is contained in:
parent
d13170f455
commit
2937c0d891
|
@ -218,23 +218,30 @@ function calculateMktDpmPayout(contract: FullContract<DPM, any>, bet: Bet) {
|
||||||
FreeResponse
|
FreeResponse
|
||||||
>
|
>
|
||||||
|
|
||||||
if (!resolutions)
|
let probs: { [outcome: string]: number }
|
||||||
throw new Error(
|
|
||||||
'resolutions required for MKT payout of free response market'
|
if (resolutions) {
|
||||||
|
const probTotal = _.sum(Object.values(resolutions))
|
||||||
|
probs = _.mapValues(
|
||||||
|
totalShares,
|
||||||
|
(_, outcome) => (resolutions[outcome] ?? 0) / probTotal
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
const squareSum = _.sum(
|
||||||
|
Object.values(totalShares).map((shares) => shares ** 2)
|
||||||
|
)
|
||||||
|
probs = _.mapValues(totalShares, (shares) => shares ** 2 / squareSum)
|
||||||
|
}
|
||||||
|
|
||||||
const totalPool = _.sum(Object.values(pool))
|
const weightedShareTotal = _.sumBy(Object.keys(totalShares), (outcome) => {
|
||||||
const probTotal = _.sum(Object.values(resolutions))
|
return probs[outcome] * totalShares[outcome]
|
||||||
|
|
||||||
const weightedShareTotal = _.sumBy(Object.keys(resolutions), (outcome) => {
|
|
||||||
const prob = resolutions[outcome] / probTotal
|
|
||||||
return prob * totalShares[outcome]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const { outcome, amount, shares } = bet
|
const { outcome, amount, shares } = bet
|
||||||
|
|
||||||
const betP = (resolutions[outcome] ?? 0) / probTotal
|
const totalPool = _.sum(Object.values(pool))
|
||||||
const winnings = ((betP * shares) / weightedShareTotal) * totalPool
|
const poolFrac = (probs[outcome] * shares) / weightedShareTotal
|
||||||
|
const winnings = poolFrac * totalPool
|
||||||
|
|
||||||
return deductDpmFees(amount, winnings)
|
return deductDpmFees(amount, winnings)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user