fix: improve portfolio value calculation and round shares to six decimal places
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m24s

This commit is contained in:
2026-03-20 15:06:57 -04:00
parent ba8fa8e253
commit 5974e8fd87
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -45,12 +45,12 @@ export async function POST(req: NextRequest, { params }: { params: { slug: strin
const portfolioValue = fund.user.positions.reduce((sum, p) => {
const val = p.positionType === 'LONG'
? p.shares * p.hashtag.currentPrice
: p.avgBuyPrice * p.shares - (p.hashtag.currentPrice - p.avgBuyPrice) * p.shares
: (2 * p.avgBuyPrice - p.hashtag.currentPrice) * p.shares
return sum + val
}, 0)
const totalValue = fund.user.balance + portfolioValue
const nav = calcFundNav(totalValue, fund.sharesOutstanding)
const sharesToMint = amount / nav
const sharesToMint = Math.round((amount / nav) * 1e6) / 1e6
// Weighted average NAV at buy for display
const existingInvestment = await prisma.fundInvestment.findUnique({
+2 -2
View File
@@ -45,7 +45,7 @@ export async function POST(req: NextRequest, { params }: { params: { slug: strin
const portfolioValue = fund.user.positions.reduce((sum, p) => {
const val = p.positionType === 'LONG'
? p.shares * p.hashtag.currentPrice
: p.avgBuyPrice * p.shares - (p.hashtag.currentPrice - p.avgBuyPrice) * p.shares
: (2 * p.avgBuyPrice - p.hashtag.currentPrice) * p.shares
return sum + val
}, 0)
const totalValue = fund.user.balance + portfolioValue
@@ -56,7 +56,7 @@ export async function POST(req: NextRequest, { params }: { params: { slug: strin
return NextResponse.json({ error: 'Fund has insufficient cash to redeem. Try a smaller amount.' }, { status: 400 })
}
const remainingShares = investment.shares - sharesToRedeem
const remainingShares = Math.round((investment.shares - sharesToRedeem) * 1e6) / 1e6
const [updatedInvestor] = await prisma.$transaction([
// Return cash to investor