Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0x9FE48EBA298A2F9f39Ce62698663E8Eef1B42F5d
Balance 0.016500 ETH
Nonce 1
Code Size 6283 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

6283 bytes
0x608060405260043610610212575f3560e01c8063952b34dd1161011e578063b6d72870116100a8578063cfb3647b1161006d578063cfb3647b146105db578063d547741f146105fa578063d596087314610619578063d9f126f114610638578063f70dbb8b14610657575f5ffd5b8063b6d7287014610542578063c1419def14610557578063c41c82e21461057d578063c4f5183b1461059c578063c7821bc9146105bc575f5ffd5b8063a0855f2d116100ee578063a0855f2d146104d3578063a217fddf146104e8578063ae06c1b7146104fb578063b04b4f981461051a578063b53251bc1461052f575f5ffd5b8063952b34dd1461044f5780639564cb3b146104805780639ec751e91461049f578063a001ecdd146104be575f5ffd5b8063476343ee1161019f57806375b238fc1161016f57806375b238fc146103c85780637e458fc3146103e85780638456cb591461040757806391792d5b1461041b57806391d1485414610430575f5ffd5b8063476343ee146103695780635c975abb1461037d5780636e8611c614610394578063741bef1a146103a9575f5ffd5b806336568abe116101e557806336568abe146102bc57806337de8106146102db5780633e413bee146102fa5780633f4ba83a146103315780634611783014610345575f5ffd5b806301ffc9a7146102165780631f45d0e41461024a578063248a9ca31461026d5780632f2ff15d1461029b575b5f5ffd5b348015610221575f5ffd5b50610235610230366004611400565b610676565b60405190151581526020015b60405180910390f35b348015610255575f5ffd5b5061025f600b5481565b604051908152602001610241565b348015610278575f5ffd5b5061025f61028736600461142e565b5f9081526020819052604090206001015490565b3480156102a6575f5ffd5b506102ba6102b536600461145b565b6106ac565b005b3480156102c7575f5ffd5b506102ba6102d636600461145b565b6106d6565b3480156102e6575f5ffd5b506102ba6102f536600461142e565b61070e565b348015610305575f5ffd5b50600354610319906001600160a01b031681565b6040516001600160a01b039091168152602001610241565b34801561033c575f5ffd5b506102ba61072b565b348015610350575f5ffd5b506001546103199061010090046001600160a01b031681565b348015610374575f5ffd5b506102ba61074d565b348015610388575f5ffd5b5060015460ff16610235565b34801561039f575f5ffd5b5061025f60055481565b3480156103b4575f5ffd5b50600454610319906001600160a01b031681565b3480156103d3575f5ffd5b5061025f5f51602061186b5f395f51905f5281565b3480156103f3575f5ffd5b506102ba610402366004611485565b61082e565b348015610412575f5ffd5b506102ba610854565b348015610426575f5ffd5b5061025f60065481565b34801561043b575f5ffd5b5061023561044a36600461145b565b610873565b34801561045a575f5ffd5b50600a5461046b9063ffffffff1681565b60405163ffffffff9091168152602001610241565b34801561048b575f5ffd5b5061025f61049a36600461142e565b61089b565b3480156104aa575f5ffd5b5061025f6104b936600461142e565b61099d565b3480156104c9575f5ffd5b5061025f60075481565b3480156104de575f5ffd5b5061025f61271081565b3480156104f3575f5ffd5b5061025f5f81565b348015610506575f5ffd5b506102ba61051536600461142e565b6109ca565b348015610525575f5ffd5b5061025f60095481565b6102ba61053d3660046114b1565b6109e7565b34801561054d575f5ffd5b5061025f60085481565b348015610562575f5ffd5b5061056b600681565b60405160ff9091168152602001610241565b348015610588575f5ffd5b506102ba6105973660046114fa565b610a3b565b3480156105a7575f5ffd5b5060045461056b90600160a01b900460ff1681565b3480156105c7575f5ffd5b506102ba6105d636600461142e565b610be3565b3480156105e6575f5ffd5b50600254610319906001600160a01b031681565b348015610605575f5ffd5b506102ba61061436600461145b565b610c00565b348015610624575f5ffd5b506102ba6106333660046115a1565b610c24565b348015610643575f5ffd5b506102ba61065236600461142e565b610c58565b348015610662575f5ffd5b506102ba61067136600461142e565b610c75565b5f6001600160e01b03198216637965db0b60e01b14806106a657506301ffc9a760e01b6001600160e01b03198316145b92915050565b5f828152602081905260409020600101546106c681610c92565b6106d08383610c9c565b50505050565b6001600160a01b03811633146106ff5760405163334bd91960e11b815260040160405180910390fd5b6107098282610d2b565b505050565b5f51602061186b5f395f51905f5261072581610c92565b50600655565b5f51602061186b5f395f51905f5261074281610c92565b61074a610d94565b50565b5f51602061186b5f395f51905f5261076481610c92565b60405147905f90339083908381818185875af1925050503d805f81146107a5576040519150601f19603f3d011682016040523d82523d5f602084013e6107aa565b606091505b50509050806107f45760405162461bcd60e51b81526020600482015260116024820152701dda5d1a191c985dd85b0819985a5b1959607a1b60448201526064015b60405180910390fd5b60405182815233907fc0819c13be868895eb93e40eaceb96de976442fa1d404e5c55f14bb65a8c489a9060200160405180910390a2505050565b5f51602061186b5f395f51905f5261084581610c92565b506001600160a01b0316600955565b5f51602061186b5f395f51905f5261086b81610c92565b61074a610de6565b5f918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b5f5f6108a68361099d565b90505f5f60045f9054906101000a90046001600160a01b03166001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a060405180830381865afa1580156108fa573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061091e91906115d3565b509350509250508042108061093d5750600b5461093b8242611635565b115b15610964576040516316d7d15960e01b8152600481018290524260248201526044016107eb565b6004548290849061098090600160a01b900460ff16600a61172b565b61098a9190611739565b6109949190611750565b95945050505050565b6006546005548210156109c557612710600754836109bb9190611739565b6106a69190611750565b919050565b5f51602061186b5f395f51905f526109e181610c92565b50600755565b6109ef610e21565b600354600954600a546040805185151560208201526106d0948994899489946001600160a01b0390931693919263ffffffff909116910160405160208183030381529060405288610e47565b5f51602061186b5f395f51905f52610a5281610c92565b600c5460ff1615610a9b5760405162461bcd60e51b8152602060048201526013602482015272105b1c9958591e481a5b9a5d1a585b1a5e9959606a1b60448201526064016107eb565b600180546001600160a01b03808f1661010002610100600160a81b031990921691909117909155600280548d83166001600160a01b031991821617909155600380548d841690831617905560048054928c1692909116821781556040805163313ce56760e01b8152905163313ce567928281019260209291908290030181865afa158015610b2b573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b4f919061176f565b610b5b6006601261178f565b610b6591906117a8565b6004805460ff60a01b1916600160a01b60ff939093169290920291909117905560058890556006879055600786905560088590556001600160a01b038416600955600a805463ffffffff191663ffffffff8516179055600b829055600c805460ff19166001179055610bd5610d94565b505050505050505050505050565b5f51602061186b5f395f51905f52610bfa81610c92565b50600555565b5f82815260208190526040902060010154610c1a81610c92565b6106d08383610d2b565b5f51602061186b5f395f51905f52610c3b81610c92565b50600a805463ffffffff191663ffffffff92909216919091179055565b5f51602061186b5f395f51905f52610c6f81610c92565b50600855565b5f51602061186b5f395f51905f52610c8c81610c92565b50600b55565b61074a81336111f9565b5f610ca78383610873565b610d24575f838152602081815260408083206001600160a01b03861684529091529020805460ff19166001179055610cdc3390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45060016106a6565b505f6106a6565b5f610d368383610873565b15610d24575f838152602081815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45060016106a6565b610d9c611236565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b610dee610e21565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833610dc9565b60015460ff1615610e455760405163d93c066560e01b815260040160405180910390fd5b565b610e6e60405180608001604052805f81526020015f81526020015f81526020015f81525090565b610e778961089b565b815281610e84575f610e88565b6008545b602082018190528151610e9b91906117c1565b60408201819052341015610ed157604080820151905163a458261b60e01b815260048101919091523460248201526044016107eb565b600354610ee9906001600160a01b031633308c611259565b600154600354610f0c916001600160a01b0391821691610100909104168b6112c0565b6002546040516352b7631960e11b81526001600160a01b0388811660048301529091169063a56ec63290602401602060405180830381865afa158015610f54573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f7891906117d4565b60608201525b806060015189111561108f5760018054906101000a90046001600160a01b03166001600160a01b031663779b432d82606001518a8a8a8a5f8b5f604051602001610fcc911515815260200190565b6040516020818303038152906040526040518963ffffffff1660e01b8152600401610ffe9897969594939291906117eb565b5f604051808303815f87803b158015611015575f5ffd5b505af1158015611027573d5f5f3e3d5ffd5b50505050606081810151604080519182525f602083018190529082015290810188905233907f9def29ee1e52d8cc418ce8483ab7931bd160355306260e3e236c4cc907ca4e9f9060800160405180910390a26060810151611088908a611635565b9850610f7e565b60015460405163779b432d60e01b81526101009091046001600160a01b03169063779b432d906110d1908c908c908c908c908c905f908d908d906004016117eb565b5f604051808303815f87803b1580156110e8575f5ffd5b505af11580156110fa573d5f5f3e3d5ffd5b50508251602080850151604080518f81529283019390935281830152606081018b905290513393507f9def29ee1e52d8cc418ce8483ab7931bd160355306260e3e236c4cc907ca4e9f92509081900360800190a280604001513411156111ee5760408101515f90339061116d9034611635565b6040515f81818185875af1925050503d805f81146111a6576040519150601f19603f3d011682016040523d82523d5f602084013e6111ab565b606091505b50509050806111ec5760405162461bcd60e51b815260206004820152600d60248201526c1c99599d5b990819985a5b1959609a1b60448201526064016107eb565b505b505050505050505050565b6112038282610873565b6112325760405163e2517d3f60e01b81526001600160a01b0382166004820152602481018390526044016107eb565b5050565b60015460ff16610e4557604051638dfc202b60e01b815260040160405180910390fd5b6040516001600160a01b0384811660248301528381166044830152606482018390526106d09186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b03838183161783525050505061134b565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b17905261131184826113b7565b6106d0576040516001600160a01b0384811660248301525f604483015261134591869182169063095ea7b39060640161128e565b6106d084825b5f5f60205f8451602086015f885af18061136a576040513d5f823e3d81fd5b50505f513d9150811561138157806001141561138e565b6001600160a01b0384163b155b156106d057604051635274afe760e01b81526001600160a01b03851660048201526024016107eb565b5f5f5f5f60205f8651602088015f8a5af192503d91505f5190508280156113f6575081156113e857806001146113f6565b5f866001600160a01b03163b115b9695505050505050565b5f60208284031215611410575f5ffd5b81356001600160e01b031981168114611427575f5ffd5b9392505050565b5f6020828403121561143e575f5ffd5b5035919050565b80356001600160a01b03811681146109c5575f5ffd5b5f5f6040838503121561146c575f5ffd5b8235915061147c60208401611445565b90509250929050565b5f60208284031215611495575f5ffd5b61142782611445565b803563ffffffff811681146109c5575f5ffd5b5f5f5f5f608085870312156114c4575f5ffd5b843593506114d46020860161149e565b925060408501359150606085013580151581146114ef575f5ffd5b939692955090935050565b5f5f5f5f5f5f5f5f5f5f5f6101608c8e031215611515575f5ffd5b61151e8c611445565b9a5061152c60208d01611445565b995061153a60408d01611445565b985061154860608d01611445565b975060808c0135965060a08c0135955060c08c0135945060e08c013593506115736101008d01611445565b92506115826101208d0161149e565b91505f6101408d01359050809150509295989b509295989b9093969950565b5f602082840312156115b1575f5ffd5b6114278261149e565b805169ffffffffffffffffffff811681146109c5575f5ffd5b5f5f5f5f5f60a086880312156115e7575f5ffd5b6115f0866115ba565b60208701516040880151606089015192975090955093509150611615608087016115ba565b90509295509295909350565b634e487b7160e01b5f52601160045260245ffd5b818103818111156106a6576106a6611621565b6001815b60018411156116835780850481111561166757611667611621565b600184161561167557908102905b60019390931c92800261164c565b935093915050565b5f82611699575060016106a6565b816116a557505f6106a6565b81600181146116bb57600281146116c5576116e1565b60019150506106a6565b60ff8411156116d6576116d6611621565b50506001821b6106a6565b5060208310610133831016604e8410600b8410161715611704575081810a6106a6565b6117105f198484611648565b805f190482111561172357611723611621565b029392505050565b5f61142760ff84168361168b565b80820281158282048414176106a6576106a6611621565b5f8261176a57634e487b7160e01b5f52601260045260245ffd5b500490565b5f6020828403121561177f575f5ffd5b815160ff81168114611427575f5ffd5b60ff82811682821603908111156106a6576106a6611621565b60ff81811683821601908111156106a6576106a6611621565b808201808211156106a6576106a6611621565b5f602082840312156117e4575f5ffd5b5051919050565b88815263ffffffff8816602082015286604082015260018060a01b03861660608201528460808201528360a082015263ffffffff831660c082015261010060e08201525f825180610100840152806020850161012085015e5f6101208285010152610120601f19601f830116840101915050999850505050505050505056fea49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775

Verified Source Code Partial Match

Compiler: v0.8.28+commit.7893614a EVM: cancun Optimization: Yes (200 runs)
AccessControl.sol 207 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {IERC165, 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);
        _;
    }

    /// @inheritdoc IERC165
    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` from `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.4.0) (access/IAccessControl.sol)

pragma solidity >=0.8.4;

/**
 * @dev External interface of AccessControl declared to support ERC-165 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 to signal 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. This account bears the admin role (for the granted role).
     * Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
     */
    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;
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)

pragma solidity >=0.6.2;

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

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

import {IERC165} from "../utils/introspection/IERC165.sol";
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

import {IERC20} from "../token/ERC20/IERC20.sol";
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

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

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

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

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` 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 value) external returns (bool);
}
SafeERC20.sol 212 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    /**
     * @dev An operation with an ERC-20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}
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;
    }
}
Pausable.sol 112 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    bool private _paused;

    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();

    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
ERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.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 ERC-165 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 {
    /// @inheritdoc IERC165
    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.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * 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[ERC 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);
}
AggregatorV3Interface.sol 23 lines
// SPDX-License-Identifier: MIT
// https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol

pragma solidity ^0.8.0;

// solhint-disable-next-line interface-starts-with-i
interface AggregatorV3Interface {
    function decimals() external view returns (uint8);

    function description() external view returns (string memory);

    function version() external view returns (uint256);

    function getRoundData(uint80 _roundId)
        external
        view
        returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

    function latestRoundData()
        external
        view
        returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}
ITokenMinter.sol 6 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface ITokenMinter {
    function burnLimitsPerMessage(address token) external view returns (uint256);
}
ITokenMessengerV2.sol 25 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface ITokenMessengerV2 {
    function depositForBurn(
        uint256 amount,
        uint32 destinationDomain,
        bytes32 mintRecipient,
        address burnToken,
        bytes32 destinationCaller,
        uint256 maxFee,
        uint32 minFinalityThreshold
    ) external;

    function depositForBurnWithHook(
        uint256 amount,
        uint32 destinationDomain,
        bytes32 mintRecipient,
        address burnToken,
        bytes32 destinationCaller,
        uint256 maxFee,
        uint32 minFinalityThreshold,
        bytes calldata hookData
    ) external;
}
IYeiCctpV2Agent.sol 41 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IYeiCctpV2Agent {
    error InsufficientFee(uint256 required, uint256 got);
    error ExceededBurnLimit(uint256 limit, uint256 got);
    error StalePriceData(uint256 updatedAt, uint256 currentTime);

    event DepositForBurn(
        address indexed from, uint256 amount, uint256 fee, uint256 feeForGasOnDestination, bytes32 mintRecipient
    );
    event FeesWithdrawn(address indexed owner, uint256 balance);

    function depositForBurn(uint256 amount, uint32 destinationDomain, bytes32 mintRecipient, bool gasOnDestination)
        external
        payable;

    function getFeeInUSDC(uint256 amount) external view returns (uint256);

    function getFeeInNativeToken(uint256 amount) external view returns (uint256);

    function setOracleStalenessThreshold(uint256 _oracleStalenessThreshold) external;

    function init(
        address _tokenMessenger,
        address _tokenMinter,
        address _usdc,
        address _priceFeed,
        uint256 _fixedFeeThreshold,
        uint256 _fixedFee,
        uint256 _feePercentage,
        uint256 _gasOnDestinationFee,
        address _destinationCaller,
        uint32 _finalityThreshold,
        uint256 _oracleStalenessThreshold
    ) external;

    function pause() external;

    function unpause() external;
}
YeiCctpV2Agent.sol 210 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";

import {AggregatorV3Interface} from "../interfaces/AggregatorV3Interface.sol";
import {IYeiCctpV2Agent} from "../interfaces/v2/IYeiCctpV2Agent.sol";
import {ITokenMessengerV2} from "../interfaces/v2/ITokenMessengerV2.sol";
import {ITokenMinter} from "../interfaces/ITokenMinter.sol";

contract YeiCctpV2Agent is IYeiCctpV2Agent, AccessControl, Pausable {
    using SafeERC20 for IERC20;

    bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
    uint256 public constant FEE_PERCENTAGE_BASIS = 1e4;
    uint8 public constant USDC_DECIMALS = 6;

    ITokenMessengerV2 public tokenMessenger;
    ITokenMinter public tokenMinter;
    IERC20 public usdc;
    AggregatorV3Interface public priceFeed;
    uint8 public decimalScale;

    uint256 public fixedFeeThreshold;
    uint256 public fixedFee;
    uint256 public feePercentage;
    uint256 public gasOnDestinationFee;
    bytes32 public destinationCaller;
    uint32 public finalityThreshold;
    uint256 public oracleStalenessThreshold;
    bool private initialized;

    // Empty hook data for intermediate burns (no gas on destination)
    bytes private constant EMPTY_HOOK_DATA = abi.encode(false);

    constructor(address admin) {
        _grantRole(DEFAULT_ADMIN_ROLE, admin);
        _grantRole(ADMIN_ROLE, admin);
        _pause();
    }

    function init(
        address _tokenMessenger,
        address _tokenMinter,
        address _usdc,
        address _priceFeed,
        uint256 _fixedFeeThreshold,
        uint256 _fixedFee,
        uint256 _feePercentage,
        uint256 _gasOnDestinationFee,
        address _destinationCaller,
        uint32 _finalityThreshold,
        uint256 _oracleStalenessThreshold
    ) external onlyRole(ADMIN_ROLE) {
        require(!initialized, "Already initialized");

        tokenMessenger = ITokenMessengerV2(_tokenMessenger);
        tokenMinter = ITokenMinter(_tokenMinter);
        usdc = IERC20(_usdc);
        priceFeed = AggregatorV3Interface(_priceFeed);
        decimalScale = 18 - USDC_DECIMALS + priceFeed.decimals();
        fixedFeeThreshold = _fixedFeeThreshold;
        fixedFee = _fixedFee;
        feePercentage = _feePercentage;
        gasOnDestinationFee = _gasOnDestinationFee;
        destinationCaller = bytes32(uint256(uint160(_destinationCaller)));
        finalityThreshold = _finalityThreshold;
        oracleStalenessThreshold = _oracleStalenessThreshold;
        initialized = true;
        _unpause();
    }

    function depositForBurn(uint256 amount, uint32 destinationDomain, bytes32 mintRecipient, bool gasOnDestination)
        external
        payable
        whenNotPaused
    {
        _depositForBurn(
            amount,
            destinationDomain,
            mintRecipient,
            address(usdc),
            destinationCaller,
            finalityThreshold,
            abi.encode(gasOnDestination),
            gasOnDestination
        );
    }

    struct depositForBurnVars {
        uint256 fee;
        uint256 feeForGasOnDestination;
        uint256 totalFee;
        uint256 burnLimit;
    }

    function _depositForBurn(
        uint256 amount,
        uint32 destinationDomain,
        bytes32 mintRecipient,
        address burnToken,
        bytes32 _destinationCaller,
        uint32 _finalityThreshold,
        bytes memory hookData,
        bool gasOnDestination
    ) internal {
        depositForBurnVars memory vars;
        vars.fee = getFeeInNativeToken(amount);
        vars.feeForGasOnDestination = gasOnDestination ? gasOnDestinationFee : 0;
        vars.totalFee = vars.fee + vars.feeForGasOnDestination;
        if (msg.value < vars.totalFee) {
            revert InsufficientFee(vars.totalFee, msg.value);
        }

        usdc.safeTransferFrom(msg.sender, address(this), amount);
        usdc.forceApprove(address(tokenMessenger), amount);

        vars.burnLimit = tokenMinter.burnLimitsPerMessage(burnToken);

        while (amount > vars.burnLimit) {
            tokenMessenger.depositForBurnWithHook(
                vars.burnLimit,
                destinationDomain,
                mintRecipient,
                burnToken,
                _destinationCaller,
                0,
                _finalityThreshold,
                EMPTY_HOOK_DATA
            );
            emit DepositForBurn(msg.sender, vars.burnLimit, 0, 0, mintRecipient);
            amount -= vars.burnLimit;
        }

        // Handle remaining amount
        tokenMessenger.depositForBurnWithHook(
            amount, destinationDomain, mintRecipient, burnToken, _destinationCaller, 0, _finalityThreshold, hookData
        );
        emit DepositForBurn(msg.sender, amount, vars.fee, vars.feeForGasOnDestination, mintRecipient);

        if (msg.value > vars.totalFee) {
            (bool success,) = payable(msg.sender).call{value: msg.value - vars.totalFee}("");
            require(success, "refund failed");
        }
    }

    function getFeeInUSDC(uint256 amount) public view returns (uint256 fee) {
        fee = fixedFee;
        if (amount < fixedFeeThreshold) {
            fee = (amount * feePercentage) / FEE_PERCENTAGE_BASIS;
        }
    }

    function getFeeInNativeToken(uint256 amount) public view returns (uint256) {
        uint256 feeInUSDC = getFeeInUSDC(amount);
        (, int256 price,, uint256 updatedAt,) = priceFeed.latestRoundData();

        if (block.timestamp < updatedAt || block.timestamp - updatedAt > oracleStalenessThreshold) {
            revert StalePriceData(updatedAt, block.timestamp);
        }

        return 10 ** decimalScale * feeInUSDC / uint256(price);
    }

    function withdrawFees() external onlyRole(ADMIN_ROLE) {
        uint256 amount = address(this).balance;
        (bool success,) = payable(msg.sender).call{value: amount}("");
        require(success, "withdrawal failed");
        emit FeesWithdrawn(msg.sender, amount);
    }

    function setFixedFeeThreshold(uint256 _fixedFeeThreshold) external onlyRole(ADMIN_ROLE) {
        fixedFeeThreshold = _fixedFeeThreshold;
    }

    function setFixedFee(uint256 _fixedFee) external onlyRole(ADMIN_ROLE) {
        fixedFee = _fixedFee;
    }

    function setFeePercentage(uint256 _feePercentage) external onlyRole(ADMIN_ROLE) {
        feePercentage = _feePercentage;
    }

    function setGasOnDestinationFee(uint256 _gasOnDestinationFee) external onlyRole(ADMIN_ROLE) {
        gasOnDestinationFee = _gasOnDestinationFee;
    }

    function setDestinationCaller(address _destinationCaller) external onlyRole(ADMIN_ROLE) {
        destinationCaller = bytes32(uint256(uint160(_destinationCaller)));
    }

    function setFinalityThreshold(uint32 _finalityThreshold) external onlyRole(ADMIN_ROLE) {
        finalityThreshold = _finalityThreshold;
    }

    function setOracleStalenessThreshold(uint256 _oracleStalenessThreshold) external onlyRole(ADMIN_ROLE) {
        oracleStalenessThreshold = _oracleStalenessThreshold;
    }

    function pause() external onlyRole(ADMIN_ROLE) {
        _pause();
    }

    function unpause() external onlyRole(ADMIN_ROLE) {
        _unpause();
    }
}

Read Contract

ADMIN_ROLE 0x75b238fc → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
FEE_PERCENTAGE_BASIS 0xa0855f2d → uint256
USDC_DECIMALS 0xc1419def → uint8
decimalScale 0xc4f5183b → uint8
destinationCaller 0xb04b4f98 → bytes32
feePercentage 0xa001ecdd → uint256
finalityThreshold 0x952b34dd → uint32
fixedFee 0x91792d5b → uint256
fixedFeeThreshold 0x6e8611c6 → uint256
gasOnDestinationFee 0xb6d72870 → uint256
getFeeInNativeToken 0x9564cb3b → uint256
getFeeInUSDC 0x9ec751e9 → uint256
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
oracleStalenessThreshold 0x1f45d0e4 → uint256
paused 0x5c975abb → bool
priceFeed 0x741bef1a → address
supportsInterface 0x01ffc9a7 → bool
tokenMessenger 0x46117830 → address
tokenMinter 0xcfb3647b → address
usdc 0x3e413bee → address

Write Contract 15 functions

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

depositForBurn 0xb53251bc
uint256 amount
uint32 destinationDomain
bytes32 mintRecipient
bool gasOnDestination
grantRole 0x2f2ff15d
bytes32 role
address account
init 0xc41c82e2
address _tokenMessenger
address _tokenMinter
address _usdc
address _priceFeed
uint256 _fixedFeeThreshold
uint256 _fixedFee
uint256 _feePercentage
uint256 _gasOnDestinationFee
address _destinationCaller
uint32 _finalityThreshold
uint256 _oracleStalenessThreshold
pause 0x8456cb59
No parameters
renounceRole 0x36568abe
bytes32 role
address callerConfirmation
revokeRole 0xd547741f
bytes32 role
address account
setDestinationCaller 0x7e458fc3
address _destinationCaller
setFeePercentage 0xae06c1b7
uint256 _feePercentage
setFinalityThreshold 0xd5960873
uint32 _finalityThreshold
setFixedFee 0x37de8106
uint256 _fixedFee
setFixedFeeThreshold 0xc7821bc9
uint256 _fixedFeeThreshold
setGasOnDestinationFee 0xd9f126f1
uint256 _gasOnDestinationFee
setOracleStalenessThreshold 0xf70dbb8b
uint256 _oracleStalenessThreshold
unpause 0x3f4ba83a
No parameters
withdrawFees 0x476343ee
No parameters

Token Balances (1)

View Transfers →
USDC 0.001

Recent Transactions

No transactions found for this address