Skip to content

Commit

Permalink
Merge branch 'tinlake-additions' of https://github.com/centrifuge/poo…
Browse files Browse the repository at this point in the history
…ls-subql into tinlake-additions
  • Loading branch information
hieronx committed Oct 7, 2024
2 parents bd6a97c + f5321eb commit 9a6f09c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
9 changes: 6 additions & 3 deletions chains-evm/eth/centrifuge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ network:
#dictionary: 'https://gx.api.subquery.network/sq/subquery/eth-dictionary'
dataSources:
- kind: ethereum/Runtime #PoolManager V1
startBlock: 18721030
startBlock: 20778999
# startBlock: 18721030
options:
address: '0x78E9e622A57f70F1E0Ec652A4931E4e278e58142'
- kind: ethereum/Runtime #PoolManager V2
startBlock: 20432390
startBlock: 20778999
# startBlock: 20432390
options:
address: '0x91808B5E2F6d7483D41A681034D7c9DbB64B9E29'
- kind: ethereum/Runtime #Tinlake
startBlock: 11063000
startBlock: 20778999
# startBlock: 11063000
options:
abi: navFeed
assets:
Expand Down
30 changes: 15 additions & 15 deletions src/mappings/handlers/ethHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,36 +370,36 @@ async function updateLoans(

if (prevDebt > currentDebt) {
loan.repaidAmountByPeriod = prevDebt - currentDebt
loan.totalRepaid
? (loan.totalRepaid += loan.repaidAmountByPeriod)
: (loan.totalRepaid = loan.repaidAmountByPeriod)
loan.repaysCount += BigInt(1)
loan.totalRepaid = (loan.totalRepaid || BigInt(0)) + loan.repaidAmountByPeriod
loan.repaysCount = (loan.repaysCount || BigInt(0)) + BigInt(1)
}
if (
prevDebt * (loan.interestRatePerSec / BigInt(10) ** BigInt(27)) * BigInt(86400) <
(loan.outstandingDebt || BigInt(0))
) {
loan.borrowedAmountByPeriod = (loan.outstandingDebt || BigInt(0)) - prevDebt
loan.totalBorrowed
? (loan.totalBorrowed += loan.borrowedAmountByPeriod)
: (loan.totalBorrowed = loan.borrowedAmountByPeriod)
loan.borrowsCount += BigInt(1)
loan.totalBorrowed = (loan.totalBorrowed || BigInt(0)) + loan.borrowedAmountByPeriod
loan.borrowsCount = (loan.borrowsCount || BigInt(0)) + BigInt(1)
}
logger.info(`Updating loan ${loan.id} for pool ${poolId}`)
await loan.save()

sumDebt += loan.outstandingDebt
sumBorrowed += loan.totalBorrowed
sumRepaid += loan.totalRepaid
sumInterestRatePerSec += loan.interestRatePerSec * loan.outstandingDebt
sumBorrowsCount += loan.borrowsCount
sumRepaysCount += loan.repaysCount
sumDebt += loan.outstandingDebt || BigInt(0)
sumBorrowed += loan.totalBorrowed || BigInt(0)
sumRepaid += loan.totalRepaid || BigInt(0)
sumInterestRatePerSec += (loan.interestRatePerSec || BigInt(0)) * (loan.outstandingDebt || BigInt(0))
sumBorrowsCount += loan.borrowsCount || BigInt(0)
sumRepaysCount += loan.repaysCount || BigInt(0)
}

pool.sumDebt = sumDebt
pool.sumBorrowedAmount = sumBorrowed
pool.sumRepaidAmount = sumRepaid
pool.weightedAverageInterestRatePerSec = sumInterestRatePerSec / sumDebt
if (sumDebt > BigInt(0)) {
pool.weightedAverageInterestRatePerSec = sumInterestRatePerSec / sumDebt
} else {
pool.weightedAverageInterestRatePerSec = BigInt(0)
}
pool.sumBorrowsCount = sumBorrowsCount
pool.sumRepaysCount = sumRepaysCount
await pool.save()
Expand Down

0 comments on commit 9a6f09c

Please sign in to comment.