diff --git a/contracts/DeployLiquidator.sol b/contracts/DeployLiquidator.sol index 95fe0ca..872ad8a 100644 --- a/contracts/DeployLiquidator.sol +++ b/contracts/DeployLiquidator.sol @@ -13,19 +13,20 @@ contract DeployLiquidator is Script { function run() public { uint256 deployerPrivateKey = vm.envUint("LIQUIDATOR_PRIVATE_KEY"); - address swapperAddress = 0x2Bba09866b6F1025258542478C39720A09B728bF; + address swapperAddress = 0xF1dE0e31C107A0cBFC3DB5F65eB28bB7ea7143dE; address swapVerifierAddress = 0xae26485ACDDeFd486Fe9ad7C2b34169d360737c7; address evcAddress = 0x0C9a3dd6b8F28529d72d7f9cE918D493519EE383; address pyth = 0x4305FB66699C3B2702D4d05CF36551390A4c69C6; + address owner = 0x8cbB534874bab83e44a7325973D2F04493359dF8; - address deployer = vm.addr(deployerPrivateKey); + // address deployer = vm.addr(deployerPrivateKey); vm.startBroadcast(deployerPrivateKey); uint256 beforeGas = gasleft(); console2.log("Gas before: ", beforeGas); console2.log("Gas price: ", tx.gasprice); - Liquidator liquidator = new Liquidator(deployer, swapperAddress, swapVerifierAddress, evcAddress, pyth); + Liquidator liquidator = new Liquidator(owner, swapperAddress, swapVerifierAddress, evcAddress, pyth); uint256 afterGas = gasleft(); console2.log("Gas after: ", afterGas); diff --git a/contracts/Liquidator.sol b/contracts/Liquidator.sol index 7b9b4cc..54a0731 100644 --- a/contracts/Liquidator.sol +++ b/contracts/Liquidator.sol @@ -23,7 +23,9 @@ contract Liquidator { error Unauthorized(); error LessThanExpectedCollateralReceived(); + error EmptyError(); + /// @dev If _owner == address(0), the contract is not owned (callable by anyone) constructor(address _owner, address _swapperAddress, address _swapVerifierAddress, address _evcAddress, address _pythAddress) { owner = _owner; swapperAddress = _swapperAddress; @@ -36,7 +38,7 @@ contract Liquidator { } modifier onlyOwner() { - require(msg.sender == owner, "Unauthorized"); + require(owner == address(0) || msg.sender == owner, "Unauthorized"); _; } @@ -60,7 +62,7 @@ contract Liquidator { uint256 amountCollaterallSeized ); - function liquidateSingleCollateral(LiquidationParams calldata params, bytes[] calldata swapperData) external returns (bool success) { + function liquidateSingleCollateral(LiquidationParams calldata params, bytes[] calldata swapperData) external onlyOwner returns (bool success) { bytes[] memory multicallItems = new bytes[](swapperData.length + 2); for (uint256 i = 0; i < swapperData.length; i++){ @@ -156,7 +158,7 @@ contract Liquidator { return true; } - function liquidateSingleCollateralWithPythOracle(LiquidationParams calldata params, bytes[] calldata swapperData, bytes[] calldata pythUpdateData) external payable returns (bool success) { + function liquidateSingleCollateralWithPythOracle(LiquidationParams calldata params, bytes[] calldata swapperData, bytes[] calldata pythUpdateData) external payable onlyOwner returns (bool success) { bytes[] memory multicallItems = new bytes[](swapperData.length + 2); for (uint256 i = 0; i < swapperData.length; i++){ @@ -260,6 +262,7 @@ contract Liquidator { // TODO: implement this as an operator so debt can be seized directly by whitelisted liquidators function liquidateFromExistingCollateralPosition(LiquidationParams calldata params) external + onlyOwner returns (bool success) { IEVC.BatchItem[] memory batchItems = new IEVC.BatchItem[](3); @@ -359,4 +362,21 @@ contract Liquidator { return (maxRepay, seizedCollateral); } + + /// @dev Allow arbitrary call when the Liquidator is owned. Can be used to e.g. sweep from owned Swapper + function ownerCall(address target, bytes calldata payload) external payable onlyOwner { + if (owner != address(0)) { + (bool success, bytes memory data) = target.call{value: msg.value}(payload); + if (!success) revertBytes(data); + } + } + + function revertBytes(bytes memory errMsg) internal pure { + if (errMsg.length != 0) { + assembly { + revert(add(32, errMsg), mload(errMsg)) + } + } + revert EmptyError(); + } } \ No newline at end of file