Compute volume for contracts. Show volume instead of liquidity for cpmm.
This commit is contained in:
parent
9c19966ef9
commit
6b61d7209d
|
@ -29,6 +29,7 @@ export type FullContract<
|
|||
|
||||
closeEmailsSent?: number
|
||||
|
||||
volume?: number
|
||||
volume24Hours: number
|
||||
volume7Days: number
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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>(fees ?? {}, collectedFees ?? {}),
|
||||
volume: (volume ?? 0) + Math.abs(amount),
|
||||
})
|
||||
)
|
||||
|
||||
|
|
|
@ -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>(fees ?? {}, collectedFees ?? {}),
|
||||
volume: (volume ?? 0) + bet.amount,
|
||||
})
|
||||
)
|
||||
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user