2020-08-20 15:35:05 +00:00
|
|
|
import {task} from '@nomiclabs/buidler/config';
|
|
|
|
import {
|
|
|
|
getLendingPoolAddressesProvider,
|
|
|
|
deployPriceOracle,
|
|
|
|
getMockedTokens,
|
|
|
|
getPairsTokenAggregator,
|
|
|
|
deployChainlinkProxyPriceProvider,
|
|
|
|
deployLendingRateOracle,
|
2020-08-25 12:15:35 +00:00
|
|
|
getAllMockedTokens,
|
2020-08-20 15:35:05 +00:00
|
|
|
} from '../../helpers/contracts-helpers';
|
2020-08-25 12:15:35 +00:00
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
import {
|
|
|
|
setInitialAssetPricesInOracle,
|
|
|
|
setInitialMarketRatesInRatesOracle,
|
2020-08-25 12:15:35 +00:00
|
|
|
deployAllMockAggregators,
|
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-08-25 15:15:27 +00:00
|
|
|
import {ConfigNames, loadPoolConfig} from '../../helpers/configuration';
|
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-08-20 15:35:05 +00:00
|
|
|
.addOptionalParam('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-08-20 15:35:05 +00:00
|
|
|
await localBRE.run('set-bre');
|
2020-08-25 15:15:27 +00:00
|
|
|
const poolConfig = loadPoolConfig(pool);
|
2020-08-25 12:15:35 +00:00
|
|
|
const {
|
|
|
|
Mocks: {ChainlinkAggregatorPrices, AllAssetsInitialPrices},
|
|
|
|
ProtocolGlobalParams: {UsdAddress, MockUsdPriceInWei},
|
|
|
|
LendingRateOracleRatesCommon,
|
|
|
|
} = poolConfig as ICommonConfiguration;
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-25 12:15:35 +00:00
|
|
|
const defaultTokenList = {
|
|
|
|
...Object.fromEntries(Object.keys(TokenContractId).map((symbol) => [symbol, ''])),
|
|
|
|
USD: UsdAddress,
|
|
|
|
} as iAssetBase<string>;
|
|
|
|
const mockTokens = await getAllMockedTokens();
|
|
|
|
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-08-20 15:35:05 +00:00
|
|
|
const addressesProvider = await getLendingPoolAddressesProvider();
|
|
|
|
|
|
|
|
const fallbackOracle = await deployPriceOracle(verify);
|
2020-08-25 12:15:35 +00:00
|
|
|
await waitForTx(await fallbackOracle.setEthUsdPrice(MockUsdPriceInWei));
|
|
|
|
await setInitialAssetPricesInOracle(AllAssetsInitialPrices, mockTokensAddress, fallbackOracle);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-25 12:15:35 +00:00
|
|
|
const mockAggregators = await deployAllMockAggregators(ChainlinkAggregatorPrices, verify);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
const allTokenAddresses = getAllTokenAddresses(mockTokens);
|
|
|
|
const allAggregatorsAddresses = getAllAggregatorsAddresses(mockAggregators);
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
const [tokens, aggregators] = getPairsTokenAggregator(
|
|
|
|
allTokenAddresses,
|
|
|
|
allAggregatorsAddresses
|
|
|
|
);
|
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
await deployChainlinkProxyPriceProvider([tokens, aggregators, fallbackOracle.address], verify);
|
2020-08-20 15:35:05 +00:00
|
|
|
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
|
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
const lendingRateOracle = await deployLendingRateOracle(verify);
|
2020-08-20 15:35:05 +00:00
|
|
|
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
|
|
|
|
|
|
|
|
const {USD, ...tokensAddressesWithoutUsd} = allTokenAddresses;
|
|
|
|
const allReservesAddresses = {
|
|
|
|
...tokensAddressesWithoutUsd,
|
|
|
|
};
|
|
|
|
await setInitialMarketRatesInRatesOracle(
|
2020-08-25 12:15:35 +00:00
|
|
|
LendingRateOracleRatesCommon,
|
2020-08-20 15:35:05 +00:00
|
|
|
allReservesAddresses,
|
|
|
|
lendingRateOracle
|
|
|
|
);
|
|
|
|
});
|