diff --git a/common/contract.ts b/common/contract.ts index 35566c0b..7f5c5fd5 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -29,6 +29,7 @@ export type FullContract< closeEmailsSent?: number + volume?: number volume24Hours: number volume7Days: number diff --git a/common/new-contract.ts b/common/new-contract.ts index 3b3278c2..ffd27e3f 100644 --- a/common/new-contract.ts +++ b/common/new-contract.ts @@ -34,6 +34,8 @@ export function getNewContract( ? getBinaryCpmmProps(initialProb, ante) // getBinaryDpmProps(initialProb, ante) : getFreeAnswerProps(ante) + const volume = outcomeType === 'BINARY' ? 0 : ante + const contract: Contract = removeUndefinedProps({ id, slug, @@ -54,6 +56,7 @@ export function getNewContract( lastUpdatedTime: Date.now(), closeTime, + volume, volume24Hours: 0, volume7Days: 0, diff --git a/functions/src/create-answer.ts b/functions/src/create-answer.ts index 17d085f5..bc075fb9 100644 --- a/functions/src/create-answer.ts +++ b/functions/src/create-answer.ts @@ -57,7 +57,7 @@ export const createAnswer = functions.runWith({ minInstances: 1 }).https.onCall( message: 'Requires a free response contract', } - const { closeTime } = contract + const { closeTime, volume } = contract if (closeTime && Date.now() > closeTime) return { status: 'error', message: 'Trading is closed' } @@ -121,6 +121,7 @@ export const createAnswer = functions.runWith({ minInstances: 1 }).https.onCall( totalShares: newTotalShares, totalBets: newTotalBets, answers: [...(contract.answers ?? []), answer], + volume: (volume ?? 0) + amount, }) if (!isFinite(newBalance)) { diff --git a/functions/src/place-bet.ts b/functions/src/place-bet.ts index 1a79287d..f2ce3bc0 100644 --- a/functions/src/place-bet.ts +++ b/functions/src/place-bet.ts @@ -49,7 +49,8 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall( return { status: 'error', message: 'Invalid contract' } const contract = contractSnap.data() as Contract - const { closeTime, outcomeType, mechanism, collectedFees } = contract + const { closeTime, outcomeType, mechanism, collectedFees, volume } = + contract if (closeTime && Date.now() > closeTime) return { status: 'error', message: 'Trading is closed' } @@ -129,6 +130,7 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall( totalBets: newTotalBets, totalLiquidity: newTotalLiquidity, collectedFees: addObjects(fees ?? {}, collectedFees ?? {}), + volume: (volume ?? 0) + Math.abs(amount), }) ) diff --git a/functions/src/sell-bet.ts b/functions/src/sell-bet.ts index a5bb2af9..1dd57d2b 100644 --- a/functions/src/sell-bet.ts +++ b/functions/src/sell-bet.ts @@ -35,7 +35,7 @@ export const sellBet = functions.runWith({ minInstances: 1 }).https.onCall( return { status: 'error', message: 'Invalid contract' } const contract = contractSnap.data() as Contract - const { closeTime, mechanism, collectedFees } = contract + const { closeTime, mechanism, collectedFees, volume } = contract if (closeTime && Date.now() > closeTime) return { status: 'error', message: 'Trading is closed' } @@ -81,6 +81,7 @@ export const sellBet = functions.runWith({ minInstances: 1 }).https.onCall( totalShares: newTotalShares, totalBets: newTotalBets, collectedFees: addObjects(fees ?? {}, collectedFees ?? {}), + volume: (volume ?? 0) + bet.amount, }) ) diff --git a/functions/src/update-contract-metrics.ts b/functions/src/update-contract-metrics.ts index c3801df6..d95dcd80 100644 --- a/functions/src/update-contract-metrics.ts +++ b/functions/src/update-contract-metrics.ts @@ -22,9 +22,11 @@ export const updateContractMetrics = functions.pubsub contracts.map((contract) => async () => { const volume24Hours = await computeVolumeFrom(contract, oneDay) const volume7Days = await computeVolumeFrom(contract, oneDay * 7) + const volume = await computeVolumeFrom(contract, oneDay * 365) const contractRef = firestore.doc(`contracts/${contract.id}`) return contractRef.update({ + volume, volume24Hours, volume7Days, }) diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index 70e09deb..22e07239 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -22,7 +22,6 @@ import { getDpmProbability } from '../../../common/calculate-dpm' import { createRNG, shuffle } from '../../../common/util/random' import { getCpmmProbability } from '../../../common/calculate-cpmm' import { formatMoney, formatPercent } from '../../../common/util/format' -import { getCpmmLiquidity } from '../../../common/calculate-cpmm' export type { Contract } export function contractPath(contract: Contract) { @@ -43,9 +42,7 @@ export function contractMetrics(contract: Contract) { const liquidityLabel = contract.mechanism === 'dpm-2' ? `${formatMoney(truePool)} pool` - : `${formatMoney( - contract.totalLiquidity ?? getCpmmLiquidity(pool, contract.p) - )} liquidity` + : `${formatMoney(contract.volume ?? contract.volume7Days)} volume` return { truePool, liquidityLabel, createdDate, resolvedDate } }