From 91f6406c5cf067db7434b99bfb21b6ac1cdd623a Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:55:13 +0200 Subject: [PATCH 1/5] kim v4 flashloans for the liqudations --- contracts/IonicUniV3Liquidator.sol | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contracts/IonicUniV3Liquidator.sol b/contracts/IonicUniV3Liquidator.sol index 07b8bd3f..17c0d901 100644 --- a/contracts/IonicUniV3Liquidator.sol +++ b/contracts/IonicUniV3Liquidator.sol @@ -156,6 +156,14 @@ contract IonicUniV3Liquidator is OwnableUpgradeable, ILiquidator, IUniswapV3Flas uniswapV3FlashCallback(fee0, fee1, data); } + function algebraFlashCallback( + uint256 fee0, + uint256 fee1, + bytes calldata data + ) external { + uniswapV3FlashCallback(fee0, fee1, data); + } + function uniswapV3FlashCallback( uint256 fee0, uint256 fee1, From bd9af87a0730c9ee5e4a0939fb3d92a7746e664b Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:08:56 +0300 Subject: [PATCH 2/5] kim v4 redemption strategy - algebra swap --- contracts/test/AnyLiquidationTest.t.sol | 6 +++--- contracts/test/DevTesting.t.sol | 2 +- .../AlgebraSwapLiquidatorTest.t.sol | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/contracts/test/AnyLiquidationTest.t.sol b/contracts/test/AnyLiquidationTest.t.sol index 0cd5d0ae..79ac29fe 100644 --- a/contracts/test/AnyLiquidationTest.t.sol +++ b/contracts/test/AnyLiquidationTest.t.sol @@ -602,10 +602,10 @@ contract AnyLiquidationTest is BaseTest { } function testRawLiquidation() public debuggingOnly fork(MODE_MAINNET) { - vm.prank(ap.getAddress("deployer")); + vm.prank(0x1110DECC92083fbcae218a8478F75B2Ad1b9AEe6); _functionCall( - 0x39C353Cf9041CcF467A04d0e78B63d961E81458a, - hex"86ed50b10000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa841740000000000000000000000007ceb23fd6bc0add59e62ac25578270cff1b9f6190000000000000000000000000000000000000000000000000000000005f5e10000000000000000000000000000000000000000000000000000000000000001f4", + 0x5782c512c07F217A8DE9611E7CE8c98f13193a46, + hex"55e9e8fe000000000000000000000000000000000000000000000000000000000000002000000000000000000000000073d33e0456bd0428b16305b398ada69facfe53a60000000000000000000000000000000000000000000000000062fb977fb2d11b00000000000000000000000071ef7eda2be775e5a7aa8afd02c45f059833e9d200000000000000000000000071ef7eda2be775e5a7aa8afd02c45f059833e9d2000000000000000000000000293f2b2c17f8cea4db346d87ef5712c9dd0491ef000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "raw liquidation failed" ); } diff --git a/contracts/test/DevTesting.t.sol b/contracts/test/DevTesting.t.sol index 5b18a2e3..f99873cc 100644 --- a/contracts/test/DevTesting.t.sol +++ b/contracts/test/DevTesting.t.sol @@ -190,7 +190,7 @@ contract DevTesting is BaseTest { function testAssetAsCollateralCap() public debuggingOnly fork(MODE_MAINNET) { address MODE_EZETH = 0x2416092f143378750bb29b79eD961ab195CcEea5; - address ezEthWhale = 0xd3B02d999C681BD8B75F340FA7e078cE9097bF23; + address ezEthWhale = 0x2344F131B07E6AFd943b0901C55898573F0d1561; vm.startPrank(multisig); uint256 errCode = pool._deployMarket( diff --git a/contracts/test/liquidators/AlgebraSwapLiquidatorTest.t.sol b/contracts/test/liquidators/AlgebraSwapLiquidatorTest.t.sol index 740dc9c5..e8f21837 100644 --- a/contracts/test/liquidators/AlgebraSwapLiquidatorTest.t.sol +++ b/contracts/test/liquidators/AlgebraSwapLiquidatorTest.t.sol @@ -48,4 +48,24 @@ contract AlgebraSwapLiquidatorTest is BaseTest { assertEq(address(outputToken), ankrBnbAddress, "!ankrbnb output"); assertApproxEqRel(outputAmount, inputAmount, 8e16, "!ankrbnb amount"); } + + function testModeKimV4RedemptionStrategy() public fork(MODE_MAINNET) { + address MODE_EZETH = 0x2416092f143378750bb29b79eD961ab195CcEea5; + address ezEthWhale = 0x2344F131B07E6AFd943b0901C55898573F0d1561; + address kimV4Router = 0xAc48FcF1049668B285f3dC72483DF5Ae2162f7e8; + address modeWETH = ap.getAddress("wtoken"); + + IERC20Upgradeable ezETH = IERC20Upgradeable(MODE_EZETH); + vm.prank(ezEthWhale); + ezETH.transfer(address(liquidator), 1e18); + + (IERC20Upgradeable outputToken, uint256 outputAmount) = liquidator.redeem( + ezETH, + inputAmount, + abi.encode(modeWETH, kimV4Router) + ); + + assertEq(address(outputToken), modeWETH, "!WETH output token"); + assertApproxEqRel(outputAmount, inputAmount, 8e16, "!weth amount"); + } } From afcd8a52fe47cb72b1507f725f15b06ffa226249 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:15:46 +0300 Subject: [PATCH 3/5] kim v4 redemption config and router in the registry --- .../registry/LiquidatorsRegistryExtension.sol | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol index 44fbd3d2..8a7e19b2 100644 --- a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol +++ b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol @@ -259,6 +259,8 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte strategyData = uniswapV3LiquidatorFunderData(inputToken, outputToken); } else if (isStrategy(strategy, "AlgebraSwapLiquidator")) { strategyData = algebraSwapLiquidatorData(inputToken, outputToken); + } else if (isStrategy(strategy, "KimUniV4Liquidator")) { + strategyData = kimV4LiquidatorData(inputToken, outputToken); } else if (isStrategy(strategy, "GammaAlgebraLpTokenLiquidator")) { strategyData = gammaAlgebraLpTokenLiquidatorData(inputToken, outputToken); } else if (isStrategy(strategy, "GammaUniswapV3LpTokenLiquidator")) { @@ -465,6 +467,15 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte strategyData = abi.encode(outputToken, ap.getAddress("ALGEBRA_SWAP_ROUTER")); } + function kimV4LiquidatorData(IERC20Upgradeable inputToken, IERC20Upgradeable outputToken) + internal + view + returns (bytes memory strategyData) + { + address kimV4SwapRouter = 0xAc48FcF1049668B285f3dC72483DF5Ae2162f7e8; + strategyData = abi.encode(outputToken, kimV4SwapRouter); + } + function gammaAlgebraLpTokenLiquidatorData(IERC20Upgradeable inputToken, IERC20Upgradeable outputToken) internal view From 47ab292b0b02e29123e03d19830578472baf04cd Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:29:56 +0300 Subject: [PATCH 4/5] registry for kim v4 fix --- .../registry/LiquidatorsRegistryExtension.sol | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol index 8a7e19b2..0b0f5a40 100644 --- a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol +++ b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol @@ -258,9 +258,13 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte } else if (isStrategy(strategy, "UniswapV3LiquidatorFunder")) { strategyData = uniswapV3LiquidatorFunderData(inputToken, outputToken); } else if (isStrategy(strategy, "AlgebraSwapLiquidator")) { - strategyData = algebraSwapLiquidatorData(inputToken, outputToken); - } else if (isStrategy(strategy, "KimUniV4Liquidator")) { - strategyData = kimV4LiquidatorData(inputToken, outputToken); + address swapRouter; + if (block.chainid == 34443) { + swapRouter = 0xAc48FcF1049668B285f3dC72483DF5Ae2162f7e8; + } else { + swapRouter = ap.getAddress("ALGEBRA_SWAP_ROUTER"); + } + strategyData = algebraSwapLiquidatorData(inputToken, outputToken, swapRouter); } else if (isStrategy(strategy, "GammaAlgebraLpTokenLiquidator")) { strategyData = gammaAlgebraLpTokenLiquidatorData(inputToken, outputToken); } else if (isStrategy(strategy, "GammaUniswapV3LpTokenLiquidator")) { @@ -459,21 +463,12 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte strategyData = abi.encode(getUniswapV2Router(inputToken), swapPath); } - function algebraSwapLiquidatorData(IERC20Upgradeable inputToken, IERC20Upgradeable outputToken) - internal - view - returns (bytes memory strategyData) - { - strategyData = abi.encode(outputToken, ap.getAddress("ALGEBRA_SWAP_ROUTER")); - } - - function kimV4LiquidatorData(IERC20Upgradeable inputToken, IERC20Upgradeable outputToken) + function algebraSwapLiquidatorData(IERC20Upgradeable inputToken, IERC20Upgradeable outputToken, address swapRouter) internal view returns (bytes memory strategyData) { - address kimV4SwapRouter = 0xAc48FcF1049668B285f3dC72483DF5Ae2162f7e8; - strategyData = abi.encode(outputToken, kimV4SwapRouter); + strategyData = abi.encode(outputToken, swapRouter); } function gammaAlgebraLpTokenLiquidatorData(IERC20Upgradeable inputToken, IERC20Upgradeable outputToken) From 2ec8b665e18229be6062da3eb81639277f434a40 Mon Sep 17 00:00:00 2001 From: Veliko Minkov <2662912+vminkov@users.noreply.github.com> Date: Mon, 1 Apr 2024 18:12:34 +0300 Subject: [PATCH 5/5] prettier --- .../registry/LiquidatorsRegistryExtension.sol | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol index 0b0f5a40..8189bd7a 100644 --- a/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol +++ b/contracts/liquidators/registry/LiquidatorsRegistryExtension.sol @@ -463,11 +463,11 @@ contract LiquidatorsRegistryExtension is LiquidatorsRegistryStorage, DiamondExte strategyData = abi.encode(getUniswapV2Router(inputToken), swapPath); } - function algebraSwapLiquidatorData(IERC20Upgradeable inputToken, IERC20Upgradeable outputToken, address swapRouter) - internal - view - returns (bytes memory strategyData) - { + function algebraSwapLiquidatorData( + IERC20Upgradeable inputToken, + IERC20Upgradeable outputToken, + address swapRouter + ) internal view returns (bytes memory strategyData) { strategyData = abi.encode(outputToken, swapRouter); }