Skip to content

Commit

Permalink
fix: remove duplicate repay borrow event
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Feb 26, 2024
1 parent 9c4c27b commit 78895da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 42 deletions.
36 changes: 2 additions & 34 deletions subgraphs/venus/src/mappings/vToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -309,30 +304,3 @@ export function handleRedeemV1(event: RedeemV1): void {
}
createRedeemEvent<RedeemV1>(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<RepayBorrowV1>(event, market.underlyingAddress);
}
4 changes: 1 addition & 3 deletions subgraphs/venus/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -149,5 +149,3 @@ templates:
handler: handleMintBehalf
- event: Redeem(address,uint256,uint256,uint256)
handler: handleRedeem
- event: RepayBorrow(address,address,uint256,uint256,uint256)
handler: handleRepayBorrow
10 changes: 5 additions & 5 deletions subgraphs/venus/tests/VToken/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
handleNewReserveFactor,
handleRedeem,
handleRedeemV1,
handleRepayBorrowV1,
handleRepayBorrow,
handleTransfer,
} from '../../src/mappings/vToken';
import { getMarket } from '../../src/operations/get';
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('VToken', () => {
]);

/** Fire Event */
handleRepayBorrowV1(repayBorrowEvent);
handleRepayBorrow(repayBorrowEvent);

const accountVTokenId = getAccountVTokenId(aaaTokenAddress, borrower);
const market = getMarket(aaaTokenAddress);
Expand Down Expand Up @@ -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');

Expand All @@ -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');

Expand All @@ -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');
});
Expand Down

0 comments on commit 78895da

Please sign in to comment.