From 3aa5de28b4b59b00b11515b9ee76ccad6bd19092 Mon Sep 17 00:00:00 2001 From: eboado Date: Fri, 6 Nov 2020 12:09:24 +0100 Subject: [PATCH] - Added management of WETH to ChainlinkProxyPriceProvider. --- contracts/misc/ChainlinkProxyPriceProvider.sol | 13 ++++++++++--- helpers/contracts-deployments.ts | 2 +- tasks/dev/4_oracles.ts | 7 +++++-- tasks/full/3_oracles.ts | 4 ++-- test/__setup.spec.ts | 1 + 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/contracts/misc/ChainlinkProxyPriceProvider.sol b/contracts/misc/ChainlinkProxyPriceProvider.sol index a259ba50..f6516abc 100644 --- a/contracts/misc/ChainlinkProxyPriceProvider.sol +++ b/contracts/misc/ChainlinkProxyPriceProvider.sol @@ -18,11 +18,13 @@ import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol'; contract ChainlinkProxyPriceProvider is IPriceOracleGetter, Ownable { using SafeERC20 for IERC20; + event WethSet(address indexed weth); event AssetSourceUpdated(address indexed asset, address indexed source); event FallbackOracleUpdated(address indexed fallbackOracle); mapping(address => IChainlinkAggregator) private assetsSources; IPriceOracleGetter private _fallbackOracle; + address public immutable WETH; /// @notice Constructor /// @param assets The addresses of the assets @@ -32,10 +34,13 @@ contract ChainlinkProxyPriceProvider is IPriceOracleGetter, Ownable { constructor( address[] memory assets, address[] memory sources, - address fallbackOracle + address fallbackOracle, + address weth ) public { _setFallbackOracle(fallbackOracle); _setAssetsSources(assets, sources); + WETH = weth; + emit WethSet(weth); } /// @notice External function called by the Aave governance to set or replace sources of assets @@ -77,8 +82,10 @@ contract ChainlinkProxyPriceProvider is IPriceOracleGetter, Ownable { /// @param asset The asset address function getAssetPrice(address asset) public override view returns (uint256) { IChainlinkAggregator source = assetsSources[asset]; - // If there is no registered source for the asset, call the fallbackOracle - if (address(source) == address(0)) { + + if (asset == WETH) { + return 1 ether; + } else if (address(source) == address(0)) { return _fallbackOracle.getAssetPrice(asset); } else { int256 price = IChainlinkAggregator(source).latestAnswer(); diff --git a/helpers/contracts-deployments.ts b/helpers/contracts-deployments.ts index bc5e7d81..019aff73 100644 --- a/helpers/contracts-deployments.ts +++ b/helpers/contracts-deployments.ts @@ -191,7 +191,7 @@ export const deployMockAggregator = async (price: tStringTokenSmallUnits, verify ); export const deployChainlinkProxyPriceProvider = async ( - args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress], + args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress], verify?: boolean ) => withSaveAndVerify( diff --git a/tasks/dev/4_oracles.ts b/tasks/dev/4_oracles.ts index 94b679e1..aea30974 100644 --- a/tasks/dev/4_oracles.ts +++ b/tasks/dev/4_oracles.ts @@ -13,7 +13,7 @@ import { import {ICommonConfiguration, iAssetBase, TokenContractId} from '../../helpers/types'; import {waitForTx} from '../../helpers/misc-utils'; import {getAllAggregatorsAddresses, getAllTokenAddresses} from '../../helpers/mock-helpers'; -import {ConfigNames, loadPoolConfig} from '../../helpers/configuration'; +import {ConfigNames, loadPoolConfig, getWethAddress} from '../../helpers/configuration'; import { getAllMockedTokens, getLendingPoolAddressesProvider, @@ -58,7 +58,10 @@ task('dev:deploy-oracles', 'Deploy oracles for dev enviroment') allAggregatorsAddresses ); - await deployChainlinkProxyPriceProvider([tokens, aggregators, fallbackOracle.address], verify); + await deployChainlinkProxyPriceProvider( + [tokens, aggregators, fallbackOracle.address, await getWethAddress(poolConfig)], + verify + ); await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address)); const lendingRateOracle = await deployLendingRateOracle(verify); diff --git a/tasks/full/3_oracles.ts b/tasks/full/3_oracles.ts index d5b4c3dc..6583523a 100644 --- a/tasks/full/3_oracles.ts +++ b/tasks/full/3_oracles.ts @@ -7,7 +7,7 @@ import { import {setInitialMarketRatesInRatesOracleByHelper} from '../../helpers/oracles-helpers'; import {ICommonConfiguration, eEthereumNetwork, SymbolMap} from '../../helpers/types'; import {waitForTx, filterMapBy} from '../../helpers/misc-utils'; -import {ConfigNames, loadPoolConfig} from '../../helpers/configuration'; +import {ConfigNames, loadPoolConfig, getWethAddress} from '../../helpers/configuration'; import {exit} from 'process'; import { getLendingPoolAddressesProvider, @@ -46,7 +46,7 @@ task('full:deploy-oracles', 'Deploy oracles for dev enviroment') const [tokens, aggregators] = getPairsTokenAggregator(tokensToWatch, chainlinkAggregators); const chainlinkProviderPriceProvider = await deployChainlinkProxyPriceProvider( - [tokens, aggregators, fallbackOracle], + [tokens, aggregators, fallbackOracle, await getWethAddress(poolConfig)], verify ); await waitForTx( diff --git a/test/__setup.spec.ts b/test/__setup.spec.ts index 738cd0f2..7d5db3e3 100644 --- a/test/__setup.spec.ts +++ b/test/__setup.spec.ts @@ -205,6 +205,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { tokens, aggregators, fallbackOracle.address, + mockTokens.WETH.address ]); await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));