Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0x76De282596Fde6A2Ac37f4880A02A5216e7409AC
Balance 0 ETH
Nonce 1
Code Size 2737 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

2737 bytes
0x608060405234801561000f575f80fd5b50600436106100f0575f3560e01c806391d1485411610093578063c54e44eb11610063578063c54e44eb14610228578063d547741f1461024f578063efa51cda14610262578063f45edb5f14610284575f80fd5b806391d14854146101d957806395b568eb146101ec578063977a6061146101ff578063a217fddf14610221575f80fd5b80632d2c5565116100ce5780632d2c5565146101775780632f2ff15d1461019e57806336568abe146101b35780636c19e783146101c6575f80fd5b806301ffc9a7146100f4578063238ac9331461011c578063248a9ca314610147575b5f80fd5b6101076101023660046108e9565b6102ab565b60405190151581526020015b60405180910390f35b60015461012f906001600160a01b031681565b6040516001600160a01b039091168152602001610113565b610169610155366004610917565b5f9081526020819052604090206001015490565b604051908152602001610113565b61012f7f00000000000000000000000020c27ebac43b3146d8e6dce3f6026f2e5847d44481565b6101b16101ac366004610949565b6102e1565b005b6101b16101c1366004610949565b61030b565b6101b16101d4366004610973565b610343565b6101076101e7366004610949565b61037a565b6101b16101fa3660046109a0565b6103a2565b61010761020d366004610917565b60036020525f908152604090205460ff1681565b6101695f81565b61012f7f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec781565b6101b161025d366004610949565b6104e3565b610107610270366004610917565b60026020525f908152604090205460ff1681565b6101697fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177581565b5f6001600160e01b03198216637965db0b60e01b14806102db57506301ffc9a760e01b6001600160e01b03198316145b92915050565b5f828152602081905260409020600101546102fb81610507565b6103058383610514565b50505050565b6001600160a01b03811633146103345760405163334bd91960e11b815260040160405180910390fd5b61033e82826105a3565b505050565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177561036d81610507565b6103768261060c565b5050565b5f918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b5f8481526002602052604090205460ff16156103d15760405163424e8d7160e01b815260040160405180910390fd5b6103dd848484846106b4565b6040516323b872dd60e01b81523360048201526001600160a01b037f00000000000000000000000020c27ebac43b3146d8e6dce3f6026f2e5847d44481166024830152604482018590527f000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec716906323b872dd906064015f604051808303815f87803b15801561046a575f80fd5b505af115801561047c573d5f803e3d5ffd5b5050505f8581526002602052604090819020805460ff19166001179055513391507fe42c21594344615edc873314cf723ea98594de1932173c538dd7dae0dbeb96a8906104d59087908790918252602082015260400190565b60405180910390a250505050565b5f828152602081905260409020600101546104fd81610507565b61030583836105a3565b610511813361079f565b50565b5f61051f838361037a565b61059c575f838152602081815260408083206001600160a01b03861684529091529020805460ff191660011790556105543390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45060016102db565b505f6102db565b5f6105ae838361037a565b1561059c575f838152602081815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45060016102db565b6001600160a01b0381166106605760405162461bcd60e51b8152602060048201526016602482015275496e76616c6964207369676e6572206164647265737360501b60448201526064015b60405180910390fd5b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f5553331329228fbd4123164423717a4a7539f6dfa1c3279a923b98fd681a6c739060200160405180910390a150565b6040805160208101869052908101849052606081018390524660808201525f9060a00160408051601f198184030181529082905280516020918201207f19457468657265756d205369676e6564204d6573736167653a0a33320000000091830191909152603c820152605c016040516020818303038152906040528051906020012090505f8061074483856107d8565b5090925090505f81600381111561075d5761075d610a67565b14158061077857506001546001600160a01b03838116911614155b1561079657604051638baa579f60e01b815260040160405180910390fd5b50505050505050565b6107a9828261037a565b6103765760405163e2517d3f60e01b81526001600160a01b038216600482015260248101839052604401610657565b5f805f835160410361080f576020840151604085015160608601515f1a61080188828585610821565b95509550955050505061081a565b505081515f91506002905b9250925092565b5f80807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084111561085a57505f915060039050826108df565b604080515f808252602082018084528a905260ff891692820192909252606081018790526080810186905260019060a0016020604051602081039080840390855afa1580156108ab573d5f803e3d5ffd5b5050604051601f1901519150506001600160a01b0381166108d657505f9250600191508290506108df565b92505f91508190505b9450945094915050565b5f602082840312156108f9575f80fd5b81356001600160e01b031981168114610910575f80fd5b9392505050565b5f60208284031215610927575f80fd5b5035919050565b80356001600160a01b0381168114610944575f80fd5b919050565b5f806040838503121561095a575f80fd5b8235915061096a6020840161092e565b90509250929050565b5f60208284031215610983575f80fd5b6109108261092e565b634e487b7160e01b5f52604160045260245ffd5b5f805f80608085870312156109b3575f80fd5b843593506020850135925060408501359150606085013567ffffffffffffffff808211156109df575f80fd5b818701915087601f8301126109f2575f80fd5b813581811115610a0457610a0461098c565b604051601f8201601f19908116603f01168101908382118183101715610a2c57610a2c61098c565b816040528281528a6020848701011115610a44575f80fd5b826020860160208301375f60208483010152809550505050505092959194509250565b634e487b7160e01b5f52602160045260245ffdfea26469706673582212200758e4da0e636c6d5347c4e5cbd3b352d4714425830c6195b31b87d744ba19c064736f6c63430008140033

