aave-protocol-v2/tasks/dev/4_oracles.ts

80 lines
3.1 KiB
TypeScript
Raw Normal View History

import { task } from 'hardhat/config';
import {
deployPriceOracle,
deployAaveOracle,
deployLendingRateOracle,
} from '../../helpers/contracts-deployments';
import {
setInitialAssetPricesInOracle,
2020-08-25 12:15:35 +00:00
deployAllMockAggregators,
setInitialMarketRatesInRatesOracleByHelper,
} from '../../helpers/oracles-helpers';
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 {
getAllMockedTokens,
getLendingPoolAddressesProvider,
getPairsTokenAggregator,
} from '../../helpers/contracts-getters';
task('dev:deploy-oracles', 'Deploy oracles for dev enviroment')
.addFlag('verify', 'Verify contracts at Etherscan')
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
.setAction(async ({ verify, pool }, localBRE) => {
await localBRE.run('set-DRE');
const poolConfig = loadPoolConfig(pool);
2020-08-25 12:15:35 +00:00
const {
Mocks: { AllAssetsInitialPrices },
ProtocolGlobalParams: { UsdAddress, MockUsdPriceInWei },
2020-08-25 12:15:35 +00:00
LendingRateOracleRatesCommon,
} = poolConfig as ICommonConfiguration;
2020-08-25 12:15:35 +00:00
const defaultTokenList = {
...Object.fromEntries(Object.keys(TokenContractId).map((symbol) => [symbol, ''])),
USD: UsdAddress,
} as iAssetBase<string>;
const mockTokens = await getAllMockedTokens();
const mockTokensAddress = Object.keys(mockTokens).reduce<iAssetBase<string>>((prev, curr) => {
prev[curr as keyof iAssetBase<string>] = mockTokens[curr].address;
2020-08-25 12:15:35 +00:00
return prev;
}, defaultTokenList);
const addressesProvider = await getLendingPoolAddressesProvider();
2020-11-05 15:15:52 +00:00
const admin = await addressesProvider.getPoolAdmin();
const fallbackOracle = await deployPriceOracle(verify);
2020-08-25 12:15:35 +00:00
await waitForTx(await fallbackOracle.setEthUsdPrice(MockUsdPriceInWei));
await setInitialAssetPricesInOracle(AllAssetsInitialPrices, mockTokensAddress, fallbackOracle);
2020-11-18 09:35:42 +00:00
const mockAggregators = await deployAllMockAggregators(AllAssetsInitialPrices, verify);
2020-08-21 11:07:32 +00:00
const allTokenAddresses = getAllTokenAddresses(mockTokens);
const allAggregatorsAddresses = getAllAggregatorsAddresses(mockAggregators);
const [tokens, aggregators] = getPairsTokenAggregator(
allTokenAddresses,
allAggregatorsAddresses
);
await deployAaveOracle(
[tokens, aggregators, fallbackOracle.address, await getWethAddress(poolConfig)],
verify
);
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
2020-08-21 11:07:32 +00:00
const lendingRateOracle = await deployLendingRateOracle(verify);
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
const { USD, ...tokensAddressesWithoutUsd } = allTokenAddresses;
const allReservesAddresses = {
...tokensAddressesWithoutUsd,
};
await setInitialMarketRatesInRatesOracleByHelper(
2020-08-25 12:15:35 +00:00
LendingRateOracleRatesCommon,
allReservesAddresses,
lendingRateOracle,
admin
);
});