From 78895da0e427538e97a758d0b7966f197419996a Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Mon, 26 Feb 2024 15:55:49 -0300 Subject: [PATCH] fix: remove duplicate repay borrow event --- subgraphs/venus/src/mappings/vToken.ts | 36 ++-------------------- subgraphs/venus/template.yaml | 4 +-- subgraphs/venus/tests/VToken/index.test.ts | 10 +++--- 3 files changed, 8 insertions(+), 42 deletions(-) diff --git a/subgraphs/venus/src/mappings/vToken.ts b/subgraphs/venus/src/mappings/vToken.ts index 6a4fbc24..fbbad130 100644 --- a/subgraphs/venus/src/mappings/vToken.ts +++ b/subgraphs/venus/src/mappings/vToken.ts @@ -11,16 +11,11 @@ import { NewMarketInterestRateModel, NewReserveFactor, Redeem as RedeemV1, - RepayBorrow as RepayBorrowV1, + RepayBorrow, Transfer, } from '../../generated/templates/VToken/VToken'; import { VToken as VTokenContract } from '../../generated/templates/VToken/VToken'; -import { - Mint, - MintBehalf, - Redeem, - RepayBorrow, -} from '../../generated/templates/VTokenUpdatedEvents/VToken'; +import { Mint, MintBehalf, Redeem } from '../../generated/templates/VTokenUpdatedEvents/VToken'; import { DUST_THRESHOLD, oneBigInt, zeroBigInt32 } from '../constants'; import { createBorrowEvent, @@ -309,30 +304,3 @@ export function handleRedeemV1(event: RedeemV1): void { } createRedeemEvent(event); } - -export function handleRepayBorrowV1(event: RepayBorrowV1): void { - const market = getOrCreateMarket(event.address, event); - if (event.params.accountBorrows.equals(zeroBigInt32)) { - market.borrowerCount = market.borrowerCount.minus(oneBigInt); - market.borrowerCountAdjusted = market.borrowerCountAdjusted.minus(oneBigInt); - market.save(); - } else if (event.params.accountBorrows.le(DUST_THRESHOLD)) { - // Sometimes a liquidator will leave dust behind. If this happens we'll adjust count - // because the position only exists due to a technicality - market.borrowerCountAdjusted = market.borrowerCountAdjusted.minus(oneBigInt); - market.save(); - } - - const account = getOrCreateAccount(event.params.borrower.toHex()); - - const accountVToken = getOrCreateAccountVToken(market.id, market.symbol, account.id, event); - accountVToken.storedBorrowBalanceMantissa = event.params.accountBorrows; - accountVToken.accountBorrowIndexMantissa = market.borrowIndexMantissa; - accountVToken.totalUnderlyingRepaidMantissa = accountVToken.totalUnderlyingRepaidMantissa.plus( - event.params.repayAmount, - ); - accountVToken.save(); - - getOrCreateAccountVTokenTransaction(accountVToken.id, event); - createRepayEvent(event, market.underlyingAddress); -} diff --git a/subgraphs/venus/template.yaml b/subgraphs/venus/template.yaml index 330cf8a0..e8451854 100644 --- a/subgraphs/venus/template.yaml +++ b/subgraphs/venus/template.yaml @@ -114,7 +114,7 @@ templates: - event: Borrow(address,uint256,uint256,uint256) handler: handleBorrow - event: RepayBorrow(address,address,uint256,uint256,uint256) - handler: handleRepayBorrowV1 + handler: handleRepayBorrow - event: LiquidateBorrow(address,address,uint256,address,uint256) handler: handleLiquidateBorrow - event: AccrueInterest(uint256,uint256,uint256,uint256) @@ -149,5 +149,3 @@ templates: handler: handleMintBehalf - event: Redeem(address,uint256,uint256,uint256) handler: handleRedeem - - event: RepayBorrow(address,address,uint256,uint256,uint256) - handler: handleRepayBorrow \ No newline at end of file diff --git a/subgraphs/venus/tests/VToken/index.test.ts b/subgraphs/venus/tests/VToken/index.test.ts index 943d238f..e79d9ccd 100644 --- a/subgraphs/venus/tests/VToken/index.test.ts +++ b/subgraphs/venus/tests/VToken/index.test.ts @@ -25,7 +25,7 @@ import { handleNewReserveFactor, handleRedeem, handleRedeemV1, - handleRepayBorrowV1, + handleRepayBorrow, handleTransfer, } from '../../src/mappings/vToken'; import { getMarket } from '../../src/operations/get'; @@ -228,7 +228,7 @@ describe('VToken', () => { ]); /** Fire Event */ - handleRepayBorrowV1(repayBorrowEvent); + handleRepayBorrow(repayBorrowEvent); const accountVTokenId = getAccountVTokenId(aaaTokenAddress, borrower); const market = getMarket(aaaTokenAddress); @@ -588,7 +588,7 @@ describe('VToken', () => { zeroBigInt32, ); - handleRepayBorrowV1(repayEvent); + handleRepayBorrow(repayEvent); assert.fieldEquals('Market', aaaTokenAddress.toHex(), 'borrowerCount', '1'); assert.fieldEquals('Market', aaaTokenAddress.toHex(), 'borrowerCountAdjusted', '1'); @@ -601,7 +601,7 @@ describe('VToken', () => { partialBorrowAmountWei, ); - handleRepayBorrowV1(repayEvent); + handleRepayBorrow(repayEvent); assert.fieldEquals('Market', aaaTokenAddress.toHex(), 'borrowerCount', '1'); assert.fieldEquals('Market', aaaTokenAddress.toHex(), 'borrowerCountAdjusted', '1'); @@ -614,7 +614,7 @@ describe('VToken', () => { partialBorrowAmountWei.minus(oneBigInt), ); - handleRepayBorrowV1(repayEvent); + handleRepayBorrow(repayEvent); assert.fieldEquals('Market', aaaTokenAddress.toHex(), 'borrowerCount', '1'); assert.fieldEquals('Market', aaaTokenAddress.toHex(), 'borrowerCountAdjusted', '0'); });