From 2d1d4dd58b14eff63a2d71d3750bb7a632251655 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Tue, 11 Jan 2022 21:57:28 -0600 Subject: [PATCH] contract: remove startPool, add phantomShares --- common/antes.ts | 6 +++--- common/calculate.ts | 11 +++++++---- common/contract.ts | 2 +- common/new-contract.ts | 4 ++-- web/components/contract-prob-graph.tsx | 4 ++-- web/lib/firebase/contracts.ts | 4 ++-- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/common/antes.ts b/common/antes.ts index f94c9f35..eb51b691 100644 --- a/common/antes.ts +++ b/common/antes.ts @@ -15,10 +15,10 @@ export const calcStartPool = (initialProbInt: number, ante = 0) => { const poolYes = p * ante const poolNo = (1 - p) * ante - const startYes = Math.sqrt(p) * PHANTOM_ANTE - const startNo = Math.sqrt(1 - p) * PHANTOM_ANTE + const phantomYes = Math.sqrt(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( diff --git a/common/calculate.ts b/common/calculate.ts index 11460c8d..b8a88012 100644 --- a/common/calculate.ts +++ b/common/calculate.ts @@ -120,7 +120,7 @@ export function calculateStandardPayout( const { amount, outcome: betOutcome, shares } = bet if (betOutcome !== outcome) return 0 - const { totalShares, totalBets, startPool } = contract + const { totalShares, totalBets, phantomShares } = contract if (totalShares[outcome] === 0) return 0 const truePool = contract.pool.YES + contract.pool.NO @@ -128,7 +128,8 @@ export function calculateStandardPayout( if (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] return (1 - FEES) * (amount + ((shares - amount) / total) * winningsPool) @@ -178,10 +179,12 @@ function calculateMktPayout(contract: Contract, bet: Bet) { const weightedShareTotal = p * (contract.totalShares.YES - - contract.startPool.YES - + contract.phantomShares.YES - contract.totalBets.YES) + (1 - p) * - (contract.totalShares.NO - contract.startPool.NO - contract.totalBets.NO) + (contract.totalShares.NO - + contract.phantomShares.NO - + contract.totalBets.NO) return ( (1 - FEES) * diff --git a/common/contract.ts b/common/contract.ts index eb00ae7b..385820df 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -12,7 +12,7 @@ export type Contract = { // outcomes: ['YES', 'NO'] mechanism: 'dpm-2' - startPool: { YES: number; NO: number } + phantomShares: { YES: number; NO: number } pool: { YES: number; NO: number } totalShares: { YES: number; NO: number } totalBets: { YES: number; NO: number } diff --git a/common/new-contract.ts b/common/new-contract.ts index b2fb08b5..eef7b392 100644 --- a/common/new-contract.ts +++ b/common/new-contract.ts @@ -13,7 +13,7 @@ export function getNewContract( ante?: number, closeTime?: number ) { - const { sharesYes, sharesNo, poolYes, poolNo, startYes, startNo } = + const { sharesYes, sharesNo, poolYes, poolNo, phantomYes, phantomNo } = calcStartPool(initialProb, ante) const contract: Contract = { @@ -29,7 +29,7 @@ export function getNewContract( description: description.trim(), mechanism: 'dpm-2', - startPool: { YES: startYes, NO: startNo }, + phantomShares: { YES: phantomYes, NO: phantomNo }, pool: { YES: poolYes, NO: poolNo }, totalShares: { YES: sharesYes, NO: sharesNo }, totalBets: { YES: poolYes, NO: poolNo }, diff --git a/web/components/contract-prob-graph.tsx b/web/components/contract-prob-graph.tsx index 0c059e62..691a662e 100644 --- a/web/components/contract-prob-graph.tsx +++ b/web/components/contract-prob-graph.tsx @@ -8,12 +8,12 @@ import { Contract } from '../lib/firebase/contracts' export function ContractProbGraph(props: { contract: Contract }) { const { contract } = props - const { id, startPool, resolutionTime } = contract + const { id, phantomShares, resolutionTime } = contract let bets = useBets(id) if (bets === 'loading') bets = [] - const startProb = getProbability(startPool) + const startProb = getProbability(phantomShares) const times = [ contract.createdTime, diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index 8a48843d..8556015a 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -29,7 +29,7 @@ export function contractPath(contract: Contract) { export function contractMetrics(contract: Contract) { const { pool, - startPool, + phantomShares, totalShares, createdTime, resolutionTime, @@ -40,7 +40,7 @@ export function contractMetrics(contract: Contract) { const prob = getProbability(totalShares) const probPercent = Math.round(prob * 100) + '%' - const startProb = getProbability(startPool) + const startProb = getProbability(phantomShares) const createdDate = dayjs(createdTime).format('MMM D')