Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add NAV values to epoch object #276

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ type Epoch @entity {
closedAt: Date
executedAt: Date

# NAV == totalReserve + offchainCashValue + portfolioValuation - sumPoolFeesPendingAmount
netAssetValue: BigInt # previously: portfolioValuation
totalReserve: BigInt
offchainCashValue: BigInt # previously: cashAssetValue
portfolioValuation: BigInt

# Aggregated data during this epoch
sumBorrowedAmount: BigInt
sumRepaidAmount: BigInt
Expand Down
8 changes: 7 additions & 1 deletion src/mappings/handlers/poolsHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ async function _handleEpochClosed(event: SubstrateEvent<EpochClosedExecutedEvent
const tranches = await TrancheService.getActivesByPoolId(poolId.toString())
const epoch = await EpochService.getById(poolId.toString(), epochId.toNumber())
if (!epoch) throw new Error(`Epoch ${epochId.toString(10)} not found for pool ${poolId.toString(10)}`)
await epoch.closeEpoch(timestamp)
await epoch.closeEpoch(
timestamp,
pool.netAssetValue,
pool.totalReserve,
pool.offchainCashValue,
pool.portfolioValuation
)
await epoch.saveWithStates()

const trancheIds = tranches.map((tranche) => tranche.trancheId)
Expand Down
18 changes: 17 additions & 1 deletion src/mappings/services/epochService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export class EpochService extends Epoch {
epoch.sumRedeemedAmount = BigInt(0)
epoch.sumPoolFeesPaidAmount = BigInt(0)

epoch.netAssetValue = BigInt(0)
epoch.totalReserve = BigInt(0)
epoch.offchainCashValue = BigInt(0)
epoch.portfolioValuation = BigInt(0)

epoch.states = trancheIds.map((trancheId) => {
const epochState = new EpochState(`${poolId}-${epochNr}-${trancheId}`, epoch.id, trancheId)
epochState.sumOutstandingInvestOrders = BigInt(0)
Expand Down Expand Up @@ -59,9 +64,20 @@ export class EpochService extends Epoch {
return [...this.states]
}

public closeEpoch(timestamp: Date) {
public closeEpoch(
timestamp: Date,
netAssetValue: bigint | undefined,
totalReserve: bigint | undefined,
offchainCashValue: bigint | undefined,
portfolioValuation: bigint | undefined
) {
logger.info(`Closing epoch ${this.id} on ${timestamp}`)
this.closedAt = timestamp

this.netAssetValue = netAssetValue
this.totalReserve = totalReserve
this.offchainCashValue = offchainCashValue
this.portfolioValuation = portfolioValuation
}

public async executeEpoch(timestamp: Date) {
Expand Down
Loading