Verified Source Code Partial Match

Compiler: v0.8.20+commit.a1b79de6 EVM: shanghai Optimization: Yes (200 runs)
AccessControl.sol 209 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    mapping(bytes32 role => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual returns (bool) {
        return _roles[role].hasRole[account];
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
     * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
     * is missing `role`.
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert AccessControlUnauthorizedAccount(account, role);
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address callerConfirmation) public virtual {
        if (callerConfirmation != _msgSender()) {
            revert AccessControlBadConfirmation();
        }

        _revokeRole(role, callerConfirmation);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        if (!hasRole(role, account)) {
            _roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
        if (hasRole(role, account)) {
            _roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}
IAccessControl.sol 98 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)

pragma solidity ^0.8.20;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
ECDSA.sol 174 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.20;

/**
 * @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
    }

    /**
     * @dev The signature derives the `address(0)`.
     */
    error ECDSAInvalidSignature();

    /**
     * @dev The signature has an invalid length.
     */
    error ECDSAInvalidSignatureLength(uint256 length);

    /**
     * @dev The signature has an S value that is in the upper half order.
     */
    error ECDSAInvalidSignatureS(bytes32 s);

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
     * return address(0) without also returning an error description. Errors are documented using an enum (error type)
     * and a bytes32 providing additional information about the error.
     *
     * If no error is returned, then the address can be used for verification purposes.
     *
     * The `ecrecover` EVM precompile 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 {MessageHashUtils-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]
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
        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, bytes32(signature.length));
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM precompile 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 {MessageHashUtils-toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
        _throwError(error, errorArg);
        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]
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
        unchecked {
            bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
            // We do not check for an overflow here since the shift operation results in 0 or 1.
            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.
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError, bytes32) {
        // 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, s);
        }

        // 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, bytes32(0));
        }

        return (signer, RecoverError.NoError, bytes32(0));
    }

    /**
     * @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, bytes32 errorArg) = tryRecover(hash, v, r, s);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
     */
    function _throwError(RecoverError error, bytes32 errorArg) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert ECDSAInvalidSignature();
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert ECDSAInvalidSignatureLength(uint256(errorArg));
        } else if (error == RecoverError.InvalidSignatureS) {
            revert ECDSAInvalidSignatureS(errorArg);
        }
    }
}
ERC165.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
PaymentProcessor.sol 145 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";


interface ITetherToken {
    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint8);
    function totalSupply() external view returns (uint256);
    function balanceOf(address who) external view returns (uint256);
    function transfer(address to, uint256 value) external;
    function transferFrom(address from, address to, uint256 value) external;
    function approve(address spender, uint256 value) external;
    function allowance(address owner, address spender) external view returns (uint256);

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

/**
 * @title PaymentProcessor
 * @notice Payment processor contract to handle payments for the game.
 * @dev This contract is responsible for accepting payments and firing the events. Actual payment processing is done off-chain.
 */
