Refinement of LiteMarket (#479)

* split into two function to access the pool value as number

* rename function

* changes to the exported object

* removal of totalLiquidity: this value was only set for binary markets and it's value is identical to getPoolvalue(contract)
* pool: set in the same way as in the "Market Overview" from contract-info-dialog.tsx now
* totalShares: total shares of the contract. It's value is equal to the old "pool" value in case of binary markets

* update docs

* removal of totalShares
This commit is contained in:
TrueMilli 2022-06-14 19:01:12 +02:00 committed by GitHub
parent da2c6ae037
commit 9945738811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 11 deletions

View File

@ -95,14 +95,20 @@ Requires no authorization.
description: string
tags: string[]
url: string
outcomeType: string
mechanism: string
pool: number
probability: number
probability?: number
p?: number
volume: number
volume7Days: number
volume24Hours: number
isResolved: boolean
resolutionTime?: number
resolution?: string
resolutionTime?: number
}
```

View File

@ -57,11 +57,17 @@ export function contractMetrics(contract: Contract) {
}
export function contractPool(contract: Contract) {
return getPoolValue(contract) === 0
? 'Empty Pool'
: formatMoney(getPoolValue(contract))
}
export function getPoolValue(contract: Contract) {
return contract.mechanism === 'cpmm-1'
? formatMoney(contract.totalLiquidity)
? contract.totalLiquidity
: contract.mechanism === 'dpm-2'
? formatMoney(sum(Object.values(contract.pool)))
: 'Empty pool'
? sum(Object.values(contract.pool))
: 0
}
export function getBinaryProb(contract: BinaryContract) {

View File

@ -1,8 +1,10 @@
import { Bet } from 'common/bet'
import { getProbability } from 'common/calculate'
import { Comment } from 'common/comment'
import { Contract } from 'common/contract'
import { Contract, DPM } from 'common/contract'
import { removeUndefinedProps } from 'common/util/object'
import { sum } from 'lodash'
import { getPoolValue } from 'web/lib/firebase/contracts'
export type LiteMarket = {
// Unique identifer for this market
@ -26,7 +28,7 @@ export type LiteMarket = {
pool: number
probability?: number
p?: number
totalLiquidity?: number
totalShares?: number
volume: number
volume7Days: number
@ -58,7 +60,6 @@ export function toLiteMarket(contract: Contract): LiteMarket {
description,
tags,
slug,
pool,
outcomeType,
mechanism,
volume,
@ -69,7 +70,7 @@ export function toLiteMarket(contract: Contract): LiteMarket {
resolutionTime,
} = contract
const { p, totalLiquidity } = contract as any
const { p } = contract as any
const probability =
contract.outcomeType === 'BINARY' ? getProbability(contract) : undefined
@ -88,10 +89,9 @@ export function toLiteMarket(contract: Contract): LiteMarket {
description,
tags,
url: `https://manifold.markets/${creatorUsername}/${slug}`,
pool: pool.YES + pool.NO,
pool: getPoolValue(contract),
probability,
p,
totalLiquidity,
outcomeType,
mechanism,
volume,