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