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
|
closeEmailsSent?: number
|
||||||
|
|
||||||
|
volume?: number
|
||||||
volume24Hours: number
|
volume24Hours: number
|
||||||
volume7Days: number
|
volume7Days: number
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@ export function getNewContract(
|
||||||
? getBinaryCpmmProps(initialProb, ante) // getBinaryDpmProps(initialProb, ante)
|
? getBinaryCpmmProps(initialProb, ante) // getBinaryDpmProps(initialProb, ante)
|
||||||
: getFreeAnswerProps(ante)
|
: getFreeAnswerProps(ante)
|
||||||
|
|
||||||
|
const volume = outcomeType === 'BINARY' ? 0 : ante
|
||||||
|
|
||||||
const contract: Contract = removeUndefinedProps({
|
const contract: Contract = removeUndefinedProps({
|
||||||
id,
|
id,
|
||||||
slug,
|
slug,
|
||||||
|
@ -54,6 +56,7 @@ export function getNewContract(
|
||||||
lastUpdatedTime: Date.now(),
|
lastUpdatedTime: Date.now(),
|
||||||
closeTime,
|
closeTime,
|
||||||
|
|
||||||
|
volume,
|
||||||
volume24Hours: 0,
|
volume24Hours: 0,
|
||||||
volume7Days: 0,
|
volume7Days: 0,
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ export const createAnswer = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
message: 'Requires a free response contract',
|
message: 'Requires a free response contract',
|
||||||
}
|
}
|
||||||
|
|
||||||
const { closeTime } = contract
|
const { closeTime, volume } = contract
|
||||||
if (closeTime && Date.now() > closeTime)
|
if (closeTime && Date.now() > closeTime)
|
||||||
return { status: 'error', message: 'Trading is closed' }
|
return { status: 'error', message: 'Trading is closed' }
|
||||||
|
|
||||||
|
@ -121,6 +121,7 @@ export const createAnswer = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
totalShares: newTotalShares,
|
totalShares: newTotalShares,
|
||||||
totalBets: newTotalBets,
|
totalBets: newTotalBets,
|
||||||
answers: [...(contract.answers ?? []), answer],
|
answers: [...(contract.answers ?? []), answer],
|
||||||
|
volume: (volume ?? 0) + amount,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!isFinite(newBalance)) {
|
if (!isFinite(newBalance)) {
|
||||||
|
|
|
@ -49,7 +49,8 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
return { status: 'error', message: 'Invalid contract' }
|
return { status: 'error', message: 'Invalid contract' }
|
||||||
const contract = contractSnap.data() as 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)
|
if (closeTime && Date.now() > closeTime)
|
||||||
return { status: 'error', message: 'Trading is closed' }
|
return { status: 'error', message: 'Trading is closed' }
|
||||||
|
|
||||||
|
@ -129,6 +130,7 @@ export const placeBet = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
totalBets: newTotalBets,
|
totalBets: newTotalBets,
|
||||||
totalLiquidity: newTotalLiquidity,
|
totalLiquidity: newTotalLiquidity,
|
||||||
collectedFees: addObjects<Fees>(fees ?? {}, collectedFees ?? {}),
|
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' }
|
return { status: 'error', message: 'Invalid contract' }
|
||||||
const contract = contractSnap.data() as Contract
|
const contract = contractSnap.data() as Contract
|
||||||
|
|
||||||
const { closeTime, mechanism, collectedFees } = contract
|
const { closeTime, mechanism, collectedFees, volume } = contract
|
||||||
if (closeTime && Date.now() > closeTime)
|
if (closeTime && Date.now() > closeTime)
|
||||||
return { status: 'error', message: 'Trading is closed' }
|
return { status: 'error', message: 'Trading is closed' }
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ export const sellBet = functions.runWith({ minInstances: 1 }).https.onCall(
|
||||||
totalShares: newTotalShares,
|
totalShares: newTotalShares,
|
||||||
totalBets: newTotalBets,
|
totalBets: newTotalBets,
|
||||||
collectedFees: addObjects<Fees>(fees ?? {}, collectedFees ?? {}),
|
collectedFees: addObjects<Fees>(fees ?? {}, collectedFees ?? {}),
|
||||||
|
volume: (volume ?? 0) + bet.amount,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,11 @@ export const updateContractMetrics = functions.pubsub
|
||||||
contracts.map((contract) => async () => {
|
contracts.map((contract) => async () => {
|
||||||
const volume24Hours = await computeVolumeFrom(contract, oneDay)
|
const volume24Hours = await computeVolumeFrom(contract, oneDay)
|
||||||
const volume7Days = await computeVolumeFrom(contract, oneDay * 7)
|
const volume7Days = await computeVolumeFrom(contract, oneDay * 7)
|
||||||
|
const volume = await computeVolumeFrom(contract, oneDay * 365)
|
||||||
|
|
||||||
const contractRef = firestore.doc(`contracts/${contract.id}`)
|
const contractRef = firestore.doc(`contracts/${contract.id}`)
|
||||||
return contractRef.update({
|
return contractRef.update({
|
||||||
|
volume,
|
||||||
volume24Hours,
|
volume24Hours,
|
||||||
volume7Days,
|
volume7Days,
|
||||||
})
|
})
|
||||||
|
|
|
@ -22,7 +22,6 @@ import { getDpmProbability } from '../../../common/calculate-dpm'
|
||||||
import { createRNG, shuffle } from '../../../common/util/random'
|
import { createRNG, shuffle } from '../../../common/util/random'
|
||||||
import { getCpmmProbability } from '../../../common/calculate-cpmm'
|
import { getCpmmProbability } from '../../../common/calculate-cpmm'
|
||||||
import { formatMoney, formatPercent } from '../../../common/util/format'
|
import { formatMoney, formatPercent } from '../../../common/util/format'
|
||||||
import { getCpmmLiquidity } from '../../../common/calculate-cpmm'
|
|
||||||
export type { Contract }
|
export type { Contract }
|
||||||
|
|
||||||
export function contractPath(contract: Contract) {
|
export function contractPath(contract: Contract) {
|
||||||
|
@ -43,9 +42,7 @@ export function contractMetrics(contract: Contract) {
|
||||||
const liquidityLabel =
|
const liquidityLabel =
|
||||||
contract.mechanism === 'dpm-2'
|
contract.mechanism === 'dpm-2'
|
||||||
? `${formatMoney(truePool)} pool`
|
? `${formatMoney(truePool)} pool`
|
||||||
: `${formatMoney(
|
: `${formatMoney(contract.volume ?? contract.volume7Days)} volume`
|
||||||
contract.totalLiquidity ?? getCpmmLiquidity(pool, contract.p)
|
|
||||||
)} liquidity`
|
|
||||||
|
|
||||||
return { truePool, liquidityLabel, createdDate, resolvedDate }
|
return { truePool, liquidityLabel, createdDate, resolvedDate }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user