fix: ensure non-negative payouts in fund investment calculations
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m21s

This commit is contained in:
2026-03-20 15:33:37 -04:00
parent c5076e330c
commit 1d0b160ba8
2 changed files with 4 additions and 4 deletions
@@ -89,7 +89,7 @@ export async function POST(
}, 0)
const fundTotalValue = inv.fund.user.balance + fundPortfolioValue
const nav = calcFundNav(fundTotalValue, inv.fund.sharesOutstanding)
return sum + inv.shares * nav
return sum + Math.max(0, inv.shares * nav)
}, 0)
const totalValue = user.balance + portfolioValue + fundInvestmentValue
@@ -106,7 +106,7 @@ export async function POST(
}, 0)
const fundTotalValue = inv.fund.user.balance + fundPortfolioValue
const nav = calcFundNav(fundTotalValue, inv.fund.sharesOutstanding)
const payout = inv.shares * nav
const payout = Math.max(0, inv.shares * nav)
return [
prisma.hedgeFund.update({
where: { id: inv.fundId },
+2 -2
View File
@@ -91,7 +91,7 @@ export async function POST(req: NextRequest) {
}, 0)
const fundTotalValue = inv.fund.user.balance + fundPortfolioValue
const nav = calcFundNav(fundTotalValue, inv.fund.sharesOutstanding)
return sum + inv.shares * nav
return sum + Math.max(0, inv.shares * nav)
}, 0)
const totalValue = user.balance + portfolioValue + fundInvestmentValue
@@ -108,7 +108,7 @@ export async function POST(req: NextRequest) {
}, 0)
const fundTotalValue = inv.fund.user.balance + fundPortfolioValue
const nav = calcFundNav(fundTotalValue, inv.fund.sharesOutstanding)
const payout = inv.shares * nav
const payout = Math.max(0, inv.shares * nav)
return [
prisma.hedgeFund.update({
where: { id: inv.fundId },