Skip to content
Verified contractExactMIT

Zyper7702Coordinator

Address0x362f892b1043db4e7eb101f9af9ced68d4bde445
Balance

0 ETH

 

Transactions

2

 

Compiler

solc 0.8.24

 

Same code

38 more contracts

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,053,006
Creation transaction
0x2027855cda…c4db973efd
Main copy (most transactions)
0x231a1872…66f73a5a

src/Zyper7702Coordinator.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

interface IZyper7702Executor {
    function trustedCoordinator() external view returns (address);
}

/// @notice Owner-operated, best-effort relay for EIP-7702 delegated wallets.
/// @dev The owner can execute arbitrary calls from accounts delegated to the
///      pinned executor. Users must treat delegation as full wallet authority.
contract Zyper7702Coordinator {
    error Unauthorized();
    error ZeroAddress();
    error ReentrantCall();
    error ExecutorAlreadySet();
    error ExecutorNotSet();
    error InvalidExecutor();
    error IncorrectValue(uint256 expected, uint256 actual);
    error PaymentFailed(address recipient, uint256 value);

    struct Call {
        address account;
        uint256 suppliedValue;
        uint256 gasLimit;
        bytes data;
    }

    uint256 public constant MAX_RETURN_DATA = 256;
    uint256 private constant POST_CALL_GAS_RESERVE = 100_000;
    uint256 private constant REMAINING_CALL_GAS_RESERVE = 30_000;

    address public immutable owner;
    address public executor;
    uint256 private entered = 1;

    event ExecutorSet(address indexed executor);
    event CallResult(uint256 indexed index, address indexed account, bool success, bytes returnData);
    event BuilderPaid(address indexed beneficiary, uint256 value);
    event Refunded(address indexed owner, uint256 value);

    constructor(address owner_) {
        if (owner_ == address(0)) revert ZeroAddress();
        owner = owner_;
    }

    modifier onlyOwner() {
        if (msg.sender != owner) revert Unauthorized();
        _;
    }

    modifier nonReentrant() {
        if (entered != 1) revert ReentrantCall();
        entered = 2;
        _;
        entered = 1;
    }

    /// @notice Pins the only executor this coordinator will accept.
    /// @dev One-time and owner-only, avoiding an upgrade path after wallets
    ///      have approved the deployment's bytecode.
    function setExecutor(address executor_) external onlyOwner {
        if (executor != address(0)) revert ExecutorAlreadySet();
        if (executor_ == address(0) || executor_.code.length == 0) revert InvalidExecutor();

        (bool ok, bytes memory result) = executor_.staticcall(abi.encodeCall(IZyper7702Executor.trustedCoordinator, ()));
        if (!ok || result.length < 32 || abi.decode(result, (address)) != address(this)) {
            revert InvalidExecutor();
        }
        executor = executor_;
        emit ExecutorSet(executor_);
    }

    /// @notice Relays unique calldata to each delegated wallet.
    function relay(Call[] calldata calls, uint256 bribePerSuccess) external payable onlyOwner nonReentrant {
        _requireExecutor();

        uint256 totalSupplied;
        for (uint256 i; i < calls.length; ++i) {
            totalSupplied += calls[i].suppliedValue;
        }
        uint256 expected = totalSupplied + (bribePerSuccess * calls.length);
        if (msg.value != expected) revert IncorrectValue(expected, msg.value);

        uint256 successfulValue;
        uint256 successCount;
        for (uint256 i; i < calls.length; ++i) {
            Call calldata item = calls[i];
            if (!_delegatesToExecutor(item.account)) {
                emit CallResult(i, item.account, false, bytes("INVALID_DELEGATION"));
                continue;
            }

            Call memory prepared = item;
            (bool ok, bytes memory result) = _callAccount(prepared, calls.length - i - 1);
            if (ok) {
                successfulValue += item.suppliedValue;
                ++successCount;
            }
            emit CallResult(i, item.account, ok, result);
        }

        _settle(msg.value, successfulValue, successCount * bribePerSuccess);
    }

    /// @notice Relays identical calldata and value to multiple wallets.
    function relayShared(
        address[] calldata accounts,
        uint256 suppliedValue,
        uint256 gasLimit,
        bytes calldata data,
        uint256 bribePerSuccess
    ) external payable onlyOwner nonReentrant {
        _requireExecutor();

        uint256 expected = (suppliedValue + bribePerSuccess) * accounts.length;
        if (msg.value != expected) revert IncorrectValue(expected, msg.value);

        uint256 successfulValue;
        uint256 successCount;
        for (uint256 i; i < accounts.length; ++i) {
            address account = accounts[i];
            if (!_delegatesToExecutor(account)) {
                emit CallResult(i, account, false, bytes("INVALID_DELEGATION"));
                continue;
            }

            Call memory prepared = Call(account, suppliedValue, gasLimit, data);
            uint256 remaining = accounts.length - i - 1;
            (bool ok, bytes memory result) = _callAccount(prepared, remaining);
            if (ok) {
                successfulValue += suppliedValue;
                ++successCount;
            }
            emit CallResult(i, account, ok, result);
        }

        _settle(msg.value, successfulValue, successCount * bribePerSuccess);
    }

    /// @notice Recovers ETH sent directly to the coordinator.
    function withdraw(address payable recipient, uint256 value) external onlyOwner nonReentrant {
        if (recipient == address(0)) revert ZeroAddress();
        (bool ok,) = recipient.call{value: value}("");
        if (!ok) revert PaymentFailed(recipient, value);
    }

    function _requireExecutor() private view {
        if (executor == address(0)) revert ExecutorNotSet();
    }

    /// @dev EXTCODE* reads the 23-byte EIP-7702 designator itself. It does not
    ///      follow the pointer like CALL/STATICCALL execution does.
    function _delegatesToExecutor(address account) private view returns (bool) {
        if (account == address(0)) return false;

        uint256 size;
        bytes32 word;
        assembly ("memory-safe") {
            size := extcodesize(account)
            let ptr := mload(0x40)
            extcodecopy(account, ptr, 0, 23)
            word := mload(ptr)
        }
        if (size != 23 || uint24(uint256(word) >> 232) != 0xef0100) return false;
        return address(uint160(uint256(word) >> 72)) == executor;
    }

    function _callAccount(Call memory item, uint256 remainingCalls)
        private
        returns (bool success, bytes memory result)
    {
        uint256 reserve = POST_CALL_GAS_RESERVE + (remainingCalls * REMAINING_CALL_GAS_RESERVE);
        uint256 available = gasleft();
        if (available <= reserve) {
            return (false, bytes("INSUFFICIENT_RELAY_GAS"));
        }

        uint256 maxForward = available - reserve;
        uint256 forwardGas = item.gasLimit == 0 || item.gasLimit > maxForward ? maxForward : item.gasLimit;
        bytes memory callData = item.data;
        assembly ("memory-safe") {
            success := call(forwardGas, mload(item), mload(add(item, 0x20)), add(callData, 0x20), mload(callData), 0, 0)
            let size := returndatasize()
            if gt(size, 0x100) { size := 0x100 }
            result := mload(0x40)
            mstore(result, size)
            returndatacopy(add(result, 0x20), 0, size)
            mstore(0x40, and(add(add(result, size), 0x3f), not(0x1f)))
        }
    }

    function _settle(uint256 provided, uint256 successfulValue, uint256 bribe) private {
        if (bribe != 0) {
            (bool bribeOK,) = block.coinbase.call{value: bribe}("");
            if (!bribeOK) revert PaymentFailed(block.coinbase, bribe);
            emit BuilderPaid(block.coinbase, bribe);
        }

        uint256 refund = provided - successfulValue - bribe;
        if (refund != 0) {
            (bool refundOK,) = payable(owner).call{value: refund}("");
            if (!refundOK) revert PaymentFailed(owner, refund);
            emit Refunded(owner, refund);
        }
    }

    receive() external payable {}
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    ":forge-std/=lib/forge-std/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.