Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

minor changes and optimisations #2

Open
wants to merge 5 commits into
base: reaudit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions contracts/oracles/ChainlinkPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;

Expand Down Expand Up @@ -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)) {
Expand Down
12 changes: 6 additions & 6 deletions contracts/oracles/Keep3rPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand All @@ -49,25 +49,25 @@ 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);
}

/**
* @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);
}
}
19 changes: 17 additions & 2 deletions contracts/oracles/MasterPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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`.
*/
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/fee-distributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down