contract PaymentProcessor is AccessControl {
    using ECDSA for bytes32;

    /// @notice Administrator role to manage the contract.
    bytes32 public constant ADMINISTRATOR_ROLE = keccak256("ADMIN_ROLE");

    /// @notice USDT token contract.
    ITetherToken public immutable USDT;

    /// @notice Treasury account that will be receiving funds.
    address public immutable TREASURY;

    /// @notice Off-chain signer address to validate payment payload.
    address public signer;

    /// @notice Mapping to keep track of paid refIds.
    mapping(uint256 => bool) public paid;

    /// @notice Mapping to keep track of withdrawals refIds.
    mapping(uint256 => bool) public withdrawalRefIds;

    /// @dev Events.
    event PaymentConfirmed(address indexed sender, uint256 refId, uint256 amount);
    event WithdrawalConfirmed(address indexed sender, uint256 refId, uint256 amount);
    event SignerUpdated(address newSigner);

    /// @dev Errors.
    error InvalidSignature();
    error InvalidAddress();
    error ExpiredSignature();
    error PaymentAlreadyProcessed();
    error InvalidConfiguration();

    /**
     * @notice Constructor to initialize the contract with USDT token and treasury address.
     * @param usdt USDT token address.
     * @param treasury Treasury address.
     * @param signerAddress Off-chain signer address.
     */
    constructor(address usdt, address treasury, address signerAddress, address admin) {
        if (usdt == address(0) || treasury == address(0) || signerAddress == address(0) || admin == address(0)) {
            revert InvalidConfiguration();
        }
        
        USDT = ITetherToken(usdt);
        TREASURY = treasury;

        _setSigner(signerAddress);
        
        _grantRole(ADMINISTRATOR_ROLE, admin);
        _grantRole(DEFAULT_ADMIN_ROLE, TREASURY);
    }

    /**
     * @notice Pay function to process payment.
     * @dev Approval works through the ERC20 permit function. Learn more at https://eips.ethereum.org/EIPS/eip-2612.
     * @param refId Payment reference ID.
     * @param amount Payment amount in USDT.
     * @param expiration Payment expiration timestamp.
     * @param signature Payment signature.
     */
    function pay(uint256 refId, uint256 amount, uint256 expiration, bytes memory signature)
        public
    {   

        // Check if payment has already been processed. Helps to avoid double spending.
        if (paid[refId]) {
            revert PaymentAlreadyProcessed();
        }

        // Validate the signature to be sure that payment is recorded in the system.
        _validateSignature(refId, amount, expiration, signature);

        USDT.transferFrom(msg.sender, TREASURY, amount);

        // Mark the payment as processed.
        paid[refId] = true;

        emit PaymentConfirmed(msg.sender, refId, amount);
    }

    /**
     * @notice Function to update the signer address.
     * @param signerAddress New signer address.
     */
    function setSigner(address signerAddress) public onlyRole(ADMINISTRATOR_ROLE) {
        _setSigner(signerAddress);
    }

    /**
     * @notice Function to update the signer address.
     * @param signerAddress New signer address.
     */
    function _setSigner(address signerAddress) internal {
        require(signerAddress != address(0), "Invalid signer address");

        signer = signerAddress;
        emit SignerUpdated(signerAddress);
    }

    /**
     * @notice Function to validate the signature.
     * @param refId Payment/withdrawal reference ID.
     * @param amount Payment/withdrawal amount in USDT.
     * @param expiration Payment/withdrawal expiration timestamp or block.
     * @param signature Payment/withdrawal signature.
     */
    function _validateSignature(uint256 refId, uint256 amount, uint256 expiration, bytes memory signature) internal view {
        bytes32 dataHash = keccak256(
            abi.encodePacked("\x19Ethereum Signed Message:\n32", keccak256(abi.encode(refId, amount, expiration, block.chainid)))
        );
        (address recoveredAddress ,ECDSA.RecoverError err,) = ECDSA.tryRecover(dataHash, signature);
        
        if (err != ECDSA.RecoverError.NoError || recoveredAddress != signer) {
            revert InvalidSignature();
        }
    }
}

Read Contract

ADMINISTRATOR_ROLE 0xf45edb5f → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
TREASURY 0x2d2c5565 → address
USDT 0xc54e44eb → address
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
paid 0xefa51cda → bool
signer 0x238ac933 → address
supportsInterface 0x01ffc9a7 → bool
withdrawalRefIds 0x977a6061 → bool

Write Contract 5 functions

These functions modify contract state and require a wallet transaction to execute.

grantRole 0x2f2ff15d
bytes32 role
address account
pay 0x95b568eb
uint256 refId
uint256 amount
uint256 expiration
bytes signature
renounceRole 0x36568abe
bytes32 role
address callerConfirmation
revokeRole 0xd547741f
bytes32 role
address account
setSigner 0x6c19e783
address signerAddress

Recent Transactions

No transactions found for this address