change fee structure (paid only on winnings); calculateMoneyRatio

This commit is contained in:
mantikoros 2022-01-14 11:11:01 -06:00
parent 3e08349df6
commit 6d536c4e16
3 changed files with 40 additions and 32 deletions

View File

@ -68,14 +68,18 @@ export function calculateRawShareValue(
return currentValue - postSaleValue return currentValue - postSaleValue
} }
export function calculateMoneyRatio(contract: Contract) { export function calculateMoneyRatio(contract: Contract, bet: Bet) {
const { totalShares, pool } = contract const { totalShares, pool } = contract
const { amount } = bet
const p = getProbability(totalShares) const p = getProbability(totalShares)
const actual = pool.YES + pool.NO const actual = pool.YES + pool.NO - amount
const expected = p * contract.totalBets.YES + (1 - p) * contract.totalBets.NO
return expected === 0 ? 0 : actual / expected const expected =
p * contract.totalBets.YES + (1 - p) * contract.totalBets.NO - amount
return expected <= 0 ? 0 : actual / expected
} }
export function calculateShareValue(contract: Contract, bet: Bet) { export function calculateShareValue(contract: Contract, bet: Bet) {
@ -84,7 +88,7 @@ export function calculateShareValue(contract: Contract, bet: Bet) {
bet.shares, bet.shares,
bet.outcome bet.outcome
) )
const f = calculateMoneyRatio(contract) const f = calculateMoneyRatio(contract, bet)
const myPool = contract.pool[bet.outcome] const myPool = contract.pool[bet.outcome]
const adjShareValue = Math.min(Math.min(1, f) * shareValue, myPool) const adjShareValue = Math.min(Math.min(1, f) * shareValue, myPool)
@ -92,7 +96,7 @@ export function calculateShareValue(contract: Contract, bet: Bet) {
} }
export function calculateSaleAmount(contract: Contract, bet: Bet) { export function calculateSaleAmount(contract: Contract, bet: Bet) {
return (1 - FEES) * calculateShareValue(contract, bet) return (1 - 2 * FEES) * calculateShareValue(contract, bet)
} }
export function calculatePayout( export function calculatePayout(
@ -133,7 +137,7 @@ export function calculateStandardPayout(
totalShares[outcome] - phantomShares[outcome] - totalBets[outcome] totalShares[outcome] - phantomShares[outcome] - totalBets[outcome]
const winningsPool = truePool - totalBets[outcome] const winningsPool = truePool - totalBets[outcome]
return (1 - FEES) * (amount + ((shares - amount) / total) * winningsPool) return amount + (1 - 2 * FEES) * ((shares - amount) / total) * winningsPool
} }
export function calculatePayoutAfterCorrectBet(contract: Contract, bet: Bet) { export function calculatePayoutAfterCorrectBet(contract: Contract, bet: Bet) {
@ -188,9 +192,10 @@ function calculateMktPayout(contract: Contract, bet: Bet) {
contract.totalBets.NO) contract.totalBets.NO)
return ( return (
(1 - FEES) * betP * bet.amount +
(betP * bet.amount + (1 - 2 * FEES) *
((betP * (bet.shares - bet.amount)) / weightedShareTotal) * winningsPool) ((betP * (bet.shares - bet.amount)) / weightedShareTotal) *
winningsPool
) )
} }

View File

@ -27,7 +27,21 @@ export const getStandardPayouts = (
if (betSum >= truePool) return getCancelPayouts(truePool, winningBets) if (betSum >= truePool) return getCancelPayouts(truePool, winningBets)
const creatorPayout = CREATOR_FEE * truePool const shareDifferenceSum = sumBy(winningBets, (b) => b.shares - b.amount)
const winningsPool = truePool - betSum
const winnerPayouts = winningBets.map((bet) => ({
userId: bet.userId,
payout:
bet.amount +
(1 - 2 * FEES) *
((bet.shares - bet.amount) / shareDifferenceSum) *
winningsPool,
}))
const creatorPayout = 2 * CREATOR_FEE * winningsPool
console.log( console.log(
'resolved', 'resolved',
outcome, outcome,
@ -37,18 +51,6 @@ export const getStandardPayouts = (
creatorPayout creatorPayout
) )
const shareDifferenceSum = sumBy(winningBets, (b) => b.shares - b.amount)
const winningsPool = truePool - betSum
const winnerPayouts = winningBets.map((bet) => ({
userId: bet.userId,
payout:
(1 - FEES) *
(bet.amount +
((bet.shares - bet.amount) / shareDifferenceSum) * winningsPool),
}))
return winnerPayouts.concat([ return winnerPayouts.concat([
{ userId: contract.creatorId, payout: creatorPayout }, { userId: contract.creatorId, payout: creatorPayout },
]) // add creator fee ]) // add creator fee
@ -87,21 +89,22 @@ export const getMktPayouts = (
const yesPayouts = yesBets.map((bet) => ({ const yesPayouts = yesBets.map((bet) => ({
userId: bet.userId, userId: bet.userId,
payout: payout:
(1 - FEES) * p * bet.amount +
(p * bet.amount + (1 - 2 * FEES) *
((p * (bet.shares - bet.amount)) / weightedShareTotal) * winningsPool), ((p * (bet.shares - bet.amount)) / weightedShareTotal) *
winningsPool,
})) }))
const noPayouts = noBets.map((bet) => ({ const noPayouts = noBets.map((bet) => ({
userId: bet.userId, userId: bet.userId,
payout: payout:
(1 - FEES) * (1 - p) * bet.amount +
((1 - p) * bet.amount + (1 - 2 * FEES) *
(((1 - p) * (bet.shares - bet.amount)) / weightedShareTotal) * (((1 - p) * (bet.shares - bet.amount)) / weightedShareTotal) *
winningsPool), winningsPool,
})) }))
const creatorPayout = CREATOR_FEE * truePool const creatorPayout = 2 * CREATOR_FEE * winningsPool
return [ return [
...yesPayouts, ...yesPayouts,

View File

@ -36,8 +36,8 @@ export const getSellBetInfo = (
const probBefore = getProbability(contract.totalShares) const probBefore = getProbability(contract.totalShares)
const probAfter = getProbability(newTotalShares) const probAfter = getProbability(newTotalShares)
const creatorFee = CREATOR_FEE * adjShareValue const creatorFee = 2 * CREATOR_FEE * adjShareValue
const saleAmount = (1 - FEES) * adjShareValue const saleAmount = (1 - 2 * FEES) * adjShareValue
console.log( console.log(
'SELL M$', 'SELL M$',