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

Commit 2eda87e

Browse files
tested liquidator upgrade
1 parent ca3add7 commit 2eda87e

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

contracts/IonicUniV3Liquidator.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { IUniswapV3Quoter } from "./external/uniswap/quoter/interfaces/IUniswapV
1717
import { ICErc20 } from "./compound/CTokenInterfaces.sol";
1818

1919
import "./PoolLens.sol";
20+
import "@pythnetwork/express-relay-sdk-solidity/IExpressRelay.sol";
2021

2122
/**
2223
* @title IonicUniV3Liquidator
@@ -129,7 +130,7 @@ contract IonicUniV3Liquidator is OwnableUpgradeable, ILiquidator, IUniswapV3Flas
129130

130131
function safeLiquidateToTokensWithFlashLoan(
131132
LiquidateToTokensWithFlashSwapVars calldata vars
132-
) external onlyPERPermissioned(borrower, cTokenCollateral) returns (uint256) {
133+
) external onlyPERPermissioned(vars.borrower, vars.cTokenCollateral) returns (uint256) {
133134
// Input validation
134135
require(vars.repayAmount > 0, "Repay amount must be greater than 0.");
135136

contracts/test/liquidators/IonicLiquidatorTest.sol

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IERC20Upgradeable } from "openzeppelin-contracts-upgradeable/contracts/
55
import "openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol";
66

77
import { IonicLiquidator, ILiquidator } from "../../IonicLiquidator.sol";
8+
import { IonicUniV3Liquidator } from "../../IonicUniV3Liquidator.sol";
89
import { ICurvePool } from "../../external/curve/ICurvePool.sol";
910
import { CurveSwapLiquidatorFunder } from "../../liquidators/CurveSwapLiquidatorFunder.sol";
1011
import { UniswapV3LiquidatorFunder } from "../../liquidators/UniswapV3LiquidatorFunder.sol";
@@ -23,13 +24,12 @@ import { BasePriceOracle } from "../../oracles/BasePriceOracle.sol";
2324

2425
import { BaseTest } from "../config/BaseTest.t.sol";
2526
import { UpgradesBaseTest } from "../UpgradesBaseTest.sol";
27+
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
28+
import { ProxyAdmin } from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
29+
import { PoolLens } from "../../PoolLens.sol";
2630

2731
contract MockRedemptionStrategy is IRedemptionStrategy {
28-
function redeem(
29-
IERC20Upgradeable,
30-
uint256,
31-
bytes memory
32-
) external returns (IERC20Upgradeable, uint256) {
32+
function redeem(IERC20Upgradeable, uint256, bytes memory) external returns (IERC20Upgradeable, uint256) {
3333
return (IERC20Upgradeable(address(0)), 1);
3434
}
3535

@@ -151,12 +151,56 @@ contract IonicLiquidatorTest is UpgradesBaseTest {
151151

152152
vars.redemptionStrategies[0] = IFundsConversionStrategy(0x5cA3fd2c285C4138185Ef1BdA7573D415020F3C8);
153153
vars.strategyData[
154-
0
155-
] = hex"0000000000000000000000004200000000000000000000000000000000000006000000000000000000000000ac48fcf1049668b285f3dc72483df5ae2162f7e8";
154+
0
155+
] = hex"0000000000000000000000004200000000000000000000000000000000000006000000000000000000000000ac48fcf1049668b285f3dc72483df5ae2162f7e8";
156156

157157
liquidator.safeLiquidateToTokensWithFlashLoan(vars);
158158
}
159159

160+
function testLiquidateAfterUpgradeLiquidator() public debuggingOnly forkAtBlock(MODE_MAINNET, 9382006) {
161+
// upgrade IonicLiquidator
162+
TransparentUpgradeableProxy proxyV3 = TransparentUpgradeableProxy(payable(ap.getAddress("IonicUniV3Liquidator")));
163+
IonicUniV3Liquidator implV3 = new IonicUniV3Liquidator();
164+
IonicUniV3Liquidator liquidatorV3 = IonicUniV3Liquidator(payable(ap.getAddress("IonicUniV3Liquidator")));
165+
PoolLens lens = PoolLens(0x70BB19a56BfAEc65aE861E6275A90163AbDF36a6);
166+
167+
ProxyAdmin proxyAdmin = ProxyAdmin(ap.getAddress("DefaultProxyAdmin"));
168+
169+
vm.startPrank(proxyAdmin.owner());
170+
proxyAdmin.upgrade(proxyV3, address(implV3));
171+
vm.stopPrank();
172+
173+
vm.startPrank(0x1155b614971f16758C92c4890eD338C9e3ede6b7);
174+
liquidatorV3.setPoolLens(lens);
175+
liquidatorV3.setHealthFactorThreshold(1e18);
176+
vm.stopPrank();
177+
178+
IonicComptroller pool = IonicComptroller(0xFB3323E24743Caf4ADD0fDCCFB268565c0685556);
179+
(, , uint256 liquidity, uint256 shortfall) = pool.getAccountLiquidity(0x92eA6902C5023CC632e3Fd84dE7CcA6b98FE853d);
180+
emit log_named_uint("liquidity", liquidity);
181+
emit log_named_uint("shortfall", shortfall);
182+
183+
uint256 healthFactor = lens.getHealthFactor(0x92eA6902C5023CC632e3Fd84dE7CcA6b98FE853d, pool);
184+
emit log_named_uint("hf before", healthFactor);
185+
186+
ILiquidator.LiquidateToTokensWithFlashSwapVars memory vars = ILiquidator.LiquidateToTokensWithFlashSwapVars({
187+
borrower: 0x92eA6902C5023CC632e3Fd84dE7CcA6b98FE853d,
188+
repayAmount: 1134537086250983,
189+
cErc20: ICErc20(0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2),
190+
cTokenCollateral: ICErc20(0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2),
191+
flashSwapContract: 0x468cC91dF6F669CaE6cdCE766995Bd7874052FBc,
192+
minProfitAmount: 0,
193+
redemptionStrategies: new IRedemptionStrategy[](0),
194+
strategyData: new bytes[](0),
195+
debtFundingStrategies: new IFundsConversionStrategy[](0),
196+
debtFundingStrategiesData: new bytes[](0)
197+
});
198+
liquidatorV3.safeLiquidateToTokensWithFlashLoan(vars);
199+
200+
uint256 healthFactorAfter = lens.getHealthFactor(0x92eA6902C5023CC632e3Fd84dE7CcA6b98FE853d, pool);
201+
emit log_named_uint("hf after", healthFactorAfter);
202+
}
203+
160204
// TODO test with marginal shortfall for liquidation penalty errors
161205
function _testLiquidatorLiquidate(address contractForFlashSwap) internal {
162206
IonicComptroller pool = IonicComptroller(poolAddress);

0 commit comments

Comments
 (0)