2020-11-05 11:18:20 +00:00
|
|
|
import {task} from 'hardhat/config';
|
2020-10-16 09:27:09 +00:00
|
|
|
import {getParamPerNetwork} from '../../helpers/contracts-helpers';
|
2020-08-31 10:10:40 +00:00
|
|
|
import {
|
|
|
|
deployChainlinkProxyPriceProvider,
|
|
|
|
deployLendingRateOracle,
|
2020-10-16 09:27:09 +00:00
|
|
|
} from '../../helpers/contracts-deployments';
|
2020-10-27 09:58:51 +00:00
|
|
|
import {setInitialMarketRatesInRatesOracleByHelper} from '../../helpers/oracles-helpers';
|
2020-08-31 10:10:40 +00:00
|
|
|
import {ICommonConfiguration, eEthereumNetwork, SymbolMap} from '../../helpers/types';
|
|
|
|
import {waitForTx, filterMapBy} from '../../helpers/misc-utils';
|
|
|
|
import {ConfigNames, loadPoolConfig} from '../../helpers/configuration';
|
2020-09-24 15:48:29 +00:00
|
|
|
import {exit} from 'process';
|
2020-10-15 11:57:03 +00:00
|
|
|
import {
|
|
|
|
getLendingPoolAddressesProvider,
|
|
|
|
getPairsTokenAggregator,
|
|
|
|
} from '../../helpers/contracts-getters';
|
2020-08-31 10:10:40 +00:00
|
|
|
|
|
|
|
task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
|
2020-09-24 15:48:29 +00:00
|
|
|
.addFlag('verify', 'Verify contracts at Etherscan')
|
2020-08-31 10:10:40 +00:00
|
|
|
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
|
|
|
|
.setAction(async ({verify, pool}, localBRE) => {
|
2020-09-24 15:48:29 +00:00
|
|
|
try {
|
2020-11-05 12:44:20 +00:00
|
|
|
await localBRE.run('set-DRE');
|
2020-09-24 15:48:29 +00:00
|
|
|
const network = <eEthereumNetwork>localBRE.network.name;
|
|
|
|
const poolConfig = loadPoolConfig(pool);
|
|
|
|
const {
|
|
|
|
ProtocolGlobalParams: {UsdAddress},
|
|
|
|
LendingRateOracleRatesCommon,
|
|
|
|
ReserveAssets,
|
|
|
|
FallbackOracle,
|
|
|
|
ChainlinkAggregator,
|
|
|
|
} = poolConfig as ICommonConfiguration;
|
|
|
|
const lendingRateOracles = filterMapBy(LendingRateOracleRatesCommon, (key) =>
|
2020-11-04 10:47:06 +00:00
|
|
|
Object.keys(ReserveAssets[network]).includes(key)
|
2020-09-24 15:48:29 +00:00
|
|
|
);
|
|
|
|
const addressesProvider = await getLendingPoolAddressesProvider();
|
2020-10-27 09:58:51 +00:00
|
|
|
const admin = await addressesProvider.getAaveAdmin();
|
2020-09-24 15:48:29 +00:00
|
|
|
|
|
|
|
const fallbackOracle = await getParamPerNetwork(FallbackOracle, network);
|
|
|
|
const reserveAssets = await getParamPerNetwork(ReserveAssets, network);
|
|
|
|
const chainlinkAggregators = await getParamPerNetwork(ChainlinkAggregator, network);
|
|
|
|
|
|
|
|
const tokensToWatch: SymbolMap<string> = {
|
|
|
|
...reserveAssets,
|
|
|
|
USD: UsdAddress,
|
|
|
|
};
|
|
|
|
const [tokens, aggregators] = getPairsTokenAggregator(tokensToWatch, chainlinkAggregators);
|
|
|
|
|
|
|
|
const chainlinkProviderPriceProvider = await deployChainlinkProxyPriceProvider(
|
|
|
|
[tokens, aggregators, fallbackOracle],
|
|
|
|
verify
|
|
|
|
);
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setPriceOracle(chainlinkProviderPriceProvider.address)
|
|
|
|
);
|
|
|
|
|
|
|
|
const lendingRateOracle = await deployLendingRateOracle(verify);
|
|
|
|
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
|
|
|
|
|
|
|
|
const {USD, ...tokensAddressesWithoutUsd} = tokensToWatch;
|
2020-10-27 09:58:51 +00:00
|
|
|
await setInitialMarketRatesInRatesOracleByHelper(
|
2020-09-24 15:48:29 +00:00
|
|
|
lendingRateOracles,
|
|
|
|
tokensAddressesWithoutUsd,
|
2020-10-27 09:58:51 +00:00
|
|
|
lendingRateOracle,
|
|
|
|
admin
|
2020-09-24 15:48:29 +00:00
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
exit(1);
|
|
|
|
}
|
2020-08-31 10:10:40 +00:00
|
|
|
});
|