Verified contractExactMIT
SkyLiquidatorMainnet
Address0x6fbb529f0e78ff6c39481aa5e3e7c1b9ef34ae84
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.20
- Same code
Only this contract
Details
- Compiler
- solc 0.8.20+commit.a1b79de6
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,478,189
- Creation transaction
- 0xc3b52b7ad2…339c70a0bd
Contract-5.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract SkyLiquidatorMainnet {
address public constant FIXED_OWNER = 0xa44281031A5905310ba9C71531de699C8538927E;
address public constant AAVE_V3_POOL = 0x87870bcA3f5f723514F478DE587b100010935515;
address public constant UNISWAP_V3_ROUTER = 0xE592427A0AEce92De3Edee1F18E0157C05861564;
address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
struct LiquidationParams {
address clipperContract;
uint256 auctionId;
uint256 maxCollateralToBuy;
uint256 maxPricePerCollateral;
address collateralToken;
address swapTarget;
bytes swapCalldata;
uint256 minProfitRequired;
uint256 minerBribeBps;
uint24 uniswapPoolFee;
}
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
event SkyLiquidationSuccess(
address indexed clipper,
uint256 auctionId,
uint256 grossProfitInAsset,
uint256 minerBribeEth,
uint256 netProfitInAsset
);
modifier onlyOwner() {
require(msg.sender == FIXED_OWNER, "NOT_OWNER");
_;
}
receive() external payable {}
function executeLiquidation(
address debtAsset,
uint256 debtAmount,
bytes calldata params
) external onlyOwner {
require(debtAsset != address(0), "ZERO_DEBT_ASSET");
require(debtAmount > 0, "ZERO_DEBT_AMOUNT");
(bool ok, bytes memory ret) = AAVE_V3_POOL.call(
abi.encodeWithSignature(
"flashLoanSimple(address,address,uint256,bytes,uint16)",
address(this),
debtAsset,
debtAmount,
params,
uint16(0)
)
);
if (!ok) _revertWithReason(ret, "FLASHLOAN_FAILED");
}
function executeOperation(
address asset,
uint256 amount,
uint256 premium,
address initiator,
bytes calldata params
) external returns (bool) {
require(msg.sender == AAVE_V3_POOL, "NOT_AAVE");
require(initiator == address(this), "BAD_INITIATOR");
LiquidationParams memory liq = abi.decode(params, (LiquidationParams));
require(liq.clipperContract != address(0), "ZERO_CLIPPER");
require(liq.collateralToken != address(0), "ZERO_COLLATERAL_TOKEN");
require(liq.swapTarget != address(0), "ZERO_SWAP_TARGET");
require(liq.swapCalldata.length > 0, "EMPTY_SWAP_CALLDATA");
require(liq.minerBribeBps <= 10000, "INVALID_BRIBE_BPS");
_buyAndSwap(asset, amount, liq);
_settleLiquidation(asset, amount + premium, liq);
return true;
}
function _buyAndSwap(
address asset,
uint256 amount,
LiquidationParams memory liq
) internal {
// 1. Cumparare colateral din Clipper
_safeApprove(asset, liq.clipperContract, amount);
(bool takeOk, bytes memory takeRet) = liq.clipperContract.call(
abi.encodeWithSignature(
"take(uint256,uint256,uint256,address)",
liq.auctionId,
liq.maxCollateralToBuy,
liq.maxPricePerCollateral,
address(this)
)
);
_safeApprove(asset, liq.clipperContract, 0);
if (!takeOk) _revertWithReason(takeRet, "CLIPPER_TAKE_FAILED");
uint256 collateralBalance = _balanceOf(liq.collateralToken, address(this));
require(collateralBalance > 0, "NO_COLLATERAL");
// 2. Swap colateral -> debtAsset (asset)
_safeApprove(liq.collateralToken, liq.swapTarget, collateralBalance);
(bool swapSuccess, bytes memory swapRet) = liq.swapTarget.call(liq.swapCalldata);
_safeApprove(liq.collateralToken, liq.swapTarget, 0);
if (!swapSuccess) _revertWithReason(swapRet, "SWAP_FAILED");
}
function _settleLiquidation(
address asset,
uint256 totalDebt,
LiquidationParams memory liq
) internal {
uint256 finalAssetBalance = _balanceOf(asset, address(this));
require(finalAssetBalance > totalDebt, "NO_GROSS_PROFIT");
uint256 grossProfit = finalAssetBalance - totalDebt;
uint256 bribeInAsset = (liq.minerBribeBps > 0 && block.coinbase != address(0))
? (grossProfit * liq.minerBribeBps) / 10000
: 0;
require(grossProfit - bribeInAsset >= liq.minProfitRequired, "INSUFFICIENT_NET_PROFIT");
uint256 minerBribeEth = _payMinerBribe(asset, bribeInAsset, liq.uniswapPoolFee);
uint256 remainingBalance = _balanceOf(asset, address(this));
require(remainingBalance >= totalDebt, "INSUFFICIENT_REPAY_BALANCE");
_safeApprove(asset, AAVE_V3_POOL, totalDebt);
uint256 netProfitInAsset = remainingBalance - totalDebt;
require(netProfitInAsset >= liq.minProfitRequired, "NET_PROFIT_BELOW_MIN");
if (netProfitInAsset > 0) {
_safeTransfer(asset, FIXED_OWNER, netProfitInAsset);
}
emit SkyLiquidationSuccess(
liq.clipperContract,
liq.auctionId,
grossProfit,
minerBribeEth,
netProfitInAsset
);
}
function _payMinerBribe(
address asset,
uint256 bribeInAsset,
uint24 poolFee
) internal returns (uint256 minerBribeEth) {
if (bribeInAsset == 0 || block.coinbase == address(0)) {
return 0;
}
if (asset == WETH) {
_withdrawWeth(bribeInAsset);
minerBribeEth = bribeInAsset;
} else {
uint24 fee = poolFee > 0 ? poolFee : 500;
_safeApprove(asset, UNISWAP_V3_ROUTER, bribeInAsset);
ExactInputSingleParams memory swapParams = ExactInputSingleParams({
tokenIn: asset,
tokenOut: WETH,
fee: fee,
recipient: address(this),
deadline: block.timestamp,
amountIn: bribeInAsset,
amountOutMinimum: 1,
sqrtPriceLimitX96: 0
});
(bool uniOk, bytes memory uniData) = UNISWAP_V3_ROUTER.call(
abi.encodeWithSignature(
"exactInputSingle((address,address,uint24,address,uint256,uint256,uint256,uint160))",
swapParams
)
);
_safeApprove(asset, UNISWAP_V3_ROUTER, 0);
if (!uniOk) _revertWithReason(uniData, "BRIBE_SWAP_FAILED");
minerBribeEth = uniData.length >= 32 ? abi.decode(uniData, (uint256)) : 0;
require(minerBribeEth > 0, "ZERO_WETH_BRIBE");
_withdrawWeth(minerBribeEth);
}
(bool bribeSuccess, bytes memory bribeRet) = block.coinbase.call{value: minerBribeEth}("");
if (!bribeSuccess) _revertWithReason(bribeRet, "BRIBE_TRANSFER_FAILED");
}
function _revertWithReason(bytes memory ret, string memory fallbackMsg) internal pure {
if (ret.length >= 4) {
assembly {
revert(add(ret, 0x20), mload(ret))
}
}
revert(fallbackMsg);
}
function _balanceOf(address token, address account) internal view returns (uint256) {
(bool success, bytes memory data) = token.staticcall(
abi.encodeWithSignature("balanceOf(address)", account)
);
return (success && data.length >= 32) ? abi.decode(data, (uint256)) : 0;
}
function _safeTransfer(address token, address to, uint256 amount) internal {
(bool success, bytes memory data) = token.call(
abi.encodeWithSignature("transfer(address,uint256)", to, amount)
);
require(success && (data.length == 0 || abi.decode(data, (bool))), "TRANSFER_FAILED");
}
function _safeApprove(address token, address spender, uint256 amount) internal {
if (amount > 0) {
(bool resetOk, bytes memory resetData) = token.call(
abi.encodeWithSignature("approve(address,uint256)", spender, 0)
);
require(resetOk && (resetData.length == 0 || abi.decode(resetData, (bool))), "APPROVE_RESET_FAILED");
}
(bool success, bytes memory data) = token.call(
abi.encodeWithSignature("approve(address,uint256)", spender, amount)
);
require(success && (data.length == 0 || abi.decode(data, (bool))), "APPROVE_FAILED");
}
function _withdrawWeth(uint256 amount) internal {
(bool success, bytes memory ret) = WETH.call(
abi.encodeWithSignature("withdraw(uint256)", amount)
);
if (!success) _revertWithReason(ret, "WETH_WITHDRAW_FAILED");
}
function withdrawTokens(address token, uint256 amount) external onlyOwner {
_safeTransfer(token, FIXED_OWNER, amount);
}
function withdrawETH() external onlyOwner {
(bool ok, ) = payable(FIXED_OWNER).call{value: address(this).balance}("");
require(ok, "ETH_WITHDRAW_FAILED");
}
}Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.