2020-06-08 12:03:40 +00:00
|
|
|
import rawBRE from "@nomiclabs/buidler";
|
2020-06-08 15:36:40 +00:00
|
|
|
import {MockContract} from "ethereum-waffle";
|
2020-06-08 12:03:40 +00:00
|
|
|
import {
|
|
|
|
deployLendingPoolAddressesProvider,
|
|
|
|
deployMintableErc20,
|
|
|
|
deployLendingPoolAddressesProviderRegistry,
|
|
|
|
deployFeeProvider,
|
|
|
|
deployLendingPoolConfigurator,
|
|
|
|
deployLendingPool,
|
|
|
|
deployPriceOracle,
|
|
|
|
getLendingPoolConfiguratorProxy,
|
|
|
|
deployMockAggregator,
|
|
|
|
deployChainlinkProxyPriceProvider,
|
|
|
|
deployLendingRateOracle,
|
|
|
|
deployDefaultReserveInterestRateStrategy,
|
|
|
|
deployLendingPoolLiquidationManager,
|
|
|
|
deployTokenDistributor,
|
|
|
|
deployInitializableAdminUpgradeabilityProxy,
|
|
|
|
deployMockFlashLoanReceiver,
|
|
|
|
deployWalletBalancerProvider,
|
|
|
|
getFeeProvider,
|
2020-06-09 14:36:33 +00:00
|
|
|
getLendingPool,
|
2020-06-08 12:03:40 +00:00
|
|
|
insertContractAddressInDb,
|
2020-06-08 15:36:40 +00:00
|
|
|
deployAaveProtocolTestHelpers,
|
2020-06-10 08:31:33 +00:00
|
|
|
getEthersSigners,
|
2020-06-12 20:12:53 +00:00
|
|
|
registerContractInJsonDb,
|
2020-06-30 12:09:28 +00:00
|
|
|
deployStableDebtToken,
|
|
|
|
deployVariableDebtToken,
|
2020-06-08 12:03:40 +00:00
|
|
|
} from "../helpers/contracts-helpers";
|
|
|
|
import {LendingPoolAddressesProvider} from "../types/LendingPoolAddressesProvider";
|
2020-06-10 08:31:33 +00:00
|
|
|
import {Wallet, ContractTransaction, ethers, Signer} from "ethers";
|
2020-06-08 12:03:40 +00:00
|
|
|
import {
|
|
|
|
TokenContractId,
|
|
|
|
eContractid,
|
|
|
|
iAssetBase,
|
|
|
|
tEthereumAddress,
|
|
|
|
iAssetAggregatorBase,
|
|
|
|
IMarketRates,
|
|
|
|
iMultiPoolsAssets,
|
|
|
|
AavePools,
|
|
|
|
IReserveParams,
|
|
|
|
} from "../helpers/types";
|
|
|
|
import {MintableErc20} from "../types/MintableErc20";
|
|
|
|
import {
|
|
|
|
MOCK_USD_PRICE_IN_WEI,
|
|
|
|
ALL_ASSETS_INITIAL_PRICES,
|
|
|
|
MOCK_ETH_ADDRESS,
|
|
|
|
USD_ADDRESS,
|
|
|
|
MOCK_CHAINLINK_AGGREGATORS_PRICES,
|
|
|
|
LENDING_RATE_ORACLE_RATES_COMMON,
|
|
|
|
getReservesConfigByPool,
|
|
|
|
getFeeDistributionParamsCommon,
|
|
|
|
ZERO_ADDRESS,
|
|
|
|
} from "../helpers/constants";
|
|
|
|
import {PriceOracle} from "../types/PriceOracle";
|
|
|
|
import {MockAggregator} from "../types/MockAggregator";
|
|
|
|
import {LendingRateOracle} from "../types/LendingRateOracle";
|
2020-06-20 23:40:03 +00:00
|
|
|
import {LendingPool} from "../types/LendingPool";
|
2020-06-08 12:03:40 +00:00
|
|
|
import {LendingPoolConfigurator} from "../types/LendingPoolConfigurator";
|
2020-06-18 14:36:37 +00:00
|
|
|
import { initializeMakeSuite } from './helpers/make-suite';
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-06-10 08:31:33 +00:00
|
|
|
const deployAllMockTokens = async (deployer: Signer) => {
|
2020-06-08 12:03:40 +00:00
|
|
|
const tokens: {[symbol: string]: MockContract | MintableErc20} = {};
|
|
|
|
|
2020-07-03 09:15:30 +00:00
|
|
|
|
2020-06-26 19:28:18 +00:00
|
|
|
const protoConfigData = getReservesConfigByPool(AavePools.proto);
|
|
|
|
const secondaryConfigData = getReservesConfigByPool(AavePools.secondary);
|
|
|
|
|
|
|
|
|
2020-06-08 12:03:40 +00:00
|
|
|
for (const tokenSymbol of Object.keys(TokenContractId)) {
|
2020-06-26 19:28:18 +00:00
|
|
|
|
2020-06-08 12:03:40 +00:00
|
|
|
if (tokenSymbol !== "ETH") {
|
2020-07-03 09:15:30 +00:00
|
|
|
|
2020-06-26 19:28:18 +00:00
|
|
|
let decimals = 18;
|
2020-07-03 09:15:30 +00:00
|
|
|
|
2020-06-26 19:28:18 +00:00
|
|
|
let configData = (<any>protoConfigData)[tokenSymbol];
|
2020-07-03 09:15:30 +00:00
|
|
|
|
2020-06-26 19:28:18 +00:00
|
|
|
if(!configData){
|
|
|
|
configData = (<any>secondaryConfigData)[tokenSymbol]
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!configData){
|
|
|
|
decimals = 18;
|
|
|
|
}
|
2020-07-03 09:15:30 +00:00
|
|
|
|
2020-06-08 15:36:40 +00:00
|
|
|
tokens[tokenSymbol] = await deployMintableErc20([
|
|
|
|
tokenSymbol,
|
|
|
|
tokenSymbol,
|
2020-06-26 19:28:18 +00:00
|
|
|
configData ? configData.reserveDecimals : 18,
|
2020-06-08 15:36:40 +00:00
|
|
|
]);
|
2020-06-12 20:12:53 +00:00
|
|
|
await registerContractInJsonDb(
|
|
|
|
tokenSymbol.toUpperCase(),
|
|
|
|
tokens[tokenSymbol]
|
|
|
|
);
|
2020-06-08 12:03:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tokens;
|
|
|
|
};
|
|
|
|
|
|
|
|
const setInitialAssetPricesInOracle = async (
|
|
|
|
prices: iAssetBase<tEthereumAddress>,
|
|
|
|
assetsAddresses: iAssetBase<tEthereumAddress>,
|
|
|
|
priceOracleInstance: PriceOracle
|
|
|
|
) => {
|
|
|
|
for (const [assetSymbol, price] of Object.entries(prices) as [
|
|
|
|
string,
|
|
|
|
string
|
|
|
|
][]) {
|
|
|
|
const assetAddressIndex = Object.keys(assetsAddresses).findIndex(
|
|
|
|
(value) => value === assetSymbol
|
|
|
|
);
|
|
|
|
const [, assetAddress] = (Object.entries(assetsAddresses) as [
|
|
|
|
string,
|
|
|
|
string
|
|
|
|
][])[assetAddressIndex];
|
|
|
|
await waitForTx(
|
|
|
|
await priceOracleInstance.setAssetPrice(assetAddress, price)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const deployAllMockAggregators = async (
|
|
|
|
initialPrices: iAssetAggregatorBase<string>
|
|
|
|
) => {
|
|
|
|
const aggregators: {[tokenSymbol: string]: MockAggregator} = {};
|
|
|
|
for (const tokenContractName of Object.keys(initialPrices)) {
|
|
|
|
if (tokenContractName !== "ETH") {
|
|
|
|
const priceIndex = Object.keys(initialPrices).findIndex(
|
|
|
|
(value) => value === tokenContractName
|
|
|
|
);
|
|
|
|
const [, price] = (Object.entries(initialPrices) as [string, string][])[
|
|
|
|
priceIndex
|
|
|
|
];
|
|
|
|
aggregators[tokenContractName] = await deployMockAggregator(price);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aggregators;
|
|
|
|
};
|
|
|
|
|
|
|
|
const getPairsTokenAggregator = (
|
|
|
|
allAssetsAddresses: {
|
|
|
|
[tokenSymbol: string]: tEthereumAddress;
|
|
|
|
},
|
|
|
|
aggregatorsAddresses: {[tokenSymbol: string]: tEthereumAddress}
|
|
|
|
): [string[], string[]] => {
|
|
|
|
const {ETH, ...assetsAddressesWithoutEth} = allAssetsAddresses;
|
|
|
|
|
|
|
|
const pairs = Object.entries(assetsAddressesWithoutEth).map(
|
|
|
|
([tokenSymbol, tokenAddress]) => {
|
|
|
|
if (tokenSymbol !== "ETH") {
|
|
|
|
const aggregatorAddressIndex = Object.keys(
|
|
|
|
aggregatorsAddresses
|
|
|
|
).findIndex((value) => value === tokenSymbol);
|
|
|
|
const [, aggregatorAddress] = (Object.entries(aggregatorsAddresses) as [
|
|
|
|
string,
|
|
|
|
tEthereumAddress
|
|
|
|
][])[aggregatorAddressIndex];
|
|
|
|
return [tokenAddress, aggregatorAddress];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const mappedPairs = pairs.map(([asset]) => asset);
|
|
|
|
const mappedAggregators = pairs.map(([, source]) => source);
|
|
|
|
|
|
|
|
return [mappedPairs, mappedAggregators];
|
|
|
|
};
|
|
|
|
|
|
|
|
const setInitialMarketRatesInRatesOracle = async (
|
|
|
|
marketRates: iMultiPoolsAssets<IMarketRates>,
|
|
|
|
assetsAddresses: {[x: string]: tEthereumAddress},
|
|
|
|
lendingRateOracleInstance: LendingRateOracle
|
|
|
|
) => {
|
|
|
|
for (const [assetSymbol, {borrowRate}] of Object.entries(marketRates) as [
|
|
|
|
string,
|
|
|
|
IMarketRates
|
|
|
|
][]) {
|
|
|
|
const assetAddressIndex = Object.keys(assetsAddresses).findIndex(
|
|
|
|
(value) => value === assetSymbol
|
|
|
|
);
|
|
|
|
const [, assetAddress] = (Object.entries(assetsAddresses) as [
|
|
|
|
string,
|
|
|
|
string
|
|
|
|
][])[assetAddressIndex];
|
|
|
|
await lendingRateOracleInstance.setMarketBorrowRate(
|
|
|
|
assetAddress,
|
|
|
|
borrowRate
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const initReserves = async (
|
|
|
|
reservesParams: iMultiPoolsAssets<IReserveParams>,
|
|
|
|
tokenAddresses: {[symbol: string]: tEthereumAddress},
|
|
|
|
lendingPoolAddressesProvider: LendingPoolAddressesProvider,
|
2020-06-20 23:40:03 +00:00
|
|
|
lendingPool: LendingPool,
|
2020-06-08 12:03:40 +00:00
|
|
|
lendingPoolConfigurator: LendingPoolConfigurator,
|
|
|
|
aavePool: AavePools
|
|
|
|
) => {
|
|
|
|
if (aavePool !== AavePools.proto && aavePool !== AavePools.secondary) {
|
|
|
|
console.log(`Invalid Aave pool ${aavePool}`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let [assetSymbol, {reserveDecimals}] of Object.entries(
|
|
|
|
reservesParams
|
|
|
|
) as [string, IReserveParams][]) {
|
|
|
|
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
|
|
|
|
(value) => value === assetSymbol
|
|
|
|
);
|
|
|
|
const [, tokenAddress] = (Object.entries(tokenAddresses) as [
|
|
|
|
string,
|
|
|
|
string
|
|
|
|
][])[assetAddressIndex];
|
2020-07-03 09:15:30 +00:00
|
|
|
|
2020-06-26 12:34:44 +00:00
|
|
|
const {isActive: reserveInitialized} = await lendingPool.getReserveConfigurationData(
|
2020-06-08 12:03:40 +00:00
|
|
|
tokenAddress
|
|
|
|
);
|
|
|
|
|
|
|
|
if (reserveInitialized) {
|
|
|
|
console.log(
|
|
|
|
`Reserve ${assetSymbol} is already active, skipping configuration`
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const reserveParamIndex = Object.keys(reservesParams).findIndex(
|
|
|
|
(value) => value === assetSymbol
|
|
|
|
);
|
|
|
|
const [
|
|
|
|
,
|
|
|
|
{
|
|
|
|
baseVariableBorrowRate,
|
|
|
|
variableRateSlope1,
|
|
|
|
variableRateSlope2,
|
|
|
|
stableRateSlope1,
|
|
|
|
stableRateSlope2,
|
|
|
|
},
|
|
|
|
] = (Object.entries(reservesParams) as [string, IReserveParams][])[
|
|
|
|
reserveParamIndex
|
|
|
|
];
|
|
|
|
const rateStrategyContract = await deployDefaultReserveInterestRateStrategy(
|
|
|
|
[
|
|
|
|
lendingPoolAddressesProvider.address,
|
|
|
|
baseVariableBorrowRate,
|
|
|
|
variableRateSlope1,
|
|
|
|
variableRateSlope2,
|
|
|
|
stableRateSlope1,
|
|
|
|
stableRateSlope2,
|
|
|
|
]
|
|
|
|
);
|
2020-06-30 12:09:28 +00:00
|
|
|
|
|
|
|
const stableDebtToken = await deployStableDebtToken([
|
|
|
|
`Aave stable debt bearing ${assetSymbol}`,
|
|
|
|
`stableDebt${assetSymbol}`,
|
|
|
|
reserveDecimals,
|
|
|
|
tokenAddress,
|
|
|
|
lendingPoolAddressesProvider.address
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
const variableDebtToken = await deployVariableDebtToken([
|
|
|
|
`Aave stable debt bearing ${assetSymbol}`,
|
|
|
|
`stableDebt${assetSymbol}`,
|
|
|
|
reserveDecimals,
|
|
|
|
tokenAddress,
|
|
|
|
lendingPoolAddressesProvider.address
|
|
|
|
]
|
|
|
|
)
|
2020-07-03 09:15:30 +00:00
|
|
|
|
2020-06-30 12:09:28 +00:00
|
|
|
console.log(`Debt tokens for ${assetSymbol}: stable ${stableDebtToken.address} variable ${variableDebtToken.address}`)
|
2020-07-03 09:15:30 +00:00
|
|
|
|
2020-06-08 12:03:40 +00:00
|
|
|
if (process.env.POOL === AavePools.secondary) {
|
|
|
|
if (assetSymbol.search("UNI") === -1) {
|
|
|
|
assetSymbol = `Uni${assetSymbol}`;
|
|
|
|
} else {
|
|
|
|
assetSymbol = assetSymbol.replace(/_/g, "").replace("UNI", "Uni");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await lendingPoolConfigurator.initReserveWithData(
|
|
|
|
tokenAddress,
|
|
|
|
`Aave Interest bearing ${assetSymbol}`,
|
|
|
|
`a${assetSymbol}`,
|
2020-06-30 12:09:28 +00:00
|
|
|
stableDebtToken.address,
|
|
|
|
variableDebtToken.address,
|
2020-06-08 12:03:40 +00:00
|
|
|
reserveDecimals,
|
|
|
|
rateStrategyContract.address
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(
|
|
|
|
`Reserve initialization for ${assetSymbol} failed with error ${e}. Skipped.`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const enableReservesToBorrow = async (
|
|
|
|
reservesParams: iMultiPoolsAssets<IReserveParams>,
|
|
|
|
tokenAddresses: {[symbol: string]: tEthereumAddress},
|
2020-06-20 23:40:03 +00:00
|
|
|
lendingPool: LendingPool,
|
2020-06-08 12:03:40 +00:00
|
|
|
lendingPoolConfigurator: LendingPoolConfigurator
|
|
|
|
) => {
|
|
|
|
for (const [
|
|
|
|
assetSymbol,
|
|
|
|
{borrowingEnabled, stableBorrowRateEnabled},
|
|
|
|
] of Object.entries(reservesParams) as [string, IReserveParams][]) {
|
|
|
|
if (!borrowingEnabled) continue;
|
|
|
|
try {
|
|
|
|
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
|
|
|
|
(value) => value === assetSymbol
|
|
|
|
);
|
|
|
|
const [, tokenAddress] = (Object.entries(tokenAddresses) as [
|
|
|
|
string,
|
|
|
|
string
|
|
|
|
][])[assetAddressIndex];
|
2020-06-26 12:34:44 +00:00
|
|
|
const {borrowingEnabled: borrowingAlreadyEnabled} = await lendingPool.getReserveConfigurationData(
|
2020-06-08 12:03:40 +00:00
|
|
|
tokenAddress
|
|
|
|
);
|
|
|
|
|
|
|
|
if (borrowingAlreadyEnabled) {
|
|
|
|
console.log(
|
|
|
|
`Reserve ${assetSymbol} is already enabled for borrowing, skipping`
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
await lendingPoolConfigurator.enableBorrowingOnReserve(
|
|
|
|
tokenAddress,
|
|
|
|
stableBorrowRateEnabled
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(
|
|
|
|
`Enabling reserve for borrowings for ${assetSymbol} failed with error ${e}. Skipped.`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const enableReservesAsCollateral = async (
|
|
|
|
reservesParams: iMultiPoolsAssets<IReserveParams>,
|
|
|
|
tokenAddresses: {[symbol: string]: tEthereumAddress},
|
2020-06-20 23:40:03 +00:00
|
|
|
lendingPool: LendingPool,
|
2020-06-08 12:03:40 +00:00
|
|
|
lendingPoolConfigurator: LendingPoolConfigurator
|
|
|
|
) => {
|
|
|
|
for (const [
|
|
|
|
assetSymbol,
|
|
|
|
{baseLTVAsCollateral, liquidationBonus, liquidationThreshold},
|
|
|
|
] of Object.entries(reservesParams) as [string, IReserveParams][]) {
|
|
|
|
if (baseLTVAsCollateral === "-1") continue;
|
|
|
|
|
|
|
|
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
|
|
|
|
(value) => value === assetSymbol
|
|
|
|
);
|
|
|
|
const [, tokenAddress] = (Object.entries(tokenAddresses) as [
|
|
|
|
string,
|
|
|
|
string
|
|
|
|
][])[assetAddressIndex];
|
2020-06-26 12:34:44 +00:00
|
|
|
const {usageAsCollateralEnabled: alreadyEnabled} = await lendingPool.getReserveConfigurationData(
|
2020-06-08 12:03:40 +00:00
|
|
|
tokenAddress
|
|
|
|
);
|
|
|
|
|
|
|
|
if (alreadyEnabled) {
|
|
|
|
console.log(
|
|
|
|
`Reserve ${assetSymbol} is already enabled as collateral, skipping`
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await lendingPoolConfigurator.enableReserveAsCollateral(
|
|
|
|
tokenAddress,
|
|
|
|
baseLTVAsCollateral,
|
|
|
|
liquidationThreshold,
|
|
|
|
liquidationBonus
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(
|
|
|
|
`Enabling reserve as collateral for ${assetSymbol} failed with error ${e}. Skipped.`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-12 20:12:53 +00:00
|
|
|
export const waitForTx = async (tx: ContractTransaction) => await tx.wait();
|
2020-06-08 12:03:40 +00:00
|
|
|
|
2020-06-10 08:31:33 +00:00
|
|
|
const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
2020-06-08 12:03:40 +00:00
|
|
|
console.time("setup");
|
2020-06-10 08:31:33 +00:00
|
|
|
const lendingPoolManager = 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
|
|
|
|
|
|
|
const addressesProvider = await deployLendingPoolAddressesProvider();
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setLendingPoolManager(lendingPoolManager)
|
|
|
|
);
|
|
|
|
|
|
|
|
const addressesProviderRegistry = await deployLendingPoolAddressesProviderRegistry();
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProviderRegistry.registerAddressesProvider(
|
|
|
|
addressesProvider.address,
|
|
|
|
0
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
const feeProviderImpl = await deployFeeProvider();
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setFeeProviderImpl(feeProviderImpl.address)
|
|
|
|
);
|
|
|
|
const feeProviderProxy = await getFeeProvider(
|
|
|
|
await addressesProvider.getFeeProvider()
|
|
|
|
);
|
|
|
|
await insertContractAddressInDb(
|
|
|
|
eContractid.FeeProvider,
|
|
|
|
feeProviderProxy.address
|
|
|
|
);
|
|
|
|
|
|
|
|
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-07-03 09:15:30 +00:00
|
|
|
|
2020-06-08 12:03:40 +00:00
|
|
|
const lendingPoolImpl = await deployLendingPool();
|
2020-06-20 23:40:03 +00:00
|
|
|
|
|
|
|
console.log("Deployed lending pool, address:", lendingPoolImpl.address)
|
2020-06-08 12:03:40 +00:00
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setLendingPoolImpl(lendingPoolImpl.address)
|
|
|
|
);
|
2020-06-20 23:40:03 +00:00
|
|
|
|
|
|
|
console.log("Added pool to addresses provider")
|
|
|
|
|
|
|
|
const address = await addressesProvider.getLendingPool()
|
|
|
|
console.log("Address is ", address)
|
2020-06-09 14:36:33 +00:00
|
|
|
const lendingPoolProxy = await getLendingPool(
|
2020-07-03 09:15:30 +00:00
|
|
|
address
|
2020-06-08 12:03:40 +00:00
|
|
|
);
|
2020-06-20 23:40:03 +00:00
|
|
|
|
2020-06-26 12:34:44 +00:00
|
|
|
console.log("implementation set, address:", lendingPoolProxy.address)
|
2020-06-20 23:40:03 +00:00
|
|
|
|
2020-06-08 12:03:40 +00:00
|
|
|
await insertContractAddressInDb(
|
|
|
|
eContractid.LendingPool,
|
|
|
|
lendingPoolProxy.address
|
|
|
|
);
|
|
|
|
|
|
|
|
const fallbackOracle = await deployPriceOracle();
|
|
|
|
await waitForTx(await fallbackOracle.setEthUsdPrice(MOCK_USD_PRICE_IN_WEI));
|
|
|
|
await setInitialAssetPricesInOracle(
|
|
|
|
ALL_ASSETS_INITIAL_PRICES,
|
|
|
|
{
|
|
|
|
ETH: MOCK_ETH_ADDRESS,
|
|
|
|
DAI: mockTokens.DAI.address,
|
|
|
|
TUSD: mockTokens.TUSD.address,
|
|
|
|
USDC: mockTokens.USDC.address,
|
|
|
|
USDT: mockTokens.USDT.address,
|
|
|
|
SUSD: mockTokens.SUSD.address,
|
|
|
|
LEND: mockTokens.LEND.address,
|
|
|
|
BAT: mockTokens.BAT.address,
|
|
|
|
REP: mockTokens.REP.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,
|
|
|
|
|
|
|
|
USD: USD_ADDRESS,
|
|
|
|
|
|
|
|
UNI_DAI_ETH: mockTokens.UNI_DAI_ETH.address,
|
|
|
|
UNI_USDC_ETH: mockTokens.UNI_USDC_ETH.address,
|
|
|
|
UNI_SETH_ETH: mockTokens.UNI_SETH_ETH.address,
|
|
|
|
UNI_LEND_ETH: mockTokens.UNI_LEND_ETH.address,
|
|
|
|
UNI_MKR_ETH: mockTokens.UNI_MKR_ETH.address,
|
|
|
|
UNI_LINK_ETH: mockTokens.UNI_LINK_ETH.address,
|
|
|
|
},
|
|
|
|
fallbackOracle
|
|
|
|
);
|
|
|
|
|
|
|
|
const mockAggregators = await deployAllMockAggregators(
|
|
|
|
MOCK_CHAINLINK_AGGREGATORS_PRICES
|
|
|
|
);
|
|
|
|
|
|
|
|
const allTokenAddresses = Object.entries(mockTokens).reduce(
|
|
|
|
(
|
|
|
|
accum: {[tokenSymbol: string]: tEthereumAddress},
|
|
|
|
[tokenSymbol, tokenContract]
|
|
|
|
) => ({
|
|
|
|
...accum,
|
|
|
|
[tokenSymbol]: tokenContract.address,
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
const allAggregatorsAddresses = Object.entries(mockAggregators).reduce(
|
|
|
|
(
|
|
|
|
accum: {[tokenSymbol: string]: tEthereumAddress},
|
|
|
|
[tokenSymbol, aggregator]
|
|
|
|
) => ({
|
|
|
|
...accum,
|
|
|
|
[tokenSymbol]: aggregator.address,
|
|
|
|
}),
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
|
|
|
const [tokens, aggregators] = getPairsTokenAggregator(
|
|
|
|
allTokenAddresses,
|
|
|
|
allAggregatorsAddresses
|
|
|
|
);
|
|
|
|
|
|
|
|
const chainlinkProxyPriceProvider = await deployChainlinkProxyPriceProvider([
|
|
|
|
tokens,
|
|
|
|
aggregators,
|
|
|
|
fallbackOracle.address,
|
|
|
|
]);
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setPriceOracle(chainlinkProxyPriceProvider.address)
|
|
|
|
);
|
|
|
|
|
|
|
|
const lendingRateOracle = await deployLendingRateOracle();
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setLendingRateOracle(lendingRateOracle.address)
|
|
|
|
);
|
|
|
|
|
|
|
|
const {USD, ...tokensAddressesWithoutUsd} = allTokenAddresses;
|
|
|
|
const allReservesAddresses = {
|
|
|
|
ETH: MOCK_ETH_ADDRESS,
|
|
|
|
...tokensAddressesWithoutUsd,
|
|
|
|
};
|
|
|
|
await setInitialMarketRatesInRatesOracle(
|
|
|
|
LENDING_RATE_ORACLE_RATES_COMMON,
|
|
|
|
allReservesAddresses,
|
|
|
|
lendingRateOracle
|
|
|
|
);
|
|
|
|
|
|
|
|
const {
|
|
|
|
UNI_DAI_ETH,
|
|
|
|
UNI_USDC_ETH,
|
|
|
|
UNI_SETH_ETH,
|
|
|
|
UNI_LINK_ETH,
|
|
|
|
UNI_MKR_ETH,
|
|
|
|
UNI_LEND_ETH,
|
|
|
|
...protoPoolReservesAddresses
|
|
|
|
} = <{[symbol: string]: tEthereumAddress}>allReservesAddresses;
|
|
|
|
|
|
|
|
const reservesParams = getReservesConfigByPool(AavePools.proto);
|
|
|
|
|
2020-06-20 23:40:03 +00:00
|
|
|
console.log("Initialize configuration")
|
2020-06-08 12:03:40 +00:00
|
|
|
await initReserves(
|
|
|
|
reservesParams,
|
|
|
|
protoPoolReservesAddresses,
|
|
|
|
addressesProvider,
|
2020-06-20 23:40:03 +00:00
|
|
|
lendingPoolProxy,
|
2020-06-08 12:03:40 +00:00
|
|
|
lendingPoolConfiguratorProxy,
|
|
|
|
AavePools.proto
|
|
|
|
);
|
|
|
|
await enableReservesToBorrow(
|
|
|
|
reservesParams,
|
|
|
|
protoPoolReservesAddresses,
|
2020-06-20 23:40:03 +00:00
|
|
|
lendingPoolProxy,
|
2020-06-08 12:03:40 +00:00
|
|
|
lendingPoolConfiguratorProxy
|
|
|
|
);
|
|
|
|
await enableReservesAsCollateral(
|
|
|
|
reservesParams,
|
|
|
|
protoPoolReservesAddresses,
|
2020-06-20 23:40:03 +00:00
|
|
|
lendingPoolProxy,
|
2020-06-08 12:03:40 +00:00
|
|
|
lendingPoolConfiguratorProxy
|
|
|
|
);
|
|
|
|
|
|
|
|
const liquidationManager = await deployLendingPoolLiquidationManager();
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setLendingPoolLiquidationManager(
|
|
|
|
liquidationManager.address
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
const {receivers, percentages} = getFeeDistributionParamsCommon(
|
2020-06-10 08:31:33 +00:00
|
|
|
lendingPoolManager
|
2020-06-08 12:03:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const tokenDistributorImpl = await deployTokenDistributor();
|
|
|
|
const tokenDistributorProxy = await deployInitializableAdminUpgradeabilityProxy();
|
|
|
|
const implementationParams = tokenDistributorImpl.interface.functions.initialize.encode(
|
|
|
|
[
|
|
|
|
ZERO_ADDRESS,
|
|
|
|
tokensAddressesWithoutUsd.LEND,
|
2020-07-03 09:15:30 +00:00
|
|
|
'0x0000000000000000000000000000000000000000', // TODO: finish removal
|
2020-06-08 12:03:40 +00:00
|
|
|
receivers,
|
|
|
|
percentages,
|
|
|
|
Object.values(tokensAddressesWithoutUsd),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
await waitForTx(
|
|
|
|
await tokenDistributorProxy.initialize(
|
|
|
|
tokenDistributorImpl.address,
|
2020-06-10 08:31:33 +00:00
|
|
|
await secondaryWallet.getAddress(),
|
2020-06-08 12:03:40 +00:00
|
|
|
implementationParams
|
|
|
|
)
|
|
|
|
);
|
|
|
|
await waitForTx(
|
|
|
|
await addressesProvider.setTokenDistributor(tokenDistributorProxy.address)
|
|
|
|
);
|
|
|
|
|
2020-06-12 13:41:52 +00:00
|
|
|
await insertContractAddressInDb(
|
|
|
|
eContractid.TokenDistributor,
|
|
|
|
tokenDistributorProxy.address
|
|
|
|
);
|
|
|
|
|
|
|
|
const mockFlashLoanReceiver = await deployMockFlashLoanReceiver(
|
|
|
|
addressesProvider.address
|
|
|
|
);
|
|
|
|
await insertContractAddressInDb(
|
|
|
|
eContractid.MockFlashLoanReceiver,
|
|
|
|
mockFlashLoanReceiver.address
|
|
|
|
);
|
2020-06-08 12:03:40 +00:00
|
|
|
|
|
|
|
await deployWalletBalancerProvider(addressesProvider.address);
|
|
|
|
|
2020-06-08 15:36:40 +00:00
|
|
|
const testHelpers = await deployAaveProtocolTestHelpers(
|
|
|
|
addressesProvider.address
|
|
|
|
);
|
|
|
|
|
|
|
|
await insertContractAddressInDb(
|
|
|
|
eContractid.AaveProtocolTestHelpers,
|
|
|
|
testHelpers.address
|
|
|
|
);
|
|
|
|
|
2020-06-08 12:03:40 +00:00
|
|
|
console.timeEnd("setup");
|
|
|
|
};
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
await rawBRE.run("set-bre");
|
2020-06-10 08:31:33 +00:00
|
|
|
const [deployer, secondaryWallet] = await getEthersSigners();
|
2020-06-12 13:41:52 +00:00
|
|
|
console.log("-> Deploying test environment...");
|
2020-06-08 12:03:40 +00:00
|
|
|
await buildTestEnv(deployer, secondaryWallet);
|
2020-06-18 14:36:37 +00:00
|
|
|
await initializeMakeSuite();
|
2020-06-08 12:03:40 +00:00
|
|
|
console.log("\n***************");
|
|
|
|
console.log("Setup and snapshot finished");
|
|
|
|
console.log("***************\n");
|
|
|
|
});
|