ETH Price: $3,260.54 (+3.33%)

Contract Diff Checker

Contract Name:
RelayReceiver

Contract Source Code:

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

contract RelayReceiver {
    // --- Structs ---

    struct Call {
        address to;
        bytes data;
        uint256 value;
    }

    // --- Errors ---

    error CallFailed();
    error NativeTransferFailed();
    error Unauthorized();

    // --- Events ---

    event FundsForwarded();
    event FundsForwardedWithData(bytes data);

    // --- Fields ---

    address private immutable SOLVER;

    // --- Constructor ---

    constructor(address solver) {
        SOLVER = solver;
    }

    // --- Public methods ---

    receive() external payable {
        send(SOLVER, msg.value);
        emit FundsForwarded();
    }

    fallback() external payable {
        send(SOLVER, msg.value);
        emit FundsForwardedWithData(msg.data);
    }

    function forward(bytes calldata data) external payable {
        send(SOLVER, msg.value);
        emit FundsForwardedWithData(data);
    }

    // --- Restricted methods ---

    function makeCalls(Call[] calldata calls) external payable {
        if (msg.sender != SOLVER) {
            revert Unauthorized();
        }

        unchecked {
            uint256 length = calls.length;
            for (uint256 i; i < length; i++) {
                Call memory c = calls[i];

                (bool success, ) = c.to.call{value: c.value}(c.data);
                if (!success) {
                    revert CallFailed();
                }
            }
        }
    }

    // --- Internal methods ---

    function send(address to, uint256 value) internal {
        bool success;
        assembly {
            // Save gas by avoiding copying the return data to memory.
            // Provide at most 100k gas to the internal call, which is
            // more than enough to cover common use-cases of logic for
            // receiving native tokens (eg. SCW payable fallbacks).
            success := call(100000, to, value, 0, 0, 0, 0)
        }

        if (!success) {
            revert NativeTransferFailed();
        }
    }
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):