From abe2f7f623041bb8fb111ffd62b04c2b0a127496 Mon Sep 17 00:00:00 2001 From: Filippo Date: Mon, 10 Oct 2022 14:16:20 +0200 Subject: [PATCH] 103 totalinvested and totalredeemed are missing in poolsnapshot (#107) * fix: add missing properties to snapshot * deploy: update node and query versions * fix: pool investment and redemptions totals --- .github/workflows/deploy.yml | 4 ++-- schema.graphql | 4 +++- src/mappings/handlers/loansHandlers.ts | 2 +- src/mappings/handlers/poolsHandlers.ts | 4 +++- src/mappings/services/epochService.ts | 4 +--- src/mappings/services/poolService.ts | 8 ++++++++ src/mappings/services/trancheService.ts | 6 +++++- 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 159d6074..661377fd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -63,5 +63,5 @@ jobs: --projectName="$SUBQL_PROJ_NAME" \ --ipfsCID="$IPFSCID" \ --type=primary \ - --indexerVersion="v1.9.2" \ - --queryVersion="v1.4.0" + --indexerVersion="v1.10.2" \ + --queryVersion="v1.6.0" diff --git a/schema.graphql b/schema.graphql index a4be822c..9bc4ceb9 100644 --- a/schema.graphql +++ b/schema.graphql @@ -33,6 +33,7 @@ type Pool @entity { type PoolState @entity { id: ID! #poolId type: String! @index + #States netAssetValue: BigInt! totalReserve: BigInt! @@ -74,6 +75,8 @@ type PoolSnapshot @entity { # Aggregated transaction data over the last period totalBorrowed_: BigInt totalRepaid_: BigInt + totalInvested_: BigInt + totalRedeemed_: BigInt totalNumberOfLoans_: BigInt # Cumulated transaction data since pool creation @@ -161,7 +164,6 @@ type Epoch @entity { totalRepaid: BigInt! totalInvested: BigInt! totalRedeemed: BigInt! - totalRedeemedCurrency: BigInt! epochStates: [EpochState] @derivedFrom(field: "epoch") diff --git a/src/mappings/handlers/loansHandlers.ts b/src/mappings/handlers/loansHandlers.ts index a9dd82e3..6d7141c3 100644 --- a/src/mappings/handlers/loansHandlers.ts +++ b/src/mappings/handlers/loansHandlers.ts @@ -133,7 +133,7 @@ async function _handleLoanClosed(event: SubstrateEvent) await loan.close() await loan.save() - const bt = await BorrowerTransactionService.repaid({ + const bt = await BorrowerTransactionService.closed({ poolId: poolId.toString(), loanId: loanId.toString(), address: account.account.id, diff --git a/src/mappings/handlers/poolsHandlers.ts b/src/mappings/handlers/poolsHandlers.ts index 95bf699e..0710da5a 100644 --- a/src/mappings/handlers/poolsHandlers.ts +++ b/src/mappings/handlers/poolsHandlers.ts @@ -113,6 +113,8 @@ async function _handleEpochExecuted(event: SubstrateEvent): Promise< await epoch.save() await poolService.executeEpoch(epochId.toNumber()) + await poolService.increaseTotalInvested(epoch.epoch.totalInvested) + await poolService.increaseTotalRedeemed(epoch.epoch.totalRedeemed) await poolService.save() // Compute and save aggregated order fulfillment @@ -123,7 +125,7 @@ async function _handleEpochExecuted(event: SubstrateEvent): Promise< await tranche.updateSupply() await tranche.updatePrice(epochState.price) await tranche.updateFulfilledInvestOrders(epochState.fulfilledInvestOrders) - await tranche.updateFulfilledRedeemOrders(epochState.fulfilledRedeemOrders) + await tranche.updateFulfilledRedeemOrders(epochState.fulfilledRedeemOrders, digits) await tranche.save() // Carry over aggregated unfulfilled orders to next epoch diff --git a/src/mappings/services/epochService.ts b/src/mappings/services/epochService.ts index 5246dc85..164619a3 100644 --- a/src/mappings/services/epochService.ts +++ b/src/mappings/services/epochService.ts @@ -25,7 +25,6 @@ export class EpochService { epoch.totalRepaid = BigInt(0) epoch.totalInvested = BigInt(0) epoch.totalRedeemed = BigInt(0) - epoch.totalRedeemedCurrency = BigInt(0) const epochStates: EpochState[] = [] for (const trancheId of trancheIds) { @@ -85,8 +84,7 @@ export class EpochService { ) this.epoch.totalInvested += epochState.fulfilledInvestOrders - this.epoch.totalRedeemed += epochState.fulfilledRedeemOrders - this.epoch.totalRedeemedCurrency += epochState.fulfilledRedeemOrdersCurrency + this.epoch.totalRedeemed += epochState.fulfilledRedeemOrdersCurrency } return this } diff --git a/src/mappings/services/poolService.ts b/src/mappings/services/poolService.ts index b2005d10..4aa61eef 100644 --- a/src/mappings/services/poolService.ts +++ b/src/mappings/services/poolService.ts @@ -112,6 +112,14 @@ export class PoolService { this.poolState.totalEverNumberOfLoans = this.poolState.totalEverNumberOfLoans + BigInt(1) } + public increaseTotalInvested = (currencyAmount: bigint) => { + this.poolState.totalInvested_ += currencyAmount + } + + public increaseTotalRedeemed = (currencyAmount: bigint) => { + this.poolState.totalRedeemed_ += currencyAmount + } + public closeEpoch = (epochId: number) => { this.pool.lastEpochClosed = epochId this.pool.currentEpoch = epochId + 1 diff --git a/src/mappings/services/trancheService.ts b/src/mappings/services/trancheService.ts index 89356b72..42cf0934 100644 --- a/src/mappings/services/trancheService.ts +++ b/src/mappings/services/trancheService.ts @@ -216,8 +216,12 @@ export class TrancheService { return this } - public updateFulfilledRedeemOrders = (amount: bigint) => { + public updateFulfilledRedeemOrders = (amount: bigint, digits: number) => { this.trancheState.fulfilledRedeemOrders_ = this.trancheState.fulfilledRedeemOrders_ + amount + this.trancheState.fulfilledRedeemOrdersCurrency_ = this.computeCurrencyAmount( + this.trancheState.fulfilledRedeemOrders_, + digits + ) return this }