From 3c3e4d146aff5c15b869088b555e9a60586c7f19 Mon Sep 17 00:00:00 2001 From: emilio Date: Thu, 13 Aug 2020 13:06:23 +0200 Subject: [PATCH] First refactor of the tests; replaced ETH with WETH in the configuration --- deployed-contracts.json | 86 ++++++----- helpers/constants.ts | 9 +- helpers/contracts-helpers.ts | 28 ++-- helpers/types.ts | 9 +- test/__setup.spec.ts | 20 +-- test/atoken-transfer.spec.ts | 21 ++- test/configurator.spec.ts | 142 +++++++++--------- test/flashloan.spec.ts | 34 ++--- test/helpers/actions.ts | 43 +----- test/helpers/make-suite.ts | 19 ++- test/helpers/scenarios/borrow-negatives.json | 6 +- .../scenarios/borrow-repay-stable.json | 18 ++- .../scenarios/borrow-repay-variable.json | 54 ++++--- test/helpers/scenarios/deposit.json | 15 +- .../scenarios/interest-redirection.json | 3 +- .../scenarios/rebalance-stable-rate.json | 9 +- test/helpers/scenarios/redeem-negatives.json | 6 +- test/helpers/scenarios/redeem.json | 12 +- .../scenarios/set-use-as-collateral.json | 15 +- test/helpers/scenarios/swap-rate-mode.json | 3 +- test/helpers/utils/helpers.ts | 28 +--- test/liquidation-atoken.spec.ts | 50 +++--- test/liquidation-underlying.spec.ts | 38 ++--- test/scenario.spec.ts | 3 +- 24 files changed, 343 insertions(+), 328 deletions(-) diff --git a/deployed-contracts.json b/deployed-contracts.json index 1c408f8e..4d470127 100644 --- a/deployed-contracts.json +++ b/deployed-contracts.json @@ -1,7 +1,7 @@ { "MintableERC20": { "buidlerevm": { - "address": "0xB00cC45B4a7d3e1FEE684cFc4417998A1c183e6d", + "address": "0x58F132FBB86E21545A4Bace3C19f1C05d86d7A22", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -11,7 +11,7 @@ }, "LendingPoolAddressesProvider": { "buidlerevm": { - "address": "0x58F132FBB86E21545A4Bace3C19f1C05d86d7A22", + "address": "0xa4bcDF64Cdd5451b6ac3743B414124A6299B65FF", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -21,7 +21,7 @@ }, "LendingPoolAddressesProviderRegistry": { "buidlerevm": { - "address": "0x22474D350EC2dA53D717E30b96e9a2B7628Ede5b", + "address": "0x5A0773Ff307Bf7C71a832dBB5312237fD3437f9F", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -31,7 +31,7 @@ }, "FeeProvider": { "buidlerevm": { - "address": "0x852e3718A320aD93Ad8692E8D663d247e4c1b400" + "address": "0xD9273d497eDBC967F39d419461CfcF382a0A822e" }, "localhost": { "address": "0x0f2cE53B3410a2007d6C4ad8940Ffa5AdCC2916C" @@ -49,7 +49,7 @@ }, "LendingPoolConfigurator": { "buidlerevm": { - "address": "0xA10958a24032283FbE2D23cedf264d6eC9411CBA" + "address": "0x9EC0480CF106d6dc1c7849BA141a56F874170F97" }, "localhost": { "address": "0x0ca5E5B6F09C97f30Ed6e5E99be65A38eE7edfaB" @@ -62,7 +62,7 @@ }, "LendingPool": { "buidlerevm": { - "address": "0x2C4603396dE2F08642354A3A102760827FfFe113" + "address": "0x6642B57e4265BAD868C17Fc1d1F4F88DBBA04Aa8" }, "localhost": { "address": "0x7FE8419fACf45dFa93d471644e87122923EC9D94" @@ -70,7 +70,7 @@ }, "PriceOracle": { "buidlerevm": { - "address": "0xE4C10Db67595aF2Cb4166c8C274e0140f7E43059", + "address": "0x099d9fF8F818290C8b5B7Db5bFca84CEebd2714c", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -80,7 +80,7 @@ }, "MockAggregator": { "buidlerevm": { - "address": "0xEC1C93A9f6a9e18E97784c76aC52053587FcDB89", + "address": "0xAF6BA11790D1942625C0c2dA07da19AB63845cfF", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -90,7 +90,7 @@ }, "ChainlinkProxyPriceProvider": { "buidlerevm": { - "address": "0x7B6C3e5486D9e6959441ab554A889099eed76290", + "address": "0xD83D2773a7873ae2b5f8Fb92097e20a8C64F691E", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -100,7 +100,7 @@ }, "LendingRateOracle": { "buidlerevm": { - "address": "0xD83D2773a7873ae2b5f8Fb92097e20a8C64F691E", + "address": "0xf91aC1098F3b154671Ce83290114aaE45ac0225f", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -110,7 +110,7 @@ }, "DefaultReserveInterestRateStrategy": { "buidlerevm": { - "address": "0x09d728F76D543DB1925f7d1Fd8823e4e82700F99", + "address": "0x09d7cb7a0606a7f10DC8a37b3e0E420F39f0FAF1", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -146,7 +146,7 @@ }, "TokenDistributor": { "buidlerevm": { - "address": "0x03A6802eF9060a8E1f0e56Bafc9C9AB1A26a1f06" + "address": "0x22B37db37e9992728245A7dD0536892AF9bA1baB" }, "localhost": { "address": "0x39f713653d31a8e0D7a51061F1159861290e65Fd" @@ -154,7 +154,7 @@ }, "InitializableAdminUpgradeabilityProxy": { "buidlerevm": { - "address": "0x03A6802eF9060a8E1f0e56Bafc9C9AB1A26a1f06", + "address": "0x22B37db37e9992728245A7dD0536892AF9bA1baB", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -164,7 +164,7 @@ }, "MockFlashLoanReceiver": { "buidlerevm": { - "address": "0x9D37fB22EA7d655f12E68DABBf6B6585A00774C3" + "address": "0x850Fae11E1313e6C23Db7c2410Ec0985d9Ea325A" }, "localhost": { "address": "0xC4e948241c7A63d1f21fD98D652aE4B59180e07F" @@ -172,7 +172,7 @@ }, "WalletBalanceProvider": { "buidlerevm": { - "address": "0x2005823e074313cd644035557bF4FFa0ca0Bddff", + "address": "0x22058276Dd278bD037591805E62E797012d666f6", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -222,7 +222,7 @@ }, "USDC": { "buidlerevm": { - "address": "0xf784709d2317D872237C4bC22f867d1BAe2913AB", + "address": "0x3619DbE27d7c1e7E91aA738697Ae7Bc5FC3eACA5", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -232,7 +232,7 @@ }, "USDT": { "buidlerevm": { - "address": "0x3619DbE27d7c1e7E91aA738697Ae7Bc5FC3eACA5", + "address": "0x038B86d9d8FAFdd0a02ebd1A476432877b0107C8", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -242,7 +242,7 @@ }, "SUSD": { "buidlerevm": { - "address": "0x038B86d9d8FAFdd0a02ebd1A476432877b0107C8", + "address": "0x1A1FEe7EeD918BD762173e4dc5EfDB8a78C924A8", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -252,7 +252,7 @@ }, "ZRX": { "buidlerevm": { - "address": "0x1A1FEe7EeD918BD762173e4dc5EfDB8a78C924A8", + "address": "0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -262,7 +262,7 @@ }, "MKR": { "buidlerevm": { - "address": "0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e", + "address": "0xc4905364b78a742ccce7B890A89514061E47068D", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -272,7 +272,7 @@ }, "WBTC": { "buidlerevm": { - "address": "0xc4905364b78a742ccce7B890A89514061E47068D", + "address": "0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -282,7 +282,7 @@ }, "LINK": { "buidlerevm": { - "address": "0xD6C850aeBFDC46D7F4c207e445cC0d6B0919BDBe", + "address": "0x8B5B7a6055E54a36fF574bbE40cf2eA68d5554b3", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -292,7 +292,7 @@ }, "KNC": { "buidlerevm": { - "address": "0x8B5B7a6055E54a36fF574bbE40cf2eA68d5554b3", + "address": "0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -302,7 +302,7 @@ }, "MANA": { "buidlerevm": { - "address": "0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0", + "address": "0x20Ce94F404343aD2752A2D01b43fa407db9E0D00", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -312,7 +312,7 @@ }, "REP": { "buidlerevm": { - "address": "0x20Ce94F404343aD2752A2D01b43fa407db9E0D00", + "address": "0x1d80315fac6aBd3EfeEbE97dEc44461ba7556160", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -322,7 +322,7 @@ }, "SNX": { "buidlerevm": { - "address": "0x1d80315fac6aBd3EfeEbE97dEc44461ba7556160", + "address": "0x2D8553F9ddA85A9B3259F6Bf26911364B85556F5", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -332,7 +332,7 @@ }, "BUSD": { "buidlerevm": { - "address": "0x2D8553F9ddA85A9B3259F6Bf26911364B85556F5", + "address": "0x52d3b94181f8654db2530b0fEe1B19173f519C52", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -342,7 +342,7 @@ }, "USD": { "buidlerevm": { - "address": "0x52d3b94181f8654db2530b0fEe1B19173f519C52", + "address": "0xd15468525c35BDBC1eD8F2e09A00F8a173437f2f", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -352,7 +352,7 @@ }, "UNI_DAI_ETH": { "buidlerevm": { - "address": "0xd15468525c35BDBC1eD8F2e09A00F8a173437f2f", + "address": "0x7e35Eaf7e8FBd7887ad538D4A38Df5BbD073814a", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -362,7 +362,7 @@ }, "UNI_USDC_ETH": { "buidlerevm": { - "address": "0x7e35Eaf7e8FBd7887ad538D4A38Df5BbD073814a", + "address": "0x5bcb88A0d20426e451332eE6C4324b0e663c50E0", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -372,7 +372,7 @@ }, "UNI_SETH_ETH": { "buidlerevm": { - "address": "0x5bcb88A0d20426e451332eE6C4324b0e663c50E0", + "address": "0x3521eF8AaB0323004A6dD8b03CE890F4Ea3A13f5", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -382,7 +382,7 @@ }, "UNI_LINK_ETH": { "buidlerevm": { - "address": "0x3521eF8AaB0323004A6dD8b03CE890F4Ea3A13f5", + "address": "0x53369fd4680FfE3DfF39Fc6DDa9CfbfD43daeA2E", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -392,7 +392,7 @@ }, "UNI_MKR_ETH": { "buidlerevm": { - "address": "0x53369fd4680FfE3DfF39Fc6DDa9CfbfD43daeA2E", + "address": "0xB00cC45B4a7d3e1FEE684cFc4417998A1c183e6d", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -402,7 +402,7 @@ }, "UNI_LEND_ETH": { "buidlerevm": { - "address": "0xB00cC45B4a7d3e1FEE684cFc4417998A1c183e6d", + "address": "0x58F132FBB86E21545A4Bace3C19f1C05d86d7A22", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -412,7 +412,7 @@ }, "AaveProtocolTestHelpers": { "buidlerevm": { - "address": "0x850Fae11E1313e6C23Db7c2410Ec0985d9Ea325A" + "address": "0x6D3540a9F1a769bfd91A4A33169a8361aa82dC0F" }, "localhost": { "address": "0x26af54A97F214dB563711B0670c4FbA2Eb935E37" @@ -420,7 +420,7 @@ }, "StableDebtToken": { "buidlerevm": { - "address": "0xb2B548BE73010C188C083c510d255Aed74843b05", + "address": "0x5Ea694f66BD0CBd08FC7967af01b67Dcef68cC5c", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -430,7 +430,7 @@ }, "VariableDebtToken": { "buidlerevm": { - "address": "0x5Ea694f66BD0CBd08FC7967af01b67Dcef68cC5c", + "address": "0xd4e934C2749CA8C1618659D02E7B28B074bf4df7", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "localhost": { @@ -444,14 +444,20 @@ "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" }, "buidlerevm": { - "address": "0xd4e934C2749CA8C1618659D02E7B28B074bf4df7", + "address": "0x8280D40C9E9F04229D2435EAad6e0011309ce81B", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } }, "MockAToken": { "buidlerevm": { - "address": "0xccdf1DECe9c9631081b952Cd51A579E75c33C565", + "address": "0x7f23223A2FAf869962B38f5eC4aAB7f37454A45e", + "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" + } + }, + "WETH": { + "buidlerevm": { + "address": "0xf784709d2317D872237C4bC22f867d1BAe2913AB", "deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6" } } -} +} \ No newline at end of file diff --git a/helpers/constants.ts b/helpers/constants.ts index efeaca36..412d2256 100644 --- a/helpers/constants.ts +++ b/helpers/constants.ts @@ -38,7 +38,6 @@ export const APPROVAL_AMOUNT_LENDING_POOL = '1000000000000000000000000000'; export const TOKEN_DISTRIBUTOR_PERCENTAGE_BASE = '10000'; export const MOCK_USD_PRICE_IN_WEI = '5848466240000000'; export const USD_ADDRESS = '0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96'; -export const MOCK_ETH_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'; export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; export const ONE_ADDRESS = '0x0000000000000000000000000000000000000001'; export const AAVE_REFERRAL = '0'; @@ -92,6 +91,7 @@ export const MOCK_CHAINLINK_AGGREGATORS_PRICES: iAssetAggregatorBase = { MANA: oneEther.multipliedBy('0.000158').toFixed(), SNX: oneEther.multipliedBy('0.00442616').toFixed(), BUSD: oneEther.multipliedBy('0.00736484').toFixed(), + WETH: oneEther.toFixed(), USD: MOCK_USD_PRICE_IN_WEI, UNI_DAI_ETH: oneEther.multipliedBy('2.1').toFixed(), UNI_USDC_ETH: oneEther.multipliedBy('2.1').toFixed(), @@ -103,11 +103,10 @@ export const MOCK_CHAINLINK_AGGREGATORS_PRICES: iAssetAggregatorBase = { export const ALL_ASSETS_INITIAL_PRICES: iAssetBase = { ...MOCK_CHAINLINK_AGGREGATORS_PRICES, - ETH: oneEther.toFixed(), }; export const LENDING_RATE_ORACLE_RATES_COMMON: iAavePoolAssets = { - ETH: { + WETH: { borrowRate: oneRay.multipliedBy(0.03).toFixed(), }, DAI: { @@ -255,7 +254,7 @@ export const getReservesConfigByPool = (pool: AavePools): iMultiPoolsAssets { - const token = await deployContract(eContractid.StableDebtToken, [poolAddress, underlyingAsset]); + const token = await deployContract(eContractid.StableDebtToken, [ + poolAddress, + underlyingAsset, + ]); await token.init(name, symbol, decimals); @@ -275,7 +277,10 @@ export const deployVariableDebtToken = async ([ underlyingAsset, poolAddress, ]: [string, string, string, tEthereumAddress, tEthereumAddress]) => { - const token = await deployContract(eContractid.VariableDebtToken, [poolAddress, underlyingAsset]); + const token = await deployContract(eContractid.VariableDebtToken, [ + poolAddress, + underlyingAsset, + ]); await token.init(name, symbol, decimals); @@ -466,25 +471,16 @@ export const getParamPerPool = ({proto, secondary}: iParamsPerPool, pool: }; export const convertToCurrencyDecimals = async (tokenAddress: tEthereumAddress, amount: string) => { - const isEth = tokenAddress === MOCK_ETH_ADDRESS; - let decimals = '18'; - - if (!isEth) { - const token = await getIErc20Detailed(tokenAddress); - decimals = (await token.decimals()).toString(); - } + const token = await getIErc20Detailed(tokenAddress); + let decimals = (await token.decimals()).toString(); return ethers.utils.parseUnits(amount, decimals); }; export const convertToCurrencyUnits = async (tokenAddress: string, amount: string) => { - const isEth = tokenAddress === MOCK_ETH_ADDRESS; - let decimals = new BigNumber(18); - if (!isEth) { - const token = await getIErc20Detailed(tokenAddress); - decimals = new BigNumber(await token.decimals()); - } + const token = await getIErc20Detailed(tokenAddress); + let decimals = new BigNumber(await token.decimals()); const currencyUnit = new BigNumber(10).pow(decimals); const amountInCurrencyUnits = new BigNumber(amount).div(currencyUnit); return amountInCurrencyUnits.toFixed(); diff --git a/helpers/types.ts b/helpers/types.ts index a3264335..873479ae 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -73,7 +73,7 @@ export type tStringTokenSmallUnits = string; // 1 wei, or 1 basic unit of USDC, export type tBigNumberTokenSmallUnits = BigNumber; export interface iAssetBase { - ETH: T; + WETH: T; DAI: T; TUSD: T; USDC: T; @@ -107,7 +107,7 @@ export type iAssetsWithoutUSD = Omit, 'USD'>; export type iAavePoolAssets = Pick< iAssetsWithoutUSD, - | 'ETH' + | 'WETH' | 'DAI' | 'TUSD' | 'USDC' @@ -124,6 +124,7 @@ export type iAavePoolAssets = Pick< | 'ZRX' | 'SNX' | 'BUSD' + | 'WETH' >; export type iUniAssets = Pick< @@ -133,7 +134,7 @@ export type iUniAssets = Pick< export type iAaveSecondPoolAssets = Pick< iAssetBase, - | 'ETH' + | 'WETH' | 'DAI' | 'USDC' | 'USDT' @@ -156,7 +157,7 @@ export enum TokenContractId { LEND = 'LEND', TUSD = 'TUSD', BAT = 'BAT', - ETH = 'ETH', + WETH = 'WETH', USDC = 'USDC', USDT = 'USDT', SUSD = 'SUSD', diff --git a/test/__setup.spec.ts b/test/__setup.spec.ts index 952ae07b..e3d0b358 100644 --- a/test/__setup.spec.ts +++ b/test/__setup.spec.ts @@ -45,7 +45,6 @@ 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, @@ -67,7 +66,6 @@ const deployAllMockTokens = async (deployer: Signer) => { const secondaryConfigData = getReservesConfigByPool(AavePools.secondary); for (const tokenSymbol of Object.keys(TokenContractId)) { - if (tokenSymbol !== 'ETH') { let decimals = 18; let configData = (protoConfigData)[tokenSymbol]; @@ -86,7 +84,6 @@ const deployAllMockTokens = async (deployer: Signer) => { configData ? configData.reserveDecimals : 18, ]); await registerContractInJsonDb(tokenSymbol.toUpperCase(), tokens[tokenSymbol]); - } } return tokens; @@ -225,16 +222,16 @@ const initReserves = async ( ]); const stableDebtToken = await deployStableDebtToken([ - `Aave stable debt bearing ${assetSymbol}`, - `stableDebt${assetSymbol}`, + `Aave stable debt bearing ${assetSymbol === "WETH" ? "ETH" : assetSymbol}`, + `stableDebt${assetSymbol === "WETH" ? "ETH" : assetSymbol}`, reserveDecimals, tokenAddress, lendingPool.address, ]); const variableDebtToken = await deployVariableDebtToken([ - `Aave variable debt bearing ${assetSymbol}`, - `stableDebt${assetSymbol}`, + `Aave variable debt bearing ${assetSymbol === "WETH" ? "ETH" : assetSymbol}`, + `variableDebt${assetSymbol === "WETH" ? "ETH" : assetSymbol}`, reserveDecimals, tokenAddress, lendingPool.address, @@ -243,9 +240,9 @@ const initReserves = async ( const aToken = await deployGenericAToken([ lendingPool.address, tokenAddress, - `Aave interest bearing ${assetSymbol}`, - `a${assetSymbol}` - ]); + `Aave interest bearing ${assetSymbol === "WETH" ? "ETH" : assetSymbol}`, + `a${assetSymbol === "WETH" ? "ETH" : assetSymbol}`, + ]); if (process.env.POOL === AavePools.secondary) { @@ -400,7 +397,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { await setInitialAssetPricesInOracle( ALL_ASSETS_INITIAL_PRICES, { - ETH: MOCK_ETH_ADDRESS, + WETH: mockTokens.WETH.address, DAI: mockTokens.DAI.address, TUSD: mockTokens.TUSD.address, USDC: mockTokens.USDC.address, @@ -461,7 +458,6 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => { const {USD, ...tokensAddressesWithoutUsd} = allTokenAddresses; const allReservesAddresses = { - ETH: MOCK_ETH_ADDRESS, ...tokensAddressesWithoutUsd, }; await setInitialMarketRatesInRatesOracle( diff --git a/test/atoken-transfer.spec.ts b/test/atoken-transfer.spec.ts index 0ebc24ab..ef23c87e 100644 --- a/test/atoken-transfer.spec.ts +++ b/test/atoken-transfer.spec.ts @@ -1,6 +1,5 @@ import { APPROVAL_AMOUNT_LENDING_POOL, - MOCK_ETH_ADDRESS, AAVE_REFERRAL, MAX_UINT_AMOUNT, ZERO_ADDRESS, @@ -76,7 +75,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { }); it('User 0 transfers back to user 1', async () => { - const {users, aDai, dai} = testEnv; + const {users, aDai, dai, weth} = testEnv; const aDAItoTransfer = await convertToCurrencyDecimals(dai.address, '500'); await aDai.connect(users[0].signer).transfer(users[1].address, aDAItoTransfer); @@ -92,30 +91,30 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { }); it('User 0 deposits 1 ETH and user tries to borrow, but the aTokens received as a transfer are not available as collateral (revert expected)', async () => { - const {users, pool} = testEnv; + const {users, pool, weth} = testEnv; await pool .connect(users[0].signer) - .deposit(MOCK_ETH_ADDRESS, ethers.utils.parseEther('1.0'), '0', { + .deposit(weth.address, ethers.utils.parseEther('1.0'), '0', { value: ethers.utils.parseEther('1.0'), }); await expect( pool .connect(users[1].signer) - .borrow(MOCK_ETH_ADDRESS, ethers.utils.parseEther('0.1'), RateMode.Stable, AAVE_REFERRAL), + .borrow(weth.address, ethers.utils.parseEther('0.1'), RateMode.Stable, AAVE_REFERRAL), ZERO_COLLATERAL ).to.be.revertedWith(ZERO_COLLATERAL); }); it('User 1 sets the DAI as collateral and borrows, tries to transfer everything back to user 0 (revert expected)', async () => { - const {users, pool, aDai, dai} = testEnv; + const {users, pool, aDai, dai, weth} = testEnv; await pool.connect(users[1].signer).setUserUseReserveAsCollateral(dai.address, true); const aDAItoTransfer = await convertToCurrencyDecimals(dai.address, '1000'); await pool .connect(users[1].signer) - .borrow(MOCK_ETH_ADDRESS, ethers.utils.parseEther('0.1'), RateMode.Stable, AAVE_REFERRAL); + .borrow(weth.address, ethers.utils.parseEther('0.1'), RateMode.Stable, AAVE_REFERRAL); await expect( aDai.connect(users[1].signer).transfer(users[0].address, aDAItoTransfer), @@ -124,7 +123,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { }); it('User 0 tries to transfer 0 balance (revert expected)', async () => { - const {users, pool, aDai, dai} = testEnv; + const {users, pool, aDai, dai, weth} = testEnv; await expect( aDai.connect(users[0].signer).transfer(users[1].address, '0'), TRANSFERRED_AMOUNT_GT_ZERO @@ -132,10 +131,10 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { }); it('User 1 repays the borrow, transfers aDAI back to user 0', async () => { - const {users, pool, aDai, dai} = testEnv; + const {users, pool, aDai, dai, weth} = testEnv; await pool .connect(users[1].signer) - .repay(MOCK_ETH_ADDRESS, MAX_UINT_AMOUNT, RateMode.Stable, users[1].address, { + .repay(weth.address, MAX_UINT_AMOUNT, RateMode.Stable, users[1].address, { value: ethers.utils.parseEther('1'), }); @@ -159,7 +158,7 @@ makeSuite('AToken: Transfer', (testEnv: TestEnv) => { }); it('User 0 redirects interest to user 2, transfers 500 aDAI to user 1. User 1 redirects to user 3. User 0 transfers another 100 aDAI', async () => { - const {users, pool, aDai, dai} = testEnv; + const {users, pool, aDai, dai, weth} = testEnv; let aDAItoTransfer = await convertToCurrencyDecimals(aDai.address, '500'); diff --git a/test/configurator.spec.ts b/test/configurator.spec.ts index f3af3985..869fd481 100644 --- a/test/configurator.spec.ts +++ b/test/configurator.spec.ts @@ -1,5 +1,5 @@ import {TestEnv, makeSuite} from './helpers/make-suite'; -import {MOCK_ETH_ADDRESS, RAY, APPROVAL_AMOUNT_LENDING_POOL} from '../helpers/constants'; +import {RAY, APPROVAL_AMOUNT_LENDING_POOL} from '../helpers/constants'; import {convertToCurrencyDecimals} from '../helpers/contracts-helpers'; import {ProtocolErrors} from '../helpers/types'; @@ -9,219 +9,219 @@ makeSuite('LendingPoolConfigurator', (testEnv: TestEnv) => { const {INVALID_POOL_MANAGER_CALLER_MSG} = ProtocolErrors; it('Deactivates the ETH reserve', async () => { - const {configurator, pool} = testEnv; - await configurator.deactivateReserve(MOCK_ETH_ADDRESS); - const {isActive} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); + const {configurator, pool, weth} = testEnv; + await configurator.deactivateReserve(weth.address); + const {isActive} = await pool.getReserveConfigurationData(weth.address); expect(isActive).to.be.equal(false); }); it('Rectivates the ETH reserve', async () => { - const {configurator, pool} = testEnv; - await configurator.activateReserve(MOCK_ETH_ADDRESS); + const {configurator, pool, weth} = testEnv; + await configurator.activateReserve(weth.address); - const {isActive} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); + const {isActive} = await pool.getReserveConfigurationData(weth.address); expect(isActive).to.be.equal(true); }); it('Check the onlyLendingPoolManager on deactivateReserve ', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).deactivateReserve(MOCK_ETH_ADDRESS), + configurator.connect(users[2].signer).deactivateReserve(weth.address), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Check the onlyLendingPoolManager on activateReserve ', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).activateReserve(MOCK_ETH_ADDRESS), + configurator.connect(users[2].signer).activateReserve(weth.address), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Freezes the ETH reserve', async () => { - const {configurator, pool} = testEnv; - await configurator.freezeReserve(MOCK_ETH_ADDRESS); - const {isFreezed} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); + const {configurator, pool, weth} = testEnv; + await configurator.freezeReserve(weth.address); + const {isFreezed} = await pool.getReserveConfigurationData(weth.address); expect(isFreezed).to.be.equal(true); }); it('Unfreezes the ETH reserve', async () => { - const {configurator, pool} = testEnv; - await configurator.unfreezeReserve(MOCK_ETH_ADDRESS); + const {configurator, pool, weth} = testEnv; + await configurator.unfreezeReserve(weth.address); - const {isFreezed} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); + const {isFreezed} = await pool.getReserveConfigurationData(weth.address); expect(isFreezed).to.be.equal(false); }); it('Check the onlyLendingPoolManager on freezeReserve ', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).freezeReserve(MOCK_ETH_ADDRESS), + configurator.connect(users[2].signer).freezeReserve(weth.address), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Check the onlyLendingPoolManager on unfreezeReserve ', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).unfreezeReserve(MOCK_ETH_ADDRESS), + configurator.connect(users[2].signer).unfreezeReserve(weth.address), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Deactivates the ETH reserve for borrowing', async () => { - const {configurator, pool} = testEnv; - await configurator.disableBorrowingOnReserve(MOCK_ETH_ADDRESS); - const {borrowingEnabled} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); + const {configurator, pool, weth} = testEnv; + await configurator.disableBorrowingOnReserve(weth.address); + const {borrowingEnabled} = await pool.getReserveConfigurationData(weth.address); expect(borrowingEnabled).to.be.equal(false); }); it('Activates the ETH reserve for borrowing', async () => { - const {configurator, pool} = testEnv; - await configurator.enableBorrowingOnReserve(MOCK_ETH_ADDRESS, true); - const {borrowingEnabled} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); - const {variableBorrowIndex} = await pool.getReserveData(MOCK_ETH_ADDRESS); + const {configurator, pool, weth} = testEnv; + await configurator.enableBorrowingOnReserve(weth.address, true); + const {borrowingEnabled} = await pool.getReserveConfigurationData(weth.address); + const {variableBorrowIndex} = await pool.getReserveData(weth.address); expect(borrowingEnabled).to.be.equal(true); expect(variableBorrowIndex.toString()).to.be.equal(RAY); }); it('Check the onlyLendingPoolManager on disableBorrowingOnReserve ', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).disableBorrowingOnReserve(MOCK_ETH_ADDRESS), + configurator.connect(users[2].signer).disableBorrowingOnReserve(weth.address), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Check the onlyLendingPoolManager on enableBorrowingOnReserve ', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).enableBorrowingOnReserve(MOCK_ETH_ADDRESS, true), + configurator.connect(users[2].signer).enableBorrowingOnReserve(weth.address, true), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Deactivates the ETH reserve as collateral', async () => { - const {configurator, pool} = testEnv; - await configurator.disableReserveAsCollateral(MOCK_ETH_ADDRESS); - const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); + const {configurator, pool, weth} = testEnv; + await configurator.disableReserveAsCollateral(weth.address); + const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(weth.address); expect(usageAsCollateralEnabled).to.be.equal(false); }); it('Activates the ETH reserve as collateral', async () => { - const {configurator, pool} = testEnv; - await configurator.enableReserveAsCollateral(MOCK_ETH_ADDRESS, '75', '80', '105'); + const {configurator, pool, weth} = testEnv; + await configurator.enableReserveAsCollateral(weth.address, '75', '80', '105'); - const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); + const {usageAsCollateralEnabled} = await pool.getReserveConfigurationData(weth.address); expect(usageAsCollateralEnabled).to.be.equal(true); }); it('Check the onlyLendingPoolManager on disableReserveAsCollateral ', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).disableReserveAsCollateral(MOCK_ETH_ADDRESS), + configurator.connect(users[2].signer).disableReserveAsCollateral(weth.address), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Check the onlyLendingPoolManager on enableReserveAsCollateral ', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( configurator .connect(users[2].signer) - .enableReserveAsCollateral(MOCK_ETH_ADDRESS, '75', '80', '105'), + .enableReserveAsCollateral(weth.address, '75', '80', '105'), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Disable stable borrow rate on the ETH reserve', async () => { - const {configurator, pool} = testEnv; - await configurator.disableReserveStableRate(MOCK_ETH_ADDRESS); - const {stableBorrowRateEnabled} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); + const {configurator, pool, weth} = testEnv; + await configurator.disableReserveStableRate(weth.address); + const {stableBorrowRateEnabled} = await pool.getReserveConfigurationData(weth.address); expect(stableBorrowRateEnabled).to.be.equal(false); }); it('Enables stable borrow rate on the ETH reserve', async () => { - const {configurator, pool} = testEnv; - await configurator.enableReserveStableRate(MOCK_ETH_ADDRESS); - const {stableBorrowRateEnabled} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); + const {configurator, pool, weth} = testEnv; + await configurator.enableReserveStableRate(weth.address); + const {stableBorrowRateEnabled} = await pool.getReserveConfigurationData(weth.address); expect(stableBorrowRateEnabled).to.be.equal(true); }); it('Check the onlyLendingPoolManager on disableReserveStableRate', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).disableReserveStableRate(MOCK_ETH_ADDRESS), + configurator.connect(users[2].signer).disableReserveStableRate(weth.address), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Check the onlyLendingPoolManager on enableReserveStableRate', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).enableReserveStableRate(MOCK_ETH_ADDRESS), + configurator.connect(users[2].signer).enableReserveStableRate(weth.address), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Changes LTV of the reserve', async () => { - const {configurator, pool} = testEnv; - await configurator.setLtv(MOCK_ETH_ADDRESS, '60'); - const {ltv}: any = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); + const {configurator, pool, weth} = testEnv; + await configurator.setLtv(weth.address, '60'); + const {ltv}: any = await pool.getReserveConfigurationData(weth.address); expect(ltv).to.be.bignumber.equal('60', 'Invalid LTV'); }); it('Check the onlyLendingPoolManager on setLtv', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).setLtv(MOCK_ETH_ADDRESS, '75'), + configurator.connect(users[2].signer).setLtv(weth.address, '75'), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Changes liquidation threshold of the reserve', async () => { - const {configurator, pool} = testEnv; - await configurator.setLiquidationThreshold(MOCK_ETH_ADDRESS, '75'); - const {liquidationThreshold}: any = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); + const {configurator, pool, weth} = testEnv; + await configurator.setLiquidationThreshold(weth.address, '75'); + const {liquidationThreshold}: any = await pool.getReserveConfigurationData(weth.address); expect(liquidationThreshold).to.be.bignumber.equal('75', 'Invalid Liquidation threshold'); }); it('Check the onlyLendingPoolManager on setLiquidationThreshold', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).setLiquidationThreshold(MOCK_ETH_ADDRESS, '80'), + configurator.connect(users[2].signer).setLiquidationThreshold(weth.address, '80'), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Changes liquidation bonus of the reserve', async () => { - const {configurator, pool} = testEnv; - await configurator.setLiquidationBonus(MOCK_ETH_ADDRESS, '110'); - const {liquidationBonus} = await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS); + const {configurator, pool, weth} = testEnv; + await configurator.setLiquidationBonus(weth.address, '110'); + const {liquidationBonus} = await pool.getReserveConfigurationData(weth.address); expect(liquidationBonus).to.be.bignumber.equal('110', 'Invalid Liquidation discount'); }); it('Check the onlyLendingPoolManager on setLiquidationBonus', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).setLiquidationBonus(MOCK_ETH_ADDRESS, '80'), + configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Check the onlyLendingPoolManager on setReserveDecimals', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).setReserveDecimals(MOCK_ETH_ADDRESS, '80'), + configurator.connect(users[2].signer).setReserveDecimals(weth.address, '80'), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); it('Check the onlyLendingPoolManager on setLiquidationBonus', async () => { - const {configurator, users} = testEnv; + const {configurator, users, weth} = testEnv; await expect( - configurator.connect(users[2].signer).setLiquidationBonus(MOCK_ETH_ADDRESS, '80'), + configurator.connect(users[2].signer).setLiquidationBonus(weth.address, '80'), INVALID_POOL_MANAGER_CALLER_MSG ).to.be.revertedWith(INVALID_POOL_MANAGER_CALLER_MSG); }); diff --git a/test/flashloan.spec.ts b/test/flashloan.spec.ts index 730ac53e..35f8b293 100644 --- a/test/flashloan.spec.ts +++ b/test/flashloan.spec.ts @@ -1,5 +1,5 @@ import {TestEnv, makeSuite} from './helpers/make-suite'; -import {MOCK_ETH_ADDRESS, APPROVAL_AMOUNT_LENDING_POOL, oneRay} from '../helpers/constants'; +import {APPROVAL_AMOUNT_LENDING_POOL, oneRay} from '../helpers/constants'; import { convertToCurrencyDecimals, getMockFlashLoanReceiver, @@ -29,16 +29,16 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Deposits ETH into the reserve', async () => { - const {pool} = testEnv; + const {pool, weth} = testEnv; const amountToDeposit = ethers.utils.parseEther('1'); - await pool.deposit(MOCK_ETH_ADDRESS, amountToDeposit, '0', { + await pool.deposit(weth.address, amountToDeposit, '0', { value: amountToDeposit, }); }); it('Takes ETH flashloan, returns the funds correctly', async () => { - const {pool, deployer} = testEnv; + const {pool, deployer, weth} = testEnv; // move funds to the MockFlashLoanReceiver contract to pay the fee await deployer.signer.sendTransaction({ @@ -48,14 +48,14 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { await pool.flashLoan( _mockFlashLoanReceiver.address, - MOCK_ETH_ADDRESS, + weth.address, ethers.utils.parseEther('0.8'), '0x10' ); ethers.utils.parseUnits('10000'); - const reserveData: any = await pool.getReserveData(MOCK_ETH_ADDRESS); + const reserveData: any = await pool.getReserveData(weth.address); const tokenDistributorBalance = await BRE.ethers.provider.getBalance(_tokenDistributor.address); const currentLiquidityRate = reserveData.liquidityRate; @@ -72,7 +72,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Takes an ETH flashloan as big as the available liquidity', async () => { - const {pool, deployer} = testEnv; + const {pool, deployer, weth} = testEnv; // move funds to the MockFlashLoanReceiver contract to pay the fee await deployer.signer.sendTransaction({ @@ -82,12 +82,12 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { const txResult = await pool.flashLoan( _mockFlashLoanReceiver.address, - MOCK_ETH_ADDRESS, + weth.address, '1000504000000000000', '0x10' ); - const reserveData: any = await pool.getReserveData(MOCK_ETH_ADDRESS); + const reserveData: any = await pool.getReserveData(weth.address); const tokenDistributorBalance = await BRE.ethers.provider.getBalance(_tokenDistributor.address); const currentLiqudityRate = reserveData.liquidityRate; @@ -104,7 +104,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('Takes ETH flashloan, does not return the funds (revert expected)', async () => { - const {pool, deployer} = testEnv; + const {pool, deployer, weth} = testEnv; // move funds to the MockFlashLoanReceiver contract to pay the fee await deployer.signer.sendTransaction({ @@ -117,7 +117,7 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { await expect( pool.flashLoan( _mockFlashLoanReceiver.address, - MOCK_ETH_ADDRESS, + weth.address, ethers.utils.parseEther('0.8'), '0x10' ) @@ -125,12 +125,12 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('tries to take a very small flashloan, which would result in 0 fees (revert expected)', async () => { - const {pool} = testEnv; + const {pool, weth} = testEnv; await expect( pool.flashLoan( _mockFlashLoanReceiver.address, - MOCK_ETH_ADDRESS, + weth.address, '1', //1 wei loan '0x10' ) @@ -138,12 +138,12 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('tries to take a flashloan that is bigger than the available liquidity (revert expected)', async () => { - const {pool} = testEnv; + const {pool, weth} = testEnv; await expect( pool.flashLoan( _mockFlashLoanReceiver.address, - MOCK_ETH_ADDRESS, + weth.address, '1004415000000000000', //slightly higher than the available liquidity '0x10' ), @@ -152,9 +152,9 @@ makeSuite('LendingPool FlashLoan function', (testEnv: TestEnv) => { }); it('tries to take a flashloan using a non contract address as receiver (revert expected)', async () => { - const {pool, deployer} = testEnv; + const {pool, deployer, weth} = testEnv; - await expect(pool.flashLoan(deployer.address, MOCK_ETH_ADDRESS, '1000000000000000000', '0x10')) + await expect(pool.flashLoan(deployer.address, weth.address, '1000000000000000000', '0x10')) .to.be.reverted; }); diff --git a/test/helpers/actions.ts b/test/helpers/actions.ts index 59aa27e4..b39627d5 100644 --- a/test/helpers/actions.ts +++ b/test/helpers/actions.ts @@ -23,7 +23,7 @@ import { convertToCurrencyDecimals, getAToken, } from '../../helpers/contracts-helpers'; -import {MOCK_ETH_ADDRESS, ONE_YEAR, MAX_UINT_AMOUNT} from '../../helpers/constants'; +import {ONE_YEAR, MAX_UINT_AMOUNT} from '../../helpers/constants'; import {TestEnv, SignerWithAddress} from './make-suite'; import {BRE, increaseTime, timeLatest} from '../../helpers/misc-utils'; @@ -115,10 +115,6 @@ export const configuration: ActionsConfig = {}; export const mint = async (reserveSymbol: string, amount: string, user: SignerWithAddress) => { const reserve = await getReserveAddressFromSymbol(reserveSymbol); - if (MOCK_ETH_ADDRESS.toLowerCase() === reserve.toLowerCase()) { - throw 'Cannot mint ethereum. Mint action is most likely not needed in this story'; - } - const token = await getMintableErc20(reserve); await waitForTx( @@ -130,10 +126,6 @@ export const approve = async (reserveSymbol: string, user: SignerWithAddress, te const {pool} = testEnv; const reserve = await getReserveAddressFromSymbol(reserveSymbol); - if (MOCK_ETH_ADDRESS.toLowerCase() === reserve.toLowerCase()) { - throw 'Cannot mint ethereum. Mint action is most likely not needed in this story'; - } - const token = await getMintableErc20(reserve); await token.connect(user.signer).approve(pool.address, '100000000000000000000000000000'); @@ -162,13 +154,9 @@ export const deposit = async ( testEnv ); - if (MOCK_ETH_ADDRESS === reserve) { - if (sendValue) { - const valueToSend = await convertToCurrencyDecimals(reserve, sendValue); - txOptions.value = valueToSend; - } else { - txOptions.value = amountToDeposit; - } + if (sendValue) { + const valueToSend = await convertToCurrencyDecimals(reserve, sendValue); + txOptions.value = valueToSend; } if (expectedResult === 'success') { const txResult = await waitForTx( @@ -413,26 +401,9 @@ export const repay = async ( const txOptions: any = {}; - if (MOCK_ETH_ADDRESS === reserve) { - if (sendValue) { - const valueToSend = - rateMode == RateMode.Stable - ? userDataBefore.currentStableDebt - : userDataBefore.currentVariableDebt; - - if (sendValue !== '-1') { - const valueToSend = await convertToCurrencyDecimals(reserve, sendValue); - txOptions.value = '0x' + new BigNumber(valueToSend.toString()).toString(16); - } else { - txOptions.value = - '0x' + - valueToSend - .plus((await convertToCurrencyDecimals(reserve, '0.1')).toString()) - .toString(16); //add 0.1 ETH to the repayment amount to cover for accrued interest during tx execution - } - } else { - txOptions.value = amountToRepay; - } + if (sendValue) { + const valueToSend = await convertToCurrencyDecimals(reserve, sendValue); + txOptions.value = '0x' + new BigNumber(valueToSend.toString()).toString(16); } if (expectedResult === 'success') { diff --git a/test/helpers/make-suite.ts b/test/helpers/make-suite.ts index 263ee66e..f5b00aea 100644 --- a/test/helpers/make-suite.ts +++ b/test/helpers/make-suite.ts @@ -35,6 +35,8 @@ export interface TestEnv { configurator: LendingPoolConfigurator; oracle: PriceOracle; helpersContract: AaveProtocolTestHelpers; + weth: MintableErc20; + aEth: AToken; dai: MintableErc20; aDai: AToken; usdc: MintableErc20; @@ -56,6 +58,8 @@ const testEnv: TestEnv = { configurator: {} as LendingPoolConfigurator, helpersContract: {} as AaveProtocolTestHelpers, oracle: {} as PriceOracle, + weth: {} as MintableErc20, + aEth: {} as AToken, dai: {} as MintableErc20, aDai: {} as AToken, usdc: {} as MintableErc20, @@ -91,26 +95,35 @@ export async function initializeMakeSuite() { const aDaiAddress = (await testEnv.helpersContract.getAllATokens()).find( (aToken) => aToken.symbol === 'aDAI' )?.tokenAddress; + + + const aEthAddress = (await testEnv.helpersContract.getAllATokens()).find( + (aToken) => aToken.symbol === 'aETH' + )?.tokenAddress; const reservesTokens = await testEnv.helpersContract.getAllReservesTokens(); const daiAddress = reservesTokens.find((token) => token.symbol === 'DAI')?.tokenAddress; const usdcAddress = reservesTokens.find((token) => token.symbol === 'USDC')?.tokenAddress; const lendAddress = reservesTokens.find((token) => token.symbol === 'LEND')?.tokenAddress; + const wethAddress = reservesTokens.find((token) => token.symbol === 'WETH')?.tokenAddress; - if (!aDaiAddress) { - console.log(`atoken-modifiers.spec: aDAI not correctly initialized`); + if (!aDaiAddress || !aEthAddress) { + console.log(`atoken-modifiers.spec: aTokens not correctly initialized`); process.exit(1); } - if (!daiAddress || !usdcAddress || !lendAddress) { + if (!daiAddress || !usdcAddress || !lendAddress || ! wethAddress) { console.log(`atoken-modifiers.spec: USDC or DAI not correctly initialized`); process.exit(1); } testEnv.aDai = await getAToken(aDaiAddress); + testEnv.aEth = await getAToken(aEthAddress); + testEnv.dai = await getMintableErc20(daiAddress); testEnv.usdc = await getMintableErc20(usdcAddress); testEnv.lend = await getMintableErc20(lendAddress); + testEnv.weth = await getMintableErc20(wethAddress); } export function makeSuite(name: string, tests: (testEnv: TestEnv) => void) { diff --git a/test/helpers/scenarios/borrow-negatives.json b/test/helpers/scenarios/borrow-negatives.json index 29fd60c1..7fdf2a53 100644 --- a/test/helpers/scenarios/borrow-negatives.json +++ b/test/helpers/scenarios/borrow-negatives.json @@ -34,7 +34,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "1", "sendValue": "1" @@ -86,7 +87,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "1", "sendValue": "1" diff --git a/test/helpers/scenarios/borrow-repay-stable.json b/test/helpers/scenarios/borrow-repay-stable.json index b9c406e8..5924e47e 100644 --- a/test/helpers/scenarios/borrow-repay-stable.json +++ b/test/helpers/scenarios/borrow-repay-stable.json @@ -34,7 +34,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "1", "sendValue": "1" @@ -192,7 +193,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "1", "sendValue": "1" @@ -213,7 +215,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "2", "sendValue": "1" @@ -234,7 +237,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "3", "sendValue": "1" @@ -255,7 +259,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "4", "sendValue": "1" @@ -432,7 +437,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "2", "user": "1", "sendValue": "2" diff --git a/test/helpers/scenarios/borrow-repay-variable.json b/test/helpers/scenarios/borrow-repay-variable.json index 24930996..8cf67a45 100644 --- a/test/helpers/scenarios/borrow-repay-variable.json +++ b/test/helpers/scenarios/borrow-repay-variable.json @@ -65,7 +65,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "1", "sendValue": "1" @@ -187,7 +188,8 @@ { "name": "redeem", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "-1", "user": "1" }, @@ -201,7 +203,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "0.001", "user": "2", "sendValue": "0.001" @@ -216,7 +219,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "0", "sendValue": "1" @@ -253,7 +257,8 @@ { "name": "borrow", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "0.5", "borrowRateMode": "variable", "user": "1", @@ -269,7 +274,8 @@ { "name": "repay", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "0", "user": "1", "onBehalfOf": "1", @@ -287,7 +293,8 @@ { "name": "repay", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "-1", "user": "1", "borrowRateMode": "variable", @@ -305,7 +312,8 @@ { "name": "repay", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "-1", "user": "2", "borrowRateMode": "variable", @@ -323,7 +331,8 @@ { "name": "repay", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "0.2", "user": "3", "borrowRateMode": "variable", @@ -340,7 +349,8 @@ { "name": "repay", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "-1", "borrowRateMode": "variable", "user": "1", @@ -357,7 +367,8 @@ { "name": "redeem", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "-1", "user": "0" }, @@ -443,7 +454,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "1", "sendValue": "1" @@ -533,7 +545,8 @@ { "name": "redeem", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "-1", "user": "1" }, @@ -589,7 +602,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "0.1", "user": "3", "sendValue": "0.1" @@ -615,7 +629,8 @@ { "name": "redeem", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "-1", "user": "3" }, @@ -671,7 +686,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "0.1", "user": "3", "sendValue": "0.1" @@ -697,7 +713,8 @@ { "name": "redeem", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "-1", "user": "3" }, @@ -737,7 +754,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "2", "user": "6", "sendValue": "2" diff --git a/test/helpers/scenarios/deposit.json b/test/helpers/scenarios/deposit.json index 4a1bf764..de9e381c 100644 --- a/test/helpers/scenarios/deposit.json +++ b/test/helpers/scenarios/deposit.json @@ -132,7 +132,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "0", "sendValue": "1" @@ -147,7 +148,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "1", "sendValue": "1" @@ -162,7 +164,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "0", "user": "1" }, @@ -192,7 +195,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "1", "sendValue": "0" @@ -208,7 +212,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "1", "sendValue": "0.5" diff --git a/test/helpers/scenarios/interest-redirection.json b/test/helpers/scenarios/interest-redirection.json index 1089b357..b95ee64e 100644 --- a/test/helpers/scenarios/interest-redirection.json +++ b/test/helpers/scenarios/interest-redirection.json @@ -48,7 +48,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "2", "user": "1", "sendValue": "2" diff --git a/test/helpers/scenarios/rebalance-stable-rate.json b/test/helpers/scenarios/rebalance-stable-rate.json index e0071a37..b76a169d 100644 --- a/test/helpers/scenarios/rebalance-stable-rate.json +++ b/test/helpers/scenarios/rebalance-stable-rate.json @@ -50,7 +50,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "1", "sendValue": "1" @@ -110,7 +111,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "5", "user": "2", "sendValue": "5" @@ -145,7 +147,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "3", "user": "2", "sendValue": "3" diff --git a/test/helpers/scenarios/redeem-negatives.json b/test/helpers/scenarios/redeem-negatives.json index 7c50651f..a0dc2e40 100644 --- a/test/helpers/scenarios/redeem-negatives.json +++ b/test/helpers/scenarios/redeem-negatives.json @@ -65,7 +65,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "1", "sendValue": "1" @@ -85,7 +86,8 @@ { "name": "redeem", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "-1", "user": "1" }, diff --git a/test/helpers/scenarios/redeem.json b/test/helpers/scenarios/redeem.json index 4b670c2c..201defae 100644 --- a/test/helpers/scenarios/redeem.json +++ b/test/helpers/scenarios/redeem.json @@ -126,7 +126,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "0", "sendValue": "1" @@ -141,7 +142,8 @@ { "name": "redeem", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "0.5", "user": "0" }, @@ -155,7 +157,8 @@ { "name": "redeem", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "-1", "user": "0" }, @@ -279,7 +282,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "1", "user": "1", "sendValue": "1" diff --git a/test/helpers/scenarios/set-use-as-collateral.json b/test/helpers/scenarios/set-use-as-collateral.json index c6eee86e..c869112e 100644 --- a/test/helpers/scenarios/set-use-as-collateral.json +++ b/test/helpers/scenarios/set-use-as-collateral.json @@ -48,7 +48,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "2", "user": "1", "sendValue": "2" @@ -58,7 +59,8 @@ { "name": "setUseAsCollateral", "args": { - "reserve": "ETH", + "reserve": "WETH", + "user": "1", "useAsCollateral": "false" }, @@ -83,7 +85,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "2", "user": "1", "sendValue": "2" @@ -93,7 +96,8 @@ { "name": "setUseAsCollateral", "args": { - "reserve": "ETH", + "reserve": "WETH", + "user": "1", "useAsCollateral": "true" }, @@ -117,7 +121,8 @@ { "name": "setUseAsCollateral", "args": { - "reserve": "ETH", + "reserve": "WETH", + "user": "1", "useAsCollateral": "false" }, diff --git a/test/helpers/scenarios/swap-rate-mode.json b/test/helpers/scenarios/swap-rate-mode.json index 6454656b..af202567 100644 --- a/test/helpers/scenarios/swap-rate-mode.json +++ b/test/helpers/scenarios/swap-rate-mode.json @@ -64,7 +64,8 @@ { "name": "deposit", "args": { - "reserve": "ETH", + "reserve": "WETH", + "amount": "2", "user": "1", "sendValue": "2" diff --git a/test/helpers/utils/helpers.ts b/test/helpers/utils/helpers.ts index 822be3b5..f6051f90 100644 --- a/test/helpers/utils/helpers.ts +++ b/test/helpers/utils/helpers.ts @@ -6,7 +6,7 @@ import { getMintableErc20, getAToken, } from '../../../helpers/contracts-helpers'; -import {MOCK_ETH_ADDRESS, ZERO_ADDRESS} from '../../../helpers/constants'; +import {ZERO_ADDRESS} from '../../../helpers/constants'; import {tEthereumAddress} from '../../../helpers/types'; import BigNumber from 'bignumber.js'; import {getDb, BRE} from '../../../helpers/misc-utils'; @@ -22,14 +22,9 @@ export const getReserveData = async ( const rate = (await rateOracle.getMarketBorrowRate(reserve)).toString(); - const isEthReserve = reserve === MOCK_ETH_ADDRESS; - let symbol = 'ETH'; - let decimals = new BigNumber(18); - if (!isEthReserve) { - const token = await getIErc20Detailed(reserve); - symbol = await token.symbol(); - decimals = new BigNumber(await token.decimals()); - } + const token = await getIErc20Detailed(reserve); + const symbol = await token.symbol(); + const decimals = new BigNumber(await token.decimals()); const totalLiquidity = new BigNumber(data.availableLiquidity) .plus(data.totalBorrowsStable) @@ -82,14 +77,8 @@ export const getUserData = async ( interestRedirectionAddress, ] = aTokenData; - let walletBalance; - - if (reserve === MOCK_ETH_ADDRESS) { - walletBalance = new BigNumber((await BRE.ethers.provider.getBalance(user)).toString()); - } else { - const token = await getMintableErc20(reserve); - walletBalance = new BigNumber((await token.balanceOf(user)).toString()); - } + const token = await getMintableErc20(reserve); + const walletBalance = new BigNumber((await token.balanceOf(user)).toString()); return { principalATokenBalance: new BigNumber(principalATokenBalance), @@ -112,14 +101,13 @@ export const getUserData = async ( }; export const getReserveAddressFromSymbol = async (symbol: string) => { - if (symbol.toUpperCase() === 'ETH') { - return MOCK_ETH_ADDRESS; - } + const token = await getMintableErc20( (await getDb().get(`${symbol}.${BRE.network.name}`).value()).address ); + if (!token) { throw `Could not find instance for contract ${symbol}`; } diff --git a/test/liquidation-atoken.spec.ts b/test/liquidation-atoken.spec.ts index 2a15e9a9..a79c0ce3 100644 --- a/test/liquidation-atoken.spec.ts +++ b/test/liquidation-atoken.spec.ts @@ -1,7 +1,7 @@ import BigNumber from 'bignumber.js'; import {BRE} from '../helpers/misc-utils'; -import {APPROVAL_AMOUNT_LENDING_POOL, MOCK_ETH_ADDRESS, oneEther} from '../helpers/constants'; +import {APPROVAL_AMOUNT_LENDING_POOL, oneEther} from '../helpers/constants'; import {convertToCurrencyDecimals} from '../helpers/contracts-helpers'; import {makeSuite} from './helpers/make-suite'; import {ProtocolErrors, RateMode} from '../helpers/types'; @@ -21,7 +21,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => } = ProtocolErrors; it('LIQUIDATION - Deposits ETH, borrows DAI/Check liquidation fails because health factor is above 1', async () => { - const {dai, users, pool, oracle} = testEnv; + const {dai, weth, users, pool, oracle} = testEnv; const depositor = users[0]; const borrower = users[1]; @@ -36,12 +36,12 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => await pool.connect(depositor.signer).deposit(dai.address, amountDAItoDeposit, '0'); //user 2 deposits 1 ETH - const amountETHtoDeposit = await convertToCurrencyDecimals(MOCK_ETH_ADDRESS, '1'); + const amountETHtoDeposit = await convertToCurrencyDecimals(weth.address, '1'); await pool .connect(borrower.signer) - .deposit(MOCK_ETH_ADDRESS, amountETHtoDeposit, '0', {value: amountETHtoDeposit}); + .deposit(weth.address, amountETHtoDeposit, '0', {value: amountETHtoDeposit}); - await pool.connect(borrower.signer).deposit(MOCK_ETH_ADDRESS, amountETHtoDeposit, '0', { + await pool.connect(borrower.signer).deposit(weth.address, amountETHtoDeposit, '0', { value: amountETHtoDeposit, }); @@ -70,12 +70,12 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => //someone tries to liquidate user 2 await expect( - pool.liquidationCall(MOCK_ETH_ADDRESS, dai.address, borrower.address, 1, true) + pool.liquidationCall(weth.address, dai.address, borrower.address, 1, true) ).to.be.revertedWith(HF_IS_NOT_BELLOW_THRESHOLD); }); it('LIQUIDATION - Drop the health factor below 1', async () => { - const {dai, users, pool, oracle} = testEnv; + const {dai, weth, users, pool, oracle} = testEnv; const borrower = users[1]; const daiPrice = await oracle.getAssetPrice(dai.address); @@ -91,13 +91,13 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => }); it('LIQUIDATION - Tries to liquidate a different currency than the loan principal', async () => { - const {pool, users} = testEnv; + const {pool, users, weth} = testEnv; const borrower = users[1]; //user 2 tries to borrow await expect( pool.liquidationCall( - MOCK_ETH_ADDRESS, - MOCK_ETH_ADDRESS, + weth.address, + weth.address, borrower.address, oneEther.toString(), true @@ -106,7 +106,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => }); it('LIQUIDATION - Tries to liquidate a different collateral than the borrower collateral', async () => { - const {pool, dai, users} = testEnv; + const {pool, dai, weth, users} = testEnv; const borrower = users[1]; await expect( @@ -115,7 +115,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => }); it('LIQUIDATION - Liquidates the borrow', async () => { - const {pool, dai, users, oracle} = testEnv; + const {pool, dai, weth, users, oracle} = testEnv; const borrower = users[1]; //mints dai to the caller @@ -126,7 +126,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => await dai.approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL); const daiReserveDataBefore = await getReserveData(pool, dai.address); - const ethReserveDataBefore = await pool.getReserveData(MOCK_ETH_ADDRESS); + const ethReserveDataBefore = await pool.getReserveData(weth.address); const userReserveDataBefore = await getUserData(pool, dai.address, borrower.address); @@ -135,7 +135,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => .toFixed(0); const tx = await pool.liquidationCall( - MOCK_ETH_ADDRESS, + weth.address, dai.address, borrower.address, amountToLiquidate, @@ -147,13 +147,13 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => const userGlobalDataAfter = await pool.getUserAccountData(borrower.address); const daiReserveDataAfter = await pool.getReserveData(dai.address); - const ethReserveDataAfter = await pool.getReserveData(MOCK_ETH_ADDRESS); + const ethReserveDataAfter = await pool.getReserveData(weth.address); - const collateralPrice = (await oracle.getAssetPrice(MOCK_ETH_ADDRESS)).toString(); + const collateralPrice = (await oracle.getAssetPrice(weth.address)).toString(); const principalPrice = (await oracle.getAssetPrice(dai.address)).toString(); const collateralDecimals = ( - await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS) + await pool.getReserveConfigurationData(weth.address) ).decimals.toString(); const principalDecimals = ( await pool.getReserveConfigurationData(dai.address) @@ -216,7 +216,7 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => }); it('User 3 deposits 1000 USDC, user 4 1 ETH, user 4 borrows - drops HF, liquidates the borrow', async () => { - const {users, pool, usdc, oracle, addressesProvider} = testEnv; + const {users, pool, usdc, oracle, weth} = testEnv; const depositor = users[3]; const borrower = users[4]; //mints USDC to depositor @@ -233,9 +233,9 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => await pool.connect(depositor.signer).deposit(usdc.address, amountUSDCtoDeposit, '0'); //user 4 deposits 1 ETH - const amountETHtoDeposit = await convertToCurrencyDecimals(MOCK_ETH_ADDRESS, '1'); + const amountETHtoDeposit = await convertToCurrencyDecimals(weth.address, '1'); - await pool.connect(borrower.signer).deposit(MOCK_ETH_ADDRESS, amountETHtoDeposit, '0', { + await pool.connect(borrower.signer).deposit(weth.address, amountETHtoDeposit, '0', { value: amountETHtoDeposit, }); @@ -273,14 +273,14 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => const userReserveDataBefore = await pool.getUserReserveData(usdc.address, borrower.address); const usdcReserveDataBefore = await pool.getReserveData(usdc.address); - const ethReserveDataBefore = await pool.getReserveData(MOCK_ETH_ADDRESS); + const ethReserveDataBefore = await pool.getReserveData(weth.address); const amountToLiquidate = new BigNumber(userReserveDataBefore.currentStableDebt.toString()) .div(2) .toFixed(0); await pool.liquidationCall( - MOCK_ETH_ADDRESS, + weth.address, usdc.address, borrower.address, amountToLiquidate, @@ -292,13 +292,13 @@ makeSuite('LendingPool liquidation - liquidator receiving aToken', (testEnv) => const userGlobalDataAfter = await pool.getUserAccountData(borrower.address); const usdcReserveDataAfter = await pool.getReserveData(usdc.address); - const ethReserveDataAfter = await pool.getReserveData(MOCK_ETH_ADDRESS); + const ethReserveDataAfter = await pool.getReserveData(weth.address); - const collateralPrice = (await oracle.getAssetPrice(MOCK_ETH_ADDRESS)).toString(); + const collateralPrice = (await oracle.getAssetPrice(weth.address)).toString(); const principalPrice = (await oracle.getAssetPrice(usdc.address)).toString(); const collateralDecimals = ( - await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS) + await pool.getReserveConfigurationData(weth.address) ).decimals.toString(); const principalDecimals = ( await pool.getReserveConfigurationData(usdc.address) diff --git a/test/liquidation-underlying.spec.ts b/test/liquidation-underlying.spec.ts index 83227438..ec538021 100644 --- a/test/liquidation-underlying.spec.ts +++ b/test/liquidation-underlying.spec.ts @@ -1,7 +1,7 @@ import BigNumber from 'bignumber.js'; import {BRE} from '../helpers/misc-utils'; -import {APPROVAL_AMOUNT_LENDING_POOL, MOCK_ETH_ADDRESS, oneEther} from '../helpers/constants'; +import {APPROVAL_AMOUNT_LENDING_POOL, oneEther} from '../helpers/constants'; import {convertToCurrencyDecimals} from '../helpers/contracts-helpers'; import {makeSuite} from './helpers/make-suite'; import {ProtocolErrors, RateMode} from '../helpers/types'; @@ -51,7 +51,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', } = ProtocolErrors; it('LIQUIDATION - Deposits ETH, borrows DAI', async () => { - const {dai, users, pool, oracle} = testEnv; + const {dai, weth, users, pool, oracle} = testEnv; const depositor = users[0]; const borrower = users[1]; @@ -66,9 +66,9 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', await pool.connect(depositor.signer).deposit(dai.address, amountDAItoDeposit, '0'); //user 2 deposits 1 ETH - const amountETHtoDeposit = await convertToCurrencyDecimals(MOCK_ETH_ADDRESS, '1'); + const amountETHtoDeposit = await convertToCurrencyDecimals(weth.address, '1'); - await pool.connect(borrower.signer).deposit(MOCK_ETH_ADDRESS, amountETHtoDeposit, '0', { + await pool.connect(borrower.signer).deposit(weth.address, amountETHtoDeposit, '0', { value: amountETHtoDeposit, }); @@ -98,7 +98,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', }); it('LIQUIDATION - Drop the health factor below 1', async () => { - const {dai, users, pool, oracle} = testEnv; + const {dai, weth, users, pool, oracle} = testEnv; const borrower = users[1]; const daiPrice = await oracle.getAssetPrice(dai.address); @@ -117,7 +117,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', }); it('LIQUIDATION - Liquidates the borrow', async () => { - const {dai, users, pool, oracle} = testEnv; + const {dai, weth, users, pool, oracle} = testEnv; const liquidator = users[3]; const borrower = users[1]; @@ -128,7 +128,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', await dai.connect(liquidator.signer).approve(pool.address, APPROVAL_AMOUNT_LENDING_POOL); const daiReserveDataBefore: any = await pool.getReserveData(dai.address); - const ethReserveDataBefore: any = await pool.getReserveData(MOCK_ETH_ADDRESS); + const ethReserveDataBefore: any = await pool.getReserveData(weth.address); const userReserveDataBefore: any = await getUserData(pool, dai.address, borrower.address); @@ -138,18 +138,18 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', const tx = await pool .connect(liquidator.signer) - .liquidationCall(MOCK_ETH_ADDRESS, dai.address, borrower.address, amountToLiquidate, false); + .liquidationCall(weth.address, dai.address, borrower.address, amountToLiquidate, false); const userReserveDataAfter: any = await getUserData(pool, dai.address, borrower.address); const daiReserveDataAfter: any = await pool.getReserveData(dai.address); - const ethReserveDataAfter: any = await pool.getReserveData(MOCK_ETH_ADDRESS); + const ethReserveDataAfter: any = await pool.getReserveData(weth.address); - const collateralPrice = await oracle.getAssetPrice(MOCK_ETH_ADDRESS); + const collateralPrice = await oracle.getAssetPrice(weth.address); const principalPrice = await oracle.getAssetPrice(dai.address); const collateralDecimals = ( - await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS) + await pool.getReserveConfigurationData(weth.address) ).decimals.toString(); const principalDecimals = ( await pool.getReserveConfigurationData(dai.address) @@ -208,7 +208,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', }); it('User 3 deposits 1000 USDC, user 4 1 ETH, user 4 borrows - drops HF, liquidates the borrow', async () => { - const {usdc, users, pool, oracle, addressesProvider} = testEnv; + const {usdc, users, pool, oracle, weth} = testEnv; const depositor = users[3]; const borrower = users[4]; @@ -228,9 +228,9 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', await pool.connect(depositor.signer).deposit(usdc.address, amountUSDCtoDeposit, '0'); //borrower deposits 1 ETH - const amountETHtoDeposit = await convertToCurrencyDecimals(MOCK_ETH_ADDRESS, '1'); + const amountETHtoDeposit = await convertToCurrencyDecimals(weth.address, '1'); - await pool.connect(borrower.signer).deposit(MOCK_ETH_ADDRESS, amountETHtoDeposit, '0', { + await pool.connect(borrower.signer).deposit(weth.address, amountETHtoDeposit, '0', { value: amountETHtoDeposit, }); @@ -272,7 +272,7 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', ); const usdcReserveDataBefore: any = await pool.getReserveData(usdc.address); - const ethReserveDataBefore: any = await pool.getReserveData(MOCK_ETH_ADDRESS); + const ethReserveDataBefore: any = await pool.getReserveData(weth.address); const amountToLiquidate = new BigNumber(userReserveDataBefore.currentStableDebt) .div(2) @@ -281,20 +281,20 @@ makeSuite('LendingPool liquidation - liquidator receiving the underlying asset', await pool .connect(liquidator.signer) - .liquidationCall(MOCK_ETH_ADDRESS, usdc.address, borrower.address, amountToLiquidate, false); + .liquidationCall(weth.address, usdc.address, borrower.address, amountToLiquidate, false); const userReserveDataAfter: any = await pool.getUserReserveData(usdc.address, borrower.address); const userGlobalDataAfter: any = await pool.getUserAccountData(borrower.address); const usdcReserveDataAfter: any = await pool.getReserveData(usdc.address); - const ethReserveDataAfter: any = await pool.getReserveData(MOCK_ETH_ADDRESS); + const ethReserveDataAfter: any = await pool.getReserveData(weth.address); - const collateralPrice = await oracle.getAssetPrice(MOCK_ETH_ADDRESS); + const collateralPrice = await oracle.getAssetPrice(weth.address); const principalPrice = await oracle.getAssetPrice(usdc.address); const collateralDecimals = ( - await pool.getReserveConfigurationData(MOCK_ETH_ADDRESS) + await pool.getReserveConfigurationData(weth.address) ).decimals.toString(); const principalDecimals = ( await pool.getReserveConfigurationData(usdc.address) diff --git a/test/scenario.spec.ts b/test/scenario.spec.ts index 10db45fb..5d449d76 100644 --- a/test/scenario.spec.ts +++ b/test/scenario.spec.ts @@ -4,7 +4,7 @@ import {configuration as calculationsConfiguration} from './helpers/utils/calcul import fs from 'fs'; import BigNumber from 'bignumber.js'; import {makeSuite} from './helpers/make-suite'; -import {MOCK_ETH_ADDRESS, getReservesConfigByPool} from '../helpers/constants'; +import {getReservesConfigByPool} from '../helpers/constants'; import {AavePools, iAavePoolAssets, IReserveParams} from '../helpers/types'; import {executeStory} from './helpers/scenario-engine'; @@ -26,7 +26,6 @@ fs.readdirSync(scenarioFolder).forEach((file) => { calculationsConfiguration.reservesParams = >( getReservesConfigByPool(AavePools.proto) ); - calculationsConfiguration.ethereumAddress = MOCK_ETH_ADDRESS; }); for (const story of scenario.stories) {