2020-11-05 11:18:20 +00:00
|
|
|
import {task} from 'hardhat/config';
|
2020-08-20 15:35:05 +00:00
|
|
|
import {
|
|
|
|
deployPriceOracle,
|
2020-11-17 09:24:24 +00:00
|
|
|
deployAaveOracle,
|
2020-08-20 15:35:05 +00:00
|
|
|
deployLendingRateOracle,
|
2020-10-16 09:27:09 +00:00
|
|
|
} from '../../helpers/contracts-deployments';
|
2020-08-25 12:15:35 +00:00
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
import {
|
|
|
|
setInitialAssetPricesInOracle,
|
2020-08-25 12:15:35 +00:00
|
|
|
deployAllMockAggregators,
|
2020-10-27 09:58:51 +00:00
|
|
|
setInitialMarketRatesInRatesOracleByHelper,
|
2020-08-20 15:35:05 +00:00
|
|
|
} from '../../helpers/oracles-helpers';
|
2020-08-25 12:15:35 +00:00
|
|
|
import {ICommonConfiguration, iAssetBase, TokenContractId} from '../../helpers/types';
|
2020-08-20 15:35:05 +00:00
|
|
|
import {waitForTx} from '../../helpers/misc-utils';
|
2020-08-21 11:07:32 +00:00
|
|
|
import {getAllAggregatorsAddresses, getAllTokenAddresses} from '../../helpers/mock-helpers';
|
2020-11-06 11:09:24 +00:00
|
|
|
import {ConfigNames, loadPoolConfig, getWethAddress} from '../../helpers/configuration';
|
2020-10-15 11:57:03 +00:00
|
|
|
import {
|
|
|
|
getAllMockedTokens,
|
|
|
|
getLendingPoolAddressesProvider,
|
|
|
|
getPairsTokenAggregator,
|
|
|
|
} from '../../helpers/contracts-getters';
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-31 10:10:40 +00:00
|
|
|
task('dev:deploy-oracles', 'Deploy oracles for dev enviroment')
|
2020-11-02 13:45:00 +00:00
|
|
|
.addFlag('verify', 'Verify contracts at Etherscan')
|
2020-08-25 15:15:27 +00:00
|
|
|
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
|
|
|
|
.setAction(async ({verify, pool}, localBRE) => {
|
2020-12-22 23:48:02 +00:00
|
|
|
|
2020-11-05 12:44:20 +00:00
|
|
|
await localBRE.run('set-DRE');
|
2020-08-25 15:15:27 +00:00
|
|
|
const poolConfig = loadPoolConfig(pool);
|
2020-12-22 23:48:02 +00:00
|
|
|
|
|
|
|
console.log("Initialized pool config...");
|
|
|
|
|
2020-08-25 12:15:35 +00:00
|
|
|
const {
|
2020-11-18 09:35:42 +00:00
|
|
|
Mocks: {AllAssetsInitialPrices},
|
2020-08-25 12:15:35 +00:00
|
|
|
ProtocolGlobalParams: {UsdAddress, MockUsdPriceInWei},
|
|
|
|
LendingRateOracleRatesCommon,
|
|
|
|
} = poolConfig as ICommonConfiguration;
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-12-22 23:48:02 +00:00
|
|
|
console.log("Initialized mocks, global params and lending rate oracle rates");
|
|
|
|
|
2020-08-25 12:15:35 +00:00
|
|
|
const defaultTokenList = {
|
|
|
|
...Object.fromEntries(Object.keys(TokenContractId).map((symbol) => [symbol, ''])),
|
|
|
|
USD: UsdAddress,
|
|
|
|
} as iAssetBase<string>;
|
2020-12-22 23:48:02 +00:00
|
|
|
|
|
|
|
console.log("Initialized defaultTokenList");
|
|
|
|
|
2020-08-25 12:15:35 +00:00
|
|
|
const mockTokens = await getAllMockedTokens();
|
2020-12-22 23:48:02 +00:00
|
|
|
|
|
|
|
console.log("Initialized mock tokens");
|
|
|
|
|
2020-08-25 12:15:35 +00:00
|
|
|
const mockTokensAddress = Object.keys(mockTokens).reduce<iAssetBase<string>>((prev, curr) => {
|
2020-08-25 15:15:27 +00:00
|
|
|
prev[curr as keyof iAssetBase<string>] = mockTokens[curr].address;
|
2020-08-25 12:15:35 +00:00
|
|
|
return prev;
|
|
|
|
}, defaultTokenList);
|
2020-12-22 23:48:02 +00:00
|
|
|
console.log(mockTokensAddress);
|
|
|
|
console.log("Initialized mock tokens addresses");
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
const addressesProvider = await getLendingPoolAddressesProvider();
|
2020-12-22 23:48:02 +00:00
|
|
|
|
2020-12-25 05:47:30 +00:00
|
|
|
console.log("Got the addresses provider (check if different both times):", addressesProvider.address);
|
2020-12-22 23:48:02 +00:00
|
|
|
|
2020-11-05 15:15:52 +00:00
|
|
|
const admin = await addressesProvider.getPoolAdmin();
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-12-22 23:48:02 +00:00
|
|
|
console.log("Got the admin");
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
const fallbackOracle = await deployPriceOracle(verify);
|
2020-12-22 23:48:02 +00:00
|
|
|
|
|
|
|
console.log("Deployed fallback price oracle");
|
|
|
|
|
2020-08-25 12:15:35 +00:00
|
|
|
await waitForTx(await fallbackOracle.setEthUsdPrice(MockUsdPriceInWei));
|
2020-12-22 23:48:02 +00:00
|
|
|
|
|
|
|
console.log("set fallback ETH USD price");
|
|
|
|
|
2020-08-25 12:15:35 +00:00
|
|
|
await setInitialAssetPricesInOracle(AllAssetsInitialPrices, mockTokensAddress, fallbackOracle);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-12-22 23:48:02 +00:00
|
|
|
console.log("Set initial asset prices in oracle");
|
|
|
|
|
2020-11-18 09:35:42 +00:00
|
|
|
const mockAggregators = await deployAllMockAggregators(AllAssetsInitialPrices, verify);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-12-22 23:48:02 +00:00
|
|
|
console.log("Deployed mock aggregators");
|
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
const allTokenAddresses = getAllTokenAddresses(mockTokens);
|
2020-12-22 23:48:02 +00:00
|
|
|
|
|
|
|
console.log("Got all mock token addresses");
|
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
const allAggregatorsAddresses = getAllAggregatorsAddresses(mockAggregators);
|
|
|
|
|
2020-12-22 23:48:02 +00:00
|
|
|
console.log("Got all aggregator addresses");
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
const [tokens, aggregators] = getPairsTokenAggregator(
|
|
|
|
allTokenAddresses,
|
|
|
|
allAggregatorsAddresses
|
|
|
|
);
|
2020-12-22 23:48:02 +00:00
|
|
|
|
|
|
|
console.log("Got \"pairsToken aggregator\"");
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-11-17 09:24:24 +00:00
|
|
|
await deployAaveOracle(
|
2020-11-06 11:09:24 +00:00
|
|
|
[tokens, aggregators, fallbackOracle.address, await getWethAddress(poolConfig)],
|
|
|
|
verify
|
|
|
|
);
|
2020-12-22 23:48:02 +00:00
|
|
|
|
|
|
|
console.log("Deployed Aave oracle");
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
|
|
|
|
|
2020-12-22 23:48:02 +00:00
|
|
|
console.log("Set price oracle in addresses provider");
|
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
const lendingRateOracle = await deployLendingRateOracle(verify);
|
2020-12-22 23:48:02 +00:00
|
|
|
|
|
|
|
console.log("Deployed lendingRateOracle");
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
|
|
|
|
|
2020-12-22 23:48:02 +00:00
|
|
|
console.log("Set lending rate oracle in addresses provider");
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
const {USD, ...tokensAddressesWithoutUsd} = allTokenAddresses;
|
2020-12-22 23:48:02 +00:00
|
|
|
|
|
|
|
console.log("Initialized object with token addresses & usd")
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
const allReservesAddresses = {
|
|
|
|
...tokensAddressesWithoutUsd,
|
|
|
|
};
|
2020-12-22 23:48:02 +00:00
|
|
|
|
|
|
|
console.log("Initialized object with all reserve addresses, allReservesAddresses:");
|
|
|
|
console.log(allReservesAddresses);
|
|
|
|
|
2020-10-27 09:58:51 +00:00
|
|
|
await setInitialMarketRatesInRatesOracleByHelper(
|
2020-08-25 12:15:35 +00:00
|
|
|
LendingRateOracleRatesCommon,
|
2020-08-20 15:35:05 +00:00
|
|
|
allReservesAddresses,
|
2020-10-27 09:58:51 +00:00
|
|
|
lendingRateOracle,
|
|
|
|
admin
|
2020-08-20 15:35:05 +00:00
|
|
|
);
|
2020-12-22 23:48:02 +00:00
|
|
|
|
|
|
|
console.log("Task complete");
|
|
|
|
});
|