store initialProbability in contracts

This commit is contained in:
mantikoros 2022-03-08 11:41:22 -06:00
parent 82c5eb85d3
commit 1dfc108ae4
3 changed files with 6 additions and 7 deletions

View File

@ -31,7 +31,7 @@ export function getProbability(contract: FullContract<DPM | CPMM, Binary>) {
export function getInitialProbability(
contract: FullContract<DPM | CPMM, Binary>
) {
return contract.mechanism === 'cpmm-1'
return contract.initialProbability ?? contract.mechanism === 'cpmm-1'
? getCpmmProbability(contract.pool)
: getDpmProbability(contract.phantomShares ?? contract.totalShares)
}

View File

@ -53,6 +53,7 @@ export type FixedPayouts = CPMM
export type Binary = {
outcomeType: 'BINARY'
initialProbability: number
resolutionProbability?: number // Used for BINARY markets resolved to MKT
}

View File

@ -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,
}