Проверенный контрактТочноеUNLICENSED
MainnetLiqArbV2
Адрес0xd1afbe0704c773ab3dedacfa7fa1e2f1eb9dbc32
- Баланс
0 ETH
- Транзакций
6
- Компилятор
solc 0.8.20
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.20+commit.a1b79de6
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- shanghai
- Через IR
- да
- Лицензия
- UNLICENSED
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 469 110
- Транзакция создания
- 0xb45a2963b2…ebfbcf3a14
7 файлов
- contracts/MainnetLiqArbV2.solглавный23,1 КБ
- /home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol4,45 КБ
- /home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol193 Б
- /home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol182 Б
- /home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2,78 КБ
- /home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol13,31 КБ
- /home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol871 Б
contracts/MainnetLiqArbV2.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
// 21 Kasım 2026 — mliq adım 4: MAINNET likidasyon kontratı V2 (Morpho + Morpho ön-likidasyon + Fluid). DEPLOY EDİLMEDİ.
// MainnetLiqArb (V1, değişmedi) temel alındı; tek giriş `executeLiq2`:
// - hedef doğrulaması: kind 0 Morpho/izinli (allowedTarget), kind 1 Morpho ön-likidasyon (PreLiquidationFactory.isPreLiquidation),
// kind 2 Fluid kasası (VaultFactory.isVault) — fabrika adresleri resmi kaynak + zincirden doğrulandı.
// - native ETH borç (Fluid ETH-borç kasaları): flash WETH → çöz → `liqTarget.call{value: liqValue}`; artan ETH geri sarılır.
// - native ETH teminat (Fluid): gelen ETH WETH'e sarılır, satış WETH'ten başlar (collateral = WETH verilir).
// - ÇOKLU ROTA satış: legs ardışık rota grupları (`routeLens`), pay `splitBps` (Σ ≤ 10000), rota başı `minOut` (MinOut revert).
// Σ splitBps < 10000 → satılmayan teminat kasaya (flash yalnız satılan kısımla kapatılır).
// - teklif: gerçekleşen kârın `bribeBps`'i (+ bribeFixed) block.coinbase'e ETH; flashToken WETH değilse bribeLeg ile WETH'e.
// kâr ≥ teklif + minProfit değilse NoProfit (revert → paket düşer, gaz yok).
// - kâr HER işlemde kasaya (WETH → ETH çözülür).
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
interface IMorphoFlashM { function flashLoan(address token, uint256 assets, bytes calldata data) external; }
interface IBalVault {
struct SingleSwap { bytes32 poolId; uint8 kind; address assetIn; address assetOut; uint256 amount; bytes userData; }
struct FundManagement { address sender; bool fromInternalBalance; address payable recipient; bool toInternalBalance; }
function flashLoan(address recipient, address[] memory tokens, uint256[] memory amounts, bytes memory userData) external;
function swap(SingleSwap memory singleSwap, FundManagement memory funds, uint256 limit, uint256 deadline) external payable returns (uint256);
}
interface IBalPool { function getPoolId() external view returns (bytes32); }
interface IAavePool { function flashLoanSimple(address receiver, address asset, uint256 amount, bytes calldata params, uint16 referralCode) external; }
interface IV2PairM {
function getReserves() external view returns (uint112, uint112, uint32);
function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external;
}
interface IClPoolM {
function swap(address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data) external returns (int256, int256);
}
interface IPoolManagerM {
struct PoolKey { address currency0; address currency1; uint24 fee; int24 tickSpacing; address hooks; }
struct SwapParams { bool zeroForOne; int256 amountSpecified; uint160 sqrtPriceLimitX96; }
function unlock(bytes calldata data) external returns (bytes memory);
function swap(PoolKey memory key, SwapParams memory params, bytes calldata hookData) external returns (int256);
function sync(address currency) external;
function settle() external payable returns (uint256);
function take(address currency, address to, uint256 amount) external;
function mint(address to, uint256 id, uint256 amount) external;
function burn(address from, uint256 id, uint256 amount) external;
function balanceOf(address owner, uint256 id) external view returns (uint256);
}
interface IWETH9M { function deposit() external payable; function withdraw(uint256) external; }
interface IERC4626M {
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
function asset() external view returns (address);
}
interface IPreLiqFactoryM { function isPreLiquidation(address) external view returns (bool); }
interface IFluidVaultFactoryM { function isVault(address) external view returns (bool); }
contract MainnetLiqArbV2 {
using SafeERC20 for IERC20;
address public constant MORPHO = 0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb;
address public constant BAL_VAULT = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
address public constant AAVE_POOL = 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2;
address public constant POOL_MANAGER = 0x000000000004444c5dc75cB358380D2e3dE08A90;
address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
uint160 internal constant MIN_SQRT = 4295128740;
uint160 internal constant MAX_SQRT = 1461446703485210103287273052203988822378723970341;
uint8 public constant KIND_V2 = 0;
uint8 public constant KIND_CL = 2;
uint8 public constant KIND_V4 = 3;
uint8 public constant KIND_CURVE = 4;
uint8 public constant KIND_BALANCER = 5;
uint8 public constant KIND_ERC4626 = 6; // ERC4626 kasa payı → redeem → alttaki varlık (DEX değil)
uint8 public constant FLAG_IN_CLAIM = 1;
uint8 public constant FLAG_OUT_CLAIM = 2;
uint8 public constant FLAG_CURVE_U256 = 4;
uint8 public constant FLAG_BRIBE_LEG = 8;
uint8 public constant SRC_MORPHO = 0;
uint8 public constant SRC_BALANCER = 1;
uint8 public constant SRC_AAVE = 2;
uint8 public constant TK_ALLOWED = 0;
uint8 public constant TK_PRELIQ = 1;
uint8 public constant TK_FLUID = 2;
address public constant PRELIQ_FACTORY = 0x6FF33615e792E35ed1026ea7cACCf42D9BF83476;
address public constant FLUID_VAULT_FACTORY = 0x324c5Dc1fC42c7a4D43d92df1eBA58a54d13Bf2d;
uint256 public constant MAX_ROUTES = 20;
struct Leg {
uint8 kind;
address pool;
address tokenIn;
address tokenOut;
uint24 fee;
int24 tickSpacing;
address hooks;
uint8 flags;
}
struct LiqJob {
address flashToken; // = borç tokenı (native ETH borçta WETH)
uint256 amount; // flash miktarı
uint256 before; // başlangıç flashToken bakiyesi
uint256 minProfit;
uint256 bribeBps;
uint256 bribeFixed;
address liqTarget; // Morpho / PreLiquidation / Fluid kasası
uint256 liqValue; // > 0 → native ETH borç: flash WETH'ten çözülüp value ile gönderilir
bytes liqCalldata; // liquidate / preLiquidate / Fluid liquidate
address collateral; // el konulan teminat (native ETH → WETH verilir; gelen ETH sarılır)
Leg[] legs; // satış rotaları (ardışık gruplar)
uint16[] splitBps; // rota başı teminat payı
uint8[] routeLens; // rota başı bacak sayısı
uint256[] minOut; // rota başı asgari flashToken çıktısı
}
/// executeLiq2 parametreleri (yığın derinliği için tek yapı).
struct Params {
address flashToken;
uint256 amount;
uint8 flashSrc;
uint8 targetKind;
address liqTarget;
uint256 liqValue;
bytes liqCalldata;
address collateral;
Leg[] legs;
uint16[] splitBps;
uint8[] routeLens;
uint256[] minOut;
uint256 minProfit;
uint256 maxBlock;
uint256 bribeBps;
uint256 bribeFixed;
Leg bribeLeg; // flashToken → WETH (flashToken WETH ise kullanılmaz)
}
address public owner;
address public pendingOwner;
address public vault;
bool public paused;
mapping(address => bool) public executors;
mapping(address => bool) public allowedTarget;
address private _expectedPool;
bool private _inFlash;
uint256 private _bribe;
uint256 private _profit;
event ExecutedLiq(address indexed flashToken, address indexed collateral, uint256 amountIn, uint256 profit, uint256 bribe, uint8 flashSrc);
event Swept(address indexed token, address indexed to, uint256 amount);
event VaultSet(address vault);
event ExecutorSet(address who, bool ok);
event Paused(bool on);
event TargetSet(address t, bool ok);
error NotOwner();
error NotExecutor();
error IsPaused();
error Expired();
error BadRoute();
error BadCaller();
error BadBribe();
error LiqFailed();
error NoProfit(uint256 profit, uint256 need);
error NoVault();
error SwapFailed();
error BadTarget();
error MinOut(uint256 route, uint256 got, uint256 need);
modifier onlyOwner() { if (msg.sender != owner) revert NotOwner(); _; }
/// owner = kasa (soğuk), executor = gönderici (constructor'da; ayrı setExecutor gerekmez).
constructor(address vault_, address owner_, address executor_) {
if (vault_ == address(0) || owner_ == address(0)) revert NoVault();
owner = owner_; vault = vault_;
if (executor_ != address(0)) executors[executor_] = true;
allowedTarget[MORPHO] = true;
}
function setAllowedTarget(address t, bool ok) external onlyOwner { allowedTarget[t] = ok; emit TargetSet(t, ok); }
function targetOk(uint8 kind, address t) public view returns (bool) {
if (kind == TK_ALLOWED) return allowedTarget[t];
if (kind == TK_PRELIQ) return IPreLiqFactoryM(PRELIQ_FACTORY).isPreLiquidation(t);
if (kind == TK_FLUID) return IFluidVaultFactoryM(FLUID_VAULT_FACTORY).isVault(t);
return false;
}
receive() external payable {}
// ───────────── yönetim ─────────────
function transferOwnership(address n) external onlyOwner { pendingOwner = n; }
function acceptOwnership() external { if (msg.sender != pendingOwner) revert NotOwner(); owner = msg.sender; pendingOwner = address(0); }
function setVault(address v) external onlyOwner { if (v == address(0)) revert NoVault(); vault = v; emit VaultSet(v); }
function setExecutor(address who, bool ok) external onlyOwner { executors[who] = ok; emit ExecutorSet(who, ok); }
function setPaused(bool on) external { if (msg.sender != owner && !executors[msg.sender]) revert NotExecutor(); if (!on && msg.sender != owner) revert NotOwner(); paused = on; emit Paused(on); }
/// Biriken kârı kasaya gönderir. WETH → ETH çözülür; diğer tokenlar olduğu gibi.
function sweep(address token) external {
if (msg.sender != owner && !executors[msg.sender]) revert NotExecutor();
address v = vault; if (v == address(0)) revert NoVault();
uint256 bal;
if (token == WETH || token == address(0)) {
uint256 w = IERC20(WETH).balanceOf(address(this));
if (w > 0) IWETH9M(WETH).withdraw(w);
bal = address(this).balance;
(bool ok,) = v.call{value: bal}(""); require(ok);
token = address(0);
} else { bal = IERC20(token).balanceOf(address(this)); IERC20(token).safeTransfer(v, bal); }
emit Swept(token, v, bal);
}
// ───────────── yürütme ─────────────
function executeLiq2(Params calldata p) external {
if (!executors[msg.sender]) revert NotExecutor();
if (paused) revert IsPaused();
if (block.number > p.maxBlock) revert Expired();
if (!targetOk(p.targetKind, p.liqTarget)) revert BadTarget();
if (p.bribeBps > 10_000) revert BadBribe();
if (p.liqValue > 0 && (p.flashToken != WETH || p.liqValue > p.amount)) revert BadRoute();
uint256 nr = p.routeLens.length;
if (nr == 0 || nr > MAX_ROUTES || p.splitBps.length != nr || p.minOut.length != nr) revert BadRoute();
uint256 tot; uint256 sb;
for (uint256 k = 0; k < nr; k++) {
uint256 L = p.routeLens[k];
if (L == 0) revert BadRoute();
if (_norm(p.legs[tot].tokenIn) != _norm(p.collateral) || _norm(p.legs[tot + L - 1].tokenOut) != p.flashToken) revert BadRoute();
tot += L; sb += p.splitBps[k];
}
if (tot != p.legs.length || sb == 0 || sb > 10_000) revert BadRoute();
bool bribeSwap = p.flashToken != WETH && (p.bribeBps > 0 || p.bribeFixed > 0);
if (bribeSwap && (_norm(p.bribeLeg.tokenIn) != p.flashToken || _norm(p.bribeLeg.tokenOut) != WETH)) revert BadBribe();
uint256 bal0 = IERC20(p.flashToken).balanceOf(address(this));
LiqJob memory j = LiqJob(p.flashToken, p.amount, bal0, p.minProfit, p.bribeBps, p.bribeFixed, p.liqTarget, p.liqValue,
p.liqCalldata, p.collateral, p.legs, p.splitBps, p.routeLens, p.minOut);
_dispatchFlash(j, p.bribeLeg, bribeSwap, p.flashSrc);
}
/// Flash → `_runLiq` → teklif (coinbase) → kâr kasaya.
function _dispatchFlash(LiqJob memory j, Leg calldata bribeLeg, bool bribeSwap, uint8 flashSrc) internal {
bytes memory data = abi.encode(j);
_inFlash = true;
if (flashSrc == SRC_MORPHO) {
IMorphoFlashM(MORPHO).flashLoan(j.flashToken, j.amount, data);
} else if (flashSrc == SRC_BALANCER) {
address[] memory t = new address[](1); t[0] = j.flashToken;
uint256[] memory a = new uint256[](1); a[0] = j.amount;
IBalVault(BAL_VAULT).flashLoan(address(this), t, a, data);
} else if (flashSrc == SRC_AAVE) {
IAavePool(AAVE_POOL).flashLoanSimple(address(this), j.flashToken, j.amount, data, 0);
} else revert BadRoute();
uint256 bribe = _bribe;
uint256 profit = _profit;
_bribe = 0; _profit = 0;
uint256 paid = 0;
if (bribe > 0) {
paid = bribeSwap ? _swap(bribeLeg, bribe) : bribe;
IWETH9M(WETH).withdraw(paid);
(bool ok,) = block.coinbase.call{value: paid}(""); if (!ok) revert BadBribe();
}
_inFlash = false;
// kâr HER işlemde kasaya: flashToken artığı (+ satılmayan teminat)
address v = vault;
uint256 rest = IERC20(j.flashToken).balanceOf(address(this));
if (rest > j.before) {
uint256 x = rest - j.before;
if (j.flashToken == WETH) { IWETH9M(WETH).withdraw(x); (bool ok2,) = v.call{value: x}(""); require(ok2); }
else IERC20(j.flashToken).safeTransfer(v, x);
}
address col = _norm(j.collateral);
if (col != j.flashToken) {
uint256 left = IERC20(col).balanceOf(address(this));
if (left > 0) IERC20(col).safeTransfer(v, left);
}
emit ExecutedLiq(j.flashToken, j.collateral, j.amount, profit, paid, flashSrc);
}
function onMorphoFlashLoan(uint256 assets, bytes calldata data) external {
if (msg.sender != MORPHO || !_inFlash) revert BadCaller();
LiqJob memory j = abi.decode(data, (LiqJob));
if (assets != j.amount) revert BadRoute();
_runLiq(j, 0);
IERC20(j.flashToken).forceApprove(MORPHO, j.amount);
}
function receiveFlashLoan(address[] calldata tokens, uint256[] calldata amounts, uint256[] calldata fees, bytes calldata data) external {
if (msg.sender != BAL_VAULT || !_inFlash) revert BadCaller();
LiqJob memory j = abi.decode(data, (LiqJob));
if (tokens.length != 1 || tokens[0] != j.flashToken || amounts[0] != j.amount) revert BadRoute();
_runLiq(j, fees[0]);
IERC20(j.flashToken).safeTransfer(BAL_VAULT, j.amount + fees[0]);
}
function executeOperation(address asset, uint256 amount, uint256 premium, address initiator, bytes calldata data) external returns (bool) {
if (msg.sender != AAVE_POOL || initiator != address(this) || !_inFlash) revert BadCaller();
LiqJob memory j = abi.decode(data, (LiqJob));
if (asset != j.flashToken || amount != j.amount) revert BadRoute();
_runLiq(j, premium);
IERC20(j.flashToken).forceApprove(AAVE_POOL, amount + premium);
return true;
}
/// 1) likidasyon (approve + çağrı; native borçta value); 2) native teminat/artık ETH sarılır; 3) rota gruplarıyla sat
/// (rota başı minOut); 4) kâr < teklif + minProfit ise geri al.
function _runLiq(LiqJob memory j, uint256 fee) internal {
address col = _norm(j.collateral);
uint256 c0 = IERC20(col).balanceOf(address(this));
if (j.liqValue > 0) {
IWETH9M(WETH).withdraw(j.liqValue);
(bool ok,) = j.liqTarget.call{value: j.liqValue}(j.liqCalldata);
if (!ok) revert LiqFailed();
} else {
IERC20(j.flashToken).forceApprove(j.liqTarget, j.amount);
(bool ok,) = j.liqTarget.call(j.liqCalldata);
if (!ok) revert LiqFailed();
IERC20(j.flashToken).forceApprove(j.liqTarget, 0);
}
// native ETH teminat / artan value → WETH
uint256 eth = address(this).balance;
if (eth > 0) IWETH9M(WETH).deposit{value: eth}();
uint256 got = IERC20(col).balanceOf(address(this)) - c0;
// teminat = borç tokenı (ör. WETH borç + ETH teminat) ise c0 flash dahil — o durumda satış rotası yine zorunlu değil
if (got == 0 && col != j.flashToken) revert LiqFailed();
uint256 nr = j.routeLens.length;
uint256 li;
for (uint256 k = 0; k < nr; k++) {
uint256 amt = got * j.splitBps[k] / 10_000;
uint256 L = j.routeLens[k];
if (amt > 0) {
address cur = col;
for (uint256 i = 0; i < L; i++) {
Leg memory l = j.legs[li + i];
if (_norm(l.tokenIn) != cur) revert BadRoute();
amt = _swap(l, amt);
cur = _norm(l.tokenOut);
}
if (amt < j.minOut[k]) revert MinOut(k, amt, j.minOut[k]);
}
li += L;
}
uint256 have = IERC20(j.flashToken).balanceOf(address(this));
uint256 owe = j.before + j.amount + fee;
uint256 profit = have > owe ? have - owe : 0;
uint256 bribe = profit * j.bribeBps / 10_000 + j.bribeFixed;
if (profit < bribe + j.minProfit) revert NoProfit(profit, bribe + j.minProfit);
_profit = profit;
_bribe = bribe;
}
function _norm(address t) internal pure returns (address) { return t == address(0) ? WETH : t; }
function _bal(address t) internal view returns (uint256) { return IERC20(_norm(t)).balanceOf(address(this)); }
function _swap(Leg memory l, uint256 amt) internal returns (uint256 out) {
if (l.kind == KIND_V4) return _swapV4(l, amt);
uint256 b0 = _bal(l.tokenOut);
bool zfo = l.tokenIn < l.tokenOut;
if (l.kind == KIND_V2) {
(uint112 r0, uint112 r1,) = IV2PairM(l.pool).getReserves();
(uint256 rin, uint256 rout) = zfo ? (uint256(r0), uint256(r1)) : (uint256(r1), uint256(r0));
uint256 inf = amt * (1_000_000 - uint256(l.fee));
uint256 o = (inf * rout) / (rin * 1_000_000 + inf);
IERC20(l.tokenIn).safeTransfer(l.pool, amt);
IV2PairM(l.pool).swap(zfo ? 0 : o, zfo ? o : 0, address(this), "");
} else if (l.kind == KIND_CL) {
_expectedPool = l.pool;
IClPoolM(l.pool).swap(address(this), zfo, int256(amt), zfo ? MIN_SQRT : MAX_SQRT, abi.encode(l.tokenIn));
_expectedPool = address(0);
} else if (l.kind == KIND_CURVE) {
IERC20(l.tokenIn).forceApprove(l.pool, amt);
bytes memory cd = (l.flags & FLAG_CURVE_U256) != 0
? abi.encodeWithSignature("exchange(uint256,uint256,uint256,uint256)", uint256(l.fee), uint256(uint24(l.tickSpacing)), amt, uint256(0))
: abi.encodeWithSignature("exchange(int128,int128,uint256,uint256)", int128(uint128(l.fee)), int128(l.tickSpacing), amt, uint256(0));
(bool ok,) = l.pool.call(cd);
if (!ok) revert SwapFailed();
} else if (l.kind == KIND_BALANCER) {
IERC20(l.tokenIn).forceApprove(BAL_VAULT, amt);
bytes32 pid = IBalPool(l.pool).getPoolId();
IBalVault(BAL_VAULT).swap(
IBalVault.SingleSwap(pid, 0, l.tokenIn, l.tokenOut, amt, ""),
IBalVault.FundManagement(address(this), false, payable(address(this)), false),
0, block.timestamp);
} else if (l.kind == KIND_ERC4626) {
// Kasa payı (l.pool=l.tokenIn=vault) → redeem → alttaki varlık (l.tokenOut) bu kontrata.
// owner=this olduğundan approve gerekmez (kendi payını yakar). Senkron olmayan/duraklatılmış
// kasada redeem REVERT eder → tüm tx geri alınır (fon riski yok). Sonra underlying ayrı
// bacakla borç tokenına satılır (gerekirse).
IERC4626M(l.pool).redeem(amt, address(this), address(this));
} else revert BadRoute();
out = _bal(l.tokenOut) - b0;
}
function _clCallback(int256 a0, int256 a1, bytes calldata data) internal {
if (msg.sender != _expectedPool || _expectedPool == address(0)) revert BadCaller();
address tin = abi.decode(data, (address));
uint256 pay = a0 > 0 ? uint256(a0) : uint256(a1);
IERC20(tin).safeTransfer(msg.sender, pay);
}
function uniswapV3SwapCallback(int256 a0, int256 a1, bytes calldata data) external { _clCallback(a0, a1, data); }
function pancakeV3SwapCallback(int256 a0, int256 a1, bytes calldata data) external { _clCallback(a0, a1, data); }
function _swapV4(Leg memory l, uint256 amt) internal returns (uint256 out) {
bytes memory r = IPoolManagerM(POOL_MANAGER).unlock(abi.encode(l, amt));
out = abi.decode(r, (uint256));
if (l.tokenOut == address(0) && (l.flags & FLAG_OUT_CLAIM) == 0) IWETH9M(WETH).deposit{value: out}();
}
function unlockCallback(bytes calldata data) external returns (bytes memory) {
if (msg.sender != POOL_MANAGER || !_inFlash) revert BadCaller();
(Leg memory l, uint256 amt) = abi.decode(data, (Leg, uint256));
IPoolManagerM pm = IPoolManagerM(POOL_MANAGER);
bool zfo = l.tokenIn < l.tokenOut;
IPoolManagerM.PoolKey memory key = IPoolManagerM.PoolKey(zfo ? l.tokenIn : l.tokenOut, zfo ? l.tokenOut : l.tokenIn, l.fee, l.tickSpacing, l.hooks);
int256 d = pm.swap(key, IPoolManagerM.SwapParams(zfo, -int256(amt), zfo ? MIN_SQRT : MAX_SQRT), "");
int128 d0 = int128(d >> 128);
int128 d1 = int128(d);
(int128 din, int128 dout) = zfo ? (d0, d1) : (d1, d0);
uint256 owe = uint256(uint128(-din));
uint256 got = uint256(uint128(dout));
if ((l.flags & FLAG_IN_CLAIM) != 0 && pm.balanceOf(address(this), uint256(uint160(l.tokenIn))) >= owe) {
pm.burn(address(this), uint256(uint160(l.tokenIn)), owe);
} else if (l.tokenIn == address(0)) {
IWETH9M(WETH).withdraw(owe);
pm.settle{value: owe}();
} else {
pm.sync(l.tokenIn);
IERC20(l.tokenIn).safeTransfer(POOL_MANAGER, owe);
pm.settle();
}
if ((l.flags & FLAG_OUT_CLAIM) != 0) pm.mint(address(this), uint256(uint160(l.tokenOut)), got);
else pm.take(l.tokenOut, address(this), got);
return abi.encode(got);
}
}
/home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/interfaces/IERC1363.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
/home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/interfaces/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)
pragma solidity >=0.4.16;
import {IERC165} from "../utils/introspection/IERC165.sol";
/home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";
/home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
/home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
if (!_safeTransfer(token, to, value, true)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
if (!_safeTransferFrom(token, from, to, value, true)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _safeTransfer(token, to, value, false);
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _safeTransferFrom(token, from, to, value, false);
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
if (!_safeApprove(token, spender, value, false)) {
if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Oppositely, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity `token.transfer(to, value)` call, relaxing the requirement on the return value: the
* return value is optional (but if data is returned, it must not be false).
*
* @param token The token targeted by the call.
* @param to The recipient of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
bytes4 selector = IERC20.transfer.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(to, shr(96, not(0))))
mstore(0x24, value)
success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
}
}
/**
* @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, relaxing the requirement on the return
* value: the return value is optional (but if data is returned, it must not be false).
*
* @param token The token targeted by the call.
* @param from The sender of the tokens
* @param to The recipient of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value,
bool bubble
) private returns (bool success) {
bytes4 selector = IERC20.transferFrom.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(from, shr(96, not(0))))
mstore(0x24, and(to, shr(96, not(0))))
mstore(0x44, value)
success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
mstore(0x60, 0)
}
}
/**
* @dev Imitates a Solidity `token.approve(spender, value)` call, relaxing the requirement on the return value:
* the return value is optional (but if data is returned, it must not be false).
*
* @param token The token targeted by the call.
* @param spender The spender of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
bytes4 selector = IERC20.approve.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(spender, shr(96, not(0))))
mstore(0x24, value)
success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
}
}
}
/home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Настройки компилятораПоказать
{
"viaIR": true,
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "shanghai",
"remappings": [
":@openzeppelin/contracts/=/home/flashbot/flashbot/lib/openzeppelin-contracts/contracts/",
":forge-std/=/home/flashbot/flashbot/lib/forge-std/src/"
]
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.