From 99457388110119801cc3d1298e988a8b39a15143 Mon Sep 17 00:00:00 2001 From: TrueMilli <61841994+TrueMilli@users.noreply.github.com> Date: Tue, 14 Jun 2022 19:01:12 +0200 Subject: [PATCH] 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 --- docs/docs/api.md | 10 ++++++++-- web/lib/firebase/contracts.ts | 12 +++++++++--- web/pages/api/v0/_types.ts | 12 ++++++------ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/docs/docs/api.md b/docs/docs/api.md index f7217045..133cbb6b 100644 --- a/docs/docs/api.md +++ b/docs/docs/api.md @@ -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 } ``` diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index 0e0ad57e..a3976339 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -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) { diff --git a/web/pages/api/v0/_types.ts b/web/pages/api/v0/_types.ts index 78fe3708..38f1aa7a 100644 --- a/web/pages/api/v0/_types.ts +++ b/web/pages/api/v0/_types.ts @@ -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,