ETH Price: $1,905.01 (+0.02%)
Gas: 20 Gwei
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multi Chain

Multichain Addresses

1 address found via
Transaction Hash
Method
Block
From
To
Value
0x60a06040161831982022-12-14 13:21:23171 days 21 hrs ago1671024083IN
 Create: ExecWithSigsFacet
0 ETH0.27073746140

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ExecWithSigsFacet

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 18 : ExecWithSigsFacet.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import {BFacetOwner} from "../facets/base/BFacetOwner.sol";
import {LibDiamond} from "../libraries/diamond/standard/LibDiamond.sol";
import {ExecWithSigsBase} from "./base/ExecWithSigsBase.sol";
import {GelatoCallUtils} from "../libraries/GelatoCallUtils.sol";
import {
    _getBalance,
    _simulateAndRevert,
    _revertWithFee
} from "../functions/Utils.sol";
import {
    ExecWithSigs,
    ExecWithSigsFeeCollector,
    ExecWithSigsRelayContext,
    Message,
    MessageFeeCollector,
    MessageRelayContext
} from "../types/CallTypes.sol";
import {_isCheckerSigner} from "./storage/SignerStorage.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {
    _encodeRelayContext,
    _encodeFeeCollector
} from "@gelatonetwork/relay-context/contracts/functions/GelatoRelayUtils.sol";

contract ExecWithSigsFacet is ExecWithSigsBase, BFacetOwner {
    using GelatoCallUtils for address;
    using LibDiamond for address;

    //solhint-disable-next-line const-name-snakecase
    string public constant name = "ExecWithSigsFacet";
    //solhint-disable-next-line const-name-snakecase
    string public constant version = "1";

    address public immutable feeCollector;

    event LogExecWithSigs(
        bytes32 correlationId,
        Message msg,
        address indexed executorSigner,
        address indexed checkerSigner,
        uint256 estimatedGasUsed,
        address sender
    );

    event LogExecWithSigsFeeCollector(
        bytes32 correlationId,
        MessageFeeCollector msg,
        address indexed executorSigner,
        address indexed checkerSigner,
        uint256 fee,
        uint256 estimatedGasUsed,
        address sender
    );

    event LogExecWithSigsRelayContext(
        bytes32 correlationId,
        MessageRelayContext msg,
        address indexed executorSigner,
        address indexed checkerSigner,
        uint256 observedFee,
        uint256 estimatedGasUsed,
        address sender
    );

    constructor(address _feeCollector) {
        feeCollector = _feeCollector;
    }

    // solhint-disable function-max-lines
    /// @param _call Execution payload packed into ExecWithSigs struct
    /// @return estimatedGasUsed Estimated gas used using gas metering
    function execWithSigs(ExecWithSigs calldata _call)
        external
        returns (uint256 estimatedGasUsed)
    {
        uint256 startGas = gasleft();

        _requireSignerDeadline(
            _call.msg.deadline,
            "ExecWithSigsFacet.execWithSigs._requireSignerDeadline:"
        );

        bytes32 digest = _getDigest(_getDomainSeparator(), _call.msg);

        address executorSigner = _requireExecutorSignerSignature(
            digest,
            _call.executorSignerSig,
            "ExecWithSigsFacet.execWithSigs._requireExecutorSignerSignature:"
        );

        address checkerSigner = _requireCheckerSignerSignature(
            digest,
            _call.checkerSignerSig,
            "ExecWithSigsFacet.execWithSigs._requireCheckerSignerSignature:"
        );

        // call forward
        _call.msg.service.revertingContractCall(
            _call.msg.data,
            "ExecWithSigsFacet.execWithSigs:"
        );

        estimatedGasUsed = startGas - gasleft();

        emit LogExecWithSigs(
            _call.correlationId,
            _call.msg,
            executorSigner,
            checkerSigner,
            estimatedGasUsed,
            msg.sender
        );
    }

    // solhint-disable function-max-lines
    /// @param _call Execution payload packed into ExecWithSigsFeeCollector struct
    /// @return estimatedGasUsed Estimated gas used using gas metering
    /// @return observedFee The fee transferred to the fee collector
    function execWithSigsFeeCollector(ExecWithSigsFeeCollector calldata _call)
        external
        returns (uint256 estimatedGasUsed, uint256 observedFee)
    {
        uint256 startGas = gasleft();

        _requireSignerDeadline(
            _call.msg.deadline,
            "ExecWithSigsFacet.execWithSigsFeeCollector._requireSignerDeadline:"
        );

        bytes32 digest = _getDigestFeeCollector(
            _getDomainSeparator(),
            _call.msg
        );

        address executorSigner = _requireExecutorSignerSignature(
            digest,
            _call.executorSignerSig,
            "ExecWithSigsFacet.execWithSigsFeeCollector._requireExecutorSignerSignature:"
        );

        address checkerSigner = _requireCheckerSignerSignature(
            digest,
            _call.checkerSignerSig,
            "ExecWithSigsFacet.execWithSigsFeeCollector._requireCheckerSignerSignature:"
        );

        {
            uint256 preFeeTokenBalance = _getBalance(
                _call.msg.feeToken,
                feeCollector
            );

            // call forward + append fee collector
            _call.msg.service.revertingContractCall(
                _encodeFeeCollector(_call.msg.data, feeCollector),
                "ExecWithSigsFacet.execWithSigsFeeCollector:"
            );

            uint256 postFeeTokenBalance = _getBalance(
                _call.msg.feeToken,
                feeCollector
            );

            observedFee = postFeeTokenBalance - preFeeTokenBalance;
        }

        estimatedGasUsed = startGas - gasleft();

        emit LogExecWithSigsFeeCollector(
            _call.correlationId,
            _call.msg,
            executorSigner,
            checkerSigner,
            observedFee,
            estimatedGasUsed,
            msg.sender
        );
    }

    // solhint-disable function-max-lines
    /// @param _call Execution payload packed into ExecWithSigsRelayContext struct
    /// @return estimatedGasUsed Estimated gas used using gas metering
    /// @return observedFee The fee transferred to the fee collector
    function execWithSigsRelayContext(ExecWithSigsRelayContext calldata _call)
        external
        returns (uint256 estimatedGasUsed, uint256 observedFee)
    {
        uint256 startGas = gasleft();

        _requireSignerDeadline(
            _call.msg.deadline,
            "ExecWithSigsFacet.execWithSigsRelayContext._requireSignerDeadline:"
        );

        bytes32 digest = _getDigestRelayContext(
            _getDomainSeparator(),
            _call.msg
        );

        address executorSigner = _requireExecutorSignerSignature(
            digest,
            _call.executorSignerSig,
            "ExecWithSigsFacet.execWithSigsRelayContext._requireExecutorSignerSignature:"
        );

        address checkerSigner = _requireCheckerSignerSignature(
            digest,
            _call.checkerSignerSig,
            "ExecWithSigsFacet.execWithSigsRelayContext._requireCheckerSignerSignature:"
        );

        {
            uint256 preFeeTokenBalance = _getBalance(
                _call.msg.feeToken,
                feeCollector
            );

            // call forward + append fee collector, feeToken, fee
            _call.msg.service.revertingContractCall(
                _encodeRelayContext(
                    _call.msg.data,
                    feeCollector,
                    _call.msg.feeToken,
                    _call.msg.fee
                ),
                "ExecWithSigsFacet.execWithSigsRelayContext:"
            );

            uint256 postFeeTokenBalance = _getBalance(
                _call.msg.feeToken,
                feeCollector
            );

            observedFee = postFeeTokenBalance - preFeeTokenBalance;
        }

        estimatedGasUsed = startGas - gasleft();

        emit LogExecWithSigsRelayContext(
            _call.correlationId,
            _call.msg,
            executorSigner,
            checkerSigner,
            observedFee,
            estimatedGasUsed,
            msg.sender
        );
    }

    /// @dev Used for off-chain simulation only!
    function simulateExecWithSigs(address _service, bytes memory _data)
        external
    {
        _simulateAndRevert(_service, gasleft(), _data);
    }

    /// @dev Used for off-chain simulation only!
    function simulateExecWithSigsFeeCollector(
        address _service,
        bytes calldata _data,
        address _feeToken
    ) external {
        uint256 startGas = gasleft();

        uint256 preFeeTokenBalance = _getBalance(_feeToken, feeCollector);

        (bool success, ) = _service.call(
            _encodeFeeCollector(_data, feeCollector)
        );

        uint256 postFeeTokenBalance = _getBalance(_feeToken, feeCollector);

        _revertWithFee(
            success,
            startGas - gasleft(),
            postFeeTokenBalance - preFeeTokenBalance
        );
    }

    /// @dev Used for off-chain simulation only!
    function simulateExecWithSigsRelayContext(
        address _service,
        bytes calldata _data,
        address _feeToken,
        uint256 _fee
    ) external {
        uint256 startGas = gasleft();

        uint256 preFeeTokenBalance = _getBalance(_feeToken, feeCollector);

        (bool success, ) = _service.call(
            _encodeRelayContext(_data, feeCollector, _feeToken, _fee)
        );

        uint256 postFeeTokenBalance = _getBalance(_feeToken, feeCollector);

        _revertWithFee(
            success,
            startGas - gasleft(),
            postFeeTokenBalance - preFeeTokenBalance
        );
    }

    //solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32) {
        return _getDomainSeparator();
    }

    function _getDomainSeparator() internal view returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    keccak256(
                        bytes(
                            //solhint-disable-next-line max-line-length
                            "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
                        )
                    ),
                    keccak256(bytes(name)),
                    keccak256(bytes(version)),
                    block.chainid,
                    address(this)
                )
            );
    }
}

File 2 of 18 : GelatoRelayUtils.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;

// Four different types of calldata packing
// 1. encodeFeeCollector: append 20 byte feeCollector address
// 2. encodeRelayContext: append 20 byte feeCollector address, 20 byte feeToken address, 32 byte uint256 fee
// 3. encodeFeeCollectorERC2771: append 20 byte feeCollector address, 20 byte _msgSender address
// 4. encodeRelayContextERC2771: append 20 byte feeCollector address, 20 byte feeToken address, 32 byte uint256 fee, 20 byte _msgSender address

function _encodeFeeCollector(bytes calldata _data, address _feeCollector)
    pure
    returns (bytes memory)
{
    return abi.encodePacked(_data, _feeCollector);
}

function _encodeRelayContext(
    bytes calldata _data,
    address _feeCollector,
    address _feeToken,
    uint256 _fee
) pure returns (bytes memory) {
    return abi.encodePacked(_data, _feeCollector, _feeToken, _fee);
}

// ERC2771 Encodings

// vanilla ERC2771 context encoding
// solhint-disable-next-line private-vars-leading-underscore, func-visibility
function _encodeERC2771Context(bytes calldata _data, address _msgSender)
    pure
    returns (bytes memory)
{
    return abi.encodePacked(_data, _msgSender);
}

function _encodeFeeCollectorERC2771(
    bytes calldata _data,
    address _feeCollector,
    address _msgSender
) pure returns (bytes memory) {
    return abi.encodePacked(_data, _feeCollector, _msgSender);
}

function _encodeRelayContextERC2771(
    bytes calldata _data,
    address _feeCollector,
    address _feeToken,
    uint256 _fee,
    address _msgSender
) pure returns (bytes memory) {
    return abi.encodePacked(_data, _feeCollector, _feeToken, _fee, _msgSender);
}

File 3 of 18 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount
    ) external returns (bool);
}

File 4 of 18 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}

File 5 of 18 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.3) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        } else if (error == RecoverError.InvalidSignatureV) {
            revert("ECDSA: invalid signature 'v' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }
        if (v != 27 && v != 28) {
            return (address(0), RecoverError.InvalidSignatureV);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}

File 6 of 18 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 *  Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
 *  See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 *  In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        return _values(set._inner);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

File 7 of 18 : Tokens.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

address constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

File 8 of 18 : BFacetOwner.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import {LibDiamond} from "../../libraries/diamond/standard/LibDiamond.sol";

abstract contract BFacetOwner {
    modifier onlyOwner() {
        LibDiamond.enforceIsContractOwner();
        _;
    }
}

File 9 of 18 : ExecWithSigsBase.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import {GelatoString} from "../../libraries/GelatoString.sol";
import {
    _wasSignatureUsedAlready,
    _setWasSignatureUsedAlready
} from "../storage/ExecWithSigsStorage.sol";
import {
    _isExecutorSigner,
    _isCheckerSigner
} from "../storage/SignerStorage.sol";
import {
    ExecWithSigs,
    Message,
    ExecWithSigsFeeCollector,
    MessageFeeCollector,
    ExecWithSigsRelayContext,
    MessageRelayContext
} from "../../types/CallTypes.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

abstract contract ExecWithSigsBase {
    using GelatoString for string;

    bytes32 public constant MESSAGE_TYPEHASH =
        keccak256(
            bytes(
                // solhint-disable-next-line max-line-length
                "Message(address service,bytes data,uint256 salt,uint256 deadline)"
            )
        );

    bytes32 public constant MESSAGE_FEE_COLLECTOR_TYPEHASH =
        keccak256(
            bytes(
                // solhint-disable-next-line max-line-length
                "MessageFeeCollector(address service,bytes data,uint256 salt,uint256 deadline,address feeToken)"
            )
        );

    bytes32 public constant MESSAGE_RELAY_CONTEXT_TYPEHASH =
        keccak256(
            bytes(
                // solhint-disable-next-line max-line-length
                "MessageRelayContext(address service,bytes data,uint256 salt,uint256 deadline,address feeToken,uint256 fee)"
            )
        );

    function _requireSignerDeadline(
        uint256 _signerDeadline,
        string memory _errorTrace
    ) internal view {
        require(
            // solhint-disable-next-line not-rely-on-time
            _signerDeadline == 0 || _signerDeadline >= block.timestamp,
            _errorTrace.suffix("deadline")
        );
    }

    function _requireExecutorSignerSignature(
        bytes32 _digest,
        bytes calldata _executorSignerSig,
        string memory _errorTrace
    ) internal returns (address executorSigner) {
        require(
            !_wasSignatureUsedAlready(_executorSignerSig),
            _errorTrace.suffix("replay")
        );

        ECDSA.RecoverError error;
        (executorSigner, error) = ECDSA.tryRecover(_digest, _executorSignerSig);

        require(
            error == ECDSA.RecoverError.NoError &&
                _isExecutorSigner(executorSigner),
            _errorTrace.suffix("ECDSA.RecoverError.NoError && isExecutorSigner")
        );

        _setWasSignatureUsedAlready(_executorSignerSig);
    }

    function _requireCheckerSignerSignature(
        bytes32 _digest,
        bytes calldata _checkerSignerSig,
        string memory _errorTrace
    ) internal returns (address checkerSigner) {
        require(
            !_wasSignatureUsedAlready(_checkerSignerSig),
            _errorTrace.suffix("replay")
        );

        ECDSA.RecoverError error;
        (checkerSigner, error) = ECDSA.tryRecover(_digest, _checkerSignerSig);

        require(
            error == ECDSA.RecoverError.NoError &&
                _isCheckerSigner(checkerSigner),
            _errorTrace.suffix("ECDSA.RecoverError.NoError && isCheckerSigner")
        );

        _setWasSignatureUsedAlready(_checkerSignerSig);
    }

    function _getDigest(bytes32 _domainSeparator, Message calldata _msg)
        internal
        pure
        returns (bytes32 digest)
    {
        digest = keccak256(
            abi.encodePacked(
                "\x19\x01",
                _domainSeparator,
                keccak256(_abiEncodeExecWithSigs(_msg))
            )
        );
    }

    function _getDigestFeeCollector(
        bytes32 _domainSeparator,
        MessageFeeCollector calldata _msg
    ) internal pure returns (bytes32 digest) {
        digest = keccak256(
            abi.encodePacked(
                "\x19\x01",
                _domainSeparator,
                keccak256(_abiEncodeExecWithSigsFeeCollector(_msg))
            )
        );
    }

    function _getDigestRelayContext(
        bytes32 _domainSeparator,
        MessageRelayContext calldata _msg
    ) internal pure returns (bytes32 digest) {
        digest = keccak256(
            abi.encodePacked(
                "\x19\x01",
                _domainSeparator,
                keccak256(_abiEncodeExecWithSigsRelayContext(_msg))
            )
        );
    }

    function _abiEncodeExecWithSigs(Message calldata _msg)
        internal
        pure
        returns (bytes memory)
    {
        return
            abi.encode(
                MESSAGE_TYPEHASH,
                _msg.service,
                keccak256(_msg.data),
                _msg.salt,
                _msg.deadline
            );
    }

    function _abiEncodeExecWithSigsFeeCollector(
        MessageFeeCollector calldata _msg
    ) internal pure returns (bytes memory) {
        return
            abi.encode(
                MESSAGE_FEE_COLLECTOR_TYPEHASH,
                _msg.service,
                keccak256(_msg.data),
                _msg.salt,
                _msg.deadline,
                _msg.feeToken
            );
    }

    function _abiEncodeExecWithSigsRelayContext(
        MessageRelayContext calldata _msg
    ) internal pure returns (bytes memory) {
        return
            abi.encode(
                MESSAGE_RELAY_CONTEXT_TYPEHASH,
                _msg.service,
                keccak256(_msg.data),
                _msg.salt,
                _msg.deadline,
                _msg.feeToken,
                _msg.fee
            );
    }
}

File 10 of 18 : ExecWithSigsStorage.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

struct ExecWithSigsStorage {
    mapping(bytes32 => bool) wasSignatureUsedAlready;
}

bytes32 constant _EXEC_WITH_SIGS_STORAGE = keccak256(
    "gelato.diamond.execWithSigs.storage"
);

function _wasSignatureUsedAlready(bytes calldata _signature)
    view
    returns (bool)
{
    return
        _execWithSigsStorage().wasSignatureUsedAlready[keccak256(_signature)];
}

function _setWasSignatureUsedAlready(bytes calldata _signature) {
    _execWithSigsStorage().wasSignatureUsedAlready[
        keccak256(_signature)
    ] = true;
}

//solhint-disable-next-line private-vars-leading-underscore
function _execWithSigsStorage()
    pure
    returns (ExecWithSigsStorage storage ewss)
{
    bytes32 position = _EXEC_WITH_SIGS_STORAGE;
    assembly {
        ewss.slot := position
    }
}

File 11 of 18 : SignerStorage.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import {
    EnumerableSet
} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

using EnumerableSet for EnumerableSet.AddressSet;

struct SignerStorage {
    EnumerableSet.AddressSet executorSigners;
    EnumerableSet.AddressSet checkerSigners;
}

bytes32 constant _SIGNER_STORAGE_POSITION = keccak256(
    "gelato.diamond.signer.storage"
);

function _addExecutorSigner(address _executor) returns (bool) {
    return _signerStorage().executorSigners.add(_executor);
}

function _removeExecutorSigner(address _executor) returns (bool) {
    return _signerStorage().executorSigners.remove(_executor);
}

function _isExecutorSigner(address _executorSigner) view returns (bool) {
    return _signerStorage().executorSigners.contains(_executorSigner);
}

function _executorSignerAt(uint256 _index) view returns (address) {
    return _signerStorage().executorSigners.at(_index);
}

function _executorSigners() view returns (address[] memory) {
    return _signerStorage().executorSigners.values();
}

function _numberOfExecutorSigners() view returns (uint256) {
    return _signerStorage().executorSigners.length();
}

function _addCheckerSigner(address _checker) returns (bool) {
    return _signerStorage().checkerSigners.add(_checker);
}

function _removeCheckerSigner(address _checker) returns (bool) {
    return _signerStorage().checkerSigners.remove(_checker);
}

function _isCheckerSigner(address _checker) view returns (bool) {
    return _signerStorage().checkerSigners.contains(_checker);
}

function _checkerSignerAt(uint256 _index) view returns (address) {
    return _signerStorage().checkerSigners.at(_index);
}

function _checkerSigners() view returns (address[] memory checkers) {
    return _signerStorage().checkerSigners.values();
}

function _numberOfCheckerSigners() view returns (uint256) {
    return _signerStorage().checkerSigners.length();
}

function _signerStorage() pure returns (SignerStorage storage ess) {
    bytes32 position = _SIGNER_STORAGE_POSITION;
    assembly {
        ess.slot := position
    }
}

File 12 of 18 : Utils.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import {NATIVE_TOKEN} from "../constants/Tokens.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

function _getBalance(address token, address user) view returns (uint256) {
    if (token == address(0)) return 0;
    return token == NATIVE_TOKEN ? user.balance : IERC20(token).balanceOf(user);
}

function _simulateAndRevert(
    address _service,
    uint256 _gasleft,
    bytes memory _data
) {
    assembly {
        let success := call(
            gas(),
            _service,
            0,
            add(_data, 0x20),
            mload(_data),
            0,
            0
        )

        mstore(0x00, success) // store success bool in first word
        mstore(0x20, sub(_gasleft, gas())) // store gas after success
        mstore(0x40, returndatasize()) // store length of return data size in third word
        returndatacopy(0x60, 0, returndatasize()) // store actual return data in fourth word and onwards
        revert(0, add(returndatasize(), 0x60))
    }
}

function _revertWithFee(
    bool _success,
    uint256 _estimatedGasUsed,
    uint256 _observedFee
) pure {
    assembly {
        mstore(0x00, _success)
        mstore(0x20, _estimatedGasUsed)
        mstore(0x40, _observedFee)
        mstore(0x60, returndatasize())
        returndatacopy(0x80, 0, returndatasize())

        revert(0, add(returndatasize(), 0x80))
    }
}

File 13 of 18 : IDiamondCut.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamond Standard: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/

interface IDiamondCut {
    enum FacetCutAction {
        Add,
        Replace,
        Remove
    }
    // Add=0, Replace=1, Remove=2

    struct FacetCut {
        address facetAddress;
        FacetCutAction action;
        bytes4[] functionSelectors;
    }

    event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);

    /// @notice Add/replace/remove any number of functions and optionally execute
    ///         a function with delegatecall
    /// @param _diamondCut Contains the facet addresses and function selectors
    /// @param _init The address of the contract or facet to execute _calldata
    /// @param _calldata A function call, including function selector and arguments
    ///                  _calldata is executed with delegatecall on _init
    function diamondCut(
        FacetCut[] calldata _diamondCut,
        address _init,
        bytes calldata _calldata
    ) external;
}

File 14 of 18 : GelatoBytes.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

library GelatoBytes {
    function calldataSliceSelector(bytes calldata _bytes)
        internal
        pure
        returns (bytes4 selector)
    {
        selector =
            _bytes[0] |
            (bytes4(_bytes[1]) >> 8) |
            (bytes4(_bytes[2]) >> 16) |
            (bytes4(_bytes[3]) >> 24);
    }

    function memorySliceSelector(bytes memory _bytes)
        internal
        pure
        returns (bytes4 selector)
    {
        selector =
            _bytes[0] |
            (bytes4(_bytes[1]) >> 8) |
            (bytes4(_bytes[2]) >> 16) |
            (bytes4(_bytes[3]) >> 24);
    }

    function revertWithError(bytes memory _bytes, string memory _tracingInfo)
        internal
        pure
    {
        // 68: 32-location, 32-length, 4-ErrorSelector, UTF-8 err
        if (_bytes.length % 32 == 4) {
            bytes4 selector;
            assembly {
                selector := mload(add(0x20, _bytes))
            }
            if (selector == 0x08c379a0) {
                // Function selector for Error(string)
                assembly {
                    _bytes := add(_bytes, 68)
                }
                revert(string(abi.encodePacked(_tracingInfo, string(_bytes))));
            } else {
                revert(
                    string(abi.encodePacked(_tracingInfo, "NoErrorSelector"))
                );
            }
        } else {
            revert(
                string(abi.encodePacked(_tracingInfo, "UnexpectedReturndata"))
            );
        }
    }

    function returnError(bytes memory _bytes, string memory _tracingInfo)
        internal
        pure
        returns (string memory)
    {
        // 68: 32-location, 32-length, 4-ErrorSelector, UTF-8 err
        if (_bytes.length % 32 == 4) {
            bytes4 selector;
            assembly {
                selector := mload(add(0x20, _bytes))
            }
            if (selector == 0x08c379a0) {
                // Function selector for Error(string)
                assembly {
                    _bytes := add(_bytes, 68)
                }
                return string(abi.encodePacked(_tracingInfo, string(_bytes)));
            } else {
                return
                    string(abi.encodePacked(_tracingInfo, "NoErrorSelector"));
            }
        } else {
            return
                string(abi.encodePacked(_tracingInfo, "UnexpectedReturndata"));
        }
    }
}

File 15 of 18 : GelatoCallUtils.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import {GelatoBytes} from "./GelatoBytes.sol";

library GelatoCallUtils {
    using GelatoBytes for bytes;

    function revertingContractCall(
        address _contract,
        bytes memory _data,
        string memory _errorMsg
    ) internal returns (bytes memory returndata) {
        bool success;
        (success, returndata) = _contract.call(_data);

        // solhint-disable-next-line max-line-length
        // https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/f9b6fc3fdab7aca33a9cfa8837c5cd7f67e176be/contracts/utils/AddressUpgradeable.sol#L177
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(
                    isContract(_contract),
                    string(abi.encodePacked(_errorMsg, "Call to non contract"))
                );
            }
        } else {
            returndata.revertWithError(_errorMsg);
        }
    }

    // solhint-disable-next-line max-line-length
    // https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/f9b6fc3fdab7aca33a9cfa8837c5cd7f67e176be/contracts/utils/AddressUpgradeable.sol#L36
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }
}

File 16 of 18 : GelatoString.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

library GelatoString {
    function startsWithOK(string memory _str) internal pure returns (bool) {
        if (
            bytes(_str).length >= 2 &&
            bytes(_str)[0] == "O" &&
            bytes(_str)[1] == "K"
        ) return true;
        return false;
    }

    function revertWithInfo(string memory _error, string memory _tracingInfo)
        internal
        pure
    {
        revert(string(abi.encodePacked(_tracingInfo, _error)));
    }

    function prefix(string memory _second, string memory _first)
        internal
        pure
        returns (string memory)
    {
        return string(abi.encodePacked(_first, _second));
    }

    function suffix(string memory _first, string memory _second)
        internal
        pure
        returns (string memory)
    {
        return string(abi.encodePacked(_first, _second));
    }
}

File 17 of 18 : LibDiamond.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
// solhint-disable max-line-length
// https://github.com/mudgen/diamond-3/blob/b009cd08b7822bad727bbcc47aa1b50d8b50f7f0/contracts/libraries/LibDiamond.sol#L1

/******************************************************************************\
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* EIP-2535 Diamond Standard: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/

import "../../../interfaces/diamond/standard/IDiamondCut.sol";

// Custom due to incorrect string casting (non UTF-8 formatted)
import {GelatoBytes} from "../../../libraries/GelatoBytes.sol";

library LibDiamond {
    bytes32 constant DIAMOND_STORAGE_POSITION =
        keccak256("diamond.standard.diamond.storage");

    struct FacetAddressAndPosition {
        address facetAddress;
        uint16 functionSelectorPosition; // position in facetFunctionSelectors.functionSelectors array
    }

    struct FacetFunctionSelectors {
        bytes4[] functionSelectors;
        uint16 facetAddressPosition; // position of facetAddress in facetAddresses array
    }

    struct DiamondStorage {
        // maps function selector to the facet address and
        // the position of the selector in the facetFunctionSelectors.selectors array
        mapping(bytes4 => FacetAddressAndPosition) selectorToFacetAndPosition;
        // maps facet addresses to function selectors
        mapping(address => FacetFunctionSelectors) facetFunctionSelectors;
        // facet addresses
        address[] facetAddresses;
        // Used to query if a contract implements an interface.
        // Used to implement ERC-165.
        mapping(bytes4 => bool) supportedInterfaces;
        // owner of the contract
        address contractOwner;
    }

    function diamondStorage()
        internal
        pure
        returns (DiamondStorage storage ds)
    {
        bytes32 position = DIAMOND_STORAGE_POSITION;
        assembly {
            ds.slot := position
        }
    }

    event OwnershipTransferred(
        address indexed previousOwner,
        address indexed newOwner
    );

    function setContractOwner(address _newOwner) internal {
        DiamondStorage storage ds = diamondStorage();
        address previousOwner = ds.contractOwner;
        ds.contractOwner = _newOwner;
        emit OwnershipTransferred(previousOwner, _newOwner);
    }

    function contractOwner() internal view returns (address contractOwner_) {
        contractOwner_ = diamondStorage().contractOwner;
    }

    function isContractOwner(address _guy) internal view returns (bool) {
        return _guy == contractOwner();
    }

    function enforceIsContractOwner() internal view {
        require(
            msg.sender == diamondStorage().contractOwner,
            "LibDiamond: Must be contract owner"
        );
    }

    event DiamondCut(
        IDiamondCut.FacetCut[] _diamondCut,
        address _init,
        bytes _calldata
    );

    // Internal function version of diamondCut
    function diamondCut(
        IDiamondCut.FacetCut[] memory _diamondCut,
        address _init,
        bytes memory _calldata
    ) internal {
        for (
            uint256 facetIndex;
            facetIndex < _diamondCut.length;
            facetIndex++
        ) {
            IDiamondCut.FacetCutAction action = _diamondCut[facetIndex].action;
            if (action == IDiamondCut.FacetCutAction.Add) {
                addFunctions(
                    _diamondCut[facetIndex].facetAddress,
                    _diamondCut[facetIndex].functionSelectors
                );
            } else if (action == IDiamondCut.FacetCutAction.Replace) {
                replaceFunctions(
                    _diamondCut[facetIndex].facetAddress,
                    _diamondCut[facetIndex].functionSelectors
                );
            } else if (action == IDiamondCut.FacetCutAction.Remove) {
                removeFunctions(
                    _diamondCut[facetIndex].facetAddress,
                    _diamondCut[facetIndex].functionSelectors
                );
            } else {
                revert("LibDiamondCut: Incorrect FacetCutAction");
            }
        }
        emit DiamondCut(_diamondCut, _init, _calldata);
        initializeDiamondCut(_init, _calldata);
    }

    function addFunctions(
        address _facetAddress,
        bytes4[] memory _functionSelectors
    ) internal {
        require(
            _functionSelectors.length > 0,
            "LibDiamondCut: No selectors in facet to cut"
        );
        DiamondStorage storage ds = diamondStorage();
        // uint16 selectorCount = uint16(diamondStorage().selectors.length);
        require(
            _facetAddress != address(0),
            "LibDiamondCut: Add facet can't be address(0)"
        );
        uint16 selectorPosition = uint16(
            ds.facetFunctionSelectors[_facetAddress].functionSelectors.length
        );
        // add new facet address if it does not exist
        if (selectorPosition == 0) {
            enforceHasContractCode(
                _facetAddress,
                "LibDiamondCut: New facet has no code"
            );
            ds
                .facetFunctionSelectors[_facetAddress]
                .facetAddressPosition = uint16(ds.facetAddresses.length);
            ds.facetAddresses.push(_facetAddress);
        }
        for (
            uint256 selectorIndex;
            selectorIndex < _functionSelectors.length;
            selectorIndex++
        ) {
            bytes4 selector = _functionSelectors[selectorIndex];
            address oldFacetAddress = ds
                .selectorToFacetAndPosition[selector]
                .facetAddress;
            require(
                oldFacetAddress == address(0),
                "LibDiamondCut: Can't add function that already exists"
            );
            ds.facetFunctionSelectors[_facetAddress].functionSelectors.push(
                selector
            );
            ds
                .selectorToFacetAndPosition[selector]
                .facetAddress = _facetAddress;
            ds
                .selectorToFacetAndPosition[selector]
                .functionSelectorPosition = selectorPosition;
            selectorPosition++;
        }
    }

    function replaceFunctions(
        address _facetAddress,
        bytes4[] memory _functionSelectors
    ) internal {
        require(
            _functionSelectors.length > 0,
            "LibDiamondCut: No selectors in facet to cut"
        );
        DiamondStorage storage ds = diamondStorage();
        require(
            _facetAddress != address(0),
            "LibDiamondCut: Add facet can't be address(0)"
        );
        uint16 selectorPosition = uint16(
            ds.facetFunctionSelectors[_facetAddress].functionSelectors.length
        );
        // add new facet address if it does not exist
        if (selectorPosition == 0) {
            enforceHasContractCode(
                _facetAddress,
                "LibDiamondCut: New facet has no code"
            );
            ds
                .facetFunctionSelectors[_facetAddress]
                .facetAddressPosition = uint16(ds.facetAddresses.length);
            ds.facetAddresses.push(_facetAddress);
        }
        for (
            uint256 selectorIndex;
            selectorIndex < _functionSelectors.length;
            selectorIndex++
        ) {
            bytes4 selector = _functionSelectors[selectorIndex];
            address oldFacetAddress = ds
                .selectorToFacetAndPosition[selector]
                .facetAddress;
            require(
                oldFacetAddress != _facetAddress,
                "LibDiamondCut: Can't replace function with same function"
            );
            removeFunction(oldFacetAddress, selector);
            // add function
            ds
                .selectorToFacetAndPosition[selector]
                .functionSelectorPosition = selectorPosition;
            ds.facetFunctionSelectors[_facetAddress].functionSelectors.push(
                selector
            );
            ds
                .selectorToFacetAndPosition[selector]
                .facetAddress = _facetAddress;
            selectorPosition++;
        }
    }

    function removeFunctions(
        address _facetAddress,
        bytes4[] memory _functionSelectors
    ) internal {
        require(
            _functionSelectors.length > 0,
            "LibDiamondCut: No selectors in facet to cut"
        );
        DiamondStorage storage ds = diamondStorage();
        // if function does not exist then do nothing and return
        require(
            _facetAddress == address(0),
            "LibDiamondCut: Remove facet address must be address(0)"
        );
        for (
            uint256 selectorIndex;
            selectorIndex < _functionSelectors.length;
            selectorIndex++
        ) {
            bytes4 selector = _functionSelectors[selectorIndex];
            address oldFacetAddress = ds
                .selectorToFacetAndPosition[selector]
                .facetAddress;
            removeFunction(oldFacetAddress, selector);
        }
    }

    function removeFunction(address _facetAddress, bytes4 _selector) internal {
        DiamondStorage storage ds = diamondStorage();
        require(
            _facetAddress != address(0),
            "LibDiamondCut: Can't remove function that doesn't exist"
        );
        // an immutable function is a function defined directly in a diamond
        require(
            _facetAddress != address(this),
            "LibDiamondCut: Can't remove immutable function"
        );
        // replace selector with last selector, then delete last selector
        uint256 selectorPosition = ds
            .selectorToFacetAndPosition[_selector]
            .functionSelectorPosition;
        uint256 lastSelectorPosition = ds
            .facetFunctionSelectors[_facetAddress]
            .functionSelectors
            .length - 1;
        // if not the same then replace _selector with lastSelector
        if (selectorPosition != lastSelectorPosition) {
            bytes4 lastSelector = ds
                .facetFunctionSelectors[_facetAddress]
                .functionSelectors[lastSelectorPosition];
            ds.facetFunctionSelectors[_facetAddress].functionSelectors[
                    selectorPosition
                ] = lastSelector;
            ds
                .selectorToFacetAndPosition[lastSelector]
                .functionSelectorPosition = uint16(selectorPosition);
        }
        // delete the last selector
        ds.facetFunctionSelectors[_facetAddress].functionSelectors.pop();
        delete ds.selectorToFacetAndPosition[_selector];

        // if no more selectors for facet address then delete the facet address
        if (lastSelectorPosition == 0) {
            // replace facet address with last facet address and delete last facet address
            uint256 lastFacetAddressPosition = ds.facetAddresses.length - 1;
            uint256 facetAddressPosition = ds
                .facetFunctionSelectors[_facetAddress]
                .facetAddressPosition;
            if (facetAddressPosition != lastFacetAddressPosition) {
                address lastFacetAddress = ds.facetAddresses[
                    lastFacetAddressPosition
                ];
                ds.facetAddresses[facetAddressPosition] = lastFacetAddress;
                ds
                    .facetFunctionSelectors[lastFacetAddress]
                    .facetAddressPosition = uint16(facetAddressPosition);
            }
            ds.facetAddresses.pop();
            delete ds
                .facetFunctionSelectors[_facetAddress]
                .facetAddressPosition;
        }
    }

    function initializeDiamondCut(address _init, bytes memory _calldata)
        internal
    {
        if (_init == address(0)) {
            require(
                _calldata.length == 0,
                "LibDiamondCut: _init is address(0) but_calldata is not empty"
            );
        } else {
            require(
                _calldata.length > 0,
                "LibDiamondCut: _calldata is empty but _init is not address(0)"
            );
            if (_init != address(this)) {
                enforceHasContractCode(
                    _init,
                    "LibDiamondCut: _init address has no code"
                );
            }
            (bool success, bytes memory error) = _init.delegatecall(_calldata);
            if (!success) {
                if (error.length > 0) {
                    // bubble up the error
                    GelatoBytes.revertWithError(error, "LibDiamondCut:_init:");
                } else {
                    revert("LibDiamondCut: _init function reverted");
                }
            }
        }
    }

    function enforceHasContractCode(
        address _contract,
        string memory _errorMessage
    ) internal view {
        uint256 contractSize;
        assembly {
            contractSize := extcodesize(_contract)
        }
        require(contractSize > 0, _errorMessage);
    }
}

File 18 of 18 : CallTypes.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

struct Message {
    address service;
    bytes data;
    uint256 salt;
    uint256 deadline;
}

struct MessageFeeCollector {
    address service;
    bytes data;
    uint256 salt;
    uint256 deadline;
    address feeToken;
}

struct MessageRelayContext {
    address service;
    bytes data;
    uint256 salt;
    uint256 deadline;
    address feeToken;
    uint256 fee;
}

struct ExecWithSigs {
    bytes32 correlationId;
    Message msg;
    bytes executorSignerSig;
    bytes checkerSignerSig;
}

struct ExecWithSigsFeeCollector {
    bytes32 correlationId;
    MessageFeeCollector msg;
    bytes executorSignerSig;
    bytes checkerSignerSig;
}

struct ExecWithSigsRelayContext {
    bytes32 correlationId;
    MessageRelayContext msg;
    bytes executorSignerSig;
    bytes checkerSignerSig;
}

Settings
{
  "evmVersion": "london",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs",
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": [],
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_feeCollector","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"correlationId","type":"bytes32"},{"components":[{"internalType":"address","name":"service","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"indexed":false,"internalType":"struct Message","name":"msg","type":"tuple"},{"indexed":true,"internalType":"address","name":"executorSigner","type":"address"},{"indexed":true,"internalType":"address","name":"checkerSigner","type":"address"},{"indexed":false,"internalType":"uint256","name":"estimatedGasUsed","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"LogExecWithSigs","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"correlationId","type":"bytes32"},{"components":[{"internalType":"address","name":"service","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"address","name":"feeToken","type":"address"}],"indexed":false,"internalType":"struct MessageFeeCollector","name":"msg","type":"tuple"},{"indexed":true,"internalType":"address","name":"executorSigner","type":"address"},{"indexed":true,"internalType":"address","name":"checkerSigner","type":"address"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"estimatedGasUsed","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"LogExecWithSigsFeeCollector","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"correlationId","type":"bytes32"},{"components":[{"internalType":"address","name":"service","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"address","name":"feeToken","type":"address"},{"internalType":"uint256","name":"fee","type":"uint256"}],"indexed":false,"internalType":"struct MessageRelayContext","name":"msg","type":"tuple"},{"indexed":true,"internalType":"address","name":"executorSigner","type":"address"},{"indexed":true,"internalType":"address","name":"checkerSigner","type":"address"},{"indexed":false,"internalType":"uint256","name":"observedFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"estimatedGasUsed","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"LogExecWithSigsRelayContext","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MESSAGE_FEE_COLLECTOR_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MESSAGE_RELAY_CONTEXT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MESSAGE_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bytes32","name":"correlationId","type":"bytes32"},{"components":[{"internalType":"address","name":"service","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct Message","name":"msg","type":"tuple"},{"internalType":"bytes","name":"executorSignerSig","type":"bytes"},{"internalType":"bytes","name":"checkerSignerSig","type":"bytes"}],"internalType":"struct ExecWithSigs","name":"_call","type":"tuple"}],"name":"execWithSigs","outputs":[{"internalType":"uint256","name":"estimatedGasUsed","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes32","name":"correlationId","type":"bytes32"},{"components":[{"internalType":"address","name":"service","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"address","name":"feeToken","type":"address"}],"internalType":"struct MessageFeeCollector","name":"msg","type":"tuple"},{"internalType":"bytes","name":"executorSignerSig","type":"bytes"},{"internalType":"bytes","name":"checkerSignerSig","type":"bytes"}],"internalType":"struct ExecWithSigsFeeCollector","name":"_call","type":"tuple"}],"name":"execWithSigsFeeCollector","outputs":[{"internalType":"uint256","name":"estimatedGasUsed","type":"uint256"},{"internalType":"uint256","name":"observedFee","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes32","name":"correlationId","type":"bytes32"},{"components":[{"internalType":"address","name":"service","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"address","name":"feeToken","type":"address"},{"internalType":"uint256","name":"fee","type":"uint256"}],"internalType":"struct MessageRelayContext","name":"msg","type":"tuple"},{"internalType":"bytes","name":"executorSignerSig","type":"bytes"},{"internalType":"bytes","name":"checkerSignerSig","type":"bytes"}],"internalType":"struct ExecWithSigsRelayContext","name":"_call","type":"tuple"}],"name":"execWithSigsRelayContext","outputs":[{"internalType":"uint256","name":"estimatedGasUsed","type":"uint256"},{"internalType":"uint256","name":"observedFee","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeCollector","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_service","type":"address"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"simulateExecWithSigs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_service","type":"address"},{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"address","name":"_feeToken","type":"address"}],"name":"simulateExecWithSigsFeeCollector","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_service","type":"address"},{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"address","name":"_feeToken","type":"address"},{"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"simulateExecWithSigsRelayContext","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]

60a060405234801561001057600080fd5b506040516122cf3803806122cf83398101604081905261002f91610040565b6001600160a01b0316608052610070565b60006020828403121561005257600080fd5b81516001600160a01b038116811461006957600080fd5b9392505050565b6080516122056100ca600039600081816101d0015281816103160152818161035f01528181610467015281816104a001528181610521015281816108b5015281816109bd015281816109f60152610a7501526122056000f3fe608060405234801561001057600080fd5b50600436106100cf5760003560e01c8063544dd3951161008c57806383ec30771161006657806383ec3077146101c3578063c415b95c146101cb578063cd2cf3661461020a578063f111786a1461021d57600080fd5b8063544dd3951461018857806354fd4d501461019057806367c62fe0146101b057600080fd5b806306fdde03146100d45780630a4806ce1461011a5780631c367bc3146101425780633644e515146101575780634522589f1461016d57806346e356b114610180575b600080fd5b61010460405180604001604052806011815260200170115e1958d5da5d1a14da59dcd19858d95d607a1b81525081565b604051610111919061163e565b60405180910390f35b61012d610128366004611689565b610230565b60408051928352602083019190915201610111565b610155610150366004611724565b61045a565b005b61015f610570565b604051908152602001610111565b61015f61017b366004611689565b61057f565b61015f610745565b61015f610768565b610104604051806040016040528060018152602001603160f81b81525081565b6101556101be3660046117a7565b61078b565b61015f61079a565b6101f27f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610111565b61012d610218366004611689565b6107bd565b61015561022b366004611869565b6109b0565b60008060005a905061026a61024860208601866118ce565b606001356040518060800160405280604281526020016120ba60429139610ab4565b6000610289610277610b17565b61028460208801886118ce565b610bf2565b905060006102bc8261029e60408901896118ee565b6040518060800160405280604b8152602001611ec6604b9139610c48565b905060006102ef836102d160608a018a6118ee565b6040518060800160405280604a8152602001611f88604a9139610d66565b9050600061033a61030360208a018a6118ce565b6103149060a0810190608001611935565b7f0000000000000000000000000000000000000000000000000000000000000000610e52565b90506103c761038361034f60208b018b6118ce565b61035d9060208101906118ee565b7f0000000000000000000000000000000000000000000000000000000000000000610f12565b6040518060600160405280602b8152602001612166602b91396103a960208c018c6118ce565b6103b7906020810190611935565b6001600160a01b03169190610f41565b5060006103da61030360208b018b6118ce565b90506103e68282611950565b965050505a6103f59085611950565b95506001600160a01b038082169083167febee01ccf79a62d5083b2b10c32a7991d2c2acfc80c6d73c0380901c888ccbc1893561043560208c018c6118ce565b898b336040516104499594939291906119e0565b60405180910390a350505050915091565b60005a9050600061048b847f0000000000000000000000000000000000000000000000000000000000000000610e52565b90506000876001600160a01b03166104c688887f00000000000000000000000000000000000000000000000000000000000000008989611017565b6040516104d39190611a72565b6000604051808303816000865af19150503d8060008114610510576040519150601f19603f3d011682016040523d82523d6000602084013e610515565b606091505b505090506000610545867f0000000000000000000000000000000000000000000000000000000000000000610e52565b9050610565825a6105569087611950565b6105608685611950565b61104c565b505050505050505050565b600061057a610b17565b905090565b6000805a90506105b76105956020850185611a84565b60600135604051806060016040528060368152602001611f1160369139610ab4565b60006105d66105c4610b17565b6105d16020870187611a84565b61106a565b90506000610609826105eb60408801886118ee565b6040518060600160405280603f8152602001612191603f9139610c48565b9050600061063c8361061e60608901896118ee565b6040518060600160405280603e815260200161204f603e9139610d66565b90506106d661064e6020880188611a84565b61065c9060208101906118ee565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505060408051808201909152601f81527f45786563576974685369677346616365742e6578656357697468536967733a006020808301919091529092506103a991508a018a611a84565b505a6106e29085611950565b94506001600160a01b038082169083167f7bfffe4b1a7ee0d5ebb45f7d8b0eea0a4ddfa94221b2325b850e5a5925e5e970883561072260208b018b611a84565b89336040516107349493929190611a9a565b60405180910390a350505050919050565b604051806080016040528060418152602001611f47604191398051906020012081565b6040518060a00160405280606a81526020016120fc606a91398051906020012081565b610796825a83611076565b5050565b6040518060800160405280605e8152602001611dad605e91398051906020012081565b60008060005a90506107f76107d56020860186611b0f565b60600135604051806080016040528060428152602001611e8460429139610ab4565b6000610816610804610b17565b6108116020880188611b0f565b61109f565b905060006108498261082b60408901896118ee565b6040518060800160405280604b8152602001611e39604b9139610c48565b9050600061087c8361085e60608a018a6118ee565b6040518060800160405280604a8152602001611d63604a9139610d66565b9050600061089061030360208a018a611b0f565b905061092e6109086108a560208b018b611b0f565b6108b39060208101906118ee565b7f00000000000000000000000000000000000000000000000000000000000000006108e160208e018e611b0f565b6108f29060a0810190608001611935565b6108ff60208f018f611b0f565b60a00135611017565b6040518060600160405280602b8152602001612024602b91396103a960208c018c611b0f565b50600061094161030360208b018b611b0f565b905061094d8282611950565b965050505a61095c9085611950565b95506001600160a01b038082169083167fa5c57cb93d2124da6530c224fa6138483ff7ecd2959d2dad024a9d050076cc1a893561099c60208c018c611b0f565b898b33604051610449959493929190611b25565b60005a905060006109e1837f0000000000000000000000000000000000000000000000000000000000000000610e52565b90506000866001600160a01b0316610a1a87877f0000000000000000000000000000000000000000000000000000000000000000610f12565b604051610a279190611a72565b6000604051808303816000865af19150503d8060008114610a64576040519150601f19603f3d011682016040523d82523d6000602084013e610a69565b606091505b505090506000610a99857f0000000000000000000000000000000000000000000000000000000000000000610e52565b9050610aaa825a6105569087611950565b5050505050505050565b811580610ac15750428210155b604080518082019091526008815267646561646c696e6560c01b6020820152610aeb9083906110ab565b90610b125760405162461bcd60e51b8152600401610b09919061163e565b60405180910390fd5b505050565b6000604051806080016040528060528152602001611fd26052913980516020918201206040805180820182526011815270115e1958d5da5d1a14da59dcd19858d95d607a1b908401528051808201825260018152603160f81b908401528051928301919091527f176566dd3634ff88354f49a20832f5507a82745dc224d42b5843c5e757ade4b5908201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b600082610bfe836110d7565b8051602091820120604051610c2a93920161190160f01b81526002810192909252602282015260420190565b60405160208183030381529060405280519060200120905092915050565b6000610c548484611197565b15610c86604051806040016040528060068152602001657265706c617960d01b815250846110ab90919063ffffffff16565b90610ca45760405162461bcd60e51b8152600401610b09919061163e565b506000610ce78686868080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506111f192505050565b90925090506000816004811115610d0057610d00611bd2565b148015610d115750610d1182611236565b610d346040518060600160405280602e8152602001611e0b602e913985906110ab565b90610d525760405162461bcd60e51b8152600401610b09919061163e565b50610d5d8585611280565b50949350505050565b6000610d728484611197565b15610da4604051806040016040528060068152602001657265706c617960d01b815250846110ab90919063ffffffff16565b90610dc25760405162461bcd60e51b8152600401610b09919061163e565b506000610e058686868080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506111f192505050565b90925090506000816004811115610e1e57610e1e611bd2565b148015610e2f5750610e2f826112e7565b610d346040518060600160405280602d815260200161208d602d913985906110ab565b60006001600160a01b038316610e6a57506000610f0c565b6001600160a01b03831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee14610efd576040516370a0823160e01b81526001600160a01b0383811660048301528416906370a0823190602401602060405180830381865afa158015610ed4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ef89190611be8565b610f09565b816001600160a01b0316315b90505b92915050565b6060838383604051602001610f2993929190611c01565b60405160208183030381529060405290509392505050565b60606000846001600160a01b031684604051610f5d9190611a72565b6000604051808303816000865af19150503d8060008114610f9a576040519150601f19603f3d011682016040523d82523d6000602084013e610f9f565b606091505b50925090508015611005578151600003611000576001600160a01b0385163b151583604051602001610fd19190611c27565b60405160208183030381529060405290610ffe5760405162461bcd60e51b8152600401610b09919061163e565b505b61100f565b61100f8284611350565b509392505050565b60608585858585604051602001611032959493929190611c5f565b604051602081830303815290604052905095945050505050565b8260005281602052806040523d6060523d600060803e60803d016000fd5b600082610bfe836113e2565b6000808251602084016000875af16000525a82036020523d6040523d600060603e60603d016000fd5b600082610bfe83611471565b606082826040516020016110c0929190611c96565b604051602081830303815290604052905092915050565b60606040518060800160405280605e8152602001611dad605e913980516020918201209061110790840184611935565b61111460208501856118ee565b604051611122929190611cc5565b6040518091039020846040013585606001358660800160208101906111479190611935565b6040805160208101979097526001600160a01b03958616908701526060860193909352608085019190915260a08401521660c082015260e0015b6040516020818303038152906040529050919050565b60007f90f0bdc952e556bcffe177d42d0a1e2c48fc4212efc230d6acee71a6d61164446040516000906111cd9086908690611cc5565b604080519182900390912082526020820192909252016000205460ff169392505050565b60008082516041036112275760208301516040840151606085015160001a61121b8782858561152d565b9450945050505061122f565b506000905060025b9250929050565b6000610f0c827fdee078fadc21593590e9046d81e4518a7b3feb16bdee74b2d2488cd4455264d0906001600160a01b03811660009081526001830160205260408120541515610f09565b60017f90f0bdc952e556bcffe177d42d0a1e2c48fc4212efc230d6acee71a6d61164446040516000906112b69086908690611cc5565b6040518091039020815260200190815260200160002060006101000a81548160ff0219169083151502179055505050565b6001600160a01b03811660009081527fdee078fadc21593590e9046d81e4518a7b3feb16bdee74b2d2488cd4455264d36020526040812054610f0c907fdee078fadc21593590e9046d81e4518a7b3feb16bdee74b2d2488cd4455264d290849084901515610f09565b6020825161135e9190611cd5565b6004036113d15760208201516001600160e01b0319811662461bcd60e51b036113c057604483019250818360405160200161139a929190611c96565b60408051601f198184030181529082905262461bcd60e51b8252610b099160040161163e565b8160405160200161139a9190611cf7565b8060405160200161139a9190611d2a565b6060604051806080016040528060418152602001611f476041913980516020918201209061141290840184611935565b61141f60208501856118ee565b60405161142d929190611cc5565b6040805191829003822060208301949094526001600160a01b03909216818301526060808201939093529084013560808201529083013560a082015260c001611181565b60606040518060a00160405280606a81526020016120fc606a91398051602091820120906114a190840184611935565b6114ae60208501856118ee565b6040516114bc929190611cc5565b6040518091039020846040013585606001358660800160208101906114e19190611935565b6040805160208101979097526001600160a01b03958616908701526060860193909352608085019190915260a084810191909152911660c083015283013560e082015261010001611181565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156115645750600090506003611611565b8460ff16601b1415801561157c57508460ff16601c14155b1561158d5750600090506004611611565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa1580156115e1573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661160a57600060019250925050611611565b9150600090505b94509492505050565b60005b8381101561163557818101518382015260200161161d565b50506000910152565b602081526000825180602084015261165d81604085016020870161161a565b601f01601f19169190910160400192915050565b60006080828403121561168357600080fd5b50919050565b60006020828403121561169b57600080fd5b813567ffffffffffffffff8111156116b257600080fd5b6116be84828501611671565b949350505050565b80356001600160a01b03811681146116dd57600080fd5b919050565b60008083601f8401126116f457600080fd5b50813567ffffffffffffffff81111561170c57600080fd5b60208301915083602082850101111561122f57600080fd5b60008060008060006080868803121561173c57600080fd5b611745866116c6565b9450602086013567ffffffffffffffff81111561176157600080fd5b61176d888289016116e2565b90955093506117809050604087016116c6565b949793965091946060013592915050565b634e487b7160e01b600052604160045260246000fd5b600080604083850312156117ba57600080fd5b6117c3836116c6565b9150602083013567ffffffffffffffff808211156117e057600080fd5b818501915085601f8301126117f457600080fd5b81358181111561180657611806611791565b604051601f8201601f19908116603f0116810190838211818310171561182e5761182e611791565b8160405282815288602084870101111561184757600080fd5b8260208601602083013760006020848301015280955050505050509250929050565b6000806000806060858703121561187f57600080fd5b611888856116c6565b9350602085013567ffffffffffffffff8111156118a457600080fd5b6118b0878288016116e2565b90945092506118c39050604086016116c6565b905092959194509250565b60008235609e198336030181126118e457600080fd5b9190910192915050565b6000808335601e1984360301811261190557600080fd5b83018035915067ffffffffffffffff82111561192057600080fd5b60200191503681900382131561122f57600080fd5b60006020828403121561194757600080fd5b610f09826116c6565b81810381811115610f0c57634e487b7160e01b600052601160045260246000fd5b6000808335601e1984360301811261198857600080fd5b830160208101925035905067ffffffffffffffff8111156119a857600080fd5b80360382131561122f57600080fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b85815260a0602082015260006001600160a01b03806119fe886116c6565b1660a0840152611a116020880188611971565b60a060c0860152611a27610140860182846119b7565b915050604088013560e0850152606088013561010085015281611a4c60808a016116c6565b166101208501526040840196909652606083019490945250911660809091015292915050565b600082516118e481846020870161161a565b60008235607e198336030181126118e457600080fd5b8481526080602082015260006001600160a01b0380611ab8876116c6565b166080840152611acb6020870187611971565b608060a0860152611ae1610100860182846119b7565b60408981013560c08801526060998a013560e088015286019790975250509290921693019290925292915050565b6000823560be198336030181126118e457600080fd5b85815260a0602082015260006001600160a01b0380611b43886116c6565b1660a0840152611b566020880188611971565b60c080860152611b6b610160860182846119b7565b915050604088013560e0850152606088013561010085015281611b9060808a016116c6565b1661012085015260a08801356101408501528092505050846040830152836060830152611bc860808301846001600160a01b03169052565b9695505050505050565b634e487b7160e01b600052602160045260246000fd5b600060208284031215611bfa57600080fd5b5051919050565b8284823760609190911b6bffffffffffffffffffffffff19169101908152601401919050565b60008251611c3981846020870161161a565b7310d85b1b081d1bc81b9bdb8818dbdb9d1c9858dd60621b920191825250601401919050565b848682376bffffffffffffffffffffffff19606094851b8116959091019485529190921b1660148301526028820152604801919050565b60008351611ca881846020880161161a565b835190830190611cbc81836020880161161a565b01949350505050565b8183823760009101908152919050565b600082611cf257634e487b7160e01b600052601260045260246000fd5b500690565b60008251611d0981846020870161161a565b6e2737a2b93937b929b2b632b1ba37b960891b920191825250600f01919050565b60008251611d3c81846020870161161a565b73556e657870656374656452657475726e6461746160601b92019182525060140191905056fe45786563576974685369677346616365742e65786563576974685369677352656c6179436f6e746578742e5f72657175697265436865636b65725369676e65725369676e61747572653a4d657373616765466565436f6c6c6563746f72286164647265737320736572766963652c627974657320646174612c75696e743235362073616c742c75696e7432353620646561646c696e652c6164647265737320666565546f6b656e2945434453412e5265636f7665724572726f722e4e6f4572726f722026262069734578656375746f725369676e657245786563576974685369677346616365742e65786563576974685369677352656c6179436f6e746578742e5f726571756972654578656375746f725369676e65725369676e61747572653a45786563576974685369677346616365742e65786563576974685369677352656c6179436f6e746578742e5f726571756972655369676e6572446561646c696e653a45786563576974685369677346616365742e657865635769746853696773466565436f6c6c6563746f722e5f726571756972654578656375746f725369676e65725369676e61747572653a45786563576974685369677346616365742e6578656357697468536967732e5f726571756972655369676e6572446561646c696e653a4d657373616765286164647265737320736572766963652c627974657320646174612c75696e743235362073616c742c75696e7432353620646561646c696e652945786563576974685369677346616365742e657865635769746853696773466565436f6c6c6563746f722e5f72657175697265436865636b65725369676e65725369676e61747572653a454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e74726163742945786563576974685369677346616365742e65786563576974685369677352656c6179436f6e746578743a45786563576974685369677346616365742e6578656357697468536967732e5f72657175697265436865636b65725369676e65725369676e61747572653a45434453412e5265636f7665724572726f722e4e6f4572726f72202626206973436865636b65725369676e657245786563576974685369677346616365742e657865635769746853696773466565436f6c6c6563746f722e5f726571756972655369676e6572446561646c696e653a4d65737361676552656c6179436f6e74657874286164647265737320736572766963652c627974657320646174612c75696e743235362073616c742c75696e7432353620646561646c696e652c6164647265737320666565546f6b656e2c75696e74323536206665652945786563576974685369677346616365742e657865635769746853696773466565436f6c6c6563746f723a45786563576974685369677346616365742e6578656357697468536967732e5f726571756972654578656375746f725369676e65725369676e61747572653aa2646970667358221220464aebcfe82880d92b9d3f4aa970bffaa0ef9ebe313136f72008a0943b17fc6564736f6c634300081100330000000000000000000000003ac05161b76a35c1c28dc99aa01bed7b24cea3bf

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

0000000000000000000000003ac05161b76a35c1c28dc99aa01bed7b24cea3bf

-----Decoded View---------------
Arg [0] : _feeCollector (address): 0x3AC05161b76a35c1c28dC99Aa01BEd7B24cEA3bf

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000003ac05161b76a35c1c28dc99aa01bed7b24cea3bf


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.

Validator Index Block Amount
View All Withdrawals

Txn Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.