2020-11-18 18:18:02 +00:00
|
|
|
import { task } from 'hardhat/config';
|
2021-01-11 01:40:23 +00:00
|
|
|
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
|
2020-11-18 18:18:02 +00:00
|
|
|
import { deployAaveOracle, deployLendingRateOracle } from '../../helpers/contracts-deployments';
|
2021-02-13 02:40:20 +00:00
|
|
|
import { setInitialMarketRatesInRatesOracleByHelper } from '../../helpers/oracles-helpers';
|
2021-02-23 14:42:47 +00:00
|
|
|
import { ICommonConfiguration, eNetwork, SymbolMap } from '../../helpers/types';
|
2020-11-18 18:18:02 +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-18 18:18:02 +00:00
|
|
|
getAaveOracle,
|
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';
|
2021-03-15 10:52:57 +00:00
|
|
|
import { AaveOracle, LendingRateOracle } from '../../types';
|
2021-07-16 17:26:49 +00:00
|
|
|
import { ethers } from 'ethers';
|
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-18 18:18:02 +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');
|
2021-02-23 14:42:47 +00:00
|
|
|
const network = <eNetwork>DRE.network.name;
|
2020-09-24 15:48:29 +00:00
|
|
|
const poolConfig = loadPoolConfig(pool);
|
|
|
|
const {
|
2020-11-18 18:18:02 +00:00
|
|
|
ProtocolGlobalParams: { UsdAddress },
|
2020-09-24 15:48:29 +00:00
|
|
|
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);
|
2020-11-18 18:18:02 +00:00
|
|
|
const aaveOracleAddress = getParamPerNetwork(poolConfig.AaveOracle, network);
|
2020-11-12 13:12:26 +00:00
|
|
|
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);
|
2021-01-11 01:40:23 +00:00
|
|
|
|
2021-02-12 16:08:36 +00:00
|
|
|
let aaveOracle: AaveOracle;
|
2021-03-15 10:52:57 +00:00
|
|
|
let lendingRateOracle: LendingRateOracle;
|
|
|
|
|
2021-02-12 16:08:36 +00:00
|
|
|
if (notFalsyOrZeroAddress(aaveOracleAddress)) {
|
2021-03-02 16:21:04 +00:00
|
|
|
aaveOracle = await await getAaveOracle(aaveOracleAddress);
|
2021-02-12 16:08:36 +00:00
|
|
|
} else {
|
|
|
|
aaveOracle = await deployAaveOracle(
|
2021-07-16 17:26:49 +00:00
|
|
|
[
|
|
|
|
tokens,
|
|
|
|
aggregators,
|
|
|
|
fallbackOracleAddress,
|
|
|
|
await getWethAddress(poolConfig),
|
|
|
|
ethers.constants.WeiPerEther.toString(),
|
|
|
|
],
|
2021-02-12 16:08:36 +00:00
|
|
|
verify
|
2021-02-23 14:42:47 +00:00
|
|
|
);
|
2021-03-15 10:52:57 +00:00
|
|
|
await waitForTx(await aaveOracle.setAssetSources(tokens, aggregators));
|
2021-02-12 16:08:36 +00:00
|
|
|
}
|
2021-02-18 21:50:15 +00:00
|
|
|
|
2021-03-15 10:52:57 +00:00
|
|
|
if (notFalsyOrZeroAddress(lendingRateOracleAddress)) {
|
2021-03-29 10:13:56 +00:00
|
|
|
lendingRateOracle = await getLendingRateOracle(lendingRateOracleAddress);
|
2021-03-15 10:52:57 +00:00
|
|
|
} else {
|
|
|
|
lendingRateOracle = await deployLendingRateOracle(verify);
|
|
|
|
const { USD, ...tokensAddressesWithoutUsd } = tokensToWatch;
|
|
|
|
await setInitialMarketRatesInRatesOracleByHelper(
|
|
|
|
lendingRateOracles,
|
|
|
|
tokensAddressesWithoutUsd,
|
|
|
|
lendingRateOracle,
|
|
|
|
admin
|
|
|
|
);
|
|
|
|
}
|
2021-03-29 10:13:56 +00:00
|
|
|
|
2021-03-15 10:52:57 +00:00
|
|
|
console.log('Aave Oracle: %s', lendingRateOracle.address);
|
|
|
|
console.log('Lending Rate Oracle: %s', lendingRateOracle.address);
|
2021-03-29 10:13:56 +00:00
|
|
|
|
2020-11-12 13:12:26 +00:00
|
|
|
// Register the proxy price provider on the addressesProvider
|
2020-11-18 18:18:02 +00:00
|
|
|
await waitForTx(await addressesProvider.setPriceOracle(aaveOracle.address));
|
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
|
2021-05-18 08:40:22 +00:00
|
|
|
}/fork/${DRE.tenderlyNetwork.getFork()}/simulation/${DRE.tenderlyNetwork.getHead()}`;
|
2020-11-16 15:08:07 +00:00
|
|
|
console.error('Check tx error:', transactionLink);
|
|
|
|
}
|
|
|
|
throw error;
|
2020-09-24 15:48:29 +00:00
|
|
|
}
|
2020-08-31 10:10:40 +00:00
|
|
|
});
|