From 4174983d3e3a0018c49969ff97f279843c34fcfa Mon Sep 17 00:00:00 2001 From: Filippo Fontana Date: Fri, 7 Jun 2024 13:16:19 +0200 Subject: [PATCH] feat: track realizedProfit in pool entity --- schema.graphql | 4 ++++ src/mappings/handlers/loansHandlers.ts | 9 ++++++--- src/mappings/services/poolService.ts | 6 ++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/schema.graphql b/schema.graphql index 10fc29fd..f0a963bd 100644 --- a/schema.graphql +++ b/schema.graphql @@ -67,6 +67,8 @@ type Pool @entity { sumPoolFeesPaidAmount: BigInt #Applies to All sumPoolFeesPendingAmount: BigInt #Applies to All + sumRealizedProfitFifoByPeriod: BigInt + # Cumulated transaction data since pool creation sumBorrowedAmount: BigInt sumRepaidAmount: BigInt @@ -123,6 +125,8 @@ type PoolSnapshot @entity { sumPoolFeesPaidAmount: BigInt #Applies to All sumPoolFeesPendingAmount: BigInt #Applies to All + sumRealizedProfitFifoByPeriod: BigInt + # Cumulated transaction data since pool creation sumBorrowedAmount: BigInt sumRepaidAmount: BigInt diff --git a/src/mappings/handlers/loansHandlers.ts b/src/mappings/handlers/loansHandlers.ts index 41e6564f..a5fbae00 100644 --- a/src/mappings/handlers/loansHandlers.ts +++ b/src/mappings/handlers/loansHandlers.ts @@ -222,6 +222,7 @@ async function _handleLoanRepaid(event: SubstrateEvent) { quantity.toBigInt(), settlementPrice.toBigInt() ) + await pool.increaseRealizedProfitFifo(realizedProfitFifo) } const at = await AssetTransactionService.repaid({ ...assetTransactionBaseData, realizedProfitFifo }) @@ -337,6 +338,7 @@ async function _handleLoanDebtTransferred(event: SubstrateEvent