Make volume a non-optional field of contract

This commit is contained in:
James Grugett 2022-03-23 00:09:47 -05:00
parent 510e4400d3
commit 69e142e279
5 changed files with 4 additions and 6 deletions

View File

@ -29,7 +29,7 @@ export type FullContract<
closeEmailsSent?: number
volume?: number
volume: number
volume24Hours: number
volume7Days: number

View File

@ -121,7 +121,7 @@ export const createAnswer = functions.runWith({ minInstances: 1 }).https.onCall(
totalShares: newTotalShares,
totalBets: newTotalBets,
answers: [...(contract.answers ?? []), answer],
volume: (volume ?? 0) + amount,
volume: volume + amount,
})
if (!isFinite(newBalance)) {

View File

@ -130,7 +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),
volume: volume + Math.abs(amount),
})
)

View File

@ -81,7 +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,
volume: volume + bet.amount,
})
)

View File

@ -22,11 +22,9 @@ 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,
})