From 262ca8bafb14cc42246ad299c9170841142efad9 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 14 Sep 2021 12:27:09 -0500 Subject: [PATCH] Add oracle failure blocking After consulting an oracle about the price of a token and receiving an error, any action (mint, redeem, borrow, repayBorrow) is blocked. --- contracts/ComptrollerG6.sol | 11 +++++++++++ contracts/mocks/MockPriceProviderMoC.sol | 13 +++++++++++++ instructions | 1 + 3 files changed, 25 insertions(+) diff --git a/contracts/ComptrollerG6.sol b/contracts/ComptrollerG6.sol index 1abda85..d3bbec2 100644 --- a/contracts/ComptrollerG6.sol +++ b/contracts/ComptrollerG6.sol @@ -308,6 +308,10 @@ contract ComptrollerG6 is minter; mintAmount; + if (oracle.getUnderlyingPrice(CToken(cToken)) == 0) { + return uint256(Error.PRICE_ERROR); + } + if (!markets[cToken].isListed) { return uint256(Error.MARKET_NOT_LISTED); } @@ -361,6 +365,9 @@ contract ComptrollerG6 is return allowed; } + if (oracle.getUnderlyingPrice(CToken(cToken)) == 0) { + return uint256(Error.PRICE_ERROR); + } // Keep the flywheel moving updateCompSupplyIndex(cToken); distributeSupplierComp(cToken, redeemer, false); @@ -535,6 +542,10 @@ contract ComptrollerG6 is borrower; repayAmount; + if (oracle.getUnderlyingPrice(CToken(cToken)) == 0) { + return uint256(Error.PRICE_ERROR); + } + if (!markets[cToken].isListed) { return uint256(Error.MARKET_NOT_LISTED); } diff --git a/contracts/mocks/MockPriceProviderMoC.sol b/contracts/mocks/MockPriceProviderMoC.sol index 232deac..301d23c 100644 --- a/contracts/mocks/MockPriceProviderMoC.sol +++ b/contracts/mocks/MockPriceProviderMoC.sol @@ -58,4 +58,17 @@ contract MockPriceProviderMoC { uint256(rbtcPrice) ); } + + /** + * @notice Set a new has state + * @param _has bool value for new has state + */ + function setHasState(bool _has) public { + require( + msg.sender == guardian, + "MockPriceProviderMoC: only guardian may set the address" + ); + + has = _has; + } } diff --git a/instructions b/instructions index 5ec67cb..1d5ccec 100644 --- a/instructions +++ b/instructions @@ -10,6 +10,7 @@ load = async() => { crbtc = await ethers.getContractAt('CRBTC', cRBTC, dep); csat = await ethers.getContractAt('CRBTC', cSAT, dep); priceOracleProxy = await ethers.getContractAt('PriceOracleProxy', PriceOracleProxy, dep); + rbtcOracle = await ethers.getContractAt('MockPriceProviderMoC', RBTCOracle, dep); whitelist = await ethers.getContractAt('Whitelist', Whitelist, dep); }