diff --git a/contracts/oracles/ChainlinkPriceOracle.sol b/contracts/oracles/ChainlinkPriceOracle.sol index 8f4a284..8b43eaf 100644 --- a/contracts/oracles/ChainlinkPriceOracle.sol +++ b/contracts/oracles/ChainlinkPriceOracle.sol @@ -20,6 +20,8 @@ import "./BasePriceOracle.sol"; contract ChainlinkPriceOracle is PriceOracle, BasePriceOracle { using SafeMathUpgradeable for uint256; + address constant private WETH_ADDRESS = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); + /** * @notice Maps ERC20 token addresses to ETH-based Chainlink price feed contracts. */ @@ -46,7 +48,7 @@ contract ChainlinkPriceOracle is PriceOracle, BasePriceOracle { AggregatorV3Interface public constant BTC_ETH_PRICE_FEED = AggregatorV3Interface(0xdeb288F737066589598e9214E782fa5A8eD689e8); /** - * @notice The maxmimum number of seconds elapsed since the round was last updated before the price is considered stale. If set to 0, no limit is enforced. + * @notice The maximum number of seconds elapsed since the round was last updated before the price is considered stale. If set to 0, no limit is enforced. */ uint256 public maxSecondsBeforePriceIsStale; @@ -167,7 +169,7 @@ contract ChainlinkPriceOracle is PriceOracle, BasePriceOracle { */ function _price(address underlying) internal view returns (uint) { // Return 1e18 for WETH - if (underlying == 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2) return 1e18; + if (underlying == WETH_ADDRESS) return 1e18; // Get token/ETH price from Chainlink if (address(ethPriceFeeds[underlying]) != address(0)) { diff --git a/contracts/oracles/Keep3rPriceOracle.sol b/contracts/oracles/Keep3rPriceOracle.sol index f720a49..f696187 100644 --- a/contracts/oracles/Keep3rPriceOracle.sol +++ b/contracts/oracles/Keep3rPriceOracle.sol @@ -30,12 +30,12 @@ contract Keep3rPriceOracle is PriceOracle, BasePriceOracle { /** * @dev mStable imUSD ERC20 token contract object. */ - Keep3rV1Oracle public oracle = Keep3rV1Oracle(0x73353801921417F465377c8d898c6f4C0270282C); + Keep3rV1Oracle immutable public oracle; /** * @dev WETH token contract address. */ - address constant public WETH_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; + address constant public WETH_ADDRESS = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); /** * @dev Returns the price in ETH of the token underlying `cToken` (implements `PriceOracle`). @@ -49,18 +49,17 @@ contract Keep3rPriceOracle is PriceOracle, BasePriceOracle { // Get price, format, and return uint256 baseUnit = 10 ** uint256(ERC20Upgradeable(underlying).decimals()); - return _price(underlying).mul(1e18).div(baseUnit); + return _price(underlying, baseUnit).mul(1e18).div(baseUnit); } /** * @dev Internal function returning the price in ETH of `underlying`. */ - function _price(address underlying) internal view returns (uint) { + function _price(address underlying, uint256 baseUnit) internal view returns (uint) { // Return 1e18 for WETH if (underlying == WETH_ADDRESS) return 1e18; // Call Keep3r for ERC20/ETH price and return - uint256 baseUnit = 10 ** uint256(ERC20Upgradeable(underlying).decimals()); return oracle.current(underlying, baseUnit, WETH_ADDRESS); } @@ -68,6 +67,7 @@ contract Keep3rPriceOracle is PriceOracle, BasePriceOracle { * @dev Returns the price in ETH of `underlying` (implements `BasePriceOracle`). */ function price(address underlying) external override view returns (uint) { - return _price(underlying); + uint256 baseUnit = 10 ** uint256(ERC20Upgradeable(underlying).decimals()); + return _price(underlying, baseUnit); } } diff --git a/contracts/oracles/MasterPriceOracle.sol b/contracts/oracles/MasterPriceOracle.sol index 1f7e846..30132ea 100644 --- a/contracts/oracles/MasterPriceOracle.sol +++ b/contracts/oracles/MasterPriceOracle.sol @@ -23,6 +23,8 @@ contract MasterPriceOracle is PriceOracle, BasePriceOracle { */ address public admin; + address constant private WETH_ADDRESS = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); + /** * @dev Controls if `admin` can overwrite existing assignments of oracles to underlying tokens. */ @@ -73,6 +75,19 @@ contract MasterPriceOracle is PriceOracle, BasePriceOracle { */ event NewAdmin(address oldAdmin, address newAdmin); + /** + * @dev Changes ability of admin to overwrite to false. This is irreversible! + */ + function revokeCanAdminOverwrite() external onlyAdmin { + canAdminOverwrite = false; + emit RevokeCanAdminOverwrite(msg.sender, false); + } + + /** + * @dev Event emitted when `canAdminOverwrite` is changed. + */ + event RevokeCanAdminOverwrite(address admin, bool canOverwrite); + /** * @dev Modifier that checks if `msg.sender == admin`. */ @@ -92,7 +107,7 @@ contract MasterPriceOracle is PriceOracle, BasePriceOracle { address underlying = address(CErc20(address(cToken)).underlying()); // Return 1e18 for WETH - if (underlying == 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2) return 1e18; + if (underlying == WETH_ADDRESS) return 1e18; // Get underlying price from assigned oracle return oracles[underlying].getUnderlyingPrice(cToken); @@ -103,7 +118,7 @@ contract MasterPriceOracle is PriceOracle, BasePriceOracle { */ function price(address underlying) external override view returns (uint) { // Return 1e18 for WETH - if (underlying == 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2) return 1e18; + if (underlying == WETH_ADDRESS) return 1e18; // Get underlying price from assigned oracle return BasePriceOracle(address(oracles[underlying])).price(underlying); diff --git a/test/fee-distributor.js b/test/fee-distributor.js index 12734b1..beef1ba 100644 --- a/test/fee-distributor.js +++ b/test/fee-distributor.js @@ -10,7 +10,7 @@ const IERC20Upgradeable = artifacts.require("IERC20Upgradeable"); contract("FuseFeeDistributor", accounts => { it("should withdraw ETH sent to the contract", async () => { let feeDistributorInstance = await FuseFeeDistributor.deployed(); - var amount = web3.utils.toBN(1e17); + var amount = web3.utils.toBN(1e16); await web3.eth.sendTransaction({ from: process.env.DEVELOPMENT_ADDRESS, to: FuseFeeDistributor.address, value: amount, gasPrice: 0 }); var accountBalanceBeforeWithdrawal = web3.utils.toBN(await web3.eth.getBalance(process.env.DEVELOPMENT_ADDRESS)); await feeDistributorInstance._withdrawAssets("0x0000000000000000000000000000000000000000", { from: process.env.DEVELOPMENT_ADDRESS, gasPrice: 0 });