diff --git a/common/calculate.ts b/common/calculate.ts index c86780be..831b37de 100644 --- a/common/calculate.ts +++ b/common/calculate.ts @@ -104,7 +104,9 @@ export function calculateShareValue(contract: Contract, bet: Bet) { } export function calculateSaleAmount(contract: Contract, bet: Bet) { - return (1 - FEES) * calculateShareValue(contract, bet) + const { amount } = bet + const winnings = calculateShareValue(contract, bet) + return deductFees(amount, winnings) } export function calculatePayout( diff --git a/common/sell-bet.ts b/common/sell-bet.ts index eeeed355..88191742 100644 --- a/common/sell-bet.ts +++ b/common/sell-bet.ts @@ -1,5 +1,5 @@ import { Bet } from './bet' -import { calculateShareValue, getProbability } from './calculate' +import { calculateShareValue, deductFees, getProbability } from './calculate' import { Contract } from './contract' import { CREATOR_FEE, FEES } from './fees' import { User } from './user' @@ -36,8 +36,9 @@ export const getSellBetInfo = ( const probBefore = getProbability(contract.totalShares) const probAfter = getProbability(newTotalShares) - const creatorFee = CREATOR_FEE * adjShareValue - const saleAmount = (1 - FEES) * adjShareValue + const profit = adjShareValue - amount + const creatorFee = CREATOR_FEE * Math.max(0, profit) + const saleAmount = deductFees(amount, adjShareValue) console.log( 'SELL M$',