2020-08-20 15:35:05 +00:00
|
|
|
import {task} from '@nomiclabs/buidler/config';
|
|
|
|
import {
|
2020-08-21 11:07:32 +00:00
|
|
|
getLendingPoolAddressesProvider,
|
|
|
|
initReserves,
|
|
|
|
deployLendingPoolLiquidationManager,
|
|
|
|
insertContractAddressInDb,
|
|
|
|
deployMockFlashLoanReceiver,
|
|
|
|
deployWalletBalancerProvider,
|
|
|
|
deployAaveProtocolTestHelpers,
|
|
|
|
getLendingPool,
|
|
|
|
getLendingPoolConfiguratorProxy,
|
2020-08-25 12:15:35 +00:00
|
|
|
getAllMockedTokens,
|
2020-08-20 15:35:05 +00:00
|
|
|
} from '../../helpers/contracts-helpers';
|
2020-08-25 15:15:27 +00:00
|
|
|
import {getReservesConfigByPool} from '../../helpers/configuration';
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
import {tEthereumAddress, AavePools, eContractid} from '../../helpers/types';
|
|
|
|
import {waitForTx, filterMapBy} from '../../helpers/misc-utils';
|
|
|
|
import {enableReservesToBorrow, enableReservesAsCollateral} from '../../helpers/init-helpers';
|
2020-08-25 15:15:27 +00:00
|
|
|
import {getAllTokenAddresses} from '../../helpers/mock-helpers';
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
task('initialize-lending-pool', 'Initialize lending pool configuration.')
|
|
|
|
.addOptionalParam('verify', 'Verify contracts at Etherscan')
|
|
|
|
.setAction(async ({verify}, localBRE) => {
|
|
|
|
await localBRE.run('set-bre');
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-25 12:15:35 +00:00
|
|
|
const mockTokens = await getAllMockedTokens();
|
2020-08-21 11:07:32 +00:00
|
|
|
const lendingPoolProxy = await getLendingPool();
|
|
|
|
const lendingPoolConfiguratorProxy = await getLendingPoolConfiguratorProxy();
|
|
|
|
const allTokenAddresses = getAllTokenAddresses(mockTokens);
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
const addressesProvider = await getLendingPoolAddressesProvider();
|
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
const protoPoolReservesAddresses = <{[symbol: string]: tEthereumAddress}>(
|
|
|
|
filterMapBy(allTokenAddresses, (key: string) => !key.includes('UNI'))
|
|
|
|
);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
|
|
|
const reservesParams = getReservesConfigByPool(AavePools.proto);
|
|
|
|
|
|
|
|
console.log('Initialize configuration');
|
|
|
|
await initReserves(
|
|
|
|
reservesParams,
|
|
|
|
protoPoolReservesAddresses,
|
|
|
|
addressesProvider,
|
|
|
|
lendingPoolProxy,
|
|
|
|
lendingPoolConfiguratorProxy,
|
|
|
|
AavePools.proto
|
|
|
|
);
|
|
|
|
await enableReservesToBorrow(
|
|
|
|
reservesParams,
|
|
|
|
protoPoolReservesAddresses,
|
|
|
|
lendingPoolProxy,
|
|
|
|
lendingPoolConfiguratorProxy
|
|
|
|
);
|
|
|
|
await enableReservesAsCollateral(
|
|
|
|
reservesParams,
|
|
|
|
protoPoolReservesAddresses,
|
|
|
|
lendingPoolProxy,
|
|
|
|
lendingPoolConfiguratorProxy
|
|
|
|
);
|
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
const liquidationManager = await deployLendingPoolLiquidationManager(verify);
|
2020-08-20 15:35:05 +00:00
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setLendingPoolLiquidationManager(liquidationManager.address)
|
|
|
|
);
|
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
const mockFlashLoanReceiver = await deployMockFlashLoanReceiver(
|
|
|
|
addressesProvider.address,
|
|
|
|
verify
|
|
|
|
);
|
2020-08-20 15:35:05 +00:00
|
|
|
await insertContractAddressInDb(
|
|
|
|
eContractid.MockFlashLoanReceiver,
|
|
|
|
mockFlashLoanReceiver.address
|
|
|
|
);
|
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
await deployWalletBalancerProvider(addressesProvider.address, verify);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-21 11:07:32 +00:00
|
|
|
const testHelpers = await deployAaveProtocolTestHelpers(addressesProvider.address, verify);
|
2020-08-20 15:35:05 +00:00
|
|
|
|
|
|
|
await insertContractAddressInDb(eContractid.AaveProtocolTestHelpers, testHelpers.address);
|
2020-08-21 11:07:32 +00:00
|
|
|
});
|