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,
|
2020-09-24 15:48:29 +00:00
|
|
|
deployLendingPoolCollateralManager,
|
2020-08-21 11:07:32 +00:00
|
|
|
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-09-24 15:48:29 +00:00
|
|
|
import {ZERO_ADDRESS} from '../../helpers/constants';
|
2020-08-20 15:35:05 +00:00
|
|
|
|
2020-08-31 10:10:40 +00:00
|
|
|
task('dev:initialize-lending-pool', 'Initialize lending pool configuration.')
|
2020-08-21 11:07:32 +00:00
|
|
|
.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
|
|
|
|
2020-10-13 11:41:57 +00:00
|
|
|
const testHelpers = await deployAaveProtocolTestHelpers(addressesProvider.address, verify);
|
|
|
|
|
2020-08-20 15:35:05 +00:00
|
|
|
const reservesParams = getReservesConfigByPool(AavePools.proto);
|
|
|
|
|
|
|
|
await initReserves(
|
|
|
|
reservesParams,
|
|
|
|
protoPoolReservesAddresses,
|
|
|
|
addressesProvider,
|
|
|
|
lendingPoolProxy,
|
2020-10-13 11:41:57 +00:00
|
|
|
testHelpers,
|
2020-08-20 15:35:05 +00:00
|
|
|
lendingPoolConfiguratorProxy,
|
2020-08-31 10:10:40 +00:00
|
|
|
AavePools.proto,
|
2020-09-24 15:48:29 +00:00
|
|
|
ZERO_ADDRESS,
|
2020-08-31 10:10:40 +00:00
|
|
|
verify
|
2020-08-20 15:35:05 +00:00
|
|
|
);
|
|
|
|
await enableReservesToBorrow(
|
|
|
|
reservesParams,
|
|
|
|
protoPoolReservesAddresses,
|
2020-10-13 11:41:57 +00:00
|
|
|
testHelpers,
|
2020-08-20 15:35:05 +00:00
|
|
|
lendingPoolConfiguratorProxy
|
|
|
|
);
|
|
|
|
await enableReservesAsCollateral(
|
|
|
|
reservesParams,
|
|
|
|
protoPoolReservesAddresses,
|
2020-10-13 11:41:57 +00:00
|
|
|
testHelpers,
|
2020-08-20 15:35:05 +00:00
|
|
|
lendingPoolConfiguratorProxy
|
|
|
|
);
|
|
|
|
|
2020-09-24 15:48:29 +00:00
|
|
|
const collateralManager = await deployLendingPoolCollateralManager(verify);
|
2020-08-20 15:35:05 +00:00
|
|
|
await waitForTx(
|
2020-09-24 15:48:29 +00:00
|
|
|
await addressesProvider.setLendingPoolCollateralManager(collateralManager.address)
|
2020-08-20 15:35:05 +00:00
|
|
|
);
|
|
|
|
|
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
|
|
|
|
|
|
|
await insertContractAddressInDb(eContractid.AaveProtocolTestHelpers, testHelpers.address);
|
2020-08-21 11:07:32 +00:00
|
|
|
});
|