diff --git a/common/calculate-metrics.ts b/common/calculate-metrics.ts index 6cfb0421..9ad44522 100644 --- a/common/calculate-metrics.ts +++ b/common/calculate-metrics.ts @@ -97,7 +97,11 @@ export const computeBinaryCpmmElasticity = ( ) const resultNo = getCpmmProbability(poolN, pN) - return resultYes - resultNo + // handle AMM overflow + const safeYes = Number.isFinite(resultYes) ? resultYes : 1 + const safeNo = Number.isFinite(resultNo) ? resultNo : 0 + + return safeYes - safeNo } export const computeDpmElasticity = ( diff --git a/functions/src/update-metrics.ts b/functions/src/update-metrics.ts index 887dbbdc..4739dcc1 100644 --- a/functions/src/update-metrics.ts +++ b/functions/src/update-metrics.ts @@ -169,7 +169,7 @@ export async function updateMetricsCore() { return 0 } const contractRatio = - contract.flaggedByUsernames.length / (contract.uniqueBettorCount ?? 1) + contract.flaggedByUsernames.length / (contract.uniqueBettorCount || 1) return contractRatio })