update api to include cfmm props

This commit is contained in:
mantikoros 2022-03-17 11:54:49 -05:00
parent e39f6d4125
commit 927a5137a2

View File

@ -1,7 +1,8 @@
import { Bet } from '../../../../common/bet' import { Bet } from '../../../../common/bet'
import { getDpmProbability } from '../../../../common/calculate-dpm' import { getProbability } from '../../../../common/calculate'
import { Comment } from '../../../../common/comment' import { Comment } from '../../../../common/comment'
import { DPM, FullContract } from '../../../../common/contract' import { Contract } from '../../../../common/contract'
import { removeUndefinedProps } from '../../../../common/util/object'
export type LiteMarket = { export type LiteMarket = {
// Unique identifer for this market // Unique identifer for this market
@ -19,11 +20,16 @@ export type LiteMarket = {
description: string description: string
tags: string[] tags: string[]
url: string url: string
mechanism: string
pool: number pool: number
probability: number probability?: number
p?: number
totalLiquidity?: number
volume7Days: number volume7Days: number
volume24Hours: number volume24Hours: number
isResolved: boolean isResolved: boolean
resolution?: string resolution?: string
resolutionTime?: number resolutionTime?: number
@ -38,7 +44,8 @@ export type ApiError = {
error: string error: string
} }
export function toLiteMarket({ export function toLiteMarket(contract: Contract): LiteMarket {
const {
id, id,
creatorUsername, creatorUsername,
creatorName, creatorName,
@ -50,14 +57,20 @@ export function toLiteMarket({
tags, tags,
slug, slug,
pool, pool,
totalShares, mechanism,
volume7Days, volume7Days,
volume24Hours, volume24Hours,
isResolved, isResolved,
resolution, resolution,
resolutionTime, resolutionTime,
}: FullContract<DPM, any>): LiteMarket { } = contract
return {
const { p, totalLiquidity } = contract as any
const probability =
contract.outcomeType === 'BINARY' ? getProbability(contract) : undefined
return removeUndefinedProps({
id, id,
creatorUsername, creatorUsername,
creatorName, creatorName,
@ -72,11 +85,14 @@ export function toLiteMarket({
tags, tags,
url: `https://manifold.markets/${creatorUsername}/${slug}`, url: `https://manifold.markets/${creatorUsername}/${slug}`,
pool: pool.YES + pool.NO, pool: pool.YES + pool.NO,
probability: getDpmProbability(totalShares), probability,
p,
totalLiquidity,
mechanism,
volume7Days, volume7Days,
volume24Hours, volume24Hours,
isResolved, isResolved,
resolution, resolution,
resolutionTime, resolutionTime,
} })
} }