Skip to content

Commit

Permalink
fix: fall back to reserve price feed
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed May 14, 2024
1 parent 6bf3acb commit 734b42a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions contracts/PriceHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,21 @@ contract PriceHelper is IPriceHelper {
function _getUncheckedPrice(address oracle, address token) internal view returns (uint256 price, uint256 scale) {
IPriceOracleV3 priceOracle = IPriceOracleV3(oracle);

// check main price feed only
// check main price feed
IPriceFeed priceFeed = IPriceFeed(priceOracle.priceFeedsRaw(token, false));
uint8 decimals = priceFeed.decimals();
(, int256 answer,,,) = priceFeed.latestRoundData();
try priceFeed.latestRoundData() returns (uint80, int256 answer, uint256, uint256, uint80) {
price = uint256(answer);
} catch {
// Try reserve price feed
priceFeed = IPriceFeed(priceOracle.priceFeedsRaw(token, true));
decimals = priceFeed.decimals();
(, int256 answer,,,) = priceFeed.latestRoundData();
price = uint256(answer);
}

price = uint256(answer);
unchecked {
scale = 10 ** decimals; // U:[PO-1]
scale = 10 ** decimals;
}
}
}

0 comments on commit 734b42a

Please sign in to comment.