diff --git a/common/calculate-cpmm.ts b/common/calculate-cpmm.ts index e7d56ba3..92d95251 100644 --- a/common/calculate-cpmm.ts +++ b/common/calculate-cpmm.ts @@ -1,7 +1,7 @@ import { sum, groupBy, mapValues, sumBy, partition } from 'lodash' import { CPMMContract } from './contract' -import { CREATOR_FEE, Fees, LIQUIDITY_FEE, noFees, PLATFORM_FEE } from './fees' +import { CREATOR_FEE, Fees, LIQUIDITY_FEE, PLATFORM_FEE } from './fees' import { LiquidityProvision } from './liquidity-provision' import { addObjects } from './util/object' @@ -58,7 +58,7 @@ function calculateCpmmShares( : n + bet - (k * (bet + y) ** -p) ** (1 / (1 - p)) } -export function getCpmmLiquidityFee( +export function getCpmmFees( contract: CPMMContract, bet: number, outcome: string @@ -83,7 +83,7 @@ export function calculateCpmmSharesAfterFee( outcome: string ) { const { pool, p } = contract - const { remainingBet } = getCpmmLiquidityFee(contract, bet, outcome) + const { remainingBet } = getCpmmFees(contract, bet, outcome) return calculateCpmmShares(pool, p, remainingBet, outcome) } @@ -94,9 +94,7 @@ export function calculateCpmmPurchase( outcome: string ) { const { pool, p } = contract - const { remainingBet, fees } = getCpmmLiquidityFee(contract, bet, outcome) - // const remainingBet = bet - // const fees = noFees + const { remainingBet, fees } = getCpmmFees(contract, bet, outcome) const shares = calculateCpmmShares(pool, p, remainingBet, outcome) const { YES: y, NO: n } = pool @@ -176,19 +174,17 @@ export function calculateCpmmSale( throw new Error('Cannot sell non-positive shares') } - const saleValue = calculateCpmmShareValue( + const rawSaleValue = calculateCpmmShareValue( contract, shares, outcome as 'YES' | 'NO' ) - const fees = noFees - - // const { fees, remainingBet: saleValue } = getCpmmLiquidityFee( - // contract, - // rawSaleValue, - // outcome === 'YES' ? 'NO' : 'YES' - // ) + const { fees, remainingBet: saleValue } = getCpmmFees( + contract, + rawSaleValue, + outcome === 'YES' ? 'NO' : 'YES' + ) const { pool } = contract const { YES: y, NO: n } = pool diff --git a/web/components/bet-panel.tsx b/web/components/bet-panel.tsx index f76117b9..a43f6f12 100644 --- a/web/components/bet-panel.tsx +++ b/web/components/bet-panel.tsx @@ -37,7 +37,7 @@ import { useUserContractBets } from 'web/hooks/use-user-bets' import { calculateCpmmSale, getCpmmProbability, - getCpmmLiquidityFee, + getCpmmFees, } from 'common/calculate-cpmm' import { getFormattedMappedValue } from 'common/pseudo-numeric' import { SellRow } from './sell-row' @@ -302,7 +302,7 @@ function BuyPanel(props: { const cpmmFees = contract.mechanism === 'cpmm-1' && - getCpmmLiquidityFee(contract, betAmount ?? 0, betChoice ?? 'YES').totalFees + getCpmmFees(contract, betAmount ?? 0, betChoice ?? 'YES').totalFees const dpmTooltip = contract.mechanism === 'dpm-2'