Skip to content

Commit

Permalink
fix: fallback to 0 if supplyRatePerBlock reverts
Browse files Browse the repository at this point in the history
  • Loading branch information
gleiser-oliveira committed Jul 17, 2023
1 parent 0400e50 commit 99d15c7
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions subgraphs/isolated-pools/src/operations/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Address, BigInt, Bytes } from '@graphprotocol/graph-ts';
import { PoolMetadataUpdatedNewMetadataStruct } from '../../generated/PoolRegistry/PoolRegistry';
import { AccountVToken, Market } from '../../generated/schema';
import { VToken } from '../../generated/templates/VToken/VToken';
import { zeroBigInt32 } from '../constants';
import { exponentToBigDecimal, getExchangeRateBigDecimal } from '../utilities';
import { getTokenPriceInUsd } from '../utilities';
import { getOrCreateMarket } from './getOrCreate';
Expand Down Expand Up @@ -190,10 +191,20 @@ export const updateMarket = (
.div(exponentToBigDecimal(market.underlyingDecimals))
.truncate(market.underlyingDecimals);

// Must convert to BigDecimal, and remove 10^18 that is used for Exp in Venus Solidity
market.borrowRateMantissa = marketContract.borrowRatePerBlock();
// calling supplyRatePerBlock & borrowRatePerBlock can fail due to external reasons, so we fall back to 0 in case of an error
const borrowRatePerBlockResult = marketContract.try_borrowRatePerBlock();
if (borrowRatePerBlockResult.reverted) {
market.borrowRateMantissa = zeroBigInt32;
} else {
market.borrowRateMantissa = borrowRatePerBlockResult.value;
}

market.supplyRateMantissa = marketContract.supplyRatePerBlock();
const supplyRatePerBlockResult = marketContract.try_supplyRatePerBlock();
if (supplyRatePerBlockResult.reverted) {
market.supplyRateMantissa = zeroBigInt32;
} else {
market.supplyRateMantissa = supplyRatePerBlockResult.value;
}

market.treasuryTotalBorrowsMantissa = marketContract.totalBorrows();
market.treasuryTotalSupplyMantissa = marketContract.totalSupply();
Expand Down

0 comments on commit 99d15c7

Please sign in to comment.