aave-protocol-v2/tasks/dev/5_initialize.ts

81 lines
2.7 KiB
TypeScript
Raw Normal View History

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,
} from '../../helpers/contracts-helpers';
import {getReservesConfigByPool} from '../../helpers/configuration';
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';
import {getAllTokenAddresses} from '../../helpers/mock-helpers';
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-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);
const addressesProvider = await getLendingPoolAddressesProvider();
2020-08-21 11:07:32 +00:00
const protoPoolReservesAddresses = <{[symbol: string]: tEthereumAddress}>(
filterMapBy(allTokenAddresses, (key: string) => !key.includes('UNI'))
);
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);
await waitForTx(
await addressesProvider.setLendingPoolLiquidationManager(liquidationManager.address)
);
2020-08-21 11:07:32 +00:00
const mockFlashLoanReceiver = await deployMockFlashLoanReceiver(
addressesProvider.address,
verify
);
await insertContractAddressInDb(
eContractid.MockFlashLoanReceiver,
mockFlashLoanReceiver.address
);
2020-08-21 11:07:32 +00:00
await deployWalletBalancerProvider(addressesProvider.address, verify);
2020-08-21 11:07:32 +00:00
const testHelpers = await deployAaveProtocolTestHelpers(addressesProvider.address, verify);
await insertContractAddressInDb(eContractid.AaveProtocolTestHelpers, testHelpers.address);
2020-08-21 11:07:32 +00:00
});