Skip to content

Commit

Permalink
refactor: filter out zero borrow repay
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Nov 27, 2024
1 parent 444700e commit 9971401
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 33 deletions.
29 changes: 16 additions & 13 deletions subgraphs/isolated-pools/src/mappings/vToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import {
createTransferTransaction,
} from '../operations/create';
import { getMarket } from '../operations/get';
import { getAccountVToken } from '../operations/get';
import { getOrCreateAccount, getOrCreateAccountVToken } from '../operations/getOrCreate';
import {
updateAccountVTokenBorrow,
updateAccountVTokenRepayBorrow,
updateAccountVTokenSupply,
updateMarket,
} from '../operations/update';
Expand Down Expand Up @@ -163,21 +163,24 @@ export function handleRepayBorrow(event: RepayBorrow): void {
const market = getMarket(vTokenAddress)!;

market.totalBorrowsMantissa = event.params.totalBorrows;
const vTokenAccount = getAccountVToken(vTokenAddress, event.params.borrower);
// Its possible to call repayborrow was called without having previously borrowed
if (vTokenAccount && vTokenAccount.storedBorrowBalanceMantissa.gt(zeroBigInt32)) {
updateAccountVTokenBorrow(
event.params.borrower,
Address.fromBytes(market.pool),
vTokenAddress,
event.block.number,
event.params.accountBorrows,
);

updateAccountVTokenRepayBorrow(
event.params.borrower,
Address.fromBytes(market.pool),
vTokenAddress,
event.block.number,
event.params.accountBorrows,
);

createRepayBorrowTransaction(event);
createRepayBorrowTransaction(event);

if (event.params.accountBorrows.equals(zeroBigInt32)) {
market.borrowerCount = market.borrowerCount.minus(oneBigInt);
if (event.params.accountBorrows.equals(zeroBigInt32)) {
market.borrowerCount = market.borrowerCount.minus(oneBigInt);
}
market.save();
}
market.save();
}

/*
Expand Down
20 changes: 0 additions & 20 deletions subgraphs/isolated-pools/src/operations/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,6 @@ export const updateAccountVTokenBorrow = (
return accountVToken as AccountVToken;
};

export const updateAccountVTokenRepayBorrow = (
accountAddress: Address,
poolAddress: Address,
marketAddress: Address,
blockNumber: BigInt,
accountBorrows: BigInt,
): AccountVToken => {
const accountVToken = updateAccountVTokenAccrualBlockNumber(
accountAddress,
poolAddress,
marketAddress,
blockNumber,
);
accountVToken.storedBorrowBalanceMantissa = accountBorrows;
const vTokenContract = VToken.bind(marketAddress);
accountVToken.borrowIndex = vTokenContract.borrowIndex();
accountVToken.save();
return accountVToken as AccountVToken;
};

export const updateAccountVTokenTransferFrom = (
accountAddress: Address,
poolAddress: Address,
Expand Down

0 comments on commit 9971401

Please sign in to comment.