Skip to content

Commit

Permalink
Expose total and aum from cent-js and fix asset value in assets tab
Browse files Browse the repository at this point in the history
  • Loading branch information
sophialittlejohn committed Apr 4, 2024
1 parent 55b2766 commit c93f50c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
3 changes: 1 addition & 2 deletions centrifuge-app/src/components/Charts/CashDragChart.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function PoolPerformanceChart() {
return <Text variant="body2">No data available</Text>

// 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion centrifuge-app/src/pages/Pool/Assets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function PoolDetailAssets() {
const pageSummaryData: { label: React.ReactNode; value: React.ReactNode }[] = [
{
label: <Tooltips type="totalNav" />,
value: formatBalance(pool.nav.latest.toDecimal(), pool.currency.symbol),
value: formatBalance(pool.nav.total.toDecimal(), pool.currency.symbol),
},
{
label: (
Expand Down
2 changes: 1 addition & 1 deletion centrifuge-app/src/utils/getPoolTVL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
3 changes: 2 additions & 1 deletion centrifuge-app/src/utils/tinlake/useTinlakePools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 9 additions & 6 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,9 @@ export type Pool = {
status: 'submissionPeriod' | 'challengePeriod' | 'executionPeriod' | 'ongoing'
}
nav: {
latest: CurrencyBalance
lastUpdated: string
total: CurrencyBalance
aum: CurrencyBalance
}
parameters: {
minEpochTime: number
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c93f50c

Please sign in to comment.