From 7a2e96e844c6f0f652ed4b10583f3e3b07b185b1 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Fri, 8 Mar 2024 15:54:17 +0200 Subject: [PATCH 1/7] mode new market test --- contracts/compound/Comptroller.sol | 1 + contracts/test/DevTesting.t.sol | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/contracts/compound/Comptroller.sol b/contracts/compound/Comptroller.sol index a10e81b7..1d984c5e 100644 --- a/contracts/compound/Comptroller.sol +++ b/contracts/compound/Comptroller.sol @@ -1222,6 +1222,7 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR uint256 err = _supportMarket(cToken); IFeeDistributor(ionicAdmin).authoritiesRegistry().reconfigureAuthority(address(this)); + //supplyCaps[address(cToken)] = 1; // Set collateral factor return err == uint256(Error.NO_ERROR) ? _setCollateralFactor(cToken, collateralFactorMantissa) : err; diff --git a/contracts/test/DevTesting.t.sol b/contracts/test/DevTesting.t.sol index 2ebc3dc4..b57e35e6 100644 --- a/contracts/test/DevTesting.t.sol +++ b/contracts/test/DevTesting.t.sol @@ -18,6 +18,8 @@ contract DevTesting is BaseTest { PoolLens lens = PoolLens(0x431C87E08e2636733a945D742d25Ba77577ED480); address deployer = 0x1155b614971f16758C92c4890eD338C9e3ede6b7; + address multisig = 0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2; + ICErc20 wethMarket; ICErc20 usdcMarket; ICErc20 usdtMarket; @@ -150,13 +152,35 @@ contract DevTesting is BaseTest { } function testAssetAsCollateralCap() public debuggingOnly fork(MODE_MAINNET) { - pool.getAssetAsCollateralValueCap(wethMarket, usdcMarket, false, deployer); + address MODE_EZETH = 0x2416092f143378750bb29b79eD961ab195CcEea5; + uint256 errCode = pool._deployMarket( + 1, //delegateType + abi.encode( + MODE_EZETH, + address(pool), + payable(address(multisig)), + 0x21a455cEd9C79BC523D4E340c2B97521F4217817, // irm - jump rate model on mode + "ez ether", + "ezETH", + uint256(0), + uint256(0) + ), + "", + 0.70e18 + ); + require(errCode != 0, "error deploying market"); + + ICErc20[] memory markets = pool.getAllMarkets(); + + uint256 cap = pool.getAssetAsCollateralValueCap(markets[markets.length-1], usdcMarket, false, deployer); + + require(cap == 0, "non-zero cap"); } function testRegisterSFS() public debuggingOnly fork(MODE_MAINNET) { emit log_named_address("pool admin", pool.admin()); - vm.startPrank(0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2); + vm.startPrank(multisig); pool.registerInSFS(); ICErc20[] memory markets = pool.getAllMarkets(); From 58f8082bb9810e7fb0530401605b98e594c3a1e0 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Fri, 8 Mar 2024 16:29:51 +0200 Subject: [PATCH 2/7] testing if able to supply in a brand new market --- contracts/test/DevTesting.t.sol | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/contracts/test/DevTesting.t.sol b/contracts/test/DevTesting.t.sol index b57e35e6..cc55b0be 100644 --- a/contracts/test/DevTesting.t.sol +++ b/contracts/test/DevTesting.t.sol @@ -153,12 +153,15 @@ contract DevTesting is BaseTest { function testAssetAsCollateralCap() public debuggingOnly fork(MODE_MAINNET) { address MODE_EZETH = 0x2416092f143378750bb29b79eD961ab195CcEea5; + address ezEthWhale = 0xd3B02d999C681BD8B75F340FA7e078cE9097bF23; + + vm.startPrank(multisig); uint256 errCode = pool._deployMarket( 1, //delegateType abi.encode( MODE_EZETH, address(pool), - payable(address(multisig)), + ap.getAddress("FeeDistributor"), 0x21a455cEd9C79BC523D4E340c2B97521F4217817, // irm - jump rate model on mode "ez ether", "ezETH", @@ -168,13 +171,20 @@ contract DevTesting is BaseTest { "", 0.70e18 ); - require(errCode != 0, "error deploying market"); + vm.stopPrank(); + require(errCode == 0, "error deploying market"); ICErc20[] memory markets = pool.getAllMarkets(); + ICErc20 ezEthMarket = markets[markets.length-1]; - uint256 cap = pool.getAssetAsCollateralValueCap(markets[markets.length-1], usdcMarket, false, deployer); - + // uint256 cap = pool.getAssetAsCollateralValueCap(ezEthMarket, usdcMarket, false, deployer); + uint256 cap = pool.supplyCaps(address(ezEthMarket)); require(cap == 0, "non-zero cap"); + + vm.startPrank(ezEthWhale); + ERC20(MODE_EZETH).approve(address(ezEthMarket), 1e36); + errCode = ezEthMarket.mint(1e18); + require(errCode == 0, "should be unable to supply"); } function testRegisterSFS() public debuggingOnly fork(MODE_MAINNET) { From 1eeacb30794747a2db6ef82a3c0803c9e762e9ce Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Fri, 8 Mar 2024 16:36:41 +0200 Subject: [PATCH 3/7] ezeth market params fixes --- contracts/test/DevTesting.t.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/test/DevTesting.t.sol b/contracts/test/DevTesting.t.sol index cc55b0be..e28cfa85 100644 --- a/contracts/test/DevTesting.t.sol +++ b/contracts/test/DevTesting.t.sol @@ -163,10 +163,10 @@ contract DevTesting is BaseTest { address(pool), ap.getAddress("FeeDistributor"), 0x21a455cEd9C79BC523D4E340c2B97521F4217817, // irm - jump rate model on mode - "ez ether", + "Renzo Restaked ETH", "ezETH", - uint256(0), - uint256(0) + 0.10e18, + 0.10e18 ), "", 0.70e18 From 559923d0740dcbbcf07c378e9a7612d20735f74d Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:35:20 +0200 Subject: [PATCH 4/7] new market test --- contracts/test/DevTesting.t.sol | 36 +++++++++++++++++++ .../oracles/RedstoneAdapterOracleTest.t.sol | 9 +++++ 2 files changed, 45 insertions(+) diff --git a/contracts/test/DevTesting.t.sol b/contracts/test/DevTesting.t.sol index e28cfa85..8d1e46f8 100644 --- a/contracts/test/DevTesting.t.sol +++ b/contracts/test/DevTesting.t.sol @@ -205,6 +205,42 @@ contract DevTesting is BaseTest { require(usdcMarket.borrow(5e6) == 0, "can't borrow"); } + function testModeDeployMarket() public debuggingOnly fork(MODE_MAINNET) { + address MODE_WEETH = 0x028227c4dd1e5419d11Bb6fa6e661920c519D4F5; + address weEthWhale = 0x6e55a90772B92f17f87Be04F9562f3faafd0cc38; + + vm.startPrank(pool.admin()); + uint256 errCode = pool._deployMarket( + 1, //delegateType + abi.encode( + MODE_WEETH, + address(pool), + ap.getAddress("FeeDistributor"), + 0x21a455cEd9C79BC523D4E340c2B97521F4217817, // irm - jump rate model on mode + "Ionic Wrapped eETH", + "ionweETH", + 0.10e18, + 0.10e18 + ), + "", + 0.70e18 + ); + vm.stopPrank(); + require(errCode == 0, "error deploying market"); + + ICErc20[] memory markets = pool.getAllMarkets(); + ICErc20 weEthMarket = markets[markets.length-1]; + + // uint256 cap = pool.getAssetAsCollateralValueCap(weEthMarket, usdcMarket, false, deployer); + uint256 cap = pool.supplyCaps(address(weEthMarket)); + require(cap == 0, "non-zero cap"); + + vm.startPrank(weEthWhale); + ERC20(MODE_WEETH).approve(address(weEthMarket), 1e36); + errCode = weEthMarket.mint(0.01e18); + require(errCode == 0, "should be unable to supply"); + } + function _functionCall( address target, bytes memory data, diff --git a/contracts/test/oracles/RedstoneAdapterOracleTest.t.sol b/contracts/test/oracles/RedstoneAdapterOracleTest.t.sol index 5c2745df..2db06316 100644 --- a/contracts/test/oracles/RedstoneAdapterOracleTest.t.sol +++ b/contracts/test/oracles/RedstoneAdapterOracleTest.t.sol @@ -3,16 +3,19 @@ pragma solidity >=0.8.0; import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import { MasterPriceOracle } from "../../oracles/MasterPriceOracle.sol"; import { RedstoneAdapterPriceOracle } from "../../oracles/default/RedstoneAdapterPriceOracle.sol"; import { BaseTest } from "../config/BaseTest.t.sol"; contract RedstoneAdapterOracleTest is BaseTest { + MasterPriceOracle public mpo; RedstoneAdapterPriceOracle public oracle; address public redstoneOracleAddress; address MODE_USDC = 0xd988097fb8612cc24eeC14542bC03424c656005f; address MODE_EZETH = 0x2416092f143378750bb29b79eD961ab195CcEea5; address MODE_WBTC = 0xcDd475325D6F564d27247D1DddBb0DAc6fA0a5CF; + address MODE_WEETH = 0x028227c4dd1e5419d11Bb6fa6e661920c519D4F5; function afterForkSetUp() internal override { if (block.chainid == MODE_MAINNET) { @@ -20,10 +23,16 @@ contract RedstoneAdapterOracleTest is BaseTest { } oracle = new RedstoneAdapterPriceOracle(redstoneOracleAddress); + mpo = MasterPriceOracle(ap.getAddress("MasterPriceOracle")); } function testPrintPricesMode() public fork(MODE_MAINNET) { emit log_named_uint("ezETH price (18 dec)", oracle.price(MODE_EZETH)); emit log_named_uint("WBTC price (8 dec)", oracle.price(MODE_WBTC)); + emit log_named_uint("weETH price (18 dec)", oracle.price(MODE_WEETH)); + } + + function testPrintMpoPricesMode() public fork(MODE_MAINNET) { + emit log_named_uint("weETH price (18 dec)", mpo.price(MODE_WEETH)); } } From 0413502bc9a637a4f40a816974cf090c66b51a80 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:35:45 +0200 Subject: [PATCH 5/7] prettier --- contracts/test/DevTesting.t.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/test/DevTesting.t.sol b/contracts/test/DevTesting.t.sol index 8d1e46f8..b77de865 100644 --- a/contracts/test/DevTesting.t.sol +++ b/contracts/test/DevTesting.t.sol @@ -175,7 +175,7 @@ contract DevTesting is BaseTest { require(errCode == 0, "error deploying market"); ICErc20[] memory markets = pool.getAllMarkets(); - ICErc20 ezEthMarket = markets[markets.length-1]; + ICErc20 ezEthMarket = markets[markets.length - 1]; // uint256 cap = pool.getAssetAsCollateralValueCap(ezEthMarket, usdcMarket, false, deployer); uint256 cap = pool.supplyCaps(address(ezEthMarket)); @@ -229,7 +229,7 @@ contract DevTesting is BaseTest { require(errCode == 0, "error deploying market"); ICErc20[] memory markets = pool.getAllMarkets(); - ICErc20 weEthMarket = markets[markets.length-1]; + ICErc20 weEthMarket = markets[markets.length - 1]; // uint256 cap = pool.getAssetAsCollateralValueCap(weEthMarket, usdcMarket, false, deployer); uint256 cap = pool.supplyCaps(address(weEthMarket)); From 27b0e4921e3eb472191633970822a4f0d75f4c78 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:21:39 +0200 Subject: [PATCH 6/7] d --- contracts/test/DevTesting.t.sol | 46 +++++++++++++++++++++++++--- contracts/test/PoolLensTest.t.sol | 10 +++--- contracts/test/config/BaseTest.t.sol | 1 + 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/contracts/test/DevTesting.t.sol b/contracts/test/DevTesting.t.sol index 2f91e904..b9d07741 100644 --- a/contracts/test/DevTesting.t.sol +++ b/contracts/test/DevTesting.t.sol @@ -14,6 +14,7 @@ import { ISwapRouter } from "../external/uniswap/ISwapRouter.sol"; import { MasterPriceOracle } from "../oracles/MasterPriceOracle.sol"; import { PoolLens } from "../PoolLens.sol"; import { PoolLensSecondary } from "../PoolLensSecondary.sol"; +import { JumpRateModel } from "../compound/JumpRateModel.sol"; contract DevTesting is BaseTest { IonicComptroller pool = IonicComptroller(0xFB3323E24743Caf4ADD0fDCCFB268565c0685556); @@ -81,11 +82,28 @@ contract DevTesting is BaseTest { emit log_named_uint("hf", hf); } - function testModeMaxBorrow() public debuggingOnly fork(MODE_MAINNET) { - address user = 0x5A9e792143bf2708b4765C144451dCa54f559a19; - uint256 maxBorrow = pool.getMaxRedeemOrBorrow(user, usdcMarket, true); + function testModeUsdcBorrowCaps() public debuggingOnly fork(MODE_MAINNET) { + _testModeBorrowCaps(usdcMarket); + } + + function testModeUsdtBorrowCaps() public debuggingOnly fork(MODE_MAINNET) { + _testModeBorrowCaps(usdtMarket); + } + + function testModeWethBorrowCaps() public debuggingOnly fork(MODE_MAINNET) { + _testModeBorrowCaps(wethMarket); + wethMarket.accrueInterest(); + _testModeBorrowCaps(wethMarket); + } + + function _testModeBorrowCaps(ICErc20 market) internal { + uint256 borrowCapUsdc = pool.borrowCaps(address(market)); + uint256 totalBorrowsCurrent = market.totalBorrowsCurrent(); - emit log_named_uint("max borrow", maxBorrow); + uint256 wethBorrowAmount = 154753148031252; + console.log("borrowCapUsdc %e", borrowCapUsdc); + console.log("totalBorrowsCurrent %e", totalBorrowsCurrent); + console.log("new totalBorrowsCurrent %e", totalBorrowsCurrent + wethBorrowAmount); } function testMarketMember() public debuggingOnly fork(MODE_MAINNET) { @@ -216,11 +234,29 @@ contract DevTesting is BaseTest { vm.stopPrank(); } + function testModeBorrowRate() public fork(MODE_MAINNET) { + //ICErc20[] memory markets = pool.getAllMarkets(); + ICErc20 ezEthMarket = ICErc20(0x59e710215d45F584f44c0FEe83DA6d43D762D857); + + IonicComptroller pool = ezEthMarket.comptroller(); + vm.prank(pool.admin()); + ezEthMarket._setInterestRateModel(JumpRateModel(0x413aD59b80b1632988d478115a466bdF9B26743a)); + + JumpRateModel discRateModel = JumpRateModel(ezEthMarket.interestRateModel()); + + uint256 borrows = 200e18; + uint256 cash = 5000e18 - borrows; + uint256 reserves = 1e18; + uint256 rate = discRateModel.getBorrowRate(cash, borrows, reserves); + + emit log_named_uint("rate per year %e", rate * discRateModel.blocksPerYear()); + } + function testModeFetchBorrowers() public fork(MODE_MAINNET) { // address[] memory borrowers = pool.getAllBorrowers(); // emit log_named_uint("borrowers.len", borrowers.length); - upgradePool(); + //upgradePool(); (uint256 totalPages, address[] memory borrowersPage) = pool.getPaginatedBorrowers(1, 0); diff --git a/contracts/test/PoolLensTest.t.sol b/contracts/test/PoolLensTest.t.sol index efa7a10c..6de72cbc 100644 --- a/contracts/test/PoolLensTest.t.sol +++ b/contracts/test/PoolLensTest.t.sol @@ -15,11 +15,11 @@ contract PoolLensTest is BaseTest { function testModeFPL() public debuggingOnly fork(MODE_MAINNET) { IonicComptroller pool = IonicComptroller(0xFB3323E24743Caf4ADD0fDCCFB268565c0685556); - // PoolLens fpl = PoolLens(0x611a68618412c2e15A36e3e59C0b979746d87AB8); - // PoolLens.PoolAsset[] memory datas = fpl.getPoolAssetsWithData(pool); - // - // emit log_named_uint("ionicFee", datas[0].ionicFee); - // emit log_named_uint("adminFee", datas[0].adminFee); + PoolLens fpl = PoolLens(0x611a68618412c2e15A36e3e59C0b979746d87AB8); + PoolLens.PoolAsset[] memory datas = fpl.getPoolAssetsWithData(pool); + + emit log_named_uint("ionicFee", datas[0].ionicFee); + emit log_named_uint("adminFee", datas[0].adminFee); ICErc20[] memory markets = pool.getAllMarkets(); diff --git a/contracts/test/config/BaseTest.t.sol b/contracts/test/config/BaseTest.t.sol index 6ff8dd08..c691696e 100644 --- a/contracts/test/config/BaseTest.t.sol +++ b/contracts/test/config/BaseTest.t.sol @@ -3,6 +3,7 @@ pragma solidity >=0.8.0; import "forge-std/Vm.sol"; import "forge-std/Test.sol"; +import "forge-std/console.sol"; import { AddressesProvider } from "../../ionic/AddressesProvider.sol"; From e00e198ba3cb98dc3bddf96638c0ffc04afcf120 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:23:02 +0200 Subject: [PATCH 7/7] small fixes --- contracts/compound/Comptroller.sol | 1 - contracts/test/DevTesting.t.sol | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/compound/Comptroller.sol b/contracts/compound/Comptroller.sol index 1d984c5e..a10e81b7 100644 --- a/contracts/compound/Comptroller.sol +++ b/contracts/compound/Comptroller.sol @@ -1222,7 +1222,6 @@ contract Comptroller is ComptrollerBase, ComptrollerInterface, ComptrollerErrorR uint256 err = _supportMarket(cToken); IFeeDistributor(ionicAdmin).authoritiesRegistry().reconfigureAuthority(address(this)); - //supplyCaps[address(cToken)] = 1; // Set collateral factor return err == uint256(Error.NO_ERROR) ? _setCollateralFactor(cToken, collateralFactorMantissa) : err; diff --git a/contracts/test/DevTesting.t.sol b/contracts/test/DevTesting.t.sol index b9d07741..a32dd851 100644 --- a/contracts/test/DevTesting.t.sol +++ b/contracts/test/DevTesting.t.sol @@ -184,8 +184,8 @@ contract DevTesting is BaseTest { address(pool), ap.getAddress("FeeDistributor"), 0x21a455cEd9C79BC523D4E340c2B97521F4217817, // irm - jump rate model on mode - "Renzo Restaked ETH", - "ezETH", + "Ionic Renzo Restaked ETH", + "ionezETH", 0.10e18, 0.10e18 ),