From 8297b000fcb48c0f728346c524d7df327b36deb3 Mon Sep 17 00:00:00 2001 From: The3D Date: Fri, 16 Jul 2021 19:26:49 +0200 Subject: [PATCH] refactor: generalized the AaveOracle variables and event names --- contracts/misc/AaveOracle.sol | 19 ++++++++++++------- helpers/contracts-deployments.ts | 8 ++++---- tasks/dev/4_oracles.ts | 9 ++++++++- tasks/full/3_oracles.ts | 9 ++++++++- test-suites/test-aave/__setup.spec.ts | 18 ++++++++++-------- test-suites/test-amm/__setup.spec.ts | 4 ++-- 6 files changed, 44 insertions(+), 23 deletions(-) diff --git a/contracts/misc/AaveOracle.sol b/contracts/misc/AaveOracle.sol index 0cb8e180..bc921468 100644 --- a/contracts/misc/AaveOracle.sol +++ b/contracts/misc/AaveOracle.sol @@ -18,29 +18,34 @@ import {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol'; contract AaveOracle is IPriceOracleGetter, Ownable { using SafeERC20 for IERC20; - event WethSet(address indexed weth); + event BaseCurrencySet(address indexed baseCurrency, uint256 baseCurrencyUnit); 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; + address public immutable BASE_CURRENCY; + uint256 public immutable BASE_CURRENCY_UNIT; /// @notice Constructor /// @param assets The addresses of the assets /// @param sources The address of the source of each asset /// @param fallbackOracle The address of the fallback oracle to use if the data of an /// aggregator is not consistent + /// @param baseCurrency the base currency used for the price quotes. If USD is used, base currency is 0x0 + /// @param baseCurrencyUnit the unit of the base currency constructor( address[] memory assets, address[] memory sources, address fallbackOracle, - address weth + address baseCurrency, + uint256 baseCurrencyUnit ) public { _setFallbackOracle(fallbackOracle); _setAssetsSources(assets, sources); - WETH = weth; - emit WethSet(weth); + BASE_CURRENCY = baseCurrency; + BASE_CURRENCY_UNIT = baseCurrencyUnit; + emit BaseCurrencySet(baseCurrency, baseCurrencyUnit); } /// @notice External function called by the Aave governance to set or replace sources of assets @@ -83,8 +88,8 @@ contract AaveOracle is IPriceOracleGetter, Ownable { function getAssetPrice(address asset) public view override returns (uint256) { IChainlinkAggregator source = assetsSources[asset]; - if (asset == WETH) { - return 1 ether; + if (asset == BASE_CURRENCY) { + return BASE_CURRENCY_UNIT; } else if (address(source) == address(0)) { return _fallbackOracle.getAssetPrice(asset); } else { diff --git a/helpers/contracts-deployments.ts b/helpers/contracts-deployments.ts index 05f79206..f1ad477e 100644 --- a/helpers/contracts-deployments.ts +++ b/helpers/contracts-deployments.ts @@ -1,4 +1,4 @@ -import { Contract } from 'ethers'; +import { BigNumberish, Contract } from 'ethers'; import { DRE } from './misc-utils'; import { tEthereumAddress, @@ -188,8 +188,8 @@ export const deployAaveLibraries = async ( return { ['__$de8c0cf1a7d7c36c802af9a64fb9d86036$__']: validationLogic.address, ['__$22cd43a9dda9ce44e9b92ba393b88fb9ac$__']: reserveLogic.address, - ["__$52a8a86ab43135662ff256bbc95497e8e3$__"]: genericLogic.address, - } + ['__$52a8a86ab43135662ff256bbc95497e8e3$__']: genericLogic.address, + }; }; export const deployLendingPool = async (verify?: boolean) => { @@ -224,7 +224,7 @@ export const deployMockAggregator = async (price: tStringTokenSmallUnits, verify ); export const deployAaveOracle = async ( - args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress], + args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress, tEthereumAddress, string], verify?: boolean ) => withSaveAndVerify( diff --git a/tasks/dev/4_oracles.ts b/tasks/dev/4_oracles.ts index 23c24133..23be80f2 100644 --- a/tasks/dev/4_oracles.ts +++ b/tasks/dev/4_oracles.ts @@ -18,6 +18,7 @@ import { getLendingPoolAddressesProvider, getPairsTokenAggregator, } from '../../helpers/contracts-getters'; +import { ethers } from 'ethers'; task('dev:deploy-oracles', 'Deploy oracles for dev enviroment') .addFlag('verify', 'Verify contracts at Etherscan') @@ -58,7 +59,13 @@ task('dev:deploy-oracles', 'Deploy oracles for dev enviroment') ); await deployAaveOracle( - [tokens, aggregators, fallbackOracle.address, await getWethAddress(poolConfig)], + [ + tokens, + aggregators, + fallbackOracle.address, + await getWethAddress(poolConfig), + ethers.constants.WeiPerEther.toString(), + ], verify ); await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address)); diff --git a/tasks/full/3_oracles.ts b/tasks/full/3_oracles.ts index df06f34c..dfc6f247 100644 --- a/tasks/full/3_oracles.ts +++ b/tasks/full/3_oracles.ts @@ -18,6 +18,7 @@ import { getPairsTokenAggregator, } from '../../helpers/contracts-getters'; import { AaveOracle, LendingRateOracle } from '../../types'; +import { ethers } from 'ethers'; task('full:deploy-oracles', 'Deploy oracles for dev enviroment') .addFlag('verify', 'Verify contracts at Etherscan') @@ -55,7 +56,13 @@ task('full:deploy-oracles', 'Deploy oracles for dev enviroment') aaveOracle = await await getAaveOracle(aaveOracleAddress); } else { aaveOracle = await deployAaveOracle( - [tokens, aggregators, fallbackOracleAddress, await getWethAddress(poolConfig)], + [ + tokens, + aggregators, + fallbackOracleAddress, + await getWethAddress(poolConfig), + ethers.constants.WeiPerEther.toString(), + ], verify ); await waitForTx(await aaveOracle.setAssetSources(tokens, aggregators)); diff --git a/test-suites/test-aave/__setup.spec.ts b/test-suites/test-aave/__setup.spec.ts index 2ef2f3a0..ba58252e 100644 --- a/test-suites/test-aave/__setup.spec.ts +++ b/test-suites/test-aave/__setup.spec.ts @@ -30,7 +30,7 @@ import { authorizeWETHGateway, } from '../../helpers/contracts-deployments'; import { eEthereumNetwork } from '../../helpers/types'; -import { Signer } from 'ethers'; +import { ethers, Signer } from 'ethers'; import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types'; import { MintableERC20 } from '../../types/MintableERC20'; import { @@ -215,7 +215,13 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { const [tokens, aggregators] = getPairsTokenAggregator(allTokenAddresses, allAggregatorsAddresses); - await deployAaveOracle([tokens, aggregators, fallbackOracle.address, mockTokens.WETH.address]); + await deployAaveOracle([ + tokens, + aggregators, + fallbackOracle.address, + mockTokens.WETH.address, + ethers.constants.WeiPerEther.toString(), + ]); await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address)); const lendingRateOracle = await deployLendingRateOracle(); @@ -243,12 +249,8 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { const config = loadPoolConfig(ConfigNames.Aave); - const { - ATokenNamePrefix, - StableDebtTokenNamePrefix, - VariableDebtTokenNamePrefix, - SymbolPrefix, - } = config; + const { ATokenNamePrefix, StableDebtTokenNamePrefix, VariableDebtTokenNamePrefix, SymbolPrefix } = + config; const treasuryAddress = await getTreasuryAddress(config); await initReservesByHelper( diff --git a/test-suites/test-amm/__setup.spec.ts b/test-suites/test-amm/__setup.spec.ts index 0fae3acd..db75799f 100644 --- a/test-suites/test-amm/__setup.spec.ts +++ b/test-suites/test-amm/__setup.spec.ts @@ -29,7 +29,7 @@ import { deployFlashLiquidationAdapter, authorizeWETHGateway, } from '../../helpers/contracts-deployments'; -import { Signer } from 'ethers'; +import { ethers, Signer } from 'ethers'; import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../../helpers/types'; import { MintableERC20 } from '../../types/MintableERC20'; import { @@ -212,7 +212,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { const [tokens, aggregators] = getPairsTokenAggregator(allTokenAddresses, allAggregatorsAddresses); - await deployAaveOracle([tokens, aggregators, fallbackOracle.address, mockTokens.WETH.address]); + await deployAaveOracle([tokens, aggregators, fallbackOracle.address, mockTokens.WETH.address, ethers.constants.WeiPerEther.toString()]); await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address)); const lendingRateOracle = await deployLendingRateOracle();