From 99c3c63d1eb842162796e61652c9a553d533ca9b Mon Sep 17 00:00:00 2001 From: Jeroen Offerijns Date: Fri, 13 Sep 2024 22:17:35 +0200 Subject: [PATCH] feat: track wa interest rate --- schema.graphql | 4 ++++ src/mappings/handlers/ethHandlers.ts | 3 +++ 2 files changed, 7 insertions(+) diff --git a/schema.graphql b/schema.graphql index 4e1eaa5..e30564e 100644 --- a/schema.graphql +++ b/schema.graphql @@ -55,6 +55,8 @@ type Pool @entity { availableReserve: BigInt maxReserve: BigInt + + weightedAverageInterestRatePerSec: BigInt # Aggregated transaction data over the last period sumBorrowedAmountByPeriod: BigInt @@ -121,6 +123,8 @@ type PoolSnapshot @entity { availableReserve: BigInt maxReserve: BigInt + weightedAverageInterestRatePerSec: BigInt + # Aggregated transaction data over the last period sumBorrowedAmountByPeriod: BigInt sumRepaidAmountByPeriod: BigInt diff --git a/src/mappings/handlers/ethHandlers.ts b/src/mappings/handlers/ethHandlers.ts index 2e1ea86..f7b64fd 100644 --- a/src/mappings/handlers/ethHandlers.ts +++ b/src/mappings/handlers/ethHandlers.ts @@ -323,6 +323,7 @@ async function updateLoans(poolId: string, blockDate: Date, shelf: string, pile: let totalDebt = BigInt(0) let totalBorrowed = BigInt(0) let totalRepaid = BigInt(0) + let totalInterestRatePerSec = BigInt(0) for (let i = 0; i < existingLoans.length; i++) { const loan = existingLoans[i] const loanIndex = loan.id.split('-')[1] @@ -366,11 +367,13 @@ async function updateLoans(poolId: string, blockDate: Date, shelf: string, pile: totalDebt += loan.outstandingDebt totalBorrowed += loan.totalBorrowed totalRepaid += loan.totalRepaid + totalInterestRatePerSec += loan.interestRatePerSec * loan.outstandingDebt } pool.sumDebt = totalDebt pool.sumBorrowedAmount = totalBorrowed pool.sumRepaidAmount = totalRepaid + pool.weightedAverageInterestRatePerSec = totalInterestRatePerSec / totalDebt await pool.save() } }