From b7ce0316808d7933c78e1db0094a150b50ce0290 Mon Sep 17 00:00:00 2001 From: Jourdan Dunkley Date: Tue, 12 Mar 2024 07:54:27 -0500 Subject: [PATCH 1/5] fixed mode tests --- contracts/test/LeveredPositionTest.t.sol | 107 ++++++++++++++++++++--- 1 file changed, 94 insertions(+), 13 deletions(-) diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index b0721365..93919e7a 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -200,11 +200,7 @@ abstract contract LeveredPositionTest is MarketsTest { vm.stopPrank(); } - function _configurePairAndLiquidator( - address _collat, - address _stable, - IRedemptionStrategy _liquidator - ) internal { + function _configurePairAndLiquidator(address _collat, address _stable, IRedemptionStrategy _liquidator) internal { _configurePair(_collat, _stable); _configureTwoWayLiquidator(_collat, _stable, _liquidator); } @@ -286,14 +282,10 @@ abstract contract LeveredPositionTest is MarketsTest { } } - function _openLeveredPosition(address _positionOwner, uint256 _depositAmount) - internal - returns ( - LeveredPosition _position, - uint256 _maxRatio, - uint256 _minRatio - ) - { + function _openLeveredPosition( + address _positionOwner, + uint256 _depositAmount + ) internal returns (LeveredPosition _position, uint256 _maxRatio, uint256 _minRatio) { IERC20Upgradeable collateralToken = IERC20Upgradeable(collateralMarket.underlying()); collateralToken.transfer(_positionOwner, _depositAmount); @@ -960,6 +952,95 @@ contract DavosUsdcDusdLeveredPositionTest is LeveredPositionTest { } } +contract ModeWethUSDCLeveredPositionTest is LeveredPositionTest { + function setUp() public fork(MODE_MAINNET) {} + + function afterForkSetUp() internal override { + super.afterForkSetUp(); + + uint256 depositAmount = 10e18; + + address wethMarket = 0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2; + address USDCMarket = 0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038; + address wethWhale = 0xd60DD6981Ec336fDa40820f8cA5E99CD17dD25A0; + address USDCWhale = 0x34b83A3759ba4c9F99c339604181bf6bBdED4C79; + + _configurePair(wethMarket, USDCMarket); + _fundMarketAndSelf(ICErc20(wethMarket), wethWhale); + _fundMarketAndSelf(ICErc20(USDCMarket), USDCWhale); + + (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); + } +} + +contract ModeWethUSDTLeveredPositionTest is LeveredPositionTest { + function setUp() public fork(MODE_MAINNET) {} + + function afterForkSetUp() internal override { + super.afterForkSetUp(); + + uint256 depositAmount = 10e18; + + address wethMarket = 0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2; + address USDTMarket = 0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3; + address wethWhale = 0xd60DD6981Ec336fDa40820f8cA5E99CD17dD25A0; + address USDTWhale = 0x082321F9939373b02Ad54ea214BF6e822531e679; + + _configurePair(wethMarket, USDTMarket); + _fundMarketAndSelf(ICErc20(wethMarket), wethWhale); + _fundMarketAndSelf(ICErc20(USDTMarket), USDTWhale); + + (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); + } +} + +contract ModeWbtcUSDCLeveredPositionTest is LeveredPositionTest { + function setUp() public fork(MODE_MAINNET) {} + + function afterForkSetUp() internal override { + super.afterForkSetUp(); + + uint256 depositAmount = 10e8; + + address wbtcMarket = 0xd70254C3baD29504789714A7c69d60Ec1127375C; + address USDCMarket = 0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038; + address wbtcWhale = 0x3f3429D28438Cc14133966820b8A9Ea61Cf1D4F0; + address USDCWhale = 0x34b83A3759ba4c9F99c339604181bf6bBdED4C79; + + IERC20Upgradeable token = IERC20Upgradeable(ICErc20(wbtcMarket).underlying()); + + _configurePair(wbtcMarket, USDCMarket); + + uint256 allTokens = token.balanceOf(wbtcWhale); + + vm.prank(wbtcWhale); + token.transfer(address(this), allTokens); + vm.stopPrank(); + + (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); + } +} +contract ModeWbtcUSDTLeveredPositionTest is LeveredPositionTest { + function setUp() public fork(MODE_MAINNET) {} + + function afterForkSetUp() internal override { + super.afterForkSetUp(); + + uint256 depositAmount = 1e8; + + address wbtcMarket = 0xd70254C3baD29504789714A7c69d60Ec1127375C; + address USDTMarket = 0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3; + address wbtcWhale = 0x3f3429D28438Cc14133966820b8A9Ea61Cf1D4F0; + address USDTWhale = 0x082321F9939373b02Ad54ea214BF6e822531e679; + + _configurePair(wbtcMarket, USDTMarket); + _fundMarketAndSelf(ICErc20(wbtcMarket), wbtcWhale); + _fundMarketAndSelf(ICErc20(USDTMarket), USDTWhale); + + (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); + } +} + /* contract XYLeveredPositionTest is LeveredPositionTest { function setUp() public fork(X_CHAIN_ID) {} From 680c64eb3548fdc325e5153f6e01d10b91d353f2 Mon Sep 17 00:00:00 2001 From: Jourdan Dunkley Date: Thu, 14 Mar 2024 12:24:36 -0500 Subject: [PATCH 2/5] raised borrow caps for USDC for testing purposes --- contracts/test/LeveredPositionTest.t.sol | 28 ++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index 93919e7a..99b14856 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -962,9 +962,21 @@ contract ModeWethUSDCLeveredPositionTest is LeveredPositionTest { address wethMarket = 0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2; address USDCMarket = 0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038; - address wethWhale = 0xd60DD6981Ec336fDa40820f8cA5E99CD17dD25A0; + address wethWhale = 0x7380511493DD4c2f1dD75E9CCe5bD52C787D4B51; address USDCWhale = 0x34b83A3759ba4c9F99c339604181bf6bBdED4C79; + ICErc20[] memory cTokens = new ICErc20[](1); + cTokens[0] = ICErc20(USDCMarket); + + uint256[] memory newBorrowCaps = new uint256[](1); + newBorrowCaps[0] = 1e36; + + IonicComptroller comptroller = IonicComptroller(ICErc20(wethMarket).comptroller()); + + vm.prank(comptroller.admin()); + comptroller._setMarketBorrowCaps(cTokens, newBorrowCaps); + vm.stopPrank(); + _configurePair(wethMarket, USDCMarket); _fundMarketAndSelf(ICErc20(wethMarket), wethWhale); _fundMarketAndSelf(ICErc20(USDCMarket), USDCWhale); @@ -983,7 +995,7 @@ contract ModeWethUSDTLeveredPositionTest is LeveredPositionTest { address wethMarket = 0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2; address USDTMarket = 0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3; - address wethWhale = 0xd60DD6981Ec336fDa40820f8cA5E99CD17dD25A0; + address wethWhale = 0x7380511493DD4c2f1dD75E9CCe5bD52C787D4B51; address USDTWhale = 0x082321F9939373b02Ad54ea214BF6e822531e679; _configurePair(wethMarket, USDTMarket); @@ -1007,6 +1019,18 @@ contract ModeWbtcUSDCLeveredPositionTest is LeveredPositionTest { address wbtcWhale = 0x3f3429D28438Cc14133966820b8A9Ea61Cf1D4F0; address USDCWhale = 0x34b83A3759ba4c9F99c339604181bf6bBdED4C79; + ICErc20[] memory cTokens = new ICErc20[](1); + cTokens[0] = ICErc20(USDCMarket); + + uint256[] memory newBorrowCaps = new uint256[](1); + newBorrowCaps[0] = 1e36; + + IonicComptroller comptroller = IonicComptroller(ICErc20(wbtcMarket).comptroller()); + + vm.prank(comptroller.admin()); + comptroller._setMarketBorrowCaps(cTokens, newBorrowCaps); + vm.stopPrank(); + IERC20Upgradeable token = IERC20Upgradeable(ICErc20(wbtcMarket).underlying()); _configurePair(wbtcMarket, USDCMarket); From 9b09fd3210903f29368cda266203f69292d1390f Mon Sep 17 00:00:00 2001 From: Jourdan Dunkley Date: Sun, 17 Mar 2024 16:44:03 -0500 Subject: [PATCH 3/5] formatted test file --- contracts/test/LeveredPositionTest.t.sol | 43 +++++++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index 99b14856..4e421384 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -200,7 +200,11 @@ abstract contract LeveredPositionTest is MarketsTest { vm.stopPrank(); } - function _configurePairAndLiquidator(address _collat, address _stable, IRedemptionStrategy _liquidator) internal { + function _configurePairAndLiquidator( + address _collat, + address _stable, + IRedemptionStrategy _liquidator + ) internal { _configurePair(_collat, _stable); _configureTwoWayLiquidator(_collat, _stable, _liquidator); } @@ -282,10 +286,14 @@ abstract contract LeveredPositionTest is MarketsTest { } } - function _openLeveredPosition( - address _positionOwner, - uint256 _depositAmount - ) internal returns (LeveredPosition _position, uint256 _maxRatio, uint256 _minRatio) { + function _openLeveredPosition(address _positionOwner, uint256 _depositAmount) + internal + returns ( + LeveredPosition _position, + uint256 _maxRatio, + uint256 _minRatio + ) + { IERC20Upgradeable collateralToken = IERC20Upgradeable(collateralMarket.underlying()); collateralToken.transfer(_positionOwner, _depositAmount); @@ -998,6 +1006,18 @@ contract ModeWethUSDTLeveredPositionTest is LeveredPositionTest { address wethWhale = 0x7380511493DD4c2f1dD75E9CCe5bD52C787D4B51; address USDTWhale = 0x082321F9939373b02Ad54ea214BF6e822531e679; + ICErc20[] memory cTokens = new ICErc20[](1); + cTokens[0] = ICErc20(USDTMarket); + + uint256[] memory newBorrowCaps = new uint256[](1); + newBorrowCaps[0] = 1e36; + + IonicComptroller comptroller = IonicComptroller(ICErc20(wethMarket).comptroller()); + + vm.prank(comptroller.admin()); + comptroller._setMarketBorrowCaps(cTokens, newBorrowCaps); + vm.stopPrank(); + _configurePair(wethMarket, USDTMarket); _fundMarketAndSelf(ICErc20(wethMarket), wethWhale); _fundMarketAndSelf(ICErc20(USDTMarket), USDTWhale); @@ -1044,6 +1064,7 @@ contract ModeWbtcUSDCLeveredPositionTest is LeveredPositionTest { (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); } } + contract ModeWbtcUSDTLeveredPositionTest is LeveredPositionTest { function setUp() public fork(MODE_MAINNET) {} @@ -1057,6 +1078,18 @@ contract ModeWbtcUSDTLeveredPositionTest is LeveredPositionTest { address wbtcWhale = 0x3f3429D28438Cc14133966820b8A9Ea61Cf1D4F0; address USDTWhale = 0x082321F9939373b02Ad54ea214BF6e822531e679; + ICErc20[] memory cTokens = new ICErc20[](1); + cTokens[0] = ICErc20(USDTMarket); + + uint256[] memory newBorrowCaps = new uint256[](1); + newBorrowCaps[0] = 1e36; + + IonicComptroller comptroller = IonicComptroller(ICErc20(wbtcMarket).comptroller()); + + vm.prank(comptroller.admin()); + comptroller._setMarketBorrowCaps(cTokens, newBorrowCaps); + vm.stopPrank(); + _configurePair(wbtcMarket, USDTMarket); _fundMarketAndSelf(ICErc20(wbtcMarket), wbtcWhale); _fundMarketAndSelf(ICErc20(USDTMarket), USDTWhale); From 8b4aa2563e4dd9872794267038827044fdec9c3e Mon Sep 17 00:00:00 2001 From: Jourdan Dunkley Date: Sun, 17 Mar 2024 17:00:44 -0500 Subject: [PATCH 4/5] lowered position sizes so that tests pass --- contracts/test/LeveredPositionTest.t.sol | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index 4e421384..53867787 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -200,11 +200,7 @@ abstract contract LeveredPositionTest is MarketsTest { vm.stopPrank(); } - function _configurePairAndLiquidator( - address _collat, - address _stable, - IRedemptionStrategy _liquidator - ) internal { + function _configurePairAndLiquidator(address _collat, address _stable, IRedemptionStrategy _liquidator) internal { _configurePair(_collat, _stable); _configureTwoWayLiquidator(_collat, _stable, _liquidator); } @@ -286,14 +282,10 @@ abstract contract LeveredPositionTest is MarketsTest { } } - function _openLeveredPosition(address _positionOwner, uint256 _depositAmount) - internal - returns ( - LeveredPosition _position, - uint256 _maxRatio, - uint256 _minRatio - ) - { + function _openLeveredPosition( + address _positionOwner, + uint256 _depositAmount + ) internal returns (LeveredPosition _position, uint256 _maxRatio, uint256 _minRatio) { IERC20Upgradeable collateralToken = IERC20Upgradeable(collateralMarket.underlying()); collateralToken.transfer(_positionOwner, _depositAmount); @@ -966,7 +958,7 @@ contract ModeWethUSDCLeveredPositionTest is LeveredPositionTest { function afterForkSetUp() internal override { super.afterForkSetUp(); - uint256 depositAmount = 10e18; + uint256 depositAmount = 1e17; address wethMarket = 0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2; address USDCMarket = 0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038; @@ -1032,7 +1024,7 @@ contract ModeWbtcUSDCLeveredPositionTest is LeveredPositionTest { function afterForkSetUp() internal override { super.afterForkSetUp(); - uint256 depositAmount = 10e8; + uint256 depositAmount = 1e6; address wbtcMarket = 0xd70254C3baD29504789714A7c69d60Ec1127375C; address USDCMarket = 0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038; @@ -1071,7 +1063,7 @@ contract ModeWbtcUSDTLeveredPositionTest is LeveredPositionTest { function afterForkSetUp() internal override { super.afterForkSetUp(); - uint256 depositAmount = 1e8; + uint256 depositAmount = 1e6; address wbtcMarket = 0xd70254C3baD29504789714A7c69d60Ec1127375C; address USDTMarket = 0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3; From 4f7ff4b5e5ba4abc0910cc48440d2caf87dd9b97 Mon Sep 17 00:00:00 2001 From: Jourdan Dunkley Date: Sun, 17 Mar 2024 17:02:22 -0500 Subject: [PATCH 5/5] prettier --- contracts/test/LeveredPositionTest.t.sol | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index 53867787..2d56f3c9 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -200,7 +200,11 @@ abstract contract LeveredPositionTest is MarketsTest { vm.stopPrank(); } - function _configurePairAndLiquidator(address _collat, address _stable, IRedemptionStrategy _liquidator) internal { + function _configurePairAndLiquidator( + address _collat, + address _stable, + IRedemptionStrategy _liquidator + ) internal { _configurePair(_collat, _stable); _configureTwoWayLiquidator(_collat, _stable, _liquidator); } @@ -282,10 +286,14 @@ abstract contract LeveredPositionTest is MarketsTest { } } - function _openLeveredPosition( - address _positionOwner, - uint256 _depositAmount - ) internal returns (LeveredPosition _position, uint256 _maxRatio, uint256 _minRatio) { + function _openLeveredPosition(address _positionOwner, uint256 _depositAmount) + internal + returns ( + LeveredPosition _position, + uint256 _maxRatio, + uint256 _minRatio + ) + { IERC20Upgradeable collateralToken = IERC20Upgradeable(collateralMarket.underlying()); collateralToken.transfer(_positionOwner, _depositAmount);