From 10a694e38b720ae095f3da959d00eaa8f1eec1e2 Mon Sep 17 00:00:00 2001 From: Frederik Gartenmeister Date: Tue, 10 Sep 2024 13:46:25 +0200 Subject: [PATCH 1/6] wip: try fixing values --- .../NavManagement/NavManagementAssetTable.tsx | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx b/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx index 87d551707..b133846cc 100644 --- a/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx +++ b/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx @@ -39,7 +39,7 @@ import { useActiveDomains } from '../../utils/useLiquidityPools' import { useSuitableAccounts } from '../../utils/usePermissions' import { usePool, usePoolAccountOrders, usePoolFees } from '../../utils/usePools' import { usePoolsForWhichAccountIsFeeder } from '../../utils/usePoolsForWhichAccountIsFeeder' -import { positiveNumber } from '../../utils/validation' +import { nonNegativeNumber } from '../../utils/validation' import { isCashLoan, isExternalLoan } from '../Loan/utils' type FormValues = { @@ -202,20 +202,19 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) { ) }, [poolFees, pool.currency.decimals]) - const poolReserve = pool.reserve.total.toDecimal().toNumber() || 0 - const newNavExternal = form.values.feed.reduce( - (acc, cur) => acc + cur.quantity * (isEditing && cur.value ? cur.value : cur.oldValue), - 0 - ) - const newNavInternal = - allLoans?.reduce( - (acc, cur) => acc + (!isExternalLoan(cur) && 'presentValue' in cur ? cur.presentValue.toFloat() : 0), + /////////////// XXXXXXXXXXXXXXXXXXXXXXXXXXX --------------------------------------START---------------------------------- + + const changeInValuation = form.values.feed.reduce( + (acc, cur) => acc + cur.quantity * (isEditing && cur.value ? cur.value : cur.oldValue), 0 - ) || 0 - const newNavCash = cashLoans.reduce((acc, cur) => acc + cur.outstandingDebt.toFloat(), 0) - const newNav = newNavExternal + newNavInternal + newNavCash + poolReserve - pendingFees.toFloat() + ) + + + const totalAum = pool.nav.aum.toDecimal().add(pool.nav.reserve.toDecimal()).toNumber() + const pendingNav = totalAum.toDecimal().add(changeInValuation.toDecimal()).sub(pendingFees.toDecimal()).toNumber() + // Only for single tranche pools - const newPrice = newNav / pool.tranches[0].totalIssuance.toFloat() + const newPrice = pendingNav / pool.tranches[0].totalIssuance.toFloat() const isTinlakePool = poolId.startsWith('0x') const columns = [ @@ -276,7 +275,7 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) { header: 'New price', cell: (row: Row) => { return 'oldValue' in row && row.id !== 'reserve' && isEditing ? ( - + {({ field, meta, form }: FieldProps) => ( Confirm NAV {pool.tranches.length === 1 && ( @@ -444,32 +443,35 @@ export function NavOverviewCard({ poolId, updatedPrices }: { poolId: string; upd const quantity = (curr as ExternalLoan).pricing.outstandingQuantity.toDecimal() const updatedPrice = Dec(updatedPrices.find((p) => p.id === curr.id)?.value || 0) return CurrencyBalance.fromFloat( - prev.toDecimal().add(price.sub(updatedPrice).mul(quantity)).toString(), + prev.toDecimal().add(updatedPrice.sub(price).mul(quantity)).toString(), pool.currency.decimals ) }, new CurrencyBalance(0, pool.currency.decimals)) }, [externalLoans, pool?.nav, updatedPrices]) + + const totalAum = pool.nav.aum.toDecimal().add(pool.nav.reserve.toDecimal()).toNumber() + return ( ) } export function VisualNavCard({ currency, - current, + aum, change, pendingFees, pendingNav, }: { currency: Pick - current: number + aum: number change: number pendingFees: number pendingNav: number @@ -478,9 +480,9 @@ export function VisualNavCard({ - Current NAV + AUM - {formatBalance(current, currency.displayName, 2)} + {formatBalance(aum, currency.displayName, 2)} From 673ab5c8a2ad32efb5e4b09e3aee61ecb11c1d3f Mon Sep 17 00:00:00 2001 From: Frederik Gartenmeister Date: Tue, 10 Sep 2024 13:57:06 +0200 Subject: [PATCH 2/6] wip: try fixing build --- .../src/pages/NavManagement/NavManagementAssetTable.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx b/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx index b133846cc..fc96e9e5a 100644 --- a/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx +++ b/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx @@ -202,12 +202,10 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) { ) }, [poolFees, pool.currency.decimals]) - /////////////// XXXXXXXXXXXXXXXXXXXXXXXXXXX --------------------------------------START---------------------------------- - const changeInValuation = form.values.feed.reduce( (acc, cur) => acc + cur.quantity * (isEditing && cur.value ? cur.value : cur.oldValue), 0 - ) + ) || 0 const totalAum = pool.nav.aum.toDecimal().add(pool.nav.reserve.toDecimal()).toNumber() From 3604d0b3d02796efb8050e54676c0966a26fd900 Mon Sep 17 00:00:00 2001 From: Frederik Gartenmeister Date: Tue, 10 Sep 2024 14:02:34 +0200 Subject: [PATCH 3/6] wip: try fixing number conversion --- .../NavManagement/NavManagementAssetTable.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx b/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx index fc96e9e5a..d3d8d5448 100644 --- a/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx +++ b/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx @@ -208,11 +208,11 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) { ) || 0 - const totalAum = pool.nav.aum.toDecimal().add(pool.nav.reserve.toDecimal()).toNumber() - const pendingNav = totalAum.toDecimal().add(changeInValuation.toDecimal()).sub(pendingFees.toDecimal()).toNumber() + const totalAum = pool.nav.aum.toDecimal().add(pool.nav.reserve.toDecimal()) + const pendingNav = totalAum.toDecimal().add(changeInValuation.toDecimal()).sub(pendingFees.toDecimal()) // Only for single tranche pools - const newPrice = pendingNav / pool.tranches[0].totalIssuance.toFloat() + const newPrice = pendingNav.toFloat() / pool.tranches[0].totalIssuance.toFloat() const isTinlakePool = poolId.startsWith('0x') const columns = [ @@ -324,10 +324,10 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) { Confirm NAV {pool.tranches.length === 1 && ( @@ -448,12 +448,12 @@ export function NavOverviewCard({ poolId, updatedPrices }: { poolId: string; upd }, [externalLoans, pool?.nav, updatedPrices]) - const totalAum = pool.nav.aum.toDecimal().add(pool.nav.reserve.toDecimal()).toNumber() + const totalAum = pool.nav.aum.toDecimal().add(pool.nav.reserve.toDecimal()) return ( Date: Tue, 10 Sep 2024 15:30:39 +0200 Subject: [PATCH 4/6] fix errors --- .../NavManagement/NavManagementAssetTable.tsx | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx b/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx index d3d8d5448..a00d18432 100644 --- a/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx +++ b/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx @@ -202,17 +202,17 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) { ) }, [poolFees, pool.currency.decimals]) - const changeInValuation = form.values.feed.reduce( + const changeInValuation = + form.values.feed.reduce( (acc, cur) => acc + cur.quantity * (isEditing && cur.value ? cur.value : cur.oldValue), 0 - ) || 0 + ) || 0 - - const totalAum = pool.nav.aum.toDecimal().add(pool.nav.reserve.toDecimal()) - const pendingNav = totalAum.toDecimal().add(changeInValuation.toDecimal()).sub(pendingFees.toDecimal()) + const totalAum = pool.nav.aum.toDecimal().add(pool.reserve.available.toDecimal()) + const pendingNav = totalAum.add(changeInValuation).sub(pendingFees.toDecimal()) // Only for single tranche pools - const newPrice = pendingNav.toFloat() / pool.tranches[0].totalIssuance.toFloat() + const newPrice = pendingNav.toNumber() / pool.tranches[0].totalIssuance.toFloat() const isTinlakePool = poolId.startsWith('0x') const columns = [ @@ -324,10 +324,10 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) { Confirm NAV {pool.tranches.length === 1 && ( @@ -447,16 +447,15 @@ export function NavOverviewCard({ poolId, updatedPrices }: { poolId: string; upd }, new CurrencyBalance(0, pool.currency.decimals)) }, [externalLoans, pool?.nav, updatedPrices]) - - const totalAum = pool.nav.aum.toDecimal().add(pool.nav.reserve.toDecimal()) + const totalAum = pool.nav.aum.toDecimal().add(pool.reserve.available.toDecimal()) return ( ) } From 580a8258a8cc2f41847339667cca8740e5e2be80 Mon Sep 17 00:00:00 2001 From: Frederik Gartenmeister Date: Tue, 10 Sep 2024 16:02:44 +0200 Subject: [PATCH 5/6] wip: make numbers correct --- .../src/pages/NavManagement/NavManagementAssetTable.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx b/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx index a00d18432..3aa4ac418 100644 --- a/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx +++ b/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx @@ -208,7 +208,7 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) { 0 ) || 0 - const totalAum = pool.nav.aum.toDecimal().add(pool.reserve.available.toDecimal()) + const totalAum = pool.nav.total.toDecimal().add(pendingFees.toDecimal()) const pendingNav = totalAum.add(changeInValuation).sub(pendingFees.toDecimal()) // Only for single tranche pools @@ -447,13 +447,13 @@ export function NavOverviewCard({ poolId, updatedPrices }: { poolId: string; upd }, new CurrencyBalance(0, pool.currency.decimals)) }, [externalLoans, pool?.nav, updatedPrices]) - const totalAum = pool.nav.aum.toDecimal().add(pool.reserve.available.toDecimal()) + const totalAum = pool.nav.total.toDecimal().add(pendingFees.toDecimal()) return ( From 524cfe8edf14ed6486f43b3926da014ef9da7d2c Mon Sep 17 00:00:00 2001 From: sophian Date: Tue, 10 Sep 2024 11:05:30 -0400 Subject: [PATCH 6/6] Align nav managment tables on page and drawer --- .../NavManagement/NavManagementAssetTable.tsx | 61 ++++++------------- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx b/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx index 3aa4ac418..83cbdd0c4 100644 --- a/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx +++ b/centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx @@ -202,14 +202,20 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) { ) }, [poolFees, pool.currency.decimals]) - const changeInValuation = - form.values.feed.reduce( - (acc, cur) => acc + cur.quantity * (isEditing && cur.value ? cur.value : cur.oldValue), - 0 - ) || 0 + const changeInValuation = React.useMemo(() => { + return (externalLoans as ActiveLoan[]).reduce((prev, curr) => { + const price = curr.currentPrice.toDecimal() + const quantity = (curr as ExternalLoan).pricing.outstandingQuantity.toDecimal() + const updatedPrice = Dec(form.values.feed.find((p) => p.id === curr.id)?.value || 0) + return CurrencyBalance.fromFloat( + prev.toDecimal().add(updatedPrice.sub(price).mul(quantity)).toString(), + pool.currency.decimals + ) + }, new CurrencyBalance(0, pool.currency.decimals)) + }, [externalLoans, pool?.nav, form.values.feed]) - const totalAum = pool.nav.total.toDecimal().add(pendingFees.toDecimal()) - const pendingNav = totalAum.add(changeInValuation).sub(pendingFees.toDecimal()) + const totalAum = pool.nav.aum.toDecimal().add(pool.reserve.available.toDecimal()) + const pendingNav = totalAum.add(changeInValuation.toDecimal()).sub(pendingFees.toDecimal()) // Only for single tranche pools const newPrice = pendingNav.toNumber() / pool.tranches[0].totalIssuance.toFloat() @@ -313,7 +319,7 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) { return ( <> - + @@ -325,7 +331,7 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) { @@ -405,7 +411,7 @@ export function NavManagementAssetTable({ poolId }: { poolId: string }) { ) } -export function NavOverviewCard({ poolId, updatedPrices }: { poolId: string; updatedPrices: FormValues['feed'] }) { +export function NavOverviewCard({ poolId, changeInValuation }: { poolId: string; changeInValuation: number }) { const pool = usePool(poolId) const poolFees = usePoolFees(poolId) const today = new Date() @@ -418,44 +424,15 @@ export function NavOverviewCard({ poolId, updatedPrices }: { poolId: string; upd ) }, [poolFees, pool.currency.decimals]) - const [allLoans] = useCentrifugeQuery(['loans', poolId], (cent) => cent.pools.getLoans([poolId]), { - enabled: !!poolId && !!pool, - }) - - const externalLoans = React.useMemo( - () => - (allLoans?.filter( - // Keep external loans, except ones that are fully repaid - (l) => - isExternalLoan(l) && - l.status !== 'Closed' && - l.status !== 'Created' && - (!('presentValue' in l) || !l.presentValue.isZero()) - ) as ActiveLoan[]) ?? [], - [allLoans] - ) - - const changeInValuation = React.useMemo(() => { - return externalLoans.reduce((prev, curr) => { - const price = curr.currentPrice.toDecimal() - const quantity = (curr as ExternalLoan).pricing.outstandingQuantity.toDecimal() - const updatedPrice = Dec(updatedPrices.find((p) => p.id === curr.id)?.value || 0) - return CurrencyBalance.fromFloat( - prev.toDecimal().add(updatedPrice.sub(price).mul(quantity)).toString(), - pool.currency.decimals - ) - }, new CurrencyBalance(0, pool.currency.decimals)) - }, [externalLoans, pool?.nav, updatedPrices]) - - const totalAum = pool.nav.total.toDecimal().add(pendingFees.toDecimal()) + const totalAum = pool.nav.aum.toDecimal().add(pool.reserve.available.toDecimal()) return ( ) }