From 9c293d561f73ad8c3c7dcf68d9144bfd0e653091 Mon Sep 17 00:00:00 2001 From: Lukas Date: Wed, 5 Jul 2023 16:51:25 +0200 Subject: [PATCH] fix: add more snapshots (#119) resolves an issue with https://github.com/foundry-rs/foundry/issues/5118 --- reports/v2-report.json | 122 ++++++++++++------------- src/ProtocolV2TestBase.sol | 160 +++++++++++++++------------------ src/ProtocolV3TestBase.sol | 9 +- tests/ProtocolV2TestBase.t.sol | 28 ++++-- 4 files changed, 162 insertions(+), 157 deletions(-) diff --git a/reports/v2-report.json b/reports/v2-report.json index 8f27876..0e67b69 100644 --- a/reports/v2-report.json +++ b/reports/v2-report.json @@ -18,14 +18,14 @@ "decimals": 18, "interestRateStrategy": "0x6bcE15B789e537f3abA3C60CB183F0E8737f05eC", "isActive": true, - "isFrozen": false, + "isFrozen": true, "liquidationBonus": 10500, - "liquidationThreshold": 8250, - "ltv": 8000, + "liquidationThreshold": 7750, + "ltv": 7500, "oracle": "0x3886BA987236181D98F2401c507Fb8BeA7871dF2", "oracleDecimals": 18, "oracleDescription": "TUSD / ETH", - "oracleLatestAnswer": 552455830836469, + "oracleLatestAnswer": 523055674719847, "reserveFactor": 500, "stableBorrowRateEnabled": true, "stableDebtToken": "0x7f38d60D94652072b2C44a18c0e14A481EC3C0dd", @@ -51,7 +51,7 @@ "oracle": "0x4ad7B025127e89263242aB68F0f9c4E5C033B489", "oracleDecimals": 18, "oracleDescription": "RAI / ETH", - "oracleLatestAnswer": 1543796990011066, + "oracleLatestAnswer": 1448850805463853, "reserveFactor": 2000, "stableBorrowRateEnabled": false, "stableDebtToken": "0x9C72B8476C33AE214ee3e8C20F0bc28496a62032", @@ -75,7 +75,7 @@ "liquidationThreshold": 0, "ltv": 0, "oracle": "0xEc6f4Cd64d28Ef32507e2dc399948aAe9Bbedd7e", - "oracleLatestAnswer": 551328702172235, + "oracleLatestAnswer": 522652463342070, "reserveFactor": 1000, "stableBorrowRateEnabled": false, "stableDebtToken": "0xf8aC64ec6Ff8E0028b37EB89772d21865321bCe0", @@ -101,7 +101,7 @@ "oracle": "0x0d16d4528239e9ee52fa531af613AcdB23D88c94", "oracleDecimals": 18, "oracleDescription": "BAT / ETH", - "oracleLatestAnswer": 123825482069473, + "oracleLatestAnswer": 106296999866101, "reserveFactor": 2000, "stableBorrowRateEnabled": true, "stableDebtToken": "0x277f8676FAcf4dAA5a6EA38ba511B7F65AA02f9F", @@ -127,7 +127,7 @@ "oracle": "0x82A44D92D6c329826dc557c5E1Be6ebeC5D5FeB9", "oracleDecimals": 18, "oracleDescription": "MANA / ETH", - "oracleLatestAnswer": 273401018021917, + "oracleLatestAnswer": 203344565524561, "reserveFactor": 3500, "stableBorrowRateEnabled": true, "stableDebtToken": "0xD86C74eA2224f4B8591560652b50035E4e5c0a3b", @@ -153,7 +153,7 @@ "oracle": "0x7c5d4F8345e66f68099581Db340cd65B078C41f4", "oracleDecimals": 18, "oracleDescription": "YFI / ETH", - "oracleLatestAnswer": 3684568923041151000, + "oracleLatestAnswer": 3586318292680671000, "reserveFactor": 2000, "stableBorrowRateEnabled": false, "stableDebtToken": "0xca823F78C2Dd38993284bb42Ba9b14152082F7BD", @@ -172,14 +172,14 @@ "decimals": 18, "interestRateStrategy": "0xb2eD1eCE1c13455Ce9299d35D3B00358529f3Dc8", "isActive": true, - "isFrozen": false, + "isFrozen": true, "liquidationBonus": 10850, "liquidationThreshold": 5000, "ltv": 4000, "oracle": "0x72AFAECF99C9d9C8215fF44C77B94B99C28741e8", "oracleDecimals": 18, "oracleDescription": "1INCH / ETH", - "oracleLatestAnswer": 222150530138573, + "oracleLatestAnswer": 164697896056077, "reserveFactor": 2000, "stableBorrowRateEnabled": false, "stableDebtToken": "0x1278d6ED804d59d2d18a5Aa5638DfD591A79aF0a", @@ -205,7 +205,7 @@ "oracle": "0x029849bbc0b1d93b85a8b6190e979fd38F5760E2", "oracleDecimals": 18, "oracleDescription": "DPI / ETH", - "oracleLatestAnswer": 38342108095598820, + "oracleLatestAnswer": 38488036962912045, "reserveFactor": 2000, "stableBorrowRateEnabled": false, "stableDebtToken": "0xa3953F07f389d719F99FC378ebDb9276177d8A6e", @@ -224,14 +224,14 @@ "decimals": 18, "interestRateStrategy": "0x24ABFac8dd8f270D752837fDFe3B3C735361f4eE", "isActive": true, - "isFrozen": false, + "isFrozen": true, "liquidationBonus": 10900, "liquidationThreshold": 7700, "ltv": 6500, "oracle": "0xD6aA3D25116d8dA79Ea0246c4826EB951872e02e", "oracleDecimals": 18, "oracleDescription": "UNI / ETH", - "oracleLatestAnswer": 2942663259662463, + "oracleLatestAnswer": 2831313400000000, "reserveFactor": 2000, "stableBorrowRateEnabled": false, "stableDebtToken": "0xD939F7430dC8D5a427f156dE1012A56C18AcB6Aa", @@ -254,10 +254,10 @@ "liquidationBonus": 10500, "liquidationThreshold": 8200, "ltv": 7200, - "oracle": "0xdeb288F737066589598e9214E782fa5A8eD689e8", + "oracle": "0xFD858c8bC5ac5e10f01018bC78471bb0DC392247", "oracleDecimals": 18, - "oracleDescription": "BTC / ETH", - "oracleLatestAnswer": 14992503748125940000, + "oracleDescription": "wBTC/BTC/ETH", + "oracleLatestAnswer": 15889690483104840949, "reserveFactor": 2000, "stableBorrowRateEnabled": true, "stableDebtToken": "0x51B039b9AFE64B78758f8Ef091211b5387eA717c", @@ -283,7 +283,7 @@ "oracle": "0x3147D7203354Dc06D9fd350c7a2437bcA92387a4", "oracleDecimals": 18, "oracleDescription": "REN / ETH", - "oracleLatestAnswer": 43176464225875, + "oracleLatestAnswer": 33490415434796, "reserveFactor": 2000, "stableBorrowRateEnabled": true, "stableDebtToken": "0x3356Ec1eFA75d9D150Da1EC7d944D9EDf73703B7", @@ -300,7 +300,7 @@ "baseStableBorrowRate": 0, "borrowingEnabled": true, "decimals": 18, - "interestRateStrategy": "0x67a81df2b7FAf4a324D94De9Cc778704F4500478", + "interestRateStrategy": "0xB28cA2760001c9837430F20c50fD89Ed56A449f0", "isActive": true, "isFrozen": true, "liquidationBonus": 0, @@ -309,7 +309,7 @@ "oracle": "0x614715d2Af89E6EC99A233818275142cE88d1Cfd", "oracleDecimals": 18, "oracleDescription": "BUSD / ETH", - "oracleLatestAnswer": 551474643195905, + "oracleLatestAnswer": 523008147925097, "reserveFactor": 9990, "stableBorrowRateEnabled": false, "stableDebtToken": "0x4A7A63909A72D268b1D8a93a9395d098688e0e5C", @@ -335,7 +335,7 @@ "oracle": "0xC9CbF687f43176B302F03f5e58470b77D07c61c6", "oracleDecimals": 18, "oracleDescription": "CVX / ETH", - "oracleLatestAnswer": 2588218180190564, + "oracleLatestAnswer": 2138937652361595, "reserveFactor": 2000, "stableBorrowRateEnabled": false, "stableDebtToken": "0xB01Eb1cE1Da06179136D561766fc2d609C5F55Eb", @@ -354,14 +354,14 @@ "decimals": 18, "interestRateStrategy": "0xED6547b83276B076B771B88FcCbD68BDeDb3927f", "isActive": true, - "isFrozen": false, + "isFrozen": true, "liquidationBonus": 10700, "liquidationThreshold": 8300, "ltv": 7000, "oracle": "0xDC530D9457755926550b59e8ECcdaE7624181557", "oracleDecimals": 18, "oracleDescription": "LINK / ETH", - "oracleLatestAnswer": 3588398579153839, + "oracleLatestAnswer": 3294479840299714, "reserveFactor": 2000, "stableBorrowRateEnabled": true, "stableDebtToken": "0xFB4AEc4Cc858F2539EBd3D37f2a43eAe5b15b98a", @@ -387,7 +387,7 @@ "oracle": "0x8e0b7e6062272B5eF4524250bFFF8e5Bd3497757", "oracleDecimals": 18, "oracleDescription": "SUSD / ETH", - "oracleLatestAnswer": 552098640544149, + "oracleLatestAnswer": 520986739613243, "reserveFactor": 2000, "stableBorrowRateEnabled": false, "stableDebtToken": "0x30B0f7324feDF89d8eff397275F8983397eFe4af", @@ -411,7 +411,7 @@ "liquidationThreshold": 0, "ltv": 0, "oracle": "0x60c0b047133f696334a2b7f68af0b49d2F3D4F72", - "oracleLatestAnswer": 556235582754438, + "oracleLatestAnswer": 523492663762565, "reserveFactor": 1000, "stableBorrowRateEnabled": true, "stableDebtToken": "0x39f010127274b2dBdB770B45e1de54d974974526", @@ -437,7 +437,7 @@ "oracle": "0x773616E4d11A78F511299002da57A0a94577F1f4", "oracleDecimals": 18, "oracleDescription": "DAI / ETH", - "oracleLatestAnswer": 553339670766154, + "oracleLatestAnswer": 522208250339689, "reserveFactor": 1000, "stableBorrowRateEnabled": true, "stableDebtToken": "0x778A13D3eeb110A4f7bb6529F99c000119a08E92", @@ -463,7 +463,7 @@ "oracle": "0x6Df09E975c830ECae5bd4eD9d90f3A95a4f88012", "oracleDecimals": 18, "oracleDescription": "AAVE / ETH", - "oracleLatestAnswer": 36099992635139994, + "oracleLatestAnswer": 39160443156477875, "reserveFactor": 0, "stableBorrowRateEnabled": false, "stableDebtToken": "0x079D6a3E844BcECf5720478A718Edb6575362C5f", @@ -489,7 +489,7 @@ "oracle": "0x14d04Fff8D21bd62987a5cE9ce543d2F1edF5D3E", "oracleDecimals": 18, "oracleDescription": "FRAX / ETH", - "oracleLatestAnswer": 552317308669792, + "oracleLatestAnswer": 516094269647015, "reserveFactor": 2000, "stableBorrowRateEnabled": false, "stableDebtToken": "0x3916e3B6c84b161df1b2733dFfc9569a1dA710c2", @@ -515,7 +515,7 @@ "oracle": "0xF05D9B6C08757EAcb1fbec18e36A1B7566a13DEB", "oracleDecimals": 18, "oracleDescription": "Calculated XSUSHI / ETH", - "oracleLatestAnswer": 681598793450212, + "oracleLatestAnswer": 492180799752201, "reserveFactor": 3500, "stableBorrowRateEnabled": false, "stableDebtToken": "0x73Bfb81D7dbA75C904f430eA8BAe82DB0D41187B", @@ -541,7 +541,7 @@ "oracle": "0x3a08ebBaB125224b7b6474384Ee39fBb247D2200", "oracleDecimals": 18, "oracleDescription": "PAX / ETH", - "oracleLatestAnswer": 557439311124365, + "oracleLatestAnswer": 515650202597755, "reserveFactor": 1000, "stableBorrowRateEnabled": false, "stableDebtToken": "0x2387119bc85A74e0BBcbe190d80676CB16F10D4F", @@ -567,7 +567,7 @@ "oracle": "0x7F0D2c2838c6AC24443d13e23d99490017bDe370", "oracleDecimals": 18, "oracleDescription": "FEI / ETH", - "oracleLatestAnswer": 544556921390975, + "oracleLatestAnswer": 504497213481975, "reserveFactor": 9900, "stableBorrowRateEnabled": false, "stableDebtToken": "0xd89cF9E8A858F8B4b31Faf793505e112d6c17449", @@ -586,14 +586,14 @@ "decimals": 18, "interestRateStrategy": "0xE3a3DE71B827cB73663A24cDB6243bA7F986cC3b", "isActive": true, - "isFrozen": false, + "isFrozen": true, "liquidationBonus": 10750, "liquidationThreshold": 6400, "ltv": 5900, "oracle": "0x24551a8Fb2A7211A25a17B1481f043A8a8adC7f2", "oracleDecimals": 18, "oracleDescription": "MKR / ETH", - "oracleLatestAnswer": 345668462170372600, + "oracleLatestAnswer": 520013878884730500, "reserveFactor": 2000, "stableBorrowRateEnabled": true, "stableDebtToken": "0xC01C8E4b12a89456a9fD4e4e75B72546Bf53f0B5", @@ -619,7 +619,7 @@ "oracle": "0x986b5E1e1755e3C2440e960477f25201B0a8bbD4", "oracleDecimals": 18, "oracleDescription": "USDC / ETH", - "oracleLatestAnswer": 551987119134434, + "oracleLatestAnswer": 522852544245885, "reserveFactor": 1000, "stableBorrowRateEnabled": true, "stableDebtToken": "0xE4922afAB0BbaDd8ab2a88E0C79d884Ad337fcA6", @@ -638,14 +638,14 @@ "decimals": 18, "interestRateStrategy": "0xCc92073dDe8aE03bAA1812AC5cF22e69b5E76914", "isActive": true, - "isFrozen": false, + "isFrozen": true, "liquidationBonus": 10750, "liquidationThreshold": 6200, "ltv": 4600, "oracle": "0x79291A9d692Df95334B1a0B3B4AE6bC606782f8c", "oracleDecimals": 18, "oracleDescription": "SNX / ETH", - "oracleLatestAnswer": 1328550000000000, + "oracleLatestAnswer": 1104060582321452, "reserveFactor": 3500, "stableBorrowRateEnabled": false, "stableDebtToken": "0x8575c8ae70bDB71606A53AeA1c6789cB0fBF3166", @@ -688,12 +688,12 @@ "decimals": 18, "interestRateStrategy": "0xb2eD1eCE1c13455Ce9299d35D3B00358529f3Dc8", "isActive": true, - "isFrozen": false, + "isFrozen": true, "liquidationBonus": 10800, "liquidationThreshold": 5700, "ltv": 4700, "oracle": "0xd4641b75015E6536E8102D98479568D05D7123Db", - "oracleLatestAnswer": 5717164290439960, + "oracleLatestAnswer": 4650038966354404, "reserveFactor": 2000, "stableBorrowRateEnabled": false, "stableDebtToken": "0x34441FFD1948E49dC7a607882D0c38Efd0083815", @@ -719,7 +719,7 @@ "oracle": "0x492575FDD11a0fCf2C6C719867890a7648d526eB", "oracleDecimals": 18, "oracleDescription": "AMPL / ETH", - "oracleLatestAnswer": 574004374424052, + "oracleLatestAnswer": 674314823539109, "reserveFactor": 1000, "stableBorrowRateEnabled": false, "stableDebtToken": "0x18152C9f77DAdc737006e9430dB913159645fa87", @@ -745,7 +745,7 @@ "oracle": "0x0606Be69451B1C9861Ac6b3626b99093b713E801", "oracleDecimals": 18, "oracleDescription": "FIL / ETH", - "oracleLatestAnswer": 2480533579467301, + "oracleLatestAnswer": 2414056052898225, "reserveFactor": 3500, "stableBorrowRateEnabled": false, "stableDebtToken": "0xcAad05C49E14075077915cB5C820EB3245aFb950", @@ -766,12 +766,12 @@ "isActive": true, "isFrozen": false, "liquidationBonus": 10800, - "liquidationThreshold": 5800, - "ltv": 5200, + "liquidationThreshold": 5500, + "ltv": 4900, "oracle": "0x8a12Be339B0cD1829b91Adc01977caa5E9ac121e", "oracleDecimals": 18, "oracleDescription": "CRV / ETH", - "oracleLatestAnswer": 456588362851304, + "oracleLatestAnswer": 408574741702621, "reserveFactor": 2000, "stableBorrowRateEnabled": false, "stableDebtToken": "0x9288059a74f589C919c7Cf1Db433251CdFEB874B", @@ -797,7 +797,7 @@ "oracle": "0x2Da4983a622a8498bb1a21FaE9D8F6C664939962", "oracleDecimals": 18, "oracleDescription": "ZRX / ETH", - "oracleLatestAnswer": 126216241224476, + "oracleLatestAnswer": 121651151311811, "reserveFactor": 2000, "stableBorrowRateEnabled": true, "stableDebtToken": "0x071B4323a24E73A5afeEbe34118Cd21B8FAAF7C3", @@ -823,7 +823,7 @@ "oracle": "0x24D9aB51950F3d62E9144fdC2f3135DAA6Ce8D1B", "oracleDecimals": 18, "oracleDescription": "ENJ / ETH", - "oracleLatestAnswer": 191760000000000, + "oracleLatestAnswer": 166330674259037, "reserveFactor": 2000, "stableBorrowRateEnabled": true, "stableDebtToken": "0x943DcCA156b5312Aa24c1a08769D67FEce4ac14C", @@ -849,7 +849,7 @@ "oracle": "0xa20623070413d42a5C01Db2c8111640DD7A5A03a", "oracleDecimals": 18, "oracleDescription": "UST / ETH", - "oracleLatestAnswer": 8345103489196, + "oracleLatestAnswer": 6498773940827, "reserveFactor": 2000, "stableBorrowRateEnabled": false, "stableDebtToken": "0x7FDbfB0412700D94403c42cA3CAEeeA183F07B26", @@ -872,10 +872,10 @@ "liquidationBonus": 10700, "liquidationThreshold": 8300, "ltv": 7200, - "oracle": "0x86392dC19c0b719886221c78AB11eb8Cf5c52812", + "oracle": "0xADE6CBA6c45aa8E9d0337cAc3D2619eabc39D901", "oracleDecimals": 18, - "oracleDescription": "STETH / ETH", - "oracleLatestAnswer": 1000151316541913800, + "oracleDescription": "stETH/ETH", + "oracleLatestAnswer": 1000000000000000000, "reserveFactor": 1000, "stableBorrowRateEnabled": false, "stableDebtToken": "0x66457616Dd8489dF5D0AFD8678F4A260088aAF55", @@ -901,7 +901,7 @@ "oracle": "0xC1438AA3823A6Ba0C159CfA8D98dF5A994bA120b", "oracleDecimals": 18, "oracleDescription": "BAL / ETH", - "oracleLatestAnswer": 3041729840350375, + "oracleLatestAnswer": 2529659272901808, "reserveFactor": 2000, "stableBorrowRateEnabled": false, "stableDebtToken": "0xe569d31590307d05DA3812964F1eDd551D665a0b", @@ -927,7 +927,7 @@ "oracle": "0xEe9F2375b4bdF6387aa8265dD4FB8F16512A1d46", "oracleDecimals": 18, "oracleDescription": "USDT / ETH", - "oracleLatestAnswer": 552852720035382, + "oracleLatestAnswer": 520215900827420, "reserveFactor": 1000, "stableBorrowRateEnabled": true, "stableDebtToken": "0xe91D55AB2240594855aBd11b3faAE801Fd4c4687", @@ -953,7 +953,7 @@ "oracle": "0x656c0544eF4C98A6a98491833A89204Abb045d6b", "oracleDecimals": 18, "oracleDescription": "KNC / ETH", - "oracleLatestAnswer": 348771310000000, + "oracleLatestAnswer": 293953734359786, "reserveFactor": 2000, "stableBorrowRateEnabled": true, "stableDebtToken": "0x9915dfb872778B2890a117DA1F35F335eb06B54f", @@ -1074,15 +1074,6 @@ "variableRateSlope1": 40000000000000000000000000, "variableRateSlope2": 750000000000000000000000000 }, - "0x67a81df2b7FAf4a324D94De9Cc778704F4500478": { - "baseVariableBorrowRate": 30000000000000000000000000, - "maxExcessUsageRatio": 800000000000000000000000000, - "optimalUsageRatio": 200000000000000000000000000, - "stableRateSlope1": 70000000000000000000000000, - "stableRateSlope2": 20000000000000000000000000000, - "variableRateSlope1": 70000000000000000000000000, - "variableRateSlope2": 2000000000000000000000000000 - }, "0x6bcE15B789e537f3abA3C60CB183F0E8737f05eC": { "baseVariableBorrowRate": 0, "maxExcessUsageRatio": 200000000000000000000000000, @@ -1155,6 +1146,15 @@ "variableRateSlope1": 40000000000000000000000000, "variableRateSlope2": 750000000000000000000000000 }, + "0xB28cA2760001c9837430F20c50fD89Ed56A449f0": { + "baseVariableBorrowRate": 30000000000000000000000000, + "maxExcessUsageRatio": 980000000000000000000000000, + "optimalUsageRatio": 20000000000000000000000000, + "stableRateSlope1": 70000000000000000000000000, + "stableRateSlope2": 30000000000000000000000000000, + "variableRateSlope1": 70000000000000000000000000, + "variableRateSlope2": 3000000000000000000000000000 + }, "0xBdfC85b140edF1FeaFd6eD664027AA4C23b4A29F": { "baseVariableBorrowRate": 0, "maxExcessUsageRatio": 550000000000000000000000000, diff --git a/src/ProtocolV2TestBase.sol b/src/ProtocolV2TestBase.sol index fb0641e..5233fab 100644 --- a/src/ProtocolV2TestBase.sol +++ b/src/ProtocolV2TestBase.sol @@ -77,17 +77,56 @@ contract ProtocolV2TestBase is CommonTestBase { /** * @dev Makes a e2e test including withdrawals/borrows and supplies to various reserves. * @param pool the pool that should be tested - * @param user the user to run the tests for */ - function e2eTest(ILendingPool pool, address user) public { + function e2eTest(ILendingPool pool) public { ReserveConfig[] memory configs = _getReservesConfigs(pool); + ReserveConfig memory collateralConfig = _getFirstCollateral(configs); + for (uint256 i; i < configs.length; i++) { + if (_includeInE2e(configs[i])) { + // there's a foundry bug causing issues when this is outside the loop + uint256 snapshot = vm.snapshot(); + e2eTestAsset(pool, collateralConfig, configs[i]); + vm.revertTo(snapshot); + } + } + } + + function e2eTestAsset( + ILendingPool pool, + ReserveConfig memory collateralConfig, + ReserveConfig memory testAssetConfig + ) public { + console.log( + 'E2E: Collateral %s, TestAsset %s', + collateralConfig.symbol, + testAssetConfig.symbol + ); + address collateralSupplier = vm.addr(3); + address testAssetSupplier = vm.addr(4); + require(collateralConfig.usageAsCollateralEnabled, 'COLLATERAL_CONFIG_MUST_BE_COLLATERAL'); + uint256 testAssetAmount = _getTokenAmountByEthValue(pool, testAssetConfig, 1); + _deposit( + collateralConfig, + pool, + collateralSupplier, + _getTokenAmountByEthValue(pool, collateralConfig, 100) + ); + _deposit(testAssetConfig, pool, testAssetSupplier, testAssetAmount); uint256 snapshot = vm.snapshot(); - _supplyWithdrawFlow(configs, pool, user); - vm.revertTo(snapshot); - _variableBorrowFlow(configs, pool, user); - vm.revertTo(snapshot); - _stableBorrowFlow(configs, pool, user); + // test withdrawal + _withdraw(testAssetConfig, pool, testAssetSupplier, testAssetAmount / 2); + _withdraw(testAssetConfig, pool, testAssetSupplier, type(uint256).max); vm.revertTo(snapshot); + // test variable borrowing + if (testAssetConfig.borrowingEnabled) { + _e2eTestBorrowRepay(pool, collateralSupplier, testAssetConfig, testAssetAmount, false); + vm.revertTo(snapshot); + // test stable borrowing + if (testAssetConfig.stableBorrowRateEnabled) { + _e2eTestBorrowRepay(pool, collateralSupplier, testAssetConfig, testAssetAmount, true); + vm.revertTo(snapshot); + } + } } /** @@ -97,97 +136,46 @@ contract ProtocolV2TestBase is CommonTestBase { return !config.isFrozen && config.isActive; } - /** - * @dev returns the first collateral in the list that cannot be borrowed in stable mode - */ - function _getFirstCollateral( - ReserveConfig[] memory configs - ) private pure returns (ReserveConfig memory config) { - for (uint256 i = 0; i < configs.length; i++) { - if ( - _includeInE2e(configs[i]) && - configs[i].usageAsCollateralEnabled && - !configs[i].stableBorrowRateEnabled - ) return configs[i]; - } - revert('ERROR: No collateral found'); - } - - /** - * @dev tests that all assets can be deposited & withdrawn - */ - function _supplyWithdrawFlow( - ReserveConfig[] memory configs, + function _getTokenAmountByEthValue( ILendingPool pool, - address user - ) internal { - // test all basic interactions - for (uint256 i = 0; i < configs.length; i++) { - if (_includeInE2e(configs[i])) { - uint256 amount = 100 * 10 ** configs[i].decimals; - console.log(configs[i].symbol); - _deposit(configs[i], pool, user, amount); - _skipBlocks(1000); - if ( - block.chainid == ChainIds.MAINNET && - configs[i].underlying == AaveV2EthereumAssets.stETH_UNDERLYING - ) { - assertGe(_withdraw(configs[i], pool, user, type(uint256).max), amount - 2); - } else { - assertGe(_withdraw(configs[i], pool, user, type(uint256).max), amount); - } - } else { - console.log('SKIP: REASON_FROZEN %s', configs[i].symbol); - } - } + ReserveConfig memory config, + uint256 dollarValue + ) internal view returns (uint256) { + ILendingPoolAddressesProvider addressesProvider = ILendingPoolAddressesProvider( + pool.getAddressesProvider() + ); + IAaveOracle oracle = IAaveOracle(addressesProvider.getPriceOracle()); + uint256 latestAnswer = oracle.getAssetPrice(config.underlying); + return (dollarValue * 10 ** (18 + config.decimals)) / latestAnswer; } - /** - * @dev tests that all assets with borrowing enabled can be borrowed - */ - function _variableBorrowFlow( - ReserveConfig[] memory configs, + function _e2eTestBorrowRepay( ILendingPool pool, - address user + address borrower, + ReserveConfig memory testAssetConfig, + uint256 amount, + bool stable ) internal { - // put 1M whatever collateral, which should be enough to borrow 1 of each - ReserveConfig memory collateralConfig = _getFirstCollateral(configs); - _deposit(collateralConfig, pool, user, 1000000 ether); - for (uint256 i = 0; i < configs.length; i++) { - if (_includeInE2e(configs[i]) && configs[i].borrowingEnabled) { - uint256 amount = 10 ** configs[i].decimals; - _deposit(configs[i], pool, EOA, amount * 2); - this._borrow(configs[i], pool, user, amount, false); - } else { - console.log('SKIP: BORROWING_DISABLED %s', configs[i].symbol); - } - } + uint256 snapshot = vm.snapshot(); + this._borrow(testAssetConfig, pool, borrower, amount, stable); + _repay(testAssetConfig, pool, borrower, amount, stable); + vm.revertTo(snapshot); } /** - * @dev tests that all assets with stable borrowing enabled can be borrowed + * @dev returns the first collateral in the list that cannot be borrowed in stable mode */ - function _stableBorrowFlow( - ReserveConfig[] memory configs, - ILendingPool pool, - address user - ) internal { - // put 1M whatever collateral, which should be enough to borrow 1 of each - ReserveConfig memory collateralConfig = _getFirstCollateral(configs); - _deposit(collateralConfig, pool, user, 1000000 ether); + function _getFirstCollateral( + ReserveConfig[] memory configs + ) private pure returns (ReserveConfig memory config) { for (uint256 i = 0; i < configs.length; i++) { - uint256 amount = 10 ** configs[i].decimals; if ( _includeInE2e(configs[i]) && - configs[i].borrowingEnabled && - configs[i].stableBorrowRateEnabled - ) { - _deposit(configs[i], pool, EOA, amount * 2); - this._borrow(configs[i], pool, user, amount, true); - } else { - console.log('SKIP: STABLE_BORROWING_DISABLED %s', configs[i].symbol); - } + configs[i].usageAsCollateralEnabled && + !configs[i].stableBorrowRateEnabled + ) return configs[i]; } + revert('ERROR: No usable collateral found'); } function _deposit( @@ -287,7 +275,7 @@ contract ProtocolV2TestBase is CommonTestBase { console.log('REPAY: %s, Amount: %s', config.symbol, amount); pool.repay(config.underlying, amount, stable ? 1 : 2, user); uint256 debtAfter = IERC20(debtToken).balanceOf(user); - require(debtAfter == ((debtBefore > amount) ? debtBefore - amount : 0), '_repay() : ERROR'); + require(debtAfter == ((debtBefore - 1 > amount) ? debtBefore - amount : 0), '_repay() : ERROR'); vm.stopPrank(); } diff --git a/src/ProtocolV3TestBase.sol b/src/ProtocolV3TestBase.sol index a737f8c..54c1313 100644 --- a/src/ProtocolV3TestBase.sol +++ b/src/ProtocolV3TestBase.sol @@ -201,10 +201,13 @@ contract ProtocolV3TestBase is CommonTestBase { ReserveConfig[] memory configs ) private pure returns (ReserveConfig memory config) { for (uint256 i = 0; i < configs.length; i++) { - if (configs[i].usageAsCollateralEnabled && !configs[i].stableBorrowRateEnabled) - return configs[i]; + if ( + _includeInE2e(configs[i]) && + configs[i].usageAsCollateralEnabled && + !configs[i].stableBorrowRateEnabled + ) return configs[i]; } - revert('ERROR: No collateral found'); + revert('ERROR: No usable collateral found'); } function _deposit( diff --git a/tests/ProtocolV2TestBase.t.sol b/tests/ProtocolV2TestBase.t.sol index 2d68584..09e48bc 100644 --- a/tests/ProtocolV2TestBase.t.sol +++ b/tests/ProtocolV2TestBase.t.sol @@ -3,20 +3,34 @@ pragma solidity ^0.8.0; import 'forge-std/Test.sol'; import {ProtocolV2TestBase, ReserveConfig} from '../src/ProtocolV2TestBase.sol'; -import {AaveV2Ethereum} from 'aave-address-book/AaveV2Ethereum.sol'; +import {AaveV2Ethereum, AaveV2EthereumAssets} from 'aave-address-book/AaveV2Ethereum.sol'; import {IERC20} from 'solidity-utils/contracts/oz-common/interfaces/IERC20.sol'; contract ProtocolV2TestBaseTest is ProtocolV2TestBase { function setUp() public { - vm.createSelectFork('mainnet', 17293676); + vm.createSelectFork('mainnet', 17627440); } - function testSnpashot() public { - createConfigurationSnapshot('v2-report', AaveV2Ethereum.POOL); - } + // function testSnpashot() public { + // createConfigurationSnapshot('v2-report', AaveV2Ethereum.POOL); + // } function testE2E() public { - address user = vm.addr(3); - e2eTest(AaveV2Ethereum.POOL, user); + e2eTest(AaveV2Ethereum.POOL); + } +} + +contract ProtocolV2TestE2ETestAsset is ProtocolV2TestBase { + function setUp() public { + vm.createSelectFork('mainnet', 17627440); + } + + function test_e2eTestAssetUSDT() public { + ReserveConfig[] memory configs = _getReservesConfigs(AaveV2Ethereum.POOL); + e2eTestAsset( + AaveV2Ethereum.POOL, + _findReserveConfig(configs, AaveV2EthereumAssets.DAI_UNDERLYING), + _findReserveConfig(configs, AaveV2EthereumAssets.USDT_UNDERLYING) + ); } }