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

104 lines
4.1 KiB
TypeScript
Raw Permalink Normal View History

import { task } from 'hardhat/config';
import { getParamPerNetwork } from '../../helpers/contracts-helpers';
import { deployAaveOracle, deployLendingRateOracle } from '../../helpers/contracts-deployments';
2021-02-13 02:40:20 +00:00
import { setInitialMarketRatesInRatesOracleByHelper } from '../../helpers/oracles-helpers';
import { ICommonConfiguration, eNetwork, SymbolMap } from '../../helpers/types';
import { waitForTx, notFalsyOrZeroAddress } from '../../helpers/misc-utils';
import {
ConfigNames,
loadPoolConfig,
getGenesisPoolAdmin,
getLendingRateOracles,
getQuoteCurrency,
} from '../../helpers/configuration';
import {
getAaveOracle,
getLendingPoolAddressesProvider,
getLendingRateOracle,
getPairsTokenAggregator,
} from '../../helpers/contracts-getters';
import { AaveOracle, LendingRateOracle } from '../../types';
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 = <eNetwork>DRE.network.name;
2020-09-24 15:48:29 +00:00
const poolConfig = loadPoolConfig(pool);
const {
ProtocolGlobalParams: { UsdAddress },
2020-09-24 15:48:29 +00:00
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 aaveOracleAddress = getParamPerNetwork(poolConfig.AaveOracle, 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,
poolConfig.OracleQuoteCurrency
);
let aaveOracle: AaveOracle;
let lendingRateOracle: LendingRateOracle;
if (notFalsyOrZeroAddress(aaveOracleAddress)) {
aaveOracle = await await getAaveOracle(aaveOracleAddress);
await waitForTx(await aaveOracle.setAssetSources(tokens, aggregators));
} else {
aaveOracle = await deployAaveOracle(
[
tokens,
aggregators,
fallbackOracleAddress,
await getQuoteCurrency(poolConfig),
poolConfig.OracleQuoteUnit,
],
verify
);
await waitForTx(await aaveOracle.setAssetSources(tokens, aggregators));
}
2021-02-18 21:50:15 +00:00
if (notFalsyOrZeroAddress(lendingRateOracleAddress)) {
lendingRateOracle = await getLendingRateOracle(lendingRateOracleAddress);
} else {
lendingRateOracle = await deployLendingRateOracle(verify);
const { USD, ...tokensAddressesWithoutUsd } = tokensToWatch;
await setInitialMarketRatesInRatesOracleByHelper(
lendingRateOracles,
tokensAddressesWithoutUsd,
lendingRateOracle,
admin
);
}
console.log('Aave Oracle: %s', aaveOracle.address);
console.log('Lending Rate Oracle: %s', lendingRateOracle.address);
// Register the proxy price provider on the addressesProvider
await waitForTx(await addressesProvider.setPriceOracle(aaveOracle.address));
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.tenderly.network().getFork()}/simulation/${DRE.tenderly.network().getHead()}`;
console.error('Check tx error:', transactionLink);
}
throw error;
2020-09-24 15:48:29 +00:00
}
});