Skip to content

Commit

Permalink
Fix NAV values (#2174)
Browse files Browse the repository at this point in the history
* Fix NAV values

* Remove deprecated query

* Fix pool performance

---------

Co-authored-by: sophian <littlejohn.sophia@gmail.com>
  • Loading branch information
hieronx and sophialittlejohn authored May 31, 2024
1 parent 381ecf2 commit b59bdd3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function PoolPerformanceChart() {
const data: ChartData[] = React.useMemo(
() =>
truncatedPoolStates?.map((day) => {
const nav = day.poolState.portfolioValuation.toDecimal().toNumber()
const nav = day.poolState.netAssetValue.toDecimal().toNumber()

return { day: new Date(day.timestamp), nav }
}) || [],
Expand Down
45 changes: 25 additions & 20 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,10 @@ export type DailyTrancheState = {

export type DailyPoolState = {
poolState: {
portfolioValuation: CurrencyBalance
cashAssetValue: CurrencyBalance
netAssetValue: CurrencyBalance
totalReserve: CurrencyBalance
offchainCashValue: CurrencyBalance
portfolioValuation: CurrencyBalance
}
poolValue: CurrencyBalance
timestamp: string
Expand Down Expand Up @@ -2226,9 +2227,10 @@ export function getPoolsModule(inst: Centrifuge) {
nodes {
id
timestamp
netAssetValue
totalReserve
offchainCashValue
portfolioValuation
cashAssetValue
blockNumber
sumPoolFeesChargedAmountByPeriod
sumPoolFeesAccruedAmountByPeriod
Expand All @@ -2237,7 +2239,6 @@ export function getPoolsModule(inst: Centrifuge) {
sumInvestedAmountByPeriod
sumRedeemedAmountByPeriod
sumInterestRepaidAmountByPeriod
value
}
pageInfo {
hasNextPage
Expand Down Expand Up @@ -2417,9 +2418,10 @@ export function getPoolsModule(inst: Centrifuge) {
poolSnapshots?.map((state) => {
const poolState = {
id: state.id,
portfolioValuation: new CurrencyBalance(state.portfolioValuation, poolCurrency.decimals),
cashAssetValue: new CurrencyBalance(state.cashAssetValue, poolCurrency.decimals),
netAssetValue: new CurrencyBalance(state.netAssetValue, poolCurrency.decimals),
totalReserve: new CurrencyBalance(state.totalReserve, poolCurrency.decimals),
offchainCashValue: new CurrencyBalance(state.offchainCashValue, poolCurrency.decimals),
portfolioValuation: new CurrencyBalance(state.portfolioValuation, poolCurrency.decimals),
sumPoolFeesChargedAmountByPeriod: new CurrencyBalance(
state.sumPoolFeesChargedAmountByPeriod ?? 0,
poolCurrency.decimals
Expand All @@ -2437,7 +2439,7 @@ export function getPoolsModule(inst: Centrifuge) {
sumInvestedAmountByPeriod: new CurrencyBalance(state.sumInvestedAmountByPeriod, poolCurrency.decimals),
sumRedeemedAmountByPeriod: new CurrencyBalance(state.sumRedeemedAmountByPeriod, poolCurrency.decimals),
}
const poolValue = new CurrencyBalance(new BN(state?.portfolioValuation || '0'), poolCurrency.decimals)
const poolValue = new CurrencyBalance(new BN(state?.netAssetValue || '0'), poolCurrency.decimals)

// TODO: This is inefficient, would be better to construct a map indexed by the timestamp
const trancheSnapshotsToday = trancheSnapshots?.filter((t) => t.timestamp === state.timestamp)
Expand Down Expand Up @@ -2465,10 +2467,18 @@ export function getPoolsModule(inst: Centrifuge) {
tranche.sumOutstandingRedeemOrdersByPeriod,
poolCurrency.decimals
),
yield30DaysAnnualized: tranche.yield30DaysAnnualized ? new Perquintill(hexToBN(tranche.yield30DaysAnnualized)) : new Perquintill(0),
yield90DaysAnnualized: tranche.yield90DaysAnnualized ? new Perquintill(hexToBN(tranche.yield90DaysAnnualized)) : new Perquintill(0),
yieldSinceInception: tranche.yieldSinceInception ? new Perquintill(hexToBN(tranche.yieldSinceInception)) : new Perquintill(0),
yieldSinceLastPeriod: tranche.yieldSinceLastPeriod ? new Perquintill(hexToBN(tranche.yieldSinceLastPeriod)) : new Perquintill(0),
yield30DaysAnnualized: tranche.yield30DaysAnnualized
? new Perquintill(hexToBN(tranche.yield30DaysAnnualized))
: new Perquintill(0),
yield90DaysAnnualized: tranche.yield90DaysAnnualized
? new Perquintill(hexToBN(tranche.yield90DaysAnnualized))
: new Perquintill(0),
yieldSinceInception: tranche.yieldSinceInception
? new Perquintill(hexToBN(tranche.yieldSinceInception))
: new Perquintill(0),
yieldSinceLastPeriod: tranche.yieldSinceLastPeriod
? new Perquintill(hexToBN(tranche.yieldSinceLastPeriod))
: new Perquintill(0),
}
})

Expand All @@ -2484,8 +2494,7 @@ export function getPoolsModule(inst: Centrifuge) {
const $query = inst.getSubqueryObservable<{
poolSnapshots: {
nodes: {
portfolioValuation: string
totalReserve: string
netAssetValue: string
periodStart: string
pool: {
currency: {
Expand All @@ -2498,8 +2507,7 @@ export function getPoolsModule(inst: Centrifuge) {
`query {
poolSnapshots(first: 1000, orderBy: PERIOD_START_ASC) {
nodes {
portfolioValuation
totalReserve
netAssetValue
periodStart
pool {
currency {
Expand All @@ -2518,12 +2526,9 @@ export function getPoolsModule(inst: Centrifuge) {
}

const mergedMap = new Map()
const formatted = data.poolSnapshots.nodes.map(({ portfolioValuation, totalReserve, periodStart, pool }) => ({
const formatted = data.poolSnapshots.nodes.map(({ netAssetValue, periodStart, pool }) => ({
dateInMilliseconds: new Date(periodStart).getTime(),
tvl: new CurrencyBalance(
new BN(portfolioValuation || '0').add(new BN(totalReserve || '0')),
pool.currency.decimals
).toDecimal(),
tvl: new CurrencyBalance(new BN(netAssetValue || '0'), pool.currency.decimals).toDecimal(),
}))

formatted.forEach((entry) => {
Expand Down
5 changes: 3 additions & 2 deletions centrifuge-js/src/types/subquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ export type SubqueryPoolSnapshot = {
id: string
timestamp: string
value: string
portfolioValuation: number
netAssetValue: number
totalReserve: number
cashAssetValue: number
offchainCashValue: number
portfolioValuation: number
sumPoolFeesChargedAmountByPeriod: string | null
sumPoolFeesAccruedAmountByPeriod: string | null
sumBorrowedAmountByPeriod: string
Expand Down

0 comments on commit b59bdd3

Please sign in to comment.