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

136 lines
4.4 KiB
TypeScript
Raw Normal View History

2020-11-05 11:18:20 +00:00
import {task} from 'hardhat/config';
import {
deployPriceOracle,
deployAaveOracle,
deployLendingRateOracle,
} from '../../helpers/contracts-deployments';
2020-08-25 12:15:35 +00:00
import {
setInitialAssetPricesInOracle,
2020-08-25 12:15:35 +00:00
deployAllMockAggregators,
setInitialMarketRatesInRatesOracleByHelper,
} from '../../helpers/oracles-helpers';
2020-08-25 12:15:35 +00:00
import {ICommonConfiguration, iAssetBase, TokenContractId} from '../../helpers/types';
import {waitForTx} from '../../helpers/misc-utils';
2020-08-21 11:07:32 +00:00
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) => {
2020-12-22 23:48:02 +00:00
await localBRE.run('set-DRE');
const poolConfig = loadPoolConfig(pool);
2020-12-22 23:48:02 +00:00
console.log("Initialized pool config...");
2020-08-25 12:15:35 +00:00
const {
2020-11-18 09:35:42 +00:00
Mocks: {AllAssetsInitialPrices},
2020-08-25 12:15:35 +00:00
ProtocolGlobalParams: {UsdAddress, MockUsdPriceInWei},
LendingRateOracleRatesCommon,
} = poolConfig as ICommonConfiguration;
2020-12-22 23:48:02 +00:00
console.log("Initialized mocks, global params and lending rate oracle rates");
2020-08-25 12:15:35 +00:00
const defaultTokenList = {
...Object.fromEntries(Object.keys(TokenContractId).map((symbol) => [symbol, ''])),
USD: UsdAddress,
} as iAssetBase<string>;
2020-12-22 23:48:02 +00:00
console.log("Initialized defaultTokenList");
2020-08-25 12:15:35 +00:00
const mockTokens = await getAllMockedTokens();
2020-12-22 23:48:02 +00:00
console.log("Initialized mock tokens");
2020-08-25 12:15:35 +00:00
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);
2020-12-22 23:48:02 +00:00
console.log(mockTokensAddress);
console.log("Initialized mock tokens addresses");
const addressesProvider = await getLendingPoolAddressesProvider();
2020-12-22 23:48:02 +00:00
2020-12-25 05:47:30 +00:00
console.log("Got the addresses provider (check if different both times):", addressesProvider.address);
2020-12-22 23:48:02 +00:00
2020-11-05 15:15:52 +00:00
const admin = await addressesProvider.getPoolAdmin();
2020-12-22 23:48:02 +00:00
console.log("Got the admin");
const fallbackOracle = await deployPriceOracle(verify);
2020-12-22 23:48:02 +00:00
console.log("Deployed fallback price oracle");
2020-08-25 12:15:35 +00:00
await waitForTx(await fallbackOracle.setEthUsdPrice(MockUsdPriceInWei));
2020-12-22 23:48:02 +00:00
console.log("set fallback ETH USD price");
2020-08-25 12:15:35 +00:00
await setInitialAssetPricesInOracle(AllAssetsInitialPrices, mockTokensAddress, fallbackOracle);
2020-12-22 23:48:02 +00:00
console.log("Set initial asset prices in oracle");
2020-11-18 09:35:42 +00:00
const mockAggregators = await deployAllMockAggregators(AllAssetsInitialPrices, verify);
2020-12-22 23:48:02 +00:00
console.log("Deployed mock aggregators");
2020-08-21 11:07:32 +00:00
const allTokenAddresses = getAllTokenAddresses(mockTokens);
2020-12-22 23:48:02 +00:00
console.log("Got all mock token addresses");
2020-08-21 11:07:32 +00:00
const allAggregatorsAddresses = getAllAggregatorsAddresses(mockAggregators);
2020-12-22 23:48:02 +00:00
console.log("Got all aggregator addresses");
const [tokens, aggregators] = getPairsTokenAggregator(
allTokenAddresses,
allAggregatorsAddresses
);
2020-12-22 23:48:02 +00:00
console.log("Got \"pairsToken aggregator\"");
await deployAaveOracle(
[tokens, aggregators, fallbackOracle.address, await getWethAddress(poolConfig)],
verify
);
2020-12-22 23:48:02 +00:00
console.log("Deployed Aave oracle");
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
2020-12-22 23:48:02 +00:00
console.log("Set price oracle in addresses provider");
2020-08-21 11:07:32 +00:00
const lendingRateOracle = await deployLendingRateOracle(verify);
2020-12-22 23:48:02 +00:00
console.log("Deployed lendingRateOracle");
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
2020-12-22 23:48:02 +00:00
console.log("Set lending rate oracle in addresses provider");
const {USD, ...tokensAddressesWithoutUsd} = allTokenAddresses;
2020-12-22 23:48:02 +00:00
console.log("Initialized object with token addresses & usd")
const allReservesAddresses = {
...tokensAddressesWithoutUsd,
};
2020-12-22 23:48:02 +00:00
console.log("Initialized object with all reserve addresses, allReservesAddresses:");
console.log(allReservesAddresses);
await setInitialMarketRatesInRatesOracleByHelper(
2020-08-25 12:15:35 +00:00
LendingRateOracleRatesCommon,
allReservesAddresses,
lendingRateOracle,
admin
);
2020-12-22 23:48:02 +00:00
console.log("Task complete");
});