From a1c3a5e5692f82d48a2ada852da2571c47bfebba Mon Sep 17 00:00:00 2001 From: mantikoros Date: Tue, 17 May 2022 17:03:18 -0400 Subject: [PATCH] use geometric mean probability to calculate fees for cfmm (a lot easier than solving the integral) --- common/calculate-cpmm.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/calculate-cpmm.ts b/common/calculate-cpmm.ts index ffe04133..75980279 100644 --- a/common/calculate-cpmm.ts +++ b/common/calculate-cpmm.ts @@ -63,8 +63,10 @@ export function getCpmmLiquidityFee( bet: number, outcome: string ) { - const prob = getCpmmProbabilityAfterBetBeforeFees(contract, outcome, bet) - const betP = outcome === 'YES' ? 1 - prob : prob + const probBefore = getCpmmProbability(contract.pool, contract.p) + const probAfter = getCpmmProbabilityAfterBetBeforeFees(contract, outcome, bet) + const probMid = Math.sqrt(probBefore * probAfter) + const betP = outcome === 'YES' ? 1 - probMid : probMid const liquidityFee = LIQUIDITY_FEE * betP * bet const platformFee = PLATFORM_FEE * betP * bet