Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #54 from ionicprotocol/feat/kim-v4-liquidations
Browse files Browse the repository at this point in the history
kim v4 liqudations
  • Loading branch information
rhlsthrm authored Apr 1, 2024
2 parents 060da65 + 2ec8b66 commit a92ec62
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 11 deletions.
8 changes: 8 additions & 0 deletions contracts/IonicUniV3Liquidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 13 additions & 7 deletions contracts/liquidators/registry/LiquidatorsRegistryExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +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);
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")) {
Expand Down Expand Up @@ -457,12 +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 algebraSwapLiquidatorData(
IERC20Upgradeable inputToken,
IERC20Upgradeable outputToken,
address swapRouter
) internal view returns (bytes memory strategyData) {
strategyData = abi.encode(outputToken, swapRouter);
}

function gammaAlgebraLpTokenLiquidatorData(IERC20Upgradeable inputToken, IERC20Upgradeable outputToken)
Expand Down
6 changes: 3 additions & 3 deletions contracts/test/AnyLiquidationTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/DevTesting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 20 additions & 0 deletions contracts/test/liquidators/AlgebraSwapLiquidatorTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit a92ec62

Please sign in to comment.