feat: Remove WETH mention from AaveOracle. Add QUOTE_CURRENCY and QUOTE_CURRENCY_UNIT to determine the quote currency of the price sources

This commit is contained in:
David Racero 2021-05-27 09:17:36 +02:00
parent 0242731f76
commit b54c6f8a24

View File

@ -18,13 +18,14 @@ import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol';
contract AaveOracle is IPriceOracleGetter, Ownable { contract AaveOracle is IPriceOracleGetter, Ownable {
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
event WethSet(address indexed weth); event QuoteCurrencySet(address indexed quoteCurrency, uint256 quoteUnit);
event AssetSourceUpdated(address indexed asset, address indexed source); event AssetSourceUpdated(address indexed asset, address indexed source);
event FallbackOracleUpdated(address indexed fallbackOracle); event FallbackOracleUpdated(address indexed fallbackOracle);
mapping(address => IChainlinkAggregator) private assetsSources; mapping(address => IChainlinkAggregator) private assetsSources;
IPriceOracleGetter private _fallbackOracle; IPriceOracleGetter private _fallbackOracle;
address public immutable WETH; address public immutable QUOTE_CURRENCY;
uint256 public immutable QUOTE_CURRENCY_UNIT;
/// @notice Constructor /// @notice Constructor
/// @param assets The addresses of the assets /// @param assets The addresses of the assets
@ -35,12 +36,14 @@ contract AaveOracle is IPriceOracleGetter, Ownable {
address[] memory assets, address[] memory assets,
address[] memory sources, address[] memory sources,
address fallbackOracle, address fallbackOracle,
address weth address quoteCurrency,
uint256 quoteCurrencyUnits
) public { ) public {
_setFallbackOracle(fallbackOracle); _setFallbackOracle(fallbackOracle);
_setAssetsSources(assets, sources); _setAssetsSources(assets, sources);
WETH = weth; QUOTE_CURRENCY = quoteCurrency;
emit WethSet(weth); QUOTE_CURRENCY_UNIT = quoteCurrencyUnits;
emit QuoteCurrencySet(quoteCurrency, quoteCurrencyUnits);
} }
/// @notice External function called by the Aave governance to set or replace sources of assets /// @notice External function called by the Aave governance to set or replace sources of assets
@ -83,8 +86,8 @@ contract AaveOracle is IPriceOracleGetter, Ownable {
function getAssetPrice(address asset) public view override returns (uint256) { function getAssetPrice(address asset) public view override returns (uint256) {
IChainlinkAggregator source = assetsSources[asset]; IChainlinkAggregator source = assetsSources[asset];
if (asset == WETH) { if (asset == QUOTE_CURRENCY) {
return 1 ether; return QUOTE_CURRENCY_UNIT;
} else if (address(source) == address(0)) { } else if (address(source) == address(0)) {
return _fallbackOracle.getAssetPrice(asset); return _fallbackOracle.getAssetPrice(asset);
} else { } else {