Verified contractPartialMIT
ArbExecutor
Address0xbfddd861b120b18158fa8a4d4ab12a22da0984ab
- Balance
0 ETH
- Transactions
25
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 10,000 runs
- EVM version
- cancun
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,063,285
- Creation transaction
- 0xd6cfa63aef…cec34acafd
src/ArbExecutor.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
/// @title ArbExecutor
/// @notice Buy a token and bridge it to the owner in ONE transaction (all-or-nothing).
/// Protections (owner-approved design, 2026-09-26):
/// - only `owner` (the hot wallet) can call anything; no key of its own; not upgradeable (no proxy, no delegatecall)
/// - fixed steps only: swap on an allowlisted router, then a bridge call on an allowlisted bridge
/// - the bridge recipient is decoded per bridge kind and MUST be the owner
/// - approvals are exact and reset to zero inside the same transaction
/// - the contract must end every call holding zero tokens and zero ETH (leftovers go to the owner), else it reverts
/// - per-call ETH cap (owner-set, tracks the wallet); pause switch; owner-only rescue
contract ArbExecutor {
// bridge kinds: how to find the recipient inside the bridge calldata
uint8 internal constant KIND_PORTAL = 1; // transferTokens(token,amount,chain,bytes32 recipient,fee,nonce)
uint8 internal constant KIND_OPSTACK = 2; // depositERC20To(l1,l2,address to,amount,minGas,extra)
uint8 internal constant KIND_NTT = 3; // transfer(amount,chain,bytes32 recipient,bytes32 refund,bool,bytes)
uint8 internal constant KIND_POS = 4; // depositFor(address user,root,bytes) (Polygon PoS / BTTC)
uint8 internal constant KIND_OFT = 5; // send((dstEid,bytes32 to,..),(fee,lzFee),address refund)
uint8 internal constant KIND_CCIP = 6; // ccipSend(selector,(bytes receiver,..))
address public immutable owner;
uint256 public maxValue;
bool public paused;
mapping(address => bool) public allowed;
uint256 private locked = 1;
struct Trade {
address router; // allowlisted DEX router / aggregator
bytes swapData; // swap calldata (output recipient = this contract)
uint256 swapValue; // native ETH into the swap
address tokenIn; // zero for native ETH buys, else pulled from the owner (exact approval)
uint256 amountIn;
address token; // token bought and bridged
uint256 minOut; // revert unless at least this much arrived; also the amount placeholder in bridgeData
address spender; // who pulls the token for the bridge (bridge itself, CCIP router, predicate ...)
address bridge; // allowlisted bridge contract
bytes bridgeData; // bridge calldata built for amount == minOut
uint256 bridgeValue; // native bridge fee
uint8 kind; // recipient layout (KIND_*)
uint256[] amountOffsets; // byte offsets in bridgeData whose word == minOut, rewritten to the real amount
uint256 granularity; // amount rounded down to a multiple (NTT trimming); 1 = none
}
event Executed(address indexed token, uint256 received, uint256 bridged, address bridge);
event Allowed(address indexed target, bool ok);
event Paused(bool paused);
event MaxValue(uint256 maxValue);
error NotOwner();
error IsPaused();
error NotAllowed(address target);
error TooMuchValue();
error ValueMismatch();
error CallFailed(bytes reason);
error InsufficientOutput(uint256 got, uint256 minOut);
error BadRecipient();
error BadAmountSlot(uint256 offset);
error Leftover();
error Reentrant();
modifier onlyOwner() {
if (msg.sender != owner) revert NotOwner();
_;
}
modifier nonReentrant() {
if (locked != 1) revert Reentrant();
locked = 2;
_;
locked = 1;
}
constructor(uint256 maxValue_, address[] memory targets) {
owner = msg.sender;
maxValue = maxValue_;
for (uint256 i; i < targets.length; ++i) {
allowed[targets[i]] = true;
emit Allowed(targets[i], true);
}
}
function setAllowed(address target, bool ok) external onlyOwner {
allowed[target] = ok;
emit Allowed(target, ok);
}
/// @notice per-call ETH cap: owner raises it as the bankroll grows (owner 2026-09-26: trade up to the wallet's ETH)
function setMaxValue(uint256 v) external onlyOwner {
maxValue = v;
emit MaxValue(v);
}
function setPaused(bool p) external onlyOwner {
paused = p;
emit Paused(p);
}
/// @notice Owner-only: send any token (or ETH with token = 0) held here back to the owner.
function rescue(address token) external onlyOwner {
if (token == address(0)) {
(bool ok,) = owner.call{value: address(this).balance}("");
require(ok);
} else {
_transfer(token, owner, _balance(token));
}
}
function execute(Trade calldata t) external payable onlyOwner nonReentrant returns (uint256 bridged) {
if (paused) revert IsPaused();
if (msg.value > maxValue) revert TooMuchValue();
if (msg.value != t.swapValue + t.bridgeValue) revert ValueMismatch();
if (!allowed[t.router]) revert NotAllowed(t.router);
if (!allowed[t.bridge]) revert NotAllowed(t.bridge);
if (!allowed[t.spender]) revert NotAllowed(t.spender);
_checkRecipient(t.kind, t.bridgeData);
// 1. buy
if (t.tokenIn != address(0)) {
_transferFrom(t.tokenIn, owner, address(this), t.amountIn);
_approve(t.tokenIn, t.router, t.amountIn);
}
uint256 before = _balance(t.token);
_call(t.router, t.swapValue, t.swapData);
if (t.tokenIn != address(0)) _approve(t.tokenIn, t.router, 0);
uint256 got = _balance(t.token) - before;
if (got < t.minOut) revert InsufficientOutput(got, t.minOut);
// 2. bridge the real amount (rounded to the bridge's granularity) to the owner
uint256 g = t.granularity == 0 ? 1 : t.granularity;
bridged = got - (got % g);
bytes memory data = t.bridgeData;
for (uint256 i; i < t.amountOffsets.length; ++i) {
uint256 off = t.amountOffsets[i];
if (off + 32 > data.length) revert BadAmountSlot(off);
uint256 cur;
assembly { cur := mload(add(add(data, 32), off)) }
if (cur != t.minOut) revert BadAmountSlot(off);
assembly { mstore(add(add(data, 32), off), bridged) }
}
_approve(t.token, t.spender, bridged);
_call(t.bridge, t.bridgeValue, data);
_approve(t.token, t.spender, 0);
// 3. nothing may stay here
uint256 rest = _balance(t.token);
if (rest > 0) _transfer(t.token, owner, rest);
if (t.tokenIn != address(0)) {
uint256 restIn = _balance(t.tokenIn);
if (restIn > 0) _transfer(t.tokenIn, owner, restIn);
}
if (address(this).balance > 0) {
(bool ok,) = owner.call{value: address(this).balance}("");
require(ok);
}
if (_balance(t.token) != 0 || address(this).balance != 0) revert Leftover();
emit Executed(t.token, got, bridged, t.bridge);
}
// ---------------------------------------------------------------- recipient checks
function _word(bytes calldata d, uint256 pos) private pure returns (bytes32 w) {
if (pos + 32 > d.length) revert BadRecipient();
assembly { w := calldataload(add(d.offset, pos)) }
}
function _checkRecipient(uint8 kind, bytes calldata d) private view {
bytes32 me = bytes32(uint256(uint160(owner)));
if (kind == KIND_PORTAL) {
if (_word(d, 4 + 32 * 3) != me) revert BadRecipient();
} else if (kind == KIND_OPSTACK) {
if (_word(d, 4 + 32 * 2) != me) revert BadRecipient();
} else if (kind == KIND_NTT) {
if (_word(d, 4 + 32 * 2) != me || _word(d, 4 + 32 * 3) != me) revert BadRecipient();
} else if (kind == KIND_POS) {
if (_word(d, 4) != me) revert BadRecipient();
} else if (kind == KIND_OFT) {
uint256 off = uint256(_word(d, 4)); // SendParam (dynamic tuple) head offset
if (_word(d, 4 + off + 32) != me) revert BadRecipient(); // SendParam.to
if (_word(d, 4 + 32 * 3) != me) revert BadRecipient(); // refundAddress
} else if (kind == KIND_CCIP) {
uint256 m = 4 + uint256(_word(d, 4 + 32)); // EVM2AnyMessage start
uint256 r = m + uint256(_word(d, m)); // receiver bytes
if (uint256(_word(d, r)) != 32 || _word(d, r + 32) != me) revert BadRecipient();
} else {
revert BadRecipient();
}
}
// ---------------------------------------------------------------- token helpers (non-standard returns tolerated)
function _call(address to, uint256 value, bytes memory data) private {
(bool ok, bytes memory ret) = to.call{value: value}(data);
if (!ok) revert CallFailed(ret);
}
function _balance(address token) private view returns (uint256 b) {
(bool ok, bytes memory ret) = token.staticcall(abi.encodeWithSelector(0x70a08231, address(this)));
require(ok && ret.length >= 32);
b = abi.decode(ret, (uint256));
}
function _tokenCall(address token, bytes memory data) private {
(bool ok, bytes memory ret) = token.call(data);
if (!ok || (ret.length > 0 && !abi.decode(ret, (bool)))) revert CallFailed(ret);
}
function _approve(address token, address spender, uint256 amount) private {
if (amount > 0) _tokenCall(token, abi.encodeWithSelector(0x095ea7b3, spender, 0)); // USDT-style tokens need 0 first
_tokenCall(token, abi.encodeWithSelector(0x095ea7b3, spender, amount));
}
function _transfer(address token, address to, uint256 amount) private {
_tokenCall(token, abi.encodeWithSelector(0xa9059cbb, to, amount));
}
function _transferFrom(address token, address from, address to, uint256 amount) private {
_tokenCall(token, abi.encodeWithSelector(0x23b872dd, from, to, amount));
}
receive() external payable {
// only refunds arriving during an owner call (bridge fee overpayment) are accepted
if (locked != 2) revert NotOwner();
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": false,
"bytecodeHash": "none",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 10000,
"enabled": true
},
"evmVersion": "cancun"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.