contract: remove startPool, add phantomShares

This commit is contained in:
mantikoros 2022-01-11 21:57:28 -06:00
parent 51a69cb916
commit 2d1d4dd58b
6 changed files with 17 additions and 14 deletions

View File

@ -15,10 +15,10 @@ export const calcStartPool = (initialProbInt: number, ante = 0) => {
const poolYes = p * ante const poolYes = p * ante
const poolNo = (1 - p) * ante const poolNo = (1 - p) * ante
const startYes = Math.sqrt(p) * PHANTOM_ANTE const phantomYes = Math.sqrt(p) * PHANTOM_ANTE
const startNo = Math.sqrt(1 - p) * PHANTOM_ANTE const phantomNo = Math.sqrt(1 - p) * PHANTOM_ANTE
return { sharesYes, sharesNo, poolYes, poolNo, startYes, startNo } return { sharesYes, sharesNo, poolYes, poolNo, phantomYes, phantomNo }
} }
export function getAnteBets( export function getAnteBets(

View File

@ -120,7 +120,7 @@ export function calculateStandardPayout(
const { amount, outcome: betOutcome, shares } = bet const { amount, outcome: betOutcome, shares } = bet
if (betOutcome !== outcome) return 0 if (betOutcome !== outcome) return 0
const { totalShares, totalBets, startPool } = contract const { totalShares, totalBets, phantomShares } = contract
if (totalShares[outcome] === 0) return 0 if (totalShares[outcome] === 0) return 0
const truePool = contract.pool.YES + contract.pool.NO const truePool = contract.pool.YES + contract.pool.NO
@ -128,7 +128,8 @@ export function calculateStandardPayout(
if (totalBets[outcome] >= truePool) if (totalBets[outcome] >= truePool)
return (amount / totalBets[outcome]) * truePool return (amount / totalBets[outcome]) * truePool
const total = totalShares[outcome] - startPool[outcome] - totalBets[outcome] const total =
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 (1 - FEES) * (amount + ((shares - amount) / total) * winningsPool)
@ -178,10 +179,12 @@ function calculateMktPayout(contract: Contract, bet: Bet) {
const weightedShareTotal = const weightedShareTotal =
p * p *
(contract.totalShares.YES - (contract.totalShares.YES -
contract.startPool.YES - contract.phantomShares.YES -
contract.totalBets.YES) + contract.totalBets.YES) +
(1 - p) * (1 - p) *
(contract.totalShares.NO - contract.startPool.NO - contract.totalBets.NO) (contract.totalShares.NO -
contract.phantomShares.NO -
contract.totalBets.NO)
return ( return (
(1 - FEES) * (1 - FEES) *

View File

@ -12,7 +12,7 @@ export type Contract = {
// outcomes: ['YES', 'NO'] // outcomes: ['YES', 'NO']
mechanism: 'dpm-2' mechanism: 'dpm-2'
startPool: { YES: number; NO: number } phantomShares: { YES: number; NO: number }
pool: { YES: number; NO: number } pool: { YES: number; NO: number }
totalShares: { YES: number; NO: number } totalShares: { YES: number; NO: number }
totalBets: { YES: number; NO: number } totalBets: { YES: number; NO: number }

View File

@ -13,7 +13,7 @@ export function getNewContract(
ante?: number, ante?: number,
closeTime?: number closeTime?: number
) { ) {
const { sharesYes, sharesNo, poolYes, poolNo, startYes, startNo } = const { sharesYes, sharesNo, poolYes, poolNo, phantomYes, phantomNo } =
calcStartPool(initialProb, ante) calcStartPool(initialProb, ante)
const contract: Contract = { const contract: Contract = {
@ -29,7 +29,7 @@ export function getNewContract(
description: description.trim(), description: description.trim(),
mechanism: 'dpm-2', mechanism: 'dpm-2',
startPool: { YES: startYes, NO: startNo }, phantomShares: { YES: phantomYes, NO: phantomNo },
pool: { YES: poolYes, NO: poolNo }, pool: { YES: poolYes, NO: poolNo },
totalShares: { YES: sharesYes, NO: sharesNo }, totalShares: { YES: sharesYes, NO: sharesNo },
totalBets: { YES: poolYes, NO: poolNo }, totalBets: { YES: poolYes, NO: poolNo },

View File

@ -8,12 +8,12 @@ import { Contract } from '../lib/firebase/contracts'
export function ContractProbGraph(props: { contract: Contract }) { export function ContractProbGraph(props: { contract: Contract }) {
const { contract } = props const { contract } = props
const { id, startPool, resolutionTime } = contract const { id, phantomShares, resolutionTime } = contract
let bets = useBets(id) let bets = useBets(id)
if (bets === 'loading') bets = [] if (bets === 'loading') bets = []
const startProb = getProbability(startPool) const startProb = getProbability(phantomShares)
const times = [ const times = [
contract.createdTime, contract.createdTime,

View File

@ -29,7 +29,7 @@ export function contractPath(contract: Contract) {
export function contractMetrics(contract: Contract) { export function contractMetrics(contract: Contract) {
const { const {
pool, pool,
startPool, phantomShares,
totalShares, totalShares,
createdTime, createdTime,
resolutionTime, resolutionTime,
@ -40,7 +40,7 @@ export function contractMetrics(contract: Contract) {
const prob = getProbability(totalShares) const prob = getProbability(totalShares)
const probPercent = Math.round(prob * 100) + '%' const probPercent = Math.round(prob * 100) + '%'
const startProb = getProbability(startPool) const startProb = getProbability(phantomShares)
const createdDate = dayjs(createdTime).format('MMM D') const createdDate = dayjs(createdTime).format('MMM D')