2020-11-05 11:18:20 +00:00
|
|
|
import rawBRE from 'hardhat';
|
2020-11-18 18:18:02 +00:00
|
|
|
import { MockContract } from 'ethereum-waffle';
|
2020-10-16 09:27:09 +00:00
|
|
|
import {
|
|
|
|
insertContractAddressInDb,
|
|
|
|
getEthersSigners,
|
|
|
|
registerContractInJsonDb,
|
|
|
|
} from '../helpers/contracts-helpers';
|
2020-06-08 12:03:40 +00:00
|
|
|
import {
|
|
|
|
deployLendingPoolAddressesProvider,
|
2020-08-25 15:15:27 +00:00
|
|
|
deployMintableERC20,
|
2020-06-08 12:03:40 +00:00
|
|
|
deployLendingPoolAddressesProviderRegistry,
|
|
|
|
deployLendingPoolConfigurator,
|
|
|
|
deployLendingPool,
|
|
|
|
deployPriceOracle,
|
2020-11-17 09:24:24 +00:00
|
|
|
deployAaveOracle,
|
2020-09-16 10:41:12 +00:00
|
|
|
deployLendingPoolCollateralManager,
|
2020-06-08 12:03:40 +00:00
|
|
|
deployMockFlashLoanReceiver,
|
|
|
|
deployWalletBalancerProvider,
|
2020-11-10 14:19:47 +00:00
|
|
|
deployAaveProtocolDataProvider,
|
2020-09-24 15:48:29 +00:00
|
|
|
deployLendingRateOracle,
|
2020-10-27 09:58:51 +00:00
|
|
|
deployStableAndVariableTokensHelper,
|
|
|
|
deployATokensAndRatesHelper,
|
2020-10-29 11:44:21 +00:00
|
|
|
deployWETHGateway,
|
|
|
|
deployWETHMocked,
|
2020-10-16 09:27:09 +00:00
|
|
|
} from '../helpers/contracts-deployments';
|
2020-11-18 18:18:02 +00:00
|
|
|
import { Signer } from 'ethers';
|
|
|
|
import { TokenContractId, eContractid, tEthereumAddress, AavePools } from '../helpers/types';
|
|
|
|
import { MintableERC20 } from '../types/MintableERC20';
|
2020-11-27 15:40:00 +00:00
|
|
|
import { ConfigNames, getReservesConfigByPool, getTreasuryAddress, loadPoolConfig } from '../helpers/configuration';
|
2020-11-18 18:18:02 +00:00
|
|
|
import { initializeMakeSuite } from './helpers/make-suite';
|
2020-08-19 14:10:08 +00:00
|
|
|
|
2020-08-20 15:38:57 +00:00
|
|
|
import {
|
|
|
|
setInitialAssetPricesInOracle,
|
|
|
|
deployAllMockAggregators,
|
2020-10-27 09:58:51 +00:00
|
|
|
setInitialMarketRatesInRatesOracleByHelper,
|
2020-08-20 15:38:57 +00:00
|
|
|
} from '../helpers/oracles-helpers';
|
2020-11-18 18:18:02 +00:00
|
|
|
import { DRE, waitForTx } from '../helpers/misc-utils';
|
2020-10-16 09:27:09 +00:00
|
|
|
import {
|
2020-10-23 16:38:27 +00:00
|
|
|
initReservesByHelper,
|
2020-10-26 16:43:10 +00:00
|
|
|
enableReservesToBorrowByHelper,
|
|
|
|
enableReservesAsCollateralByHelper,
|
2020-10-16 09:27:09 +00:00
|
|
|
} from '../helpers/init-helpers';
|
2020-11-17 08:33:45 +00:00
|
|
|
import AaveConfig from '../markets/aave';
|
2020-11-18 18:18:02 +00:00
|
|
|
import { ZERO_ADDRESS } from '../helpers/constants';
|
2020-10-15 11:57:03 +00:00
|
|
|
import {
|
|
|
|
getLendingPool,
|
|
|
|
getLendingPoolConfiguratorProxy,
|
|
|
|
getPairsTokenAggregator,
|
|
|
|
} from '../helpers/contracts-getters';
|
2020-11-18 18:18:02 +00:00
|
|
|
import { WETH9Mocked } from '../types/WETH9Mocked';
|
2020-08-25 12:15:35 +00:00
|
|
|
|
|
|
|
const MOCK_USD_PRICE_IN_WEI = AaveConfig.ProtocolGlobalParams.MockUsdPriceInWei;
|
|
|
|
const ALL_ASSETS_INITIAL_PRICES = AaveConfig.Mocks.AllAssetsInitialPrices;
|
|
|
|
const USD_ADDRESS = AaveConfig.ProtocolGlobalParams.UsdAddress;
|
2020-11-18 09:33:44 +00:00
|
|
|
const MOCK_CHAINLINK_AGGREGATORS_PRICES = AaveConfig.Mocks.AllAssetsInitialPrices;
|
2020-08-25 12:15:35 +00:00
|
|
|
const LENDING_RATE_ORACLE_RATES_COMMON = AaveConfig.LendingRateOracleRatesCommon;
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-06-10 08:31:33 +00:00
|
|
|
const deployAllMockTokens = async (deployer: Signer) => {
|
2020-11-18 18:18:02 +00:00
|
|
|
const tokens: { [symbol: string]: MockContract | MintableERC20 | WETH9Mocked } = {};
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-06-26 19:28:18 +00:00
|
|
|
const protoConfigData = getReservesConfigByPool(AavePools.proto);
|
|
|
|
|
2020-06-08 12:03:40 +00:00
|
|
|
for (const tokenSymbol of Object.keys(TokenContractId)) {
|
2020-10-29 11:44:21 +00:00
|
|
|
if (tokenSymbol === 'WETH') {
|
|
|
|
tokens[tokenSymbol] = await deployWETHMocked();
|
|
|
|
await registerContractInJsonDb(tokenSymbol.toUpperCase(), tokens[tokenSymbol]);
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-19 12:23:41 +00:00
|
|
|
let decimals = 18;
|
2020-07-03 09:15:30 +00:00
|
|
|
|
2020-08-19 12:23:41 +00:00
|
|
|
let configData = (<any>protoConfigData)[tokenSymbol];
|
2020-07-03 09:15:30 +00:00
|
|
|
|
2020-08-19 12:23:41 +00:00
|
|
|
if (!configData) {
|
|
|
|
decimals = 18;
|
|
|
|
}
|
2020-07-03 09:15:30 +00:00
|
|
|
|
2020-08-24 08:29:54 +00:00
|
|
|
tokens[tokenSymbol] = await deployMintableERC20([
|
2020-08-19 12:23:41 +00:00
|
|
|
tokenSymbol,
|
|
|
|
tokenSymbol,
|
|
|
|
configData ? configData.reserveDecimals : 18,
|
|
|
|
]);
|
|
|
|
await registerContractInJsonDb(tokenSymbol.toUpperCase(), tokens[tokenSymbol]);
|
2020-06-08 12:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tokens;
|
|
|
|
};
|
|
|
|
|
2020-06-10 08:31:33 +00:00
|
|
|
const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
2020-07-13 08:54:08 +00:00
|
|
|
console.time('setup');
|
2020-09-16 12:09:42 +00:00
|
|
|
const aaveAdmin = await deployer.getAddress();
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-06-08 15:36:40 +00:00
|
|
|
const mockTokens = await deployAllMockTokens(deployer);
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-11-26 15:11:40 +00:00
|
|
|
const addressesProvider = await deployLendingPoolAddressesProvider(AaveConfig.MarketId);
|
2020-11-05 11:35:50 +00:00
|
|
|
await waitForTx(await addressesProvider.setPoolAdmin(aaveAdmin));
|
|
|
|
|
2020-11-05 15:15:52 +00:00
|
|
|
//setting users[1] as emergency admin, which is in position 2 in the DRE addresses list
|
2020-11-05 11:35:50 +00:00
|
|
|
const addressList = await Promise.all(
|
2020-11-05 15:15:52 +00:00
|
|
|
(await DRE.ethers.getSigners()).map((signer) => signer.getAddress())
|
2020-11-05 11:35:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
await waitForTx(await addressesProvider.setEmergencyAdmin(addressList[2]));
|
2020-06-08 12:03:40 +00:00
|
|
|
|
|
|
|
const addressesProviderRegistry = await deployLendingPoolAddressesProviderRegistry();
|
|
|
|
await waitForTx(
|
2020-09-23 10:34:53 +00:00
|
|
|
await addressesProviderRegistry.registerAddressesProvider(addressesProvider.address, 1)
|
2020-06-08 12:03:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const lendingPoolImpl = await deployLendingPool();
|
2020-06-20 23:40:03 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
await waitForTx(await addressesProvider.setLendingPoolImpl(lendingPoolImpl.address));
|
2020-06-20 23:40:03 +00:00
|
|
|
|
2020-11-02 17:43:50 +00:00
|
|
|
const lendingPoolAddress = await addressesProvider.getLendingPool();
|
|
|
|
const lendingPoolProxy = await getLendingPool(lendingPoolAddress);
|
2020-06-20 23:40:03 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
await insertContractAddressInDb(eContractid.LendingPool, lendingPoolProxy.address);
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-07-23 15:18:06 +00:00
|
|
|
const lendingPoolConfiguratorImpl = await deployLendingPoolConfigurator();
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setLendingPoolConfiguratorImpl(lendingPoolConfiguratorImpl.address)
|
|
|
|
);
|
|
|
|
const lendingPoolConfiguratorProxy = await getLendingPoolConfiguratorProxy(
|
|
|
|
await addressesProvider.getLendingPoolConfigurator()
|
|
|
|
);
|
|
|
|
await insertContractAddressInDb(
|
|
|
|
eContractid.LendingPoolConfigurator,
|
|
|
|
lendingPoolConfiguratorProxy.address
|
|
|
|
);
|
|
|
|
|
2020-10-27 09:58:51 +00:00
|
|
|
// Deploy deployment helpers
|
|
|
|
await deployStableAndVariableTokensHelper([lendingPoolProxy.address, addressesProvider.address]);
|
|
|
|
await deployATokensAndRatesHelper([
|
|
|
|
lendingPoolProxy.address,
|
|
|
|
addressesProvider.address,
|
|
|
|
lendingPoolConfiguratorProxy.address,
|
|
|
|
]);
|
|
|
|
|
2020-06-08 12:03:40 +00:00
|
|
|
const fallbackOracle = await deployPriceOracle();
|
|
|
|
await waitForTx(await fallbackOracle.setEthUsdPrice(MOCK_USD_PRICE_IN_WEI));
|
|
|
|
await setInitialAssetPricesInOracle(
|
|
|
|
ALL_ASSETS_INITIAL_PRICES,
|
|
|
|
{
|
2020-08-13 11:06:23 +00:00
|
|
|
WETH: mockTokens.WETH.address,
|
2020-06-08 12:03:40 +00:00
|
|
|
DAI: mockTokens.DAI.address,
|
|
|
|
TUSD: mockTokens.TUSD.address,
|
|
|
|
USDC: mockTokens.USDC.address,
|
|
|
|
USDT: mockTokens.USDT.address,
|
|
|
|
SUSD: mockTokens.SUSD.address,
|
2020-11-02 11:37:57 +00:00
|
|
|
AAVE: mockTokens.AAVE.address,
|
2020-06-08 12:03:40 +00:00
|
|
|
BAT: mockTokens.BAT.address,
|
|
|
|
MKR: mockTokens.MKR.address,
|
|
|
|
LINK: mockTokens.LINK.address,
|
|
|
|
KNC: mockTokens.KNC.address,
|
|
|
|
WBTC: mockTokens.WBTC.address,
|
|
|
|
MANA: mockTokens.MANA.address,
|
|
|
|
ZRX: mockTokens.ZRX.address,
|
|
|
|
SNX: mockTokens.SNX.address,
|
|
|
|
BUSD: mockTokens.BUSD.address,
|
2020-11-04 10:47:06 +00:00
|
|
|
YFI: mockTokens.BUSD.address,
|
|
|
|
REN: mockTokens.REN.address,
|
|
|
|
UNI: mockTokens.UNI.address,
|
2020-11-04 20:03:58 +00:00
|
|
|
ENJ: mockTokens.ENJ.address,
|
2020-06-08 12:03:40 +00:00
|
|
|
USD: USD_ADDRESS,
|
|
|
|
},
|
|
|
|
fallbackOracle
|
|
|
|
);
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
const mockAggregators = await deployAllMockAggregators(MOCK_CHAINLINK_AGGREGATORS_PRICES);
|
2020-06-08 12:03:40 +00:00
|
|
|
|
|
|
|
const allTokenAddresses = Object.entries(mockTokens).reduce(
|
2020-11-18 18:18:02 +00:00
|
|
|
(accum: { [tokenSymbol: string]: tEthereumAddress }, [tokenSymbol, tokenContract]) => ({
|
2020-06-08 12:03:40 +00:00
|
|
|
...accum,
|
|
|
|
[tokenSymbol]: tokenContract.address,
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
const allAggregatorsAddresses = Object.entries(mockAggregators).reduce(
|
2020-11-18 18:18:02 +00:00
|
|
|
(accum: { [tokenSymbol: string]: tEthereumAddress }, [tokenSymbol, aggregator]) => ({
|
2020-06-08 12:03:40 +00:00
|
|
|
...accum,
|
|
|
|
[tokenSymbol]: aggregator.address,
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
const [tokens, aggregators] = getPairsTokenAggregator(allTokenAddresses, allAggregatorsAddresses);
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-11-18 09:33:44 +00:00
|
|
|
await deployAaveOracle([tokens, aggregators, fallbackOracle.address, mockTokens.WETH.address]);
|
2020-07-13 08:54:08 +00:00
|
|
|
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
|
2020-06-08 12:03:40 +00:00
|
|
|
|
|
|
|
const lendingRateOracle = await deployLendingRateOracle();
|
2020-07-13 08:54:08 +00:00
|
|
|
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-11-18 18:18:02 +00:00
|
|
|
const { USD, ...tokensAddressesWithoutUsd } = allTokenAddresses;
|
2020-06-08 12:03:40 +00:00
|
|
|
const allReservesAddresses = {
|
|
|
|
...tokensAddressesWithoutUsd,
|
|
|
|
};
|
2020-10-27 09:58:51 +00:00
|
|
|
await setInitialMarketRatesInRatesOracleByHelper(
|
2020-06-08 12:03:40 +00:00
|
|
|
LENDING_RATE_ORACLE_RATES_COMMON,
|
|
|
|
allReservesAddresses,
|
2020-10-27 09:58:51 +00:00
|
|
|
lendingRateOracle,
|
|
|
|
aaveAdmin
|
2020-06-08 12:03:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const reservesParams = getReservesConfigByPool(AavePools.proto);
|
|
|
|
|
2020-11-10 14:19:47 +00:00
|
|
|
const testHelpers = await deployAaveProtocolDataProvider(addressesProvider.address);
|
2020-10-12 18:07:17 +00:00
|
|
|
|
2020-11-10 14:19:47 +00:00
|
|
|
await insertContractAddressInDb(eContractid.AaveProtocolDataProvider, testHelpers.address);
|
2020-10-26 16:43:10 +00:00
|
|
|
const admin = await deployer.getAddress();
|
2020-10-12 18:07:17 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
console.log('Initialize configuration');
|
2020-11-27 15:40:00 +00:00
|
|
|
|
|
|
|
const config = loadPoolConfig(ConfigNames.Aave);
|
|
|
|
|
|
|
|
const treasuryAddress = await getTreasuryAddress(config);
|
|
|
|
|
|
|
|
await initReservesByHelper(reservesParams, allReservesAddresses, admin, treasuryAddress, ZERO_ADDRESS, false);
|
2020-11-18 09:33:44 +00:00
|
|
|
await enableReservesToBorrowByHelper(reservesParams, allReservesAddresses, testHelpers, admin);
|
2020-10-26 16:43:10 +00:00
|
|
|
await enableReservesAsCollateralByHelper(
|
2020-06-08 12:03:40 +00:00
|
|
|
reservesParams,
|
2020-11-18 09:33:44 +00:00
|
|
|
allReservesAddresses,
|
2020-10-12 18:07:17 +00:00
|
|
|
testHelpers,
|
2020-10-26 16:43:10 +00:00
|
|
|
admin
|
2020-06-08 12:03:40 +00:00
|
|
|
);
|
|
|
|
|
2020-09-16 10:41:12 +00:00
|
|
|
const collateralManager = await deployLendingPoolCollateralManager();
|
2020-06-08 12:03:40 +00:00
|
|
|
await waitForTx(
|
2020-09-16 10:41:12 +00:00
|
|
|
await addressesProvider.setLendingPoolCollateralManager(collateralManager.address)
|
2020-06-08 12:03:40 +00:00
|
|
|
);
|
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
const mockFlashLoanReceiver = await deployMockFlashLoanReceiver(addressesProvider.address);
|
|
|
|
await insertContractAddressInDb(eContractid.MockFlashLoanReceiver, mockFlashLoanReceiver.address);
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-11-20 10:32:17 +00:00
|
|
|
await deployWalletBalancerProvider();
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-11-02 17:43:50 +00:00
|
|
|
await deployWETHGateway([mockTokens.WETH.address, lendingPoolAddress]);
|
2020-10-29 11:44:21 +00:00
|
|
|
|
2020-07-13 08:54:08 +00:00
|
|
|
console.timeEnd('setup');
|
2020-06-08 12:03:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
before(async () => {
|
2020-11-05 12:44:20 +00:00
|
|
|
await rawBRE.run('set-DRE');
|
2020-06-10 08:31:33 +00:00
|
|
|
const [deployer, secondaryWallet] = await getEthersSigners();
|
2020-11-16 18:22:22 +00:00
|
|
|
const MAINNET_FORK = process.env.MAINNET_FORK === 'true';
|
|
|
|
|
|
|
|
if (MAINNET_FORK) {
|
|
|
|
await rawBRE.run('aave:mainnet');
|
|
|
|
} else {
|
|
|
|
console.log('-> Deploying test environment...');
|
|
|
|
await buildTestEnv(deployer, secondaryWallet);
|
|
|
|
}
|
|
|
|
|
2020-06-18 14:36:37 +00:00
|
|
|
await initializeMakeSuite();
|
2020-07-13 08:54:08 +00:00
|
|
|
console.log('\n***************');
|
|
|
|
console.log('Setup and snapshot finished');
|
|
|
|
console.log('***************\n');
|
2020-06-08 12:03:40 +00:00
|
|
|
});
|