Fix profit calculation for cpmm sales. Change totalValue to investment value excluding sales
This commit is contained in:
parent
a9028b0a94
commit
bfb708d477
|
@ -116,7 +116,6 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
|
|||
const { resolution } = contract
|
||||
|
||||
let invested = 0
|
||||
let salesInvested = 0
|
||||
let payout = 0
|
||||
let loan = 0
|
||||
let sellProfit = 0
|
||||
|
@ -126,7 +125,7 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
|
|||
const { isSold, sale, amount, loanAmount, isRedemption } = bet
|
||||
if (isSold) {
|
||||
sellProfit -= amount
|
||||
salesInvested += amount
|
||||
invested += amount
|
||||
} else if (sale) {
|
||||
sellProfit += sale.amount
|
||||
} else {
|
||||
|
@ -134,6 +133,8 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
|
|||
redeemed += -1 * amount
|
||||
} else if (amount > 0) {
|
||||
invested += amount
|
||||
} else {
|
||||
sellProfit -= amount
|
||||
}
|
||||
|
||||
loan += loanAmount ?? 0
|
||||
|
@ -143,17 +144,13 @@ export function getContractBetMetrics(contract: Contract, yourBets: Bet[]) {
|
|||
}
|
||||
}
|
||||
|
||||
const investedIncludingSales = invested + salesInvested
|
||||
|
||||
const totalValue = payout + sellProfit + redeemed
|
||||
const profit = totalValue - invested
|
||||
const profitPercent = (profit / investedIncludingSales) * 100
|
||||
const profit = payout - invested + sellProfit + redeemed
|
||||
const profitPercent = (profit / invested) * 100
|
||||
const netInvestment = payout - loan
|
||||
|
||||
return {
|
||||
invested,
|
||||
payout,
|
||||
totalValue,
|
||||
profit,
|
||||
profitPercent,
|
||||
netInvestment,
|
||||
|
@ -164,7 +161,6 @@ export function getContractBetNullMetrics() {
|
|||
return {
|
||||
invested: 0,
|
||||
payout: 0,
|
||||
totalValue: 0,
|
||||
profit: 0,
|
||||
profitPercent: 0,
|
||||
netInvestment: 0,
|
||||
|
|
|
@ -94,7 +94,7 @@ export function BetsList(props: { user: User }) {
|
|||
}
|
||||
const SORTS: Record<BetSort, (c: Contract) => number> = {
|
||||
profit: (c) => contractsMetrics[c.id].profit,
|
||||
value: (c) => contractsMetrics[c.id].totalValue,
|
||||
value: (c) => contractsMetrics[c.id].payout,
|
||||
newest: (c) =>
|
||||
Math.max(...contractBets[c.id].map((bet) => bet.createdTime)),
|
||||
resolutionTime: (c) => -(c.resolutionTime ?? c.closeTime ?? Infinity),
|
||||
|
@ -215,7 +215,7 @@ function MyContractBets(props: {
|
|||
const isBinary = outcomeType === 'BINARY'
|
||||
const probPercent = getBinaryProbPercent(contract)
|
||||
|
||||
const { totalValue, profit, profitPercent } = getContractBetMetrics(
|
||||
const { payout, profit, profitPercent } = getContractBetMetrics(
|
||||
contract,
|
||||
bets
|
||||
)
|
||||
|
@ -271,7 +271,7 @@ function MyContractBets(props: {
|
|||
<Row className="mr-5 justify-end sm:mr-8">
|
||||
<Col>
|
||||
<div className="whitespace-nowrap text-right text-lg">
|
||||
{formatMoney(metric === 'profit' ? profit : totalValue)}
|
||||
{formatMoney(metric === 'profit' ? profit : payout)}
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<ProfitBadge profitPercent={profitPercent} />
|
||||
|
|
Loading…
Reference in New Issue
Block a user