From 1dfc108ae478d1f5df4a7ad7c06d903a306df5c1 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Tue, 8 Mar 2022 11:41:22 -0600 Subject: [PATCH] store initialProbability in contracts --- common/calculate.ts | 2 +- common/contract.ts | 1 + common/new-contract.ts | 10 ++++------ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/common/calculate.ts b/common/calculate.ts index 21583065..6d25243e 100644 --- a/common/calculate.ts +++ b/common/calculate.ts @@ -31,7 +31,7 @@ export function getProbability(contract: FullContract) { export function getInitialProbability( contract: FullContract ) { - return contract.mechanism === 'cpmm-1' + return contract.initialProbability ?? contract.mechanism === 'cpmm-1' ? getCpmmProbability(contract.pool) : getDpmProbability(contract.phantomShares ?? contract.totalShares) } diff --git a/common/contract.ts b/common/contract.ts index 5cfd67a2..7bdaa14b 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -53,6 +53,7 @@ export type FixedPayouts = CPMM export type Binary = { outcomeType: 'BINARY' + initialProbability: number resolutionProbability?: number // Used for BINARY markets resolved to MKT } diff --git a/common/new-contract.ts b/common/new-contract.ts index 844ce704..16c55a47 100644 --- a/common/new-contract.ts +++ b/common/new-contract.ts @@ -32,7 +32,7 @@ export function getNewContract( const propsByOutcomeType = outcomeType === 'BINARY' - ? getBinaryCpmmProps(initialProb, ante, creator.id) // getBinaryDpmProps(initialProb, ante) + ? getBinaryCpmmProps(initialProb, ante) // getBinaryDpmProps(initialProb, ante) : getFreeAnswerProps(ante) const contract = removeUndefinedProps({ @@ -69,6 +69,7 @@ const getBinaryDpmProps = (initialProb: number, ante: number) => { const system: DPM & Binary = { mechanism: 'dpm-2', outcomeType: 'BINARY', + initialProbability: initialProb / 100, phantomShares: { YES: phantomYes, NO: phantomNo }, pool: { YES: poolYes, NO: poolNo }, totalShares: { YES: sharesYes, NO: sharesNo }, @@ -78,17 +79,14 @@ const getBinaryDpmProps = (initialProb: number, ante: number) => { return system } -const getBinaryCpmmProps = ( - initialProb: number, - ante: number, - userId: string -) => { +const getBinaryCpmmProps = (initialProb: number, ante: number) => { const { poolYes, poolNo } = calcCpmmInitialPool(initialProb, ante) const pool = { YES: poolYes, NO: poolNo } const system: CPMM & Binary = { mechanism: 'cpmm-1', outcomeType: 'BINARY', + initialProbability: initialProb / 100, pool: pool, }