aave-protocol-v2/tasks/full/3_oracles.ts

89 lines
3.7 KiB
TypeScript
Raw Normal View History

2020-11-05 11:18:20 +00:00
import {task} from 'hardhat/config';
import {getEthersSignersAddresses, getParamPerNetwork} from '../../helpers/contracts-helpers';
import {
deployChainlinkProxyPriceProvider,
deployLendingRateOracle,
} from '../../helpers/contracts-deployments';
import {setInitialMarketRatesInRatesOracleByHelper} from '../../helpers/oracles-helpers';
import {ICommonConfiguration, eEthereumNetwork, SymbolMap} from '../../helpers/types';
import {waitForTx, filterMapBy, notFalsyOrZeroAddress} from '../../helpers/misc-utils';
import {
ConfigNames,
loadPoolConfig,
getWethAddress,
getGenesisPoolAdmin,
getLendingRateOracles,
} from '../../helpers/configuration';
2020-09-24 15:48:29 +00:00
import {exit} from 'process';
import {
getChainlinkPriceProvider,
getLendingPoolAddressesProvider,
getLendingRateOracle,
getPairsTokenAggregator,
} from '../../helpers/contracts-getters';
task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
2020-09-24 15:48:29 +00:00
.addFlag('verify', 'Verify contracts at Etherscan')
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
.setAction(async ({verify, pool}, DRE) => {
2020-09-24 15:48:29 +00:00
try {
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;
const lendingRateOracles = getLendingRateOracles(poolConfig);
2020-09-24 15:48:29 +00:00
const addressesProvider = await getLendingPoolAddressesProvider();
const admin = await getGenesisPoolAdmin(poolConfig);
const proxyPriceProviderAddress = getParamPerNetwork(poolConfig.ProxyPriceProvider, network);
const lendingRateOracleAddress = getParamPerNetwork(poolConfig.LendingRateOracle, network);
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);
const chainlinkProviderPriceProvider = notFalsyOrZeroAddress(proxyPriceProviderAddress)
? await getChainlinkPriceProvider(proxyPriceProviderAddress)
: await deployChainlinkProxyPriceProvider(
[tokens, aggregators, fallbackOracleAddress, await getWethAddress(poolConfig)],
verify
);
const lendingRateOracle = notFalsyOrZeroAddress(lendingRateOracleAddress)
? await getLendingRateOracle(lendingRateOracleAddress)
: await deployLendingRateOracle(verify);
2020-09-24 15:48:29 +00:00
const {USD, ...tokensAddressesWithoutUsd} = tokensToWatch;
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
);
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
} 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
}
});