From 67542719da5e061cde2c4a16aa199205dc099f78 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Thu, 7 Sep 2023 14:41:32 +0300 Subject: [PATCH 01/14] retro tests --- .../LeveredPositionFactoryFirstExtension.sol | 3 +- .../registry/LiquidatorsRegistryExtension.sol | 5 +- contracts/test/LeveredPositionTest.t.sol | 105 +++++++++++++++++- contracts/test/LiquidatorsRegistryTest.t.sol | 13 +++ .../GammaLpTokenLiquidatorTest.t.sol | 22 ++++ 5 files changed, 144 insertions(+), 4 deletions(-) diff --git a/contracts/ionic/levered/LeveredPositionFactoryFirstExtension.sol b/contracts/ionic/levered/LeveredPositionFactoryFirstExtension.sol index 74b671d0..309fa496 100644 --- a/contracts/ionic/levered/LeveredPositionFactoryFirstExtension.sol +++ b/contracts/ionic/levered/LeveredPositionFactoryFirstExtension.sol @@ -29,9 +29,10 @@ contract LeveredPositionFactoryFirstExtension is error PositionNotClosed(); function _getExtensionFunctions() external pure override returns (bytes4[] memory) { - uint8 fnsCount = 8; + uint8 fnsCount = 9; bytes4[] memory functionSelectors = new bytes4[](fnsCount); functionSelectors[--fnsCount] = this.removeClosedPosition.selector; + functionSelectors[--fnsCount] = this.closeAndRemoveUserPosition.selector; functionSelectors[--fnsCount] = this.getMinBorrowNative.selector; functionSelectors[--fnsCount] = this.getRedemptionStrategies.selector; functionSelectors[--fnsCount] = this.getBorrowableMarketsByCollateral.selector; diff --git a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol index 5290ca8a..524c3e29 100644 --- a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol +++ b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol @@ -41,7 +41,7 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte uint256 public constant MAX_SLIPPAGE = 900; // 9% function _getExtensionFunctions() external pure override returns (bytes4[] memory) { - uint8 fnsCount = 7; + uint8 fnsCount = 8; bytes4[] memory functionSelectors = new bytes4[](fnsCount); functionSelectors[--fnsCount] = this.getRedemptionStrategies.selector; functionSelectors[--fnsCount] = this.getRedemptionStrategy.selector; @@ -50,6 +50,7 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte functionSelectors[--fnsCount] = this.getAllRedemptionStrategies.selector; functionSelectors[--fnsCount] = this.amountOutAndSlippageOfSwap.selector; functionSelectors[--fnsCount] = this.getSlippage.selector; + functionSelectors[--fnsCount] = this.log.selector; require(fnsCount == 0, "use the correct array length"); return functionSelectors; } @@ -257,6 +258,8 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte strategyData = uniswapV2LiquidatorData(inputToken, outputToken); } else if (isStrategy(strategy, "UniswapV3Liquidator")) { strategyData = uniswapV3LiquidatorData(inputToken, outputToken); + } else if (isStrategy(strategy, "UniswapV3LiquidatorFunder")) { + strategyData = uniswapV3LiquidatorData(inputToken, outputToken); } else if (isStrategy(strategy, "AlgebraSwapLiquidator")) { strategyData = algebraSwapLiquidatorData(inputToken, outputToken); } else if (isStrategy(strategy, "GammaAlgebraLpTokenLiquidator")) { diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index 70dc4362..097916d0 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -220,15 +220,15 @@ abstract contract LeveredPositionTest is MarketsTest { function _configurePair(address _collat, address _stable) internal { collateralMarket = ICErc20(_collat); stableMarket = ICErc20(_stable); + //upgradePoolAndMarkets(); - _unpauseMarkets(_collat, _stable); + //_unpauseMarkets(_collat, _stable); vm.prank(factory.owner()); factory._setPairWhitelisted(collateralMarket, stableMarket, true); } function _whitelistTestUser(address user) internal { address pool = address(collateralMarket.comptroller()); - ffd.authoritiesRegistry().leveredPositionsFactory(); PoolRolesAuthority pra = ffd.authoritiesRegistry().poolsAuthorities(pool); vm.startPrank(pra.owner()); @@ -922,6 +922,107 @@ contract PearlUsdrMaticUsdrLpLeveredPositionTest is LeveredPositionTest { } } +contract RetroCashAUsdcCashLeveredPositionTest is LeveredPositionTest { + function setUp() public fork(POLYGON_MAINNET) {} + + function afterForkSetUp() internal override { + super.afterForkSetUp(); + upgradeRegistry(); + + uint256 depositAmount = 700e18; + + // LP token underlying xCASH-USDC + address lpTokenMarket = 0x1D2A7078a404ab970f951d5A6dbECD9e24838FB6; + address cashMarket = 0xf69207CFDe6228A1e15A34F2b0c4fDe0845D9eBa; + address lpTokenWhale = 0x38e481367E0c50f4166AD2A1C9fde0E3c662CFBa; + address cashWhale = 0x88C522E526E5Eea8d636fd6805cA7fEB488780D0; + + _configurePair(lpTokenMarket, cashMarket); + _fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale); + _fundMarketAndSelf(ICErc20(cashMarket), cashWhale); + + (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); + } +} + +contract RetroUsdcAUsdcCashLeveredPositionTest is LeveredPositionTest { + function setUp() public fork(POLYGON_MAINNET) {} + + function afterForkSetUp() internal override { + super.afterForkSetUp(); + upgradeRegistry(); + + uint256 depositAmount = 700e18; + + // LP token underlying xCASH-USDC + address lpTokenMarket = 0x1D2A7078a404ab970f951d5A6dbECD9e24838FB6; + address usdcMarket = 0x38EbA94210bCEf3F9231E1764EE230abC14D1cbc; + address lpTokenWhale = 0x38e481367E0c50f4166AD2A1C9fde0E3c662CFBa; + address usdcWhale = 0x5a52E96BAcdaBb82fd05763E25335261B270Efcb; + + _configurePair(lpTokenMarket, usdcMarket); + _fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale); + _fundMarketAndSelf(ICErc20(usdcMarket), usdcWhale); + + (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); + } +} + +contract RetroUsdcAUsdcWethLeveredPositionTest is LeveredPositionTest { + function setUp() public fork(POLYGON_MAINNET) {} + + function afterForkSetUp() internal override { + super.afterForkSetUp(); + upgradeRegistry(); + + uint256 depositAmount = 8e18; + + // LP token underlying xUSDC-WETH05 + address lpTokenMarket = 0xC7cA03A0bE1dBAc350E5BfE5050fC5af6406490E; + address usdcMarket = 0x38EbA94210bCEf3F9231E1764EE230abC14D1cbc; + address lpTokenWhale = 0x38e481367E0c50f4166AD2A1C9fde0E3c662CFBa; + address usdcWhale = 0x5a52E96BAcdaBb82fd05763E25335261B270Efcb; + + _configurePair(lpTokenMarket, usdcMarket); + _fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale); + _fundMarketAndSelf(ICErc20(usdcMarket), usdcWhale); + + (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); + } +} + +contract RetroCashAUsdcWethLeveredPositionTest is LeveredPositionTest { + function setUp() public fork(POLYGON_MAINNET) {} + + function afterForkSetUp() internal override { + super.afterForkSetUp(); + upgradeRegistry(); + + uint256 depositAmount = 8e18; + + // LP token underlying xUSDC-WETH05 + address lpTokenMarket = 0xC7cA03A0bE1dBAc350E5BfE5050fC5af6406490E; + address cashMarket = 0xf69207CFDe6228A1e15A34F2b0c4fDe0845D9eBa; + address lpTokenWhale = 0x38e481367E0c50f4166AD2A1C9fde0E3c662CFBa; + address cashWhale = 0x88C522E526E5Eea8d636fd6805cA7fEB488780D0; + + ILiquidatorsRegistry reg = factory.liquidatorsRegistry(); + IERC20Upgradeable collatAsset = IERC20Upgradeable(ICErc20(lpTokenMarket).underlying()); + IERC20Upgradeable borrowedAsset = IERC20Upgradeable(ICErc20(cashMarket).underlying()); + reg.redemptionStrategiesByTokens(collatAsset, borrowedAsset); + reg.redemptionStrategiesByTokens(borrowedAsset, collatAsset); + reg.defaultOutputToken(borrowedAsset); + reg.defaultOutputToken(collatAsset); + revert(""); + + _configurePair(lpTokenMarket, cashMarket); + _fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale); + _fundMarketAndSelf(ICErc20(cashMarket), cashWhale); + + (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); + } +} + /* contract XYLeveredPositionTest is LeveredPositionTest { function setUp() public fork(X_CHAIN_ID) {} diff --git a/contracts/test/LiquidatorsRegistryTest.t.sol b/contracts/test/LiquidatorsRegistryTest.t.sol index 126987d1..30ad13f1 100644 --- a/contracts/test/LiquidatorsRegistryTest.t.sol +++ b/contracts/test/LiquidatorsRegistryTest.t.sol @@ -240,4 +240,17 @@ contract LiquidatorsRegistryTest is BaseTest { _swap(tusdWhale, inputToken, inputAmount, outputToken, 5e16); } + + function testRedemptionPathCashAUsdcWeth() public debuggingOnly fork(POLYGON_MAINNET) { + IERC20Upgradeable cash = IERC20Upgradeable(0x5D066D022EDE10eFa2717eD3D79f22F949F8C175); + IERC20Upgradeable usdc = IERC20Upgradeable(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174); + IERC20Upgradeable aUsdcWeth = IERC20Upgradeable(0xe058e1FfFF9B13d3FCd4803FDb55d1Cc2fe07DDC); + + upgradeRegistry(); + + registry.redemptionStrategiesByTokens(cash, aUsdcWeth); + registry.redemptionStrategiesByTokens(aUsdcWeth, cash); + registry.redemptionStrategiesByTokens(cash, usdc); + registry.redemptionStrategiesByTokens(usdc, cash); + } } diff --git a/contracts/test/liquidators/GammaLpTokenLiquidatorTest.t.sol b/contracts/test/liquidators/GammaLpTokenLiquidatorTest.t.sol index ba861a45..b1e15f21 100644 --- a/contracts/test/liquidators/GammaLpTokenLiquidatorTest.t.sol +++ b/contracts/test/liquidators/GammaLpTokenLiquidatorTest.t.sol @@ -136,4 +136,26 @@ contract GammaLpTokenLiquidatorTest is BaseTest { assertEq(IERC20Upgradeable(wtoken).balanceOf(address(uWrapper)), 0, "!unused wtoken"); assertEq(usdc.balanceOf(address(uWrapper)), 0, "!unused usdc"); } + + function testUsdcWethGammaUniV3LpTokenWrapper() public debuggingOnly fork(POLYGON_MAINNET) { + address USDC_WETH_RETRO_GAMMA_VAULT = 0xe058e1FfFF9B13d3FCd4803FDb55d1Cc2fe07DDC; + address usdcAddress = 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174; + address usdcWhale = 0xe7804c37c13166fF0b37F5aE0BB07A3aEbb6e245; + IERC20Upgradeable usdc = IERC20Upgradeable(usdcAddress); + + vm.prank(usdcWhale); + usdc.transfer(address(uWrapper), 9601.830212e6); + + (IERC20Upgradeable outputToken, uint256 outputAmount) = uWrapper.redeem( + usdc, + 9601.830212e6, + abi.encode(uniV3SwapRouter, uniProxyUni, USDC_WETH_RETRO_GAMMA_VAULT) + ); + + emit log_named_uint("lp tokens minted", outputAmount); + + assertGt(outputToken.balanceOf(address(uWrapper)), 0, "!wrapped"); + assertEq(IERC20Upgradeable(wtoken).balanceOf(address(uWrapper)), 0, "!unused wtoken"); + assertEq(usdc.balanceOf(address(uWrapper)), 0, "!unused usdc"); + } } From 15d9b04e930b94532c428cb6aa1d8d998aca18bc Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Thu, 7 Sep 2023 16:04:56 +0300 Subject: [PATCH 02/14] liquidator test --- .../registry/LiquidatorsRegistryExtension.sol | 2 ++ contracts/test/LeveredPositionTest.t.sol | 9 ------- .../UniswapV3LiquidatorFunderTest.t.sol | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol index 524c3e29..a4f08907 100644 --- a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol +++ b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol @@ -55,6 +55,8 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte return functionSelectors; } + function log(string memory, address) public pure {} + function getSlippage(IERC20Upgradeable inputToken, IERC20Upgradeable outputToken) external view diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index 097916d0..fa484c7e 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -1006,15 +1006,6 @@ contract RetroCashAUsdcWethLeveredPositionTest is LeveredPositionTest { address lpTokenWhale = 0x38e481367E0c50f4166AD2A1C9fde0E3c662CFBa; address cashWhale = 0x88C522E526E5Eea8d636fd6805cA7fEB488780D0; - ILiquidatorsRegistry reg = factory.liquidatorsRegistry(); - IERC20Upgradeable collatAsset = IERC20Upgradeable(ICErc20(lpTokenMarket).underlying()); - IERC20Upgradeable borrowedAsset = IERC20Upgradeable(ICErc20(cashMarket).underlying()); - reg.redemptionStrategiesByTokens(collatAsset, borrowedAsset); - reg.redemptionStrategiesByTokens(borrowedAsset, collatAsset); - reg.defaultOutputToken(borrowedAsset); - reg.defaultOutputToken(collatAsset); - revert(""); - _configurePair(lpTokenMarket, cashMarket); _fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale); _fundMarketAndSelf(ICErc20(cashMarket), cashWhale); diff --git a/contracts/test/liquidators/UniswapV3LiquidatorFunderTest.t.sol b/contracts/test/liquidators/UniswapV3LiquidatorFunderTest.t.sol index 8e784f3b..08c95d70 100644 --- a/contracts/test/liquidators/UniswapV3LiquidatorFunderTest.t.sol +++ b/contracts/test/liquidators/UniswapV3LiquidatorFunderTest.t.sol @@ -58,4 +58,29 @@ contract UniswapV3LiquidatorFunderTest is BaseTest { assertEq(address(outputToken), address(usdcToken), "!out tok"); assertApproxEqRel(inputValue, outputValue, 1e16, "!out amount"); } + + function testUsdcCashSwap() public debuggingOnly fork(POLYGON_MAINNET) { + IERC20Upgradeable cash = IERC20Upgradeable(0x5D066D022EDE10eFa2717eD3D79f22F949F8C175); + IERC20Upgradeable usdc = IERC20Upgradeable(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174); + address cashWhale = 0x88C522E526E5Eea8d636fd6805cA7fEB488780D0; + + bytes memory data = abi.encode(cash, usdc, 100, 0x1891783cb3497Fdad1F25C933225243c2c7c4102, 0xB758A3BFec4451f21c79b4A281CBa8cD83e70d00); + //hex" + // 0000000000000000000000005d066d022ede10efa2717ed3d79f22f949f8c175 + // 0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa84174 + // 0000000000000000000000000000000000000000000000000000000000000064 + // 000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564 + // 000000000000000000000000b758a3bfec4451f21c79b4a281cba8cd83e70d00 + // "; + uint256 amount = 9602257711282767805156; + + vm.prank(cashWhale); + cash.transfer(address(uniswapv3Liquidator), amount); + + uniswapv3Liquidator.redeem( + cash, + amount, + data + ); + } } From 5c1c91d5b44aba022ff0cc51e3b42e65e62bfe03 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Thu, 7 Sep 2023 16:08:10 +0300 Subject: [PATCH 03/14] prettier --- .../UniswapV3LiquidatorFunderTest.t.sol | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/contracts/test/liquidators/UniswapV3LiquidatorFunderTest.t.sol b/contracts/test/liquidators/UniswapV3LiquidatorFunderTest.t.sol index 08c95d70..1efe7ee5 100644 --- a/contracts/test/liquidators/UniswapV3LiquidatorFunderTest.t.sol +++ b/contracts/test/liquidators/UniswapV3LiquidatorFunderTest.t.sol @@ -64,7 +64,13 @@ contract UniswapV3LiquidatorFunderTest is BaseTest { IERC20Upgradeable usdc = IERC20Upgradeable(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174); address cashWhale = 0x88C522E526E5Eea8d636fd6805cA7fEB488780D0; - bytes memory data = abi.encode(cash, usdc, 100, 0x1891783cb3497Fdad1F25C933225243c2c7c4102, 0xB758A3BFec4451f21c79b4A281CBa8cD83e70d00); + bytes memory data = abi.encode( + cash, + usdc, + 100, + 0x1891783cb3497Fdad1F25C933225243c2c7c4102, + 0xB758A3BFec4451f21c79b4A281CBa8cD83e70d00 + ); //hex" // 0000000000000000000000005d066d022ede10efa2717ed3d79f22f949f8c175 // 0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa84174 @@ -77,10 +83,6 @@ contract UniswapV3LiquidatorFunderTest is BaseTest { vm.prank(cashWhale); cash.transfer(address(uniswapv3Liquidator), amount); - uniswapv3Liquidator.redeem( - cash, - amount, - data - ); + uniswapv3Liquidator.redeem(cash, amount, data); } } From 9a9742cbf54eaf075f30c4bfec2076b9f68f9520 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Thu, 7 Sep 2023 16:41:15 +0300 Subject: [PATCH 04/14] another retro case --- .../registry/LiquidatorsRegistryExtension.sol | 6 ++--- contracts/test/LeveredPositionTest.t.sol | 25 ++++++++++++++--- .../UniswapV3LiquidatorFunderTest.t.sol | 27 ------------------- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol index a4f08907..e55c869f 100644 --- a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol +++ b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol @@ -258,10 +258,8 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte strategyData = solidlyLpTokenLiquidatorData(inputToken, outputToken); } else if (isStrategy(strategy, "UniswapV2LiquidatorFunder")) { strategyData = uniswapV2LiquidatorData(inputToken, outputToken); - } else if (isStrategy(strategy, "UniswapV3Liquidator")) { - strategyData = uniswapV3LiquidatorData(inputToken, outputToken); } else if (isStrategy(strategy, "UniswapV3LiquidatorFunder")) { - strategyData = uniswapV3LiquidatorData(inputToken, outputToken); + strategyData = uniswapV3LiquidatorFunderData(inputToken, outputToken); } else if (isStrategy(strategy, "AlgebraSwapLiquidator")) { strategyData = algebraSwapLiquidatorData(inputToken, outputToken); } else if (isStrategy(strategy, "GammaAlgebraLpTokenLiquidator")) { @@ -438,7 +436,7 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte strategyData = abi.encode(outputToken); } - function uniswapV3LiquidatorData(IERC20Upgradeable inputToken, IERC20Upgradeable outputToken) + function uniswapV3LiquidatorFunderData(IERC20Upgradeable inputToken, IERC20Upgradeable outputToken) internal view returns (bytes memory strategyData) diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index fa484c7e..cd170975 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -950,7 +950,6 @@ contract RetroUsdcAUsdcCashLeveredPositionTest is LeveredPositionTest { function afterForkSetUp() internal override { super.afterForkSetUp(); - upgradeRegistry(); uint256 depositAmount = 700e18; @@ -973,7 +972,6 @@ contract RetroUsdcAUsdcWethLeveredPositionTest is LeveredPositionTest { function afterForkSetUp() internal override { super.afterForkSetUp(); - upgradeRegistry(); uint256 depositAmount = 8e18; @@ -996,7 +994,6 @@ contract RetroCashAUsdcWethLeveredPositionTest is LeveredPositionTest { function afterForkSetUp() internal override { super.afterForkSetUp(); - upgradeRegistry(); uint256 depositAmount = 8e18; @@ -1014,6 +1011,28 @@ contract RetroCashAUsdcWethLeveredPositionTest is LeveredPositionTest { } } +contract RetroCashAWbtcWethLeveredPositionTest is LeveredPositionTest { + function setUp() public fork(POLYGON_MAINNET) {} + + function afterForkSetUp() internal override { + super.afterForkSetUp(); + + uint256 depositAmount = 5e18; + + // LP token underlying xWBTC-WETH05 + address lpTokenMarket = 0xCB1a06eff3459078c26516ae3a1dB44A61D2DbCA; + address cashMarket = 0xf69207CFDe6228A1e15A34F2b0c4fDe0845D9eBa; + address lpTokenWhale = 0x38e481367E0c50f4166AD2A1C9fde0E3c662CFBa; + address cashWhale = 0x88C522E526E5Eea8d636fd6805cA7fEB488780D0; + + _configurePair(lpTokenMarket, cashMarket); + _fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale); + _fundMarketAndSelf(ICErc20(cashMarket), cashWhale); + + (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); + } +} + /* contract XYLeveredPositionTest is LeveredPositionTest { function setUp() public fork(X_CHAIN_ID) {} diff --git a/contracts/test/liquidators/UniswapV3LiquidatorFunderTest.t.sol b/contracts/test/liquidators/UniswapV3LiquidatorFunderTest.t.sol index 1efe7ee5..8e784f3b 100644 --- a/contracts/test/liquidators/UniswapV3LiquidatorFunderTest.t.sol +++ b/contracts/test/liquidators/UniswapV3LiquidatorFunderTest.t.sol @@ -58,31 +58,4 @@ contract UniswapV3LiquidatorFunderTest is BaseTest { assertEq(address(outputToken), address(usdcToken), "!out tok"); assertApproxEqRel(inputValue, outputValue, 1e16, "!out amount"); } - - function testUsdcCashSwap() public debuggingOnly fork(POLYGON_MAINNET) { - IERC20Upgradeable cash = IERC20Upgradeable(0x5D066D022EDE10eFa2717eD3D79f22F949F8C175); - IERC20Upgradeable usdc = IERC20Upgradeable(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174); - address cashWhale = 0x88C522E526E5Eea8d636fd6805cA7fEB488780D0; - - bytes memory data = abi.encode( - cash, - usdc, - 100, - 0x1891783cb3497Fdad1F25C933225243c2c7c4102, - 0xB758A3BFec4451f21c79b4A281CBa8cD83e70d00 - ); - //hex" - // 0000000000000000000000005d066d022ede10efa2717ed3d79f22f949f8c175 - // 0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa84174 - // 0000000000000000000000000000000000000000000000000000000000000064 - // 000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564 - // 000000000000000000000000b758a3bfec4451f21c79b4a281cba8cd83e70d00 - // "; - uint256 amount = 9602257711282767805156; - - vm.prank(cashWhale); - cash.transfer(address(uniswapv3Liquidator), amount); - - uniswapv3Liquidator.redeem(cash, amount, data); - } } From 0f6de7b0879cce34124ba8fc7afd54563b5221a5 Mon Sep 17 00:00:00 2001 From: carlomazzaferro Date: Thu, 7 Sep 2023 17:09:35 +0200 Subject: [PATCH 05/14] remove unused fn --- .../liquidators/registry/LiquidatorsRegistryExtension.sol | 3 --- 1 file changed, 3 deletions(-) diff --git a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol index e55c869f..6a2ed468 100644 --- a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol +++ b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol @@ -50,13 +50,10 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte functionSelectors[--fnsCount] = this.getAllRedemptionStrategies.selector; functionSelectors[--fnsCount] = this.amountOutAndSlippageOfSwap.selector; functionSelectors[--fnsCount] = this.getSlippage.selector; - functionSelectors[--fnsCount] = this.log.selector; require(fnsCount == 0, "use the correct array length"); return functionSelectors; } - function log(string memory, address) public pure {} - function getSlippage(IERC20Upgradeable inputToken, IERC20Upgradeable outputToken) external view From e7156c79915e5cdf9ff677cebdfa36af5cd6616a Mon Sep 17 00:00:00 2001 From: carlomazzaferro Date: Thu, 7 Sep 2023 17:25:19 +0200 Subject: [PATCH 06/14] no need to test linea pyth - we don't use it --- contracts/test/oracles/default/PythPriceOracleTest.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/test/oracles/default/PythPriceOracleTest.t.sol b/contracts/test/oracles/default/PythPriceOracleTest.t.sol index e8f88536..aba656a6 100644 --- a/contracts/test/oracles/default/PythPriceOracleTest.t.sol +++ b/contracts/test/oracles/default/PythPriceOracleTest.t.sol @@ -68,7 +68,7 @@ contract PythPriceOracleTest is BaseTest { assertApproxEqRel(price, priceMpo, 1e16); } - function testLineaTokenPrice() public fork(LINEA_MAINNET) { + function testLineaTokenPrice() public debuggingOnly fork(LINEA_MAINNET) { PythStructs.Price memory pythPrice = IPyth(lineaPyth).getPriceUnsafe(btcUsdTokenPriceFeed); emit log_named_uint("price", uint256(uint64(pythPrice.price))); emit log_named_uint("updated", pythPrice.publishTime); From 05e7648b1c4a611aa4d69d618aff6f6597e6d0f3 Mon Sep 17 00:00:00 2001 From: carlomazzaferro Date: Thu, 7 Sep 2023 17:32:46 +0200 Subject: [PATCH 07/14] fix fn count --- contracts/liquidators/registry/LiquidatorsRegistryExtension.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol index 6a2ed468..598647f7 100644 --- a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol +++ b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol @@ -41,7 +41,7 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte uint256 public constant MAX_SLIPPAGE = 900; // 9% function _getExtensionFunctions() external pure override returns (bytes4[] memory) { - uint8 fnsCount = 8; + uint8 fnsCount = 7; bytes4[] memory functionSelectors = new bytes4[](fnsCount); functionSelectors[--fnsCount] = this.getRedemptionStrategies.selector; functionSelectors[--fnsCount] = this.getRedemptionStrategy.selector; From 01bcbdf8570db882f3063e5490813bd0bdc873f7 Mon Sep 17 00:00:00 2001 From: carlomazzaferro Date: Thu, 7 Sep 2023 18:08:42 +0200 Subject: [PATCH 08/14] fix some tests --- contracts/test/AccrueInterestTest.t.sol | 6 +++++- contracts/test/AuthoritiesRegistryTest.t.sol | 1 + contracts/test/oracles/default/GammaPriceOracleTest.t.sol | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/contracts/test/AccrueInterestTest.t.sol b/contracts/test/AccrueInterestTest.t.sol index 2b6845e8..aa05dd57 100644 --- a/contracts/test/AccrueInterestTest.t.sol +++ b/contracts/test/AccrueInterestTest.t.sol @@ -1,6 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; +import { IERC20Upgradeable } from "openzeppelin-contracts-upgradeable/contracts/token/ERC20/IERC20Upgradeable.sol"; + import { UpgradesBaseTest } from "./UpgradesBaseTest.sol"; import { CErc20Delegate } from "../compound/CErc20Delegate.sol"; import { ICErc20 } from "../compound/CTokenInterfaces.sol"; @@ -183,9 +185,11 @@ contract AccrueInterestTest is UpgradesBaseTest { function testMintGated() public fork(POLYGON_MAINNET) { address newMarket = 0x26EA46e975778662f98dAa0E7a12858dA9139262; address assetWhale = 0xEd41f5967252248412E6C69475ae8a5A4274A6f8; - + // approve spending vm.startPrank(assetWhale); + IERC20Upgradeable(CErc20Delegate(newMarket).underlying()).approve(newMarket, 1e6); require(CErc20Delegate(newMarket).mint(1e6) == 0, "!mint failed"); + vm.stopPrank(); } function testDeployCToken() public debuggingOnly fork(POLYGON_MAINNET) { diff --git a/contracts/test/AuthoritiesRegistryTest.t.sol b/contracts/test/AuthoritiesRegistryTest.t.sol index 3f3fde3e..061180e6 100644 --- a/contracts/test/AuthoritiesRegistryTest.t.sol +++ b/contracts/test/AuthoritiesRegistryTest.t.sol @@ -48,6 +48,7 @@ contract AuthoritiesRegistryTest is WithPool { vm.expectRevert("not owner or pool"); registry.reconfigureAuthority(address(comptroller)); + vm.prank(registry.owner()); registry.reconfigureAuthority(address(comptroller)); } diff --git a/contracts/test/oracles/default/GammaPriceOracleTest.t.sol b/contracts/test/oracles/default/GammaPriceOracleTest.t.sol index 39238ff4..e20b87a2 100644 --- a/contracts/test/oracles/default/GammaPriceOracleTest.t.sol +++ b/contracts/test/oracles/default/GammaPriceOracleTest.t.sol @@ -65,7 +65,7 @@ contract GammaPoolPriceOracleTest is BaseTest { uint256 price_WETH_USDT = aOracle.price(WETH_USDT_QS_GAMMA_VAULT) / (1e18 / withdrawAmount); uint256 expectedPrice = priceAtWithdraw(WETH_USDT_QS_WHALE, WETH_USDT_QS_GAMMA_VAULT, withdrawAmount); - assertApproxEqRel(price_WETH_USDT, expectedPrice, 5e16, "!aWETH-USDT price"); + assertApproxEqRel(price_WETH_USDT, expectedPrice, 10e16, "!aWETH-USDT price"); } } From df2f95f24dd6c0731fe9d3ac39d5af4835d7cbd3 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Fri, 8 Sep 2023 07:49:54 +0300 Subject: [PATCH 09/14] lev pos test upgrading --- contracts/test/LeveredPositionTest.t.sol | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index cd170975..8588263a 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -19,6 +19,7 @@ import { ILeveredPositionFactory } from "../ionic/levered/ILeveredPositionFactor import { LeveredPositionsLens } from "../ionic/levered/LeveredPositionsLens.sol"; import { LiquidatorsRegistry } from "../liquidators/registry/LiquidatorsRegistry.sol"; import { LiquidatorsRegistryExtension } from "../liquidators/registry/LiquidatorsRegistryExtension.sol"; +import { LiquidatorsRegistrySecondExtension } from "../liquidators/registry/LiquidatorsRegistrySecondExtension.sol"; import { ILiquidatorsRegistry } from "../liquidators/registry/ILiquidatorsRegistry.sol"; import { IRedemptionStrategy } from "../liquidators/IRedemptionStrategy.sol"; import { ICErc20 } from "../compound/CTokenInterfaces.sol"; @@ -91,8 +92,7 @@ contract LeveredPositionFactoryTest is BaseTest { function afterForkSetUp() internal override { factory = ILeveredPositionFactory(ap.getAddress("LeveredPositionFactory")); - lens = new LeveredPositionsLens(); - lens.initialize(factory); + lens = LeveredPositionsLens(ap.getAddress("LeveredPositionsLens")); } function testChapelNetApy() public debuggingOnly fork(BSC_CHAPEL) { @@ -157,13 +157,8 @@ abstract contract LeveredPositionTest is MarketsTest { function afterForkSetUp() internal virtual override { super.afterForkSetUp(); - if (block.chainid == BSC_MAINNET) { - vm.prank(ap.owner()); - ap.setAddress("ALGEBRA_SWAP_ROUTER", 0x327Dd3208f0bCF590A66110aCB6e5e6941A4EfA0); - } - - registry = ILiquidatorsRegistry(ap.getAddress("LiquidatorsRegistry")); factory = ILeveredPositionFactory(ap.getAddress("LeveredPositionFactory")); + registry = factory.liquidatorsRegistry(); { // upgrade the factory LeveredPositionFactoryFirstExtension newExt1 = new LeveredPositionFactoryFirstExtension(); @@ -172,12 +167,14 @@ abstract contract LeveredPositionTest is MarketsTest { vm.startPrank(factory.owner()); DiamondBase asBase = DiamondBase(address(factory)); address[] memory oldExts = asBase._listExtensions(); + + emit log_named_array("old exts", oldExts); if (oldExts.length == 1) { asBase._registerExtension(newExt1, DiamondExtension(oldExts[0])); asBase._registerExtension(newExt2, DiamondExtension(address(0))); } else if (oldExts.length == 2) { - asBase._registerExtension(newExt1, DiamondExtension(oldExts[0])); - asBase._registerExtension(newExt2, DiamondExtension(oldExts[1])); + asBase._registerExtension(newExt1, DiamondExtension(oldExts[1])); + asBase._registerExtension(newExt2, DiamondExtension(oldExts[0])); } vm.stopPrank(); } @@ -188,9 +185,11 @@ abstract contract LeveredPositionTest is MarketsTest { function upgradeRegistry() internal { DiamondBase asBase = DiamondBase(address(registry)); address[] memory exts = asBase._listExtensions(); - LiquidatorsRegistryExtension newExt = new LiquidatorsRegistryExtension(); + LiquidatorsRegistryExtension newExt1 = new LiquidatorsRegistryExtension(); + LiquidatorsRegistrySecondExtension newExt2 = new LiquidatorsRegistrySecondExtension(); vm.prank(SafeOwnable(address(registry)).owner()); - asBase._registerExtension(newExt, DiamondExtension(exts[0])); + asBase._registerExtension(newExt1, DiamondExtension(exts[0])); + asBase._registerExtension(newExt2, DiamondExtension(exts[1])); } function upgradePoolAndMarkets() internal { From 2b3d5f4e2dd70a48a85df78d23063b00f36960e9 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Fri, 8 Sep 2023 14:16:36 +0300 Subject: [PATCH 10/14] lev pos factory upgrade --- contracts/test/LeveredPositionTest.t.sol | 37 ++++++++++++------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index 8588263a..633a10f5 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -159,25 +159,24 @@ abstract contract LeveredPositionTest is MarketsTest { factory = ILeveredPositionFactory(ap.getAddress("LeveredPositionFactory")); registry = factory.liquidatorsRegistry(); - { - // upgrade the factory - LeveredPositionFactoryFirstExtension newExt1 = new LeveredPositionFactoryFirstExtension(); - LeveredPositionFactorySecondExtension newExt2 = new LeveredPositionFactorySecondExtension(); - - vm.startPrank(factory.owner()); - DiamondBase asBase = DiamondBase(address(factory)); - address[] memory oldExts = asBase._listExtensions(); - - emit log_named_array("old exts", oldExts); - if (oldExts.length == 1) { - asBase._registerExtension(newExt1, DiamondExtension(oldExts[0])); - asBase._registerExtension(newExt2, DiamondExtension(address(0))); - } else if (oldExts.length == 2) { - asBase._registerExtension(newExt1, DiamondExtension(oldExts[1])); - asBase._registerExtension(newExt2, DiamondExtension(oldExts[0])); - } - vm.stopPrank(); - } + // { + // // upgrade the factory + // LeveredPositionFactoryFirstExtension newExt1 = new LeveredPositionFactoryFirstExtension(); + // LeveredPositionFactorySecondExtension newExt2 = new LeveredPositionFactorySecondExtension(); + // + // vm.startPrank(factory.owner()); + // DiamondBase asBase = DiamondBase(address(factory)); + // address[] memory oldExts = asBase._listExtensions(); + // + // if (oldExts.length == 1) { + // asBase._registerExtension(newExt1, DiamondExtension(oldExts[0])); + // asBase._registerExtension(newExt2, DiamondExtension(address(0))); + // } else if (oldExts.length == 2) { + // asBase._registerExtension(newExt1, DiamondExtension(oldExts[0])); + // asBase._registerExtension(newExt2, DiamondExtension(oldExts[1])); + // } + // vm.stopPrank(); + // } lens = LeveredPositionsLens(ap.getAddress("LeveredPositionsLens")); } From 7d1a18a67de38b8352112c38e7cc8ccc0d32dab7 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Fri, 8 Sep 2023 14:25:42 +0300 Subject: [PATCH 11/14] polygon any liquidation test fix --- contracts/test/AnyLiquidationTest.t.sol | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contracts/test/AnyLiquidationTest.t.sol b/contracts/test/AnyLiquidationTest.t.sol index f7d9490d..32e13722 100644 --- a/contracts/test/AnyLiquidationTest.t.sol +++ b/contracts/test/AnyLiquidationTest.t.sol @@ -90,7 +90,7 @@ contract AnyLiquidationTest is BaseTest { } function testSpecificRandom() public debuggingOnly { - testBscAnyLiquidation(1668); + testPolygonAnyLiquidation(14341); // testPolygonAnyLiquidation(101); } @@ -223,7 +223,7 @@ contract AnyLiquidationTest is BaseTest { (, PoolDirectory.Pool[] memory pools) = PoolDirectory(ap.getAddress("PoolDirectory")).getActivePools(); uint256 initRandom = random; - while (random - initRandom < 100) { + while (true) { // get a random pool and a random borrower from it (vars.comptroller, vars.borrower) = getPoolAndBorrower(random, pools); @@ -240,6 +240,8 @@ contract AnyLiquidationTest is BaseTest { } } } + // fail gracefully when there are no positions to liquidate + if (random - initRandom < 100) return; random++; } From 9fb4d6fb39ecacf890a45ca508af878be627ab01 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Mon, 11 Sep 2023 16:09:34 +0300 Subject: [PATCH 12/14] chapel fix --- contracts/test/LeveredPositionTest.t.sol | 1 + contracts/test/LiquidatorsRegistryTest.t.sol | 13 ------------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index 633a10f5..207d4176 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -188,6 +188,7 @@ abstract contract LeveredPositionTest is MarketsTest { LiquidatorsRegistrySecondExtension newExt2 = new LiquidatorsRegistrySecondExtension(); vm.prank(SafeOwnable(address(registry)).owner()); asBase._registerExtension(newExt1, DiamondExtension(exts[0])); + vm.prank(SafeOwnable(address(registry)).owner()); asBase._registerExtension(newExt2, DiamondExtension(exts[1])); } diff --git a/contracts/test/LiquidatorsRegistryTest.t.sol b/contracts/test/LiquidatorsRegistryTest.t.sol index 30ad13f1..126987d1 100644 --- a/contracts/test/LiquidatorsRegistryTest.t.sol +++ b/contracts/test/LiquidatorsRegistryTest.t.sol @@ -240,17 +240,4 @@ contract LiquidatorsRegistryTest is BaseTest { _swap(tusdWhale, inputToken, inputAmount, outputToken, 5e16); } - - function testRedemptionPathCashAUsdcWeth() public debuggingOnly fork(POLYGON_MAINNET) { - IERC20Upgradeable cash = IERC20Upgradeable(0x5D066D022EDE10eFa2717eD3D79f22F949F8C175); - IERC20Upgradeable usdc = IERC20Upgradeable(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174); - IERC20Upgradeable aUsdcWeth = IERC20Upgradeable(0xe058e1FfFF9B13d3FCd4803FDb55d1Cc2fe07DDC); - - upgradeRegistry(); - - registry.redemptionStrategiesByTokens(cash, aUsdcWeth); - registry.redemptionStrategiesByTokens(aUsdcWeth, cash); - registry.redemptionStrategiesByTokens(cash, usdc); - registry.redemptionStrategiesByTokens(usdc, cash); - } } From 7d744c94b8f0bd223382ceb4b8a8c82121cb9bd2 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Tue, 12 Sep 2023 13:57:15 +0300 Subject: [PATCH 13/14] more pairs tests --- contracts/test/LeveredPositionTest.t.sol | 64 ++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index 207d4176..8589193f 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -988,6 +988,27 @@ contract RetroUsdcAUsdcWethLeveredPositionTest is LeveredPositionTest { } } +contract RetroCashUsdcLeveredPositionTest is LeveredPositionTest { + function setUp() public fork(POLYGON_MAINNET) {} + + function afterForkSetUp() internal override { + super.afterForkSetUp(); + + uint256 depositAmount = 300e18; + + address cashMarket = 0xf69207CFDe6228A1e15A34F2b0c4fDe0845D9eBa; + address usdcMarket = 0x38EbA94210bCEf3F9231E1764EE230abC14D1cbc; + address cashWhale = 0x88C522E526E5Eea8d636fd6805cA7fEB488780D0; + address usdcWhale = 0x5a52E96BAcdaBb82fd05763E25335261B270Efcb; + + _configurePair(cashMarket, usdcMarket); + _fundMarketAndSelf(ICErc20(cashMarket), cashWhale); + _fundMarketAndSelf(ICErc20(usdcMarket), usdcWhale); + + (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); + } +} + contract RetroCashAUsdcWethLeveredPositionTest is LeveredPositionTest { function setUp() public fork(POLYGON_MAINNET) {} @@ -1032,6 +1053,49 @@ contract RetroCashAWbtcWethLeveredPositionTest is LeveredPositionTest { } } +contract RetroWethAWbtcWethLeveredPositionTest is LeveredPositionTest { + function setUp() public fork(POLYGON_MAINNET) {} + + function afterForkSetUp() internal override { + super.afterForkSetUp(); + + uint256 depositAmount = 1e18; + + // LP token underlying xWBTC-WETH05 + address lpTokenMarket = 0xCB1a06eff3459078c26516ae3a1dB44A61D2DbCA; + address wethMarket = 0x2469B23354cb7cA50b798663Ec5812Bf28d15e9e; + address lpTokenWhale = 0x38e481367E0c50f4166AD2A1C9fde0E3c662CFBa; + address wethWhale = 0x1eED63EfBA5f81D95bfe37d82C8E736b974F477b; + + _configurePair(lpTokenMarket, wethMarket); + _fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale); + _fundMarketAndSelf(ICErc20(wethMarket), wethWhale); + + (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); + } +} + +contract DavosUsdcDusdLeveredPositionTest is LeveredPositionTest { + function setUp() public fork(POLYGON_MAINNET) {} + + function afterForkSetUp() internal override { + super.afterForkSetUp(); + + uint256 depositAmount = 500e18; + + address dusdMarket = 0xE70d09dA78900A0429ee70b35200F70A30d7d2B9; + address usdcMarket = 0x14787e50578d8c606C3d57bDbA53dD65Fd665449; + address dusdWhale = 0xE69a1876bdACfa7A7a4F6D531BE2FDE843D2165C; + address usdcWhale = 0x5a52E96BAcdaBb82fd05763E25335261B270Efcb; + + _configurePair(dusdMarket, usdcMarket); + _fundMarketAndSelf(ICErc20(dusdMarket), dusdWhale); + _fundMarketAndSelf(ICErc20(usdcMarket), usdcWhale); + + (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); + } +} + /* contract XYLeveredPositionTest is LeveredPositionTest { function setUp() public fork(X_CHAIN_ID) {} From a3b9517b4b43630d72cb72d9ef7135977af38021 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Tue, 12 Sep 2023 16:01:36 +0300 Subject: [PATCH 14/14] tests fixes --- contracts/test/LeveredPositionTest.t.sol | 77 +----------------------- contracts/test/MaxBorrowTest.t.sol | 5 ++ 2 files changed, 7 insertions(+), 75 deletions(-) diff --git a/contracts/test/LeveredPositionTest.t.sol b/contracts/test/LeveredPositionTest.t.sol index 8589193f..a0817671 100644 --- a/contracts/test/LeveredPositionTest.t.sol +++ b/contracts/test/LeveredPositionTest.t.sol @@ -425,57 +425,6 @@ abstract contract LeveredPositionTest is MarketsTest { } } -contract WMaticStMaticLeveredPositionTest is LeveredPositionTest { - function setUp() public fork(POLYGON_MAINNET) {} - - function afterForkSetUp() internal override { - super.afterForkSetUp(); - - uint256 depositAmount = 200e18; - - address wmaticMarket = 0x4017cd39950d1297BBd9713D939bC5d9c6F2Be53; - address stmaticMarket = 0xc1B068007114dC0F14f322Ef201491717f3e52cD; - address wmaticWhale = 0x6d80113e533a2C0fe82EaBD35f1875DcEA89Ea97; - address stmaticWhale = 0x52997D5abC01e9BFDd29cccB183ffc60F6d6bF8c; - - BalancerSwapLiquidator balancerSwapLiquidator = new BalancerSwapLiquidator(); - _configurePairAndLiquidator(wmaticMarket, stmaticMarket, balancerSwapLiquidator); - _fundMarketAndSelf(ICErc20(wmaticMarket), wmaticWhale); - _fundMarketAndSelf(ICErc20(stmaticMarket), stmaticWhale); - - (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); - } -} - -contract JbrlBusdLeveredPositionTest is LeveredPositionTest { - function setUp() public fork(BSC_MAINNET) {} - - function afterForkSetUp() internal override { - super.afterForkSetUp(); - - uint256 depositAmount = 2000e18; - - address jbrlMarket = 0x82A3103bc306293227B756f7554AfAeE82F8ab7a; - address busdMarket = 0xa7213deB44f570646Ea955771Cc7f39B58841363; - address jbrlWhale = 0xBe9E8Ec25866B21bA34e97b9393BCabBcB4A5C86; - - vm.startPrank(ap.owner()); - ap.setJarvisPool( - ICErc20(jbrlMarket).underlying(), // syntheticToken - ICErc20(busdMarket).underlying(), // collateralToken - 0x0fD8170Dc284CD558325029f6AEc1538c7d99f49, // liquidityPool - 60 * 40 // expirationTime - ); - vm.stopPrank(); - - JarvisLiquidatorFunder liquidator = new JarvisLiquidatorFunder(); - _configurePairAndLiquidator(jbrlMarket, busdMarket, liquidator); - _fundMarketAndSelf(ICErc20(jbrlMarket), jbrlWhale); - - (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); - } -} - contract WmaticMaticXLeveredPositionTest is LeveredPositionTest { function setUp() public fork(POLYGON_MAINNET) {} @@ -928,7 +877,7 @@ contract RetroCashAUsdcCashLeveredPositionTest is LeveredPositionTest { super.afterForkSetUp(); upgradeRegistry(); - uint256 depositAmount = 700e18; + uint256 depositAmount = 300e18; // LP token underlying xCASH-USDC address lpTokenMarket = 0x1D2A7078a404ab970f951d5A6dbECD9e24838FB6; @@ -972,7 +921,7 @@ contract RetroUsdcAUsdcWethLeveredPositionTest is LeveredPositionTest { function afterForkSetUp() internal override { super.afterForkSetUp(); - uint256 depositAmount = 8e18; + uint256 depositAmount = 1e18; // LP token underlying xUSDC-WETH05 address lpTokenMarket = 0xC7cA03A0bE1dBAc350E5BfE5050fC5af6406490E; @@ -1031,28 +980,6 @@ contract RetroCashAUsdcWethLeveredPositionTest is LeveredPositionTest { } } -contract RetroCashAWbtcWethLeveredPositionTest is LeveredPositionTest { - function setUp() public fork(POLYGON_MAINNET) {} - - function afterForkSetUp() internal override { - super.afterForkSetUp(); - - uint256 depositAmount = 5e18; - - // LP token underlying xWBTC-WETH05 - address lpTokenMarket = 0xCB1a06eff3459078c26516ae3a1dB44A61D2DbCA; - address cashMarket = 0xf69207CFDe6228A1e15A34F2b0c4fDe0845D9eBa; - address lpTokenWhale = 0x38e481367E0c50f4166AD2A1C9fde0E3c662CFBa; - address cashWhale = 0x88C522E526E5Eea8d636fd6805cA7fEB488780D0; - - _configurePair(lpTokenMarket, cashMarket); - _fundMarketAndSelf(ICErc20(lpTokenMarket), lpTokenWhale); - _fundMarketAndSelf(ICErc20(cashMarket), cashWhale); - - (position, maxLevRatio, minLevRatio) = _openLeveredPosition(address(this), depositAmount); - } -} - contract RetroWethAWbtcWethLeveredPositionTest is LeveredPositionTest { function setUp() public fork(POLYGON_MAINNET) {} diff --git a/contracts/test/MaxBorrowTest.t.sol b/contracts/test/MaxBorrowTest.t.sol index 291652a4..67aa01c0 100644 --- a/contracts/test/MaxBorrowTest.t.sol +++ b/contracts/test/MaxBorrowTest.t.sol @@ -64,6 +64,11 @@ contract MaxBorrowTest is WithPool { vars.cTokens = new address[](1); address accountOne = address(1); + PoolRolesAuthority pra = ionicAdmin.authoritiesRegistry().poolsAuthorities(address(comptroller)); + + vm.startPrank(pra.owner()); + pra.setUserRole(accountOne, pra.BORROWER_ROLE(), true); + vm.stopPrank(); vm.prank(usdcWhale); MockERC20(address(vars.usdc)).transfer(accountOne, 10000e6);