2020-11-05 11:18:20 +00:00
|
|
|
import {task} from 'hardhat/config';
|
2020-11-18 09:33:44 +00:00
|
|
|
import {getParamPerNetwork} from '../../helpers/contracts-helpers';
|
2020-11-17 09:24:24 +00:00
|
|
|
import {deployAaveOracle, deployLendingRateOracle} 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';
|
2020-11-18 09:33:44 +00:00
|
|
|
import {waitForTx, notFalsyOrZeroAddress} from '../../helpers/misc-utils';
|
2020-11-12 13:12:26 +00:00
|
|
|
import {
|
|
|
|
ConfigNames,
|
|
|
|
loadPoolConfig,
|
|
|
|
getWethAddress,
|
|
|
|
getGenesisPoolAdmin,
|
2020-11-16 15:08:07 +00:00
|
|
|
getLendingRateOracles,
|
2020-11-12 13:12:26 +00:00
|
|
|
} from '../../helpers/configuration';
|
2020-10-15 11:57:03 +00:00
|
|
|
import {
|
2020-11-12 13:12:26 +00:00
|
|
|
getChainlinkPriceProvider,
|
2020-10-15 11:57:03 +00:00
|
|
|
getLendingPoolAddressesProvider,
|
2020-11-12 13:12:26 +00:00
|
|
|
getLendingRateOracle,
|
2020-10-15 11:57:03 +00:00
|
|
|
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)}`)
|
2020-11-16 15:08:07 +00:00
|
|
|
.setAction(async ({verify, pool}, DRE) => {
|
2020-09-24 15:48:29 +00:00
|
|
|
try {
|
2020-11-16 15:08:07 +00:00
|
|
|
await DRE.run('set-DRE');
|
|
|
|
const network = <eEthereumNetwork>DRE.network.name;
|
2020-09-24 15:48:29 +00:00
|
|
|
const poolConfig = loadPoolConfig(pool);
|
|
|
|
const {
|
|
|
|
ProtocolGlobalParams: {UsdAddress},
|
|
|
|
ReserveAssets,
|
|
|
|
FallbackOracle,
|
|
|
|
ChainlinkAggregator,
|
|
|
|
} = poolConfig as ICommonConfiguration;
|
2020-11-16 15:08:07 +00:00
|
|
|
const lendingRateOracles = getLendingRateOracles(poolConfig);
|
2020-09-24 15:48:29 +00:00
|
|
|
const addressesProvider = await getLendingPoolAddressesProvider();
|
2020-11-12 13:12:26 +00:00
|
|
|
const admin = await getGenesisPoolAdmin(poolConfig);
|
|
|
|
const proxyPriceProviderAddress = getParamPerNetwork(poolConfig.ProxyPriceProvider, network);
|
|
|
|
const lendingRateOracleAddress = getParamPerNetwork(poolConfig.LendingRateOracle, network);
|
2020-11-16 15:08:07 +00:00
|
|
|
const fallbackOracleAddress = await getParamPerNetwork(FallbackOracle, network);
|
2020-09-24 15:48:29 +00:00
|
|
|
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);
|
|
|
|
|
2020-11-16 15:08:07 +00:00
|
|
|
const chainlinkProviderPriceProvider = notFalsyOrZeroAddress(proxyPriceProviderAddress)
|
2020-11-12 13:12:26 +00:00
|
|
|
? await getChainlinkPriceProvider(proxyPriceProviderAddress)
|
2020-11-17 09:24:24 +00:00
|
|
|
: await deployAaveOracle(
|
2020-11-16 15:08:07 +00:00
|
|
|
[tokens, aggregators, fallbackOracleAddress, await getWethAddress(poolConfig)],
|
2020-11-12 13:12:26 +00:00
|
|
|
verify
|
|
|
|
);
|
2020-11-16 15:08:07 +00:00
|
|
|
const lendingRateOracle = notFalsyOrZeroAddress(lendingRateOracleAddress)
|
2020-11-12 13:12:26 +00:00
|
|
|
? await getLendingRateOracle(lendingRateOracleAddress)
|
|
|
|
: await deployLendingRateOracle(verify);
|
2020-09-24 15:48:29 +00:00
|
|
|
const {USD, ...tokensAddressesWithoutUsd} = tokensToWatch;
|
2020-11-12 13:12:26 +00:00
|
|
|
|
|
|
|
if (!lendingRateOracleAddress) {
|
|
|
|
await setInitialMarketRatesInRatesOracleByHelper(
|
|
|
|
lendingRateOracles,
|
|
|
|
tokensAddressesWithoutUsd,
|
|
|
|
lendingRateOracle,
|
|
|
|
admin
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the proxy price provider on the addressesProvider
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setPriceOracle(chainlinkProviderPriceProvider.address)
|
2020-09-24 15:48:29 +00:00
|
|
|
);
|
2020-11-12 13:12:26 +00:00
|
|
|
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
|
2020-11-16 15:08:07 +00:00
|
|
|
} catch (error) {
|
|
|
|
if (DRE.network.name.includes('tenderly')) {
|
|
|
|
const transactionLink = `https://dashboard.tenderly.co/${DRE.config.tenderly.username}/${
|
|
|
|
DRE.config.tenderly.project
|
|
|
|
}/fork/${DRE.tenderlyRPC.getFork()}/simulation/${DRE.tenderlyRPC.getHead()}`;
|
|
|
|
console.error('Check tx error:', transactionLink);
|
|
|
|
}
|
|
|
|
throw error;
|
2020-09-24 15:48:29 +00:00
|
|
|
}
|
2020-08-31 10:10:40 +00:00
|
|
|
});
|