fix: improve portfolio value calculation and round shares to six decimal places
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m24s
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m24s
This commit is contained in:
@@ -45,12 +45,12 @@ export async function POST(req: NextRequest, { params }: { params: { slug: strin
|
|||||||
const portfolioValue = fund.user.positions.reduce((sum, p) => {
|
const portfolioValue = fund.user.positions.reduce((sum, p) => {
|
||||||
const val = p.positionType === 'LONG'
|
const val = p.positionType === 'LONG'
|
||||||
? p.shares * p.hashtag.currentPrice
|
? 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
|
return sum + val
|
||||||
}, 0)
|
}, 0)
|
||||||
const totalValue = fund.user.balance + portfolioValue
|
const totalValue = fund.user.balance + portfolioValue
|
||||||
const nav = calcFundNav(totalValue, fund.sharesOutstanding)
|
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
|
// Weighted average NAV at buy for display
|
||||||
const existingInvestment = await prisma.fundInvestment.findUnique({
|
const existingInvestment = await prisma.fundInvestment.findUnique({
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export async function POST(req: NextRequest, { params }: { params: { slug: strin
|
|||||||
const portfolioValue = fund.user.positions.reduce((sum, p) => {
|
const portfolioValue = fund.user.positions.reduce((sum, p) => {
|
||||||
const val = p.positionType === 'LONG'
|
const val = p.positionType === 'LONG'
|
||||||
? p.shares * p.hashtag.currentPrice
|
? 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
|
return sum + val
|
||||||
}, 0)
|
}, 0)
|
||||||
const totalValue = fund.user.balance + portfolioValue
|
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 })
|
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([
|
const [updatedInvestor] = await prisma.$transaction([
|
||||||
// Return cash to investor
|
// Return cash to investor
|
||||||
|
|||||||
Reference in New Issue
Block a user