Skip to content

Commit

Permalink
refactor: wrap market calls with valueOrBigIntZeroIfReverted
Browse files Browse the repository at this point in the history
  • Loading branch information
gleiser-oliveira committed Jul 17, 2023
1 parent ff5ed22 commit db7f354
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions subgraphs/isolated-pools/src/operations/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,16 @@ export const updateMarket = (
market.accrualBlockNumber = marketContract.accrualBlockNumber().toI32();
market.blockTimestamp = blockTimestamp;

market.exchangeRateMantissa = marketContract.exchangeRateStored();
market.exchangeRateMantissa = valueOrBigIntZeroIfReverted(
marketContract.try_exchangeRateStored(),
);

market.borrowIndexMantissa = marketContract.borrowIndex();
market.borrowIndexMantissa = valueOrBigIntZeroIfReverted(marketContract.try_borrowIndex());

market.reservesMantissa = marketContract.totalReserves();
market.reservesMantissa = valueOrBigIntZeroIfReverted(marketContract.try_totalReserves());

market.cash = marketContract
.getCash()
const cashBigInt = valueOrBigIntZeroIfReverted(marketContract.try_getCash());
market.cash = cashBigInt
.toBigDecimal()
.div(exponentToBigDecimal(market.underlyingDecimals))
.truncate(market.underlyingDecimals);
Expand All @@ -203,8 +205,12 @@ export const updateMarket = (
market.borrowRateMantissa = valueOrBigIntZeroIfReverted(marketContract.try_borrowRatePerBlock());
market.supplyRateMantissa = valueOrBigIntZeroIfReverted(marketContract.try_supplyRatePerBlock());

market.treasuryTotalBorrowsMantissa = marketContract.totalBorrows();
market.treasuryTotalSupplyMantissa = marketContract.totalSupply();
market.treasuryTotalBorrowsMantissa = valueOrBigIntZeroIfReverted(
marketContract.try_totalBorrows(),
);
market.treasuryTotalSupplyMantissa = valueOrBigIntZeroIfReverted(
marketContract.try_totalSupply(),
);

market.save();
return market as Market;
Expand Down

0 comments on commit db7f354

Please sign in to comment.