Skip to content

Commit

Permalink
Remove double investmentValue from leaderboard profit
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Sep 21, 2024
1 parent 40b3bcb commit b375c50
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions backend/shared/src/update-user-metrics-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import {
calculateMetricsByContractAndAnswer,
calculateNewPortfolioMetrics,
} from 'common/calculate-metrics'
import { getUserLoanUpdates, isUserEligibleForLoan } from 'common/loans'
import { bulkUpdateContractMetrics } from 'shared/helpers/user-contract-metrics'
import { buildArray } from 'common/util/array'
import {
hasChanges,
hasSignificantDeepChanges,
removeUndefinedProps,
} from 'common/util/object'
Expand Down Expand Up @@ -243,10 +241,16 @@ export async function updateUserMetricsCore(
})
)

const { balance, spiceBalance, investmentValue, totalDeposits } =
newPortfolio
const {
balance,
investmentValue,
totalDeposits,
} = newPortfolio

const allTimeProfit =
balance + spiceBalance + investmentValue - totalDeposits
balance +
investmentValue -
totalDeposits -

const unresolvedMetrics = freshMetrics.filter((m) => {
const contract = contractsById[m.contractId]
Expand Down Expand Up @@ -295,7 +299,9 @@ export async function updateUserMetricsCore(
resolvedProfitAdjustment +
// Resolved profits are already included in the user's balance - deposits
sumBy(unresolvedMetrics, (m) => (m.profitAdjustment ?? 0) + m.profit) +
allTimeProfit
balance -
totalDeposits

newPortfolio.profit = leaderBoardProfit

const didPortfolioChange =
Expand All @@ -322,9 +328,9 @@ export async function updateUserMetricsCore(
allTime: allTimeProfit,
}

const nextLoanPayout = isUserEligibleForLoan(newPortfolio)
? getUserLoanUpdates(metricRelevantBetsByContract, contractsById).payout
: 0
// const nextLoanPayout = isUserEligibleForLoan(newPortfolio)
// ? getUserLoanUpdates(metricRelevantBetsByContract, contractsById).payout
// : 0

if (didPortfolioChange) {
portfolioUpdates.push({
Expand All @@ -344,15 +350,19 @@ export async function updateUserMetricsCore(
}

if (
hasChanges(user, {
profitCached: newProfit,
nextLoanCached: nextLoanPayout,
})
hasSignificantDeepChanges(
user,
{
profitCached: newProfit,
// nextLoanCached: nextLoanPayout,
},
1
)
) {
userUpdates.push({
...user,
profitCached: newProfit,
nextLoanCached: nextLoanPayout,
// nextLoanCached: nextLoanPayout,
})
}
}
Expand Down

0 comments on commit b375c50

Please sign in to comment.