From c93f50cfb256159b59e946634f3497c574557d52 Mon Sep 17 00:00:00 2001 From: sophian Date: Thu, 4 Apr 2024 15:02:44 -0400 Subject: [PATCH] Expose total and aum from cent-js and fix asset value in assets tab --- .../src/components/Charts/CashDragChart.tsx | 3 +-- .../components/Charts/PoolPerformanceChart.tsx | 2 +- .../src/components/PoolFees/ChargeFeesDrawer.tsx | 2 +- centrifuge-app/src/pages/Pool/Assets/index.tsx | 2 +- centrifuge-app/src/utils/getPoolTVL.ts | 2 +- .../src/utils/tinlake/useTinlakePools.ts | 3 ++- centrifuge-js/src/modules/pools.ts | 15 +++++++++------ 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/centrifuge-app/src/components/Charts/CashDragChart.tsx b/centrifuge-app/src/components/Charts/CashDragChart.tsx index f0c9857663..3935d49dbb 100644 --- a/centrifuge-app/src/components/Charts/CashDragChart.tsx +++ b/centrifuge-app/src/components/Charts/CashDragChart.tsx @@ -1,5 +1,4 @@ import { Box, Shelf, Stack, Text } from '@centrifuge/fabric' -import * as React from 'react' import { useParams } from 'react-router' import { CartesianGrid, ComposedChart, Line, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts' import { useTheme } from 'styled-components' @@ -30,7 +29,7 @@ export default function CashDragChart() { }) || [] // querying chain for more accurate data, since data for today from subquery is not necessarily up to date - const todayAssetValue = pool?.nav.latest.toDecimal().toNumber() || 0 + const todayAssetValue = pool?.nav.aum.toDecimal().toNumber() || 0 const todayReserve = pool?.reserve.total.toDecimal().toNumber() || 0 const cashDrag = (todayReserve / (todayAssetValue + todayReserve)) * 100 const today: ChartData = { diff --git a/centrifuge-app/src/components/Charts/PoolPerformanceChart.tsx b/centrifuge-app/src/components/Charts/PoolPerformanceChart.tsx index 6f2e82547a..36945b405f 100644 --- a/centrifuge-app/src/components/Charts/PoolPerformanceChart.tsx +++ b/centrifuge-app/src/components/Charts/PoolPerformanceChart.tsx @@ -71,7 +71,7 @@ function PoolPerformanceChart() { return No data available // querying chain for more accurate data, since data for today from subquery is not necessarily up to date - const todayAssetValue = pool?.nav.latest.toDecimal().toNumber() || 0 + const todayAssetValue = pool?.nav.aum.toDecimal().toNumber() || 0 const todayReserve = pool?.reserve.total.toDecimal().toNumber() || 0 const chartData = data.slice(-rangeNumber) diff --git a/centrifuge-app/src/components/PoolFees/ChargeFeesDrawer.tsx b/centrifuge-app/src/components/PoolFees/ChargeFeesDrawer.tsx index ef20e05958..f903004fc5 100644 --- a/centrifuge-app/src/components/PoolFees/ChargeFeesDrawer.tsx +++ b/centrifuge-app/src/components/PoolFees/ChargeFeesDrawer.tsx @@ -25,7 +25,7 @@ export const ChargeFeesDrawer = ({ onClose, isOpen }: ChargeFeesProps) => { const feeIndex = params.get('charge') const feeMetadata = feeIndex ? poolMetadata?.pool?.poolFees?.find((f) => f.id.toString() === feeIndex) : undefined const feeChainData = feeIndex ? pool?.poolFees?.find((f) => f.id.toString() === feeIndex) : undefined - const maxCharge = feeChainData?.amounts.percentOfNav.toDecimal().mul(pool.nav.latest.toDecimal()).div(100) + const maxCharge = feeChainData?.amounts.percentOfNav.toDecimal().mul(pool.nav.aum.toDecimal()).div(100) const [updateCharge, setUpdateCharge] = React.useState(false) const address = useAddress() const isAllowedToCharge = feeChainData?.destination && addressToHex(feeChainData.destination) === address diff --git a/centrifuge-app/src/pages/Pool/Assets/index.tsx b/centrifuge-app/src/pages/Pool/Assets/index.tsx index 044e73f2c5..8549702e43 100644 --- a/centrifuge-app/src/pages/Pool/Assets/index.tsx +++ b/centrifuge-app/src/pages/Pool/Assets/index.tsx @@ -68,7 +68,7 @@ export function PoolDetailAssets() { const pageSummaryData: { label: React.ReactNode; value: React.ReactNode }[] = [ { label: , - value: formatBalance(pool.nav.latest.toDecimal(), pool.currency.symbol), + value: formatBalance(pool.nav.total.toDecimal(), pool.currency.symbol), }, { label: ( diff --git a/centrifuge-app/src/utils/getPoolTVL.ts b/centrifuge-app/src/utils/getPoolTVL.ts index ff178964be..860a216f8f 100644 --- a/centrifuge-app/src/utils/getPoolTVL.ts +++ b/centrifuge-app/src/utils/getPoolTVL.ts @@ -2,5 +2,5 @@ import { Pool } from '@centrifuge/centrifuge-js' import type { TinlakePool } from './tinlake/useTinlakePools' export function getPoolTVL(pool: TinlakePool | Pool) { - return pool.nav.latest.toFloat() + pool.reserve.total.toFloat() + return pool.nav.aum.toFloat() + pool.reserve.total.toFloat() } diff --git a/centrifuge-app/src/utils/tinlake/useTinlakePools.ts b/centrifuge-app/src/utils/tinlake/useTinlakePools.ts index 676c1ec431..33dd00867e 100644 --- a/centrifuge-app/src/utils/tinlake/useTinlakePools.ts +++ b/centrifuge-app/src/utils/tinlake/useTinlakePools.ts @@ -710,8 +710,9 @@ async function getPools(pools: IpfsPools): Promise<{ pools: TinlakePool[] }> { total: data.reserve, }, nav: { - latest: data.netAssetValue, lastUpdated: new Date().toISOString(), + total: data.netAssetValue, + aum: data.netAssetValue, }, createdAt: null, isInitialised: true, diff --git a/centrifuge-js/src/modules/pools.ts b/centrifuge-js/src/modules/pools.ts index f01d589035..1a3985f09c 100644 --- a/centrifuge-js/src/modules/pools.ts +++ b/centrifuge-js/src/modules/pools.ts @@ -349,8 +349,9 @@ export type Pool = { status: 'submissionPeriod' | 'challengePeriod' | 'executionPeriod' | 'ongoing' } nav: { - latest: CurrencyBalance lastUpdated: string + total: CurrencyBalance + aum: CurrencyBalance } parameters: { minEpochTime: number @@ -1271,7 +1272,7 @@ export function getPoolsModule(inst: Centrifuge) { minRiskBuffer: tranche.minRiskBuffer, })) const poolState = { - netAssetValue: pool.nav.latest, + netAssetValue: pool.nav.aum, reserve: pool.reserve.total, tranches: solutionTranches, maxReserve: pool.reserve.max, @@ -1973,9 +1974,6 @@ export function getPoolsModule(inst: Centrifuge) { const lastUpdatedNav = new Date((portfolioValuationData?.lastUpdated ?? 0) * 1000).toISOString() // @ts-expect-error const rawNav = rawNavs && rawNavs[poolIndex]?.toJSON() - const totalNavAum = rawNav?.navAum - ? new CurrencyBalance(hexToBN(rawNav.navAum), currency.decimals) - : new CurrencyBalance(0, currency.decimals) const mappedPool: Pool = { id: poolId, @@ -2078,8 +2076,13 @@ export function getPoolsModule(inst: Centrifuge) { challengeTime: api.consts.poolSystem.challengeTime.toJSON() as number, // in blocks }, nav: { - latest: totalNavAum, lastUpdated: lastUpdatedNav, + total: rawNav?.total + ? new CurrencyBalance(hexToBN(rawNav.total).add(hexToBN(rawNav.navFees)), currency.decimals) + : new CurrencyBalance(0, currency.decimals), + aum: rawNav?.navAum + ? new CurrencyBalance(hexToBN(rawNav.navAum), currency.decimals) + : new CurrencyBalance(0, currency.decimals), }, value: rawNav?.total ? new CurrencyBalance(hexToBN(rawNav.total).add(hexToBN(rawNav.navFees)), currency.decimals)