diff --git a/contracts/interfaces/IPriceOracleGetter.sol b/contracts/interfaces/IPriceOracleGetter.sol index d6f37035..e16f89a2 100644 --- a/contracts/interfaces/IPriceOracleGetter.sol +++ b/contracts/interfaces/IPriceOracleGetter.sol @@ -8,9 +8,9 @@ pragma solidity 0.6.12; interface IPriceOracleGetter { /** - * @dev returns the asset price in ETH + * @dev returns the asset price in Quote currency * @param asset the address of the asset - * @return the ETH price of the asset + * @return the price of the asset in Quote currency **/ function getAssetPrice(address asset) external view returns (uint256); } diff --git a/helpers/configuration.ts b/helpers/configuration.ts index 0bad185b..1d706ba2 100644 --- a/helpers/configuration.ts +++ b/helpers/configuration.ts @@ -144,3 +144,15 @@ export const getLendingRateOracles = (poolConfig: IBaseConfiguration) => { Object.keys(ReserveAssets[network]).includes(key) ); }; + +export const getQuoteCurrency = async (config: IBaseConfiguration) => { + switch (config.OracleQuoteCurrency) { + case 'ETH': + case 'WETH': + return getWethAddress(config); + case 'USD': + return config.ProtocolGlobalParams.UsdAddress; + default: + throw `Quote ${config.OracleQuoteCurrency} currency not set. Add a new case to getQuoteCurrency switch`; + } +}; diff --git a/helpers/contracts-deployments.ts b/helpers/contracts-deployments.ts index bc55fb26..9572a648 100644 --- a/helpers/contracts-deployments.ts +++ b/helpers/contracts-deployments.ts @@ -225,7 +225,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/helpers/types.ts b/helpers/types.ts index e57f23c1..d481f994 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -509,6 +509,7 @@ export interface IBaseConfiguration { VariableDebtTokenImplementation?: iParamsPerNetwork; ReserveAssets: iParamsPerNetwork>; OracleQuoteCurrency: string; + OracleQuoteUnit: string; } export interface ICommonConfiguration extends IBaseConfiguration { diff --git a/markets/aave/commons.ts b/markets/aave/commons.ts index 1475edac..df66d528 100644 --- a/markets/aave/commons.ts +++ b/markets/aave/commons.ts @@ -1,4 +1,9 @@ -import { oneRay, ZERO_ADDRESS, MOCK_CHAINLINK_AGGREGATORS_PRICES } from '../../helpers/constants'; +import { + oneRay, + ZERO_ADDRESS, + MOCK_CHAINLINK_AGGREGATORS_PRICES, + oneEther, +} from '../../helpers/constants'; import { ICommonConfiguration, eEthereumNetwork } from '../../helpers/types'; // ---------------- @@ -13,6 +18,7 @@ export const CommonsConfig: ICommonConfiguration = { SymbolPrefix: '', ProviderId: 0, // Overriden in index.ts OracleQuoteCurrency: 'ETH', + OracleQuoteUnit: oneEther.toString(), ProtocolGlobalParams: { TokenDistributorPercentageBase: '10000', MockUsdPriceInWei: '5848466240000000', diff --git a/markets/amm/commons.ts b/markets/amm/commons.ts index ee6f6a59..f752ea2c 100644 --- a/markets/amm/commons.ts +++ b/markets/amm/commons.ts @@ -5,6 +5,7 @@ import { RAY, ZERO_ADDRESS, MOCK_CHAINLINK_AGGREGATORS_PRICES, + oneUsd, } from '../../helpers/constants'; import { ICommonConfiguration, eEthereumNetwork } from '../../helpers/types'; @@ -20,6 +21,7 @@ export const CommonsConfig: ICommonConfiguration = { SymbolPrefix: 'Amm', ProviderId: 0, // Overriden in index.ts OracleQuoteCurrency: 'ETH', + OracleQuoteUnit: oneEther.toString(), ProtocolGlobalParams: { TokenDistributorPercentageBase: '10000', MockUsdPriceInWei: '5848466240000000', diff --git a/markets/matic/commons.ts b/markets/matic/commons.ts index 2832d25a..dc6fb173 100644 --- a/markets/matic/commons.ts +++ b/markets/matic/commons.ts @@ -20,6 +20,7 @@ export const CommonsConfig: ICommonConfiguration = { SymbolPrefix: 'm', ProviderId: 0, // Overriden in index.ts OracleQuoteCurrency: 'ETH', + OracleQuoteUnit: oneEther.toString(), ProtocolGlobalParams: { TokenDistributorPercentageBase: '10000', MockUsdPriceInWei: '5848466240000000', diff --git a/markets/usd-amm/index.ts b/markets/usd-amm/index.ts index a6c06873..3d8193bf 100644 --- a/markets/usd-amm/index.ts +++ b/markets/usd-amm/index.ts @@ -1,5 +1,6 @@ import { MOCK_CHAINLINK_AGGREGATORS_USD_CURVE_AMM_PRICES, + oneUsd, ZERO_ADDRESS, } from '../../helpers/constants'; import { eEthereumNetwork, IUsdAmmConfiguration } from '../../helpers/types'; @@ -26,6 +27,7 @@ export const AmmConfig: IUsdAmmConfiguration = { VariableDebtTokenNamePrefix: 'Aave USD AMM Market variable debt', SymbolPrefix: 'usdAmm', OracleQuoteCurrency: 'USD', + OracleQuoteUnit: oneUsd.toString(), ProtocolGlobalParams: { TokenDistributorPercentageBase: '10000', MockUsdPriceInWei: '10000000', diff --git a/tasks/dev/4_oracles.ts b/tasks/dev/4_oracles.ts index 02f951af..38228e5b 100644 --- a/tasks/dev/4_oracles.ts +++ b/tasks/dev/4_oracles.ts @@ -12,14 +12,19 @@ import { import { ICommonConfiguration, iAssetBase, TokenContractId } from '../../helpers/types'; import { waitForTx } from '../../helpers/misc-utils'; import { getAllAggregatorsAddresses, getAllTokenAddresses } from '../../helpers/mock-helpers'; -import { ConfigNames, loadPoolConfig, getWethAddress } from '../../helpers/configuration'; +import { + ConfigNames, + loadPoolConfig, + getWethAddress, + getQuoteCurrency, +} from '../../helpers/configuration'; import { getAllMockedTokens, getLendingPoolAddressesProvider, getPairsTokenAggregator, } from '../../helpers/contracts-getters'; -task('dev:deploy-oracles', 'Deploy oracles for dev enviroment') +task('dev:deploy-oracles', 'Deploy oracles for dev environment') .addFlag('verify', 'Verify contracts at Etherscan') .addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`) .setAction(async ({ verify, pool }, localBRE) => { @@ -60,7 +65,13 @@ task('dev:deploy-oracles', 'Deploy oracles for dev enviroment') ); await deployAaveOracle( - [tokens, aggregators, fallbackOracle.address, await getWethAddress(poolConfig)], + [ + tokens, + aggregators, + fallbackOracle.address, + await getQuoteCurrency(poolConfig), + pool.OracleQuoteUnit, + ], verify ); await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address)); diff --git a/tasks/full/3_oracles.ts b/tasks/full/3_oracles.ts index c056d943..9c29cd4a 100644 --- a/tasks/full/3_oracles.ts +++ b/tasks/full/3_oracles.ts @@ -10,6 +10,7 @@ import { getWethAddress, getGenesisPoolAdmin, getLendingRateOracles, + getQuoteCurrency, } from '../../helpers/configuration'; import { getAaveOracle, @@ -59,7 +60,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 getQuoteCurrency(poolConfig), + poolConfig.OracleQuoteUnit, + ], 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 f89e93bd..69afa212 100644 --- a/test-suites/test-aave/__setup.spec.ts +++ b/test-suites/test-aave/__setup.spec.ts @@ -49,7 +49,7 @@ import { import { DRE, waitForTx } from '../../helpers/misc-utils'; import { initReservesByHelper, configureReservesByHelper } from '../../helpers/init-helpers'; import AaveConfig from '../../markets/aave'; -import { ZERO_ADDRESS } from '../../helpers/constants'; +import { oneEther, ZERO_ADDRESS } from '../../helpers/constants'; import { getLendingPool, getLendingPoolConfiguratorProxy, @@ -226,7 +226,13 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { config.OracleQuoteCurrency ); - await deployAaveOracle([tokens, aggregators, fallbackOracle.address, mockTokens.WETH.address]); + await deployAaveOracle([ + tokens, + aggregators, + fallbackOracle.address, + mockTokens.WETH.address, + oneEther.toString(), + ]); await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address)); const lendingRateOracle = await deployLendingRateOracle(); diff --git a/test-suites/test-amm/__setup.spec.ts b/test-suites/test-amm/__setup.spec.ts index d7d3cea3..407ec844 100644 --- a/test-suites/test-amm/__setup.spec.ts +++ b/test-suites/test-amm/__setup.spec.ts @@ -48,7 +48,7 @@ import { import { DRE, waitForTx } from '../../helpers/misc-utils'; import { initReservesByHelper, configureReservesByHelper } from '../../helpers/init-helpers'; import AmmConfig from '../../markets/amm'; -import { ZERO_ADDRESS } from '../../helpers/constants'; +import { oneEther, ZERO_ADDRESS } from '../../helpers/constants'; import { getLendingPool, getLendingPoolConfiguratorProxy, @@ -226,7 +226,13 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { config.OracleQuoteCurrency ); - await deployAaveOracle([tokens, aggregators, fallbackOracle.address, mockTokens.WETH.address]); + await deployAaveOracle([ + tokens, + aggregators, + fallbackOracle.address, + mockTokens.WETH.address, + oneEther.toString(), + ]); await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address)); const lendingRateOracle = await deployLendingRateOracle();