diff --git a/common/calculate-cpmm.ts b/common/calculate-cpmm.ts index 41a841a8..94b9a07b 100644 --- a/common/calculate-cpmm.ts +++ b/common/calculate-cpmm.ts @@ -1,6 +1,8 @@ import * as _ from 'lodash' import { Bet } from './bet' +import { deductFixedFees } from './calculate-fixed-payouts' import { Binary, CPMM, FullContract } from './contract' +import { CREATOR_FEE } from './fees' export function getCpmmProbability(pool: { [outcome: string]: number }) { // For binary contracts only. @@ -85,7 +87,11 @@ export function calculateCpmmSale( const newPool = { YES: newY, NO: newN } - return { saleValue, newPool } + const profit = saleValue - bet.amount + const creatorFee = CREATOR_FEE * Math.max(0, profit) + const saleAmount = deductFixedFees(bet.amount, saleValue) + + return { saleValue, newPool, creatorFee, saleAmount } } export function getCpmmProbabilityAfterSale( diff --git a/common/calculate-fixed-payouts.ts b/common/calculate-fixed-payouts.ts index 30e900f3..3d2e3a97 100644 --- a/common/calculate-fixed-payouts.ts +++ b/common/calculate-fixed-payouts.ts @@ -21,7 +21,7 @@ export function calculateFixedCancelPayout(bet: Bet) { export function calculateStandardFixedPayout(bet: Bet, outcome: string) { const { amount, outcome: betOutcome, shares } = bet if (betOutcome !== outcome) return 0 - return deductFixedFees(amount, shares - amount) + return deductFixedFees(amount, shares) } function calculateFixedMktPayout( @@ -43,7 +43,8 @@ function calculateFixedMktPayout( } export const deductFixedFees = (betAmount: number, winnings: number) => { - return winnings > betAmount - ? betAmount + (1 - FEES) * (winnings - betAmount) - : winnings + return winnings + // return winnings > betAmount + // ? betAmount + (1 - FEES) * (winnings - betAmount) + // : winnings } diff --git a/common/sell-bet.ts b/common/sell-bet.ts index 42b8f30b..58ec8855 100644 --- a/common/sell-bet.ts +++ b/common/sell-bet.ts @@ -4,11 +4,7 @@ import { calculateDpmShareValue, deductDpmFees, } from './calculate-dpm' -import { - calculateCpmmSale, - calculateCpmmShareValue, - getCpmmProbability, -} from './calculate-cpmm' +import { calculateCpmmSale, getCpmmProbability } from './calculate-cpmm' import { Binary, DPM, CPMM, FullContract } from './contract' import { CREATOR_FEE } from './fees' import { User } from './user' @@ -87,15 +83,14 @@ export const getCpmmSellBetInfo = ( const { pool } = contract const { id: betId, amount, shares, outcome } = bet - const { saleValue, newPool } = calculateCpmmSale(contract, bet) + const { saleValue, newPool, creatorFee, saleAmount } = calculateCpmmSale( + contract, + bet + ) const probBefore = getCpmmProbability(pool) const probAfter = getCpmmProbability(newPool) - const profit = saleValue - amount - const creatorFee = CREATOR_FEE * Math.max(0, profit) - const saleAmount = deductDpmFees(amount, profit) - console.log( 'SELL M$', amount,