feat: Add OracleQuoteUnit to configs and adapt deployment scripts to support the config change.

This commit is contained in:
David Racero 2021-05-27 09:35:14 +02:00
parent b54c6f8a24
commit 50f60a3666
12 changed files with 66 additions and 12 deletions

View File

@ -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);
}

View File

@ -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`;
}
};

View File

@ -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(

View File

@ -509,6 +509,7 @@ export interface IBaseConfiguration {
VariableDebtTokenImplementation?: iParamsPerNetwork<tEthereumAddress>;
ReserveAssets: iParamsPerNetwork<SymbolMap<tEthereumAddress>>;
OracleQuoteCurrency: string;
OracleQuoteUnit: string;
}
export interface ICommonConfiguration extends IBaseConfiguration {

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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));

View File

@ -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));

View File

@ -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();

View File

@ -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();