fix: ensure non-negative payouts in fund investment calculations
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m21s
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m21s
This commit is contained in:
@@ -89,7 +89,7 @@ export async function POST(
|
|||||||
}, 0)
|
}, 0)
|
||||||
const fundTotalValue = inv.fund.user.balance + fundPortfolioValue
|
const fundTotalValue = inv.fund.user.balance + fundPortfolioValue
|
||||||
const nav = calcFundNav(fundTotalValue, inv.fund.sharesOutstanding)
|
const nav = calcFundNav(fundTotalValue, inv.fund.sharesOutstanding)
|
||||||
return sum + inv.shares * nav
|
return sum + Math.max(0, inv.shares * nav)
|
||||||
}, 0)
|
}, 0)
|
||||||
const totalValue = user.balance + portfolioValue + fundInvestmentValue
|
const totalValue = user.balance + portfolioValue + fundInvestmentValue
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ export async function POST(
|
|||||||
}, 0)
|
}, 0)
|
||||||
const fundTotalValue = inv.fund.user.balance + fundPortfolioValue
|
const fundTotalValue = inv.fund.user.balance + fundPortfolioValue
|
||||||
const nav = calcFundNav(fundTotalValue, inv.fund.sharesOutstanding)
|
const nav = calcFundNav(fundTotalValue, inv.fund.sharesOutstanding)
|
||||||
const payout = inv.shares * nav
|
const payout = Math.max(0, inv.shares * nav)
|
||||||
return [
|
return [
|
||||||
prisma.hedgeFund.update({
|
prisma.hedgeFund.update({
|
||||||
where: { id: inv.fundId },
|
where: { id: inv.fundId },
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export async function POST(req: NextRequest) {
|
|||||||
}, 0)
|
}, 0)
|
||||||
const fundTotalValue = inv.fund.user.balance + fundPortfolioValue
|
const fundTotalValue = inv.fund.user.balance + fundPortfolioValue
|
||||||
const nav = calcFundNav(fundTotalValue, inv.fund.sharesOutstanding)
|
const nav = calcFundNav(fundTotalValue, inv.fund.sharesOutstanding)
|
||||||
return sum + inv.shares * nav
|
return sum + Math.max(0, inv.shares * nav)
|
||||||
}, 0)
|
}, 0)
|
||||||
const totalValue = user.balance + portfolioValue + fundInvestmentValue
|
const totalValue = user.balance + portfolioValue + fundInvestmentValue
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ export async function POST(req: NextRequest) {
|
|||||||
}, 0)
|
}, 0)
|
||||||
const fundTotalValue = inv.fund.user.balance + fundPortfolioValue
|
const fundTotalValue = inv.fund.user.balance + fundPortfolioValue
|
||||||
const nav = calcFundNav(fundTotalValue, inv.fund.sharesOutstanding)
|
const nav = calcFundNav(fundTotalValue, inv.fund.sharesOutstanding)
|
||||||
const payout = inv.shares * nav
|
const payout = Math.max(0, inv.shares * nav)
|
||||||
return [
|
return [
|
||||||
prisma.hedgeFund.update({
|
prisma.hedgeFund.update({
|
||||||
where: { id: inv.fundId },
|
where: { id: inv.fundId },
|
||||||
|
|||||||
Reference in New Issue
Block a user