Skip to content

Commit

Permalink
feat: track wa interest rate
Browse files Browse the repository at this point in the history
  • Loading branch information
hieronx committed Sep 13, 2024
1 parent 1ff84a9 commit 99c3c63
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type Pool @entity {

availableReserve: BigInt
maxReserve: BigInt

weightedAverageInterestRatePerSec: BigInt

# Aggregated transaction data over the last period
sumBorrowedAmountByPeriod: BigInt
Expand Down Expand Up @@ -121,6 +123,8 @@ type PoolSnapshot @entity {
availableReserve: BigInt
maxReserve: BigInt

weightedAverageInterestRatePerSec: BigInt

# Aggregated transaction data over the last period
sumBorrowedAmountByPeriod: BigInt
sumRepaidAmountByPeriod: BigInt
Expand Down
3 changes: 3 additions & 0 deletions src/mappings/handlers/ethHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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()
}
}
Expand Down

0 comments on commit 99c3c63

Please sign in to comment.