Skip to content

Commit

Permalink
feat: skip 0 borrower tx
Browse files Browse the repository at this point in the history
  • Loading branch information
hieronx committed Dec 27, 2023
1 parent cf69170 commit 3fce2eb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/mappings/handlers/loansHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ async function _handleLoanBorrowed(event: SubstrateEvent<LoanBorrowedEvent>): Pr
const amount = borrowAmount.isInternal
? borrowAmount.asInternal.toString()
: borrowAmount.asExternal.quantity.mul(borrowAmount.asExternal.settlementPrice).div(WAD).toString()

if (amount == '0') return

logger.info(`Loan borrowed event for pool: ${poolId.toString()} amount: ${amount.toString()}`)

const account = await AccountService.getOrInit(event.extrinsic.extrinsic.signer.toHex())
Expand Down Expand Up @@ -135,6 +138,8 @@ async function _handleLoanRepaid(event: SubstrateEvent<LoanRepaidEvent>) {
: principal.asExternal.quantity.mul(principal.asExternal.settlementPrice).div(WAD)
const amount = principalAmount.add(interest).add(unscheduled).toString()

if (amount == '0') return

logger.info(`Loan repaid event for pool: ${poolId.toString()} amount: ${amount.toString()}`)

const account = await AccountService.getOrInit(event.extrinsic.extrinsic.signer.toHex())
Expand Down Expand Up @@ -221,6 +226,8 @@ async function _handleLoanDebtTransferred(event: SubstrateEvent<LoanDebtTransfer
const pool = await PoolService.getById(poolId.toString())
if (pool === undefined) throw missingPool

if (amount.toString() == '0') return

logger.info(
`Loan debt transferred event for pool: ${poolId.toString()}, from loan: ${fromLoanId.toString()} ` +
`to loan: ${toLoanId.toString()} amount: ${amount.toString()}`
Expand Down Expand Up @@ -253,5 +260,4 @@ async function _handleLoanDebtTransferred(event: SubstrateEvent<LoanDebtTransfer

const borrowedBt = await BorrowerTransactionService.borrowed({ ...txData, loanId: toLoanId.toString() })
await borrowedBt.save()

}

0 comments on commit 3fce2eb

Please sign in to comment.