ETH Price: $1,791.17 (+13.11%)

Contract

0x129ed667bf8C065fE5f66c9b44B7cB0126D85cC3
 
Transaction Hash
Method
Block
From
To
Approve181167612025-04-19 6:15:374 days ago1745043337IN
0x129ed667...126D85cC3
0 ETH0.000000020.00086345
Approve180881062025-04-18 14:20:274 days ago1744986027IN
0x129ed667...126D85cC3
0 ETH0.000000030.00129294
Approve180296592025-04-17 5:52:136 days ago1744869133IN
0x129ed667...126D85cC3
0 ETH0.000000050.00107566
Approve175834002025-04-06 21:56:5516 days ago1743976615IN
0x129ed667...126D85cC3
0 ETH0.000000060.001343
Approve173304352025-04-01 1:24:4522 days ago1743470685IN
0x129ed667...126D85cC3
0 ETH0.000000040.00159638
Approve171769942025-03-28 12:10:0325 days ago1743163803IN
0x129ed667...126D85cC3
0 ETH00.00018531
Approve168124902025-03-20 1:39:5534 days ago1742434795IN
0x129ed667...126D85cC3
0 ETH00.00000196
Approve167613372025-03-18 21:14:4935 days ago1742332489IN
0x129ed667...126D85cC3
0 ETH0.000000020.00100097
Approve167613342025-03-18 21:14:4335 days ago1742332483IN
0x129ed667...126D85cC3
0 ETH0.000000020.00100098
Approve167613302025-03-18 21:14:3535 days ago1742332475IN
0x129ed667...126D85cC3
0 ETH0.000000020.00100096
Approve167534242025-03-18 16:51:0335 days ago1742316663IN
0x129ed667...126D85cC3
0 ETH00.00000095
Approve167028082025-03-17 12:43:5136 days ago1742215431IN
0x129ed667...126D85cC3
0 ETH0.000000020.00120684
Approve167028052025-03-17 12:43:4536 days ago1742215425IN
0x129ed667...126D85cC3
0 ETH0.000000020.00120718
Approve167028032025-03-17 12:43:4136 days ago1742215421IN
0x129ed667...126D85cC3
0 ETH0.000000020.0012073
Approve167024122025-03-17 12:30:3936 days ago1742214639IN
0x129ed667...126D85cC3
0 ETH0.000000020.0012
Approve166972322025-03-17 9:37:5936 days ago1742204279IN
0x129ed667...126D85cC3
0 ETH0.000000050.0011008
Approve166922002025-03-17 6:50:1537 days ago1742194215IN
0x129ed667...126D85cC3
0 ETH0.000000050.00115267
Approve166888202025-03-17 4:57:3537 days ago1742187455IN
0x129ed667...126D85cC3
0 ETH0.000000050.00109658
Approve166767932025-03-16 22:16:4137 days ago1742163401IN
0x129ed667...126D85cC3
0 ETH0.000000040.00104733
Approve164296812025-03-11 4:59:3743 days ago1741669177IN
0x129ed667...126D85cC3
0 ETH00.00016597
Approve164034242025-03-10 14:24:2343 days ago1741616663IN
0x129ed667...126D85cC3
0 ETH00.00013122
Approve162664752025-03-07 10:19:2546 days ago1741342765IN
0x129ed667...126D85cC3
0 ETH00.00010273
Approve162664722025-03-07 10:19:1946 days ago1741342759IN
0x129ed667...126D85cC3
0 ETH00.00009689
Approve161406092025-03-04 12:23:5349 days ago1741091033IN
0x129ed667...126D85cC3
0 ETH00.0000536
Approve158658782025-02-26 3:46:1156 days ago1740541571IN
0x129ed667...126D85cC3
0 ETH0.000000010.00059794
View all transactions

Parent Transaction Hash Block From To
View All Internal Transactions

Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
WaifuToken

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion, MIT license
File 1 of 47 : WaifuToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./ERC20Custom.sol";

contract WaifuToken is ERC20Custom, AccessControl {
    using EnumerableSet for EnumerableSet.AddressSet;
    using SafeERC20 for IERC20;

    struct ERC20TaxParameters {
        uint256 projectBuyTaxBasisPoints;
        uint256 projectSellTaxBasisPoints;
        address projectTaxRecipient;
    }

    struct BaseParameters {
        address defaultAdmin;
        address supplyRecipient;
        uint256 totalSupply;
        string name;
        string symbol;
    }

    uint256 internal constant BP_DENOM = 10000;

    EnumerableSet.AddressSet private _liquidityPools;
    bool internal _tokenHasTax;

    uint16 public projectBuyTaxBasisPoints;
    uint16 public projectSellTaxBasisPoints;
    address public projectTaxRecipient;

    event LiquidityPoolAdded(address addedPool);
    event LiquidityPoolRemoved(address removedPool);
    event ProjectTaxRecipientUpdated(address treasury);
    event ProjectTaxBasisPointsChanged(
        uint256 oldBuyBasisPoints,
        uint256 newBuyBasisPoints,
        uint256 oldSellBasisPoints,
        uint256 newSellBasisPoints
    );

    uint128 public projectTaxPendingSwap;

    constructor(
        BaseParameters memory baseParams,
        ERC20TaxParameters memory taxParams
    ) ERC20Custom(baseParams.name, baseParams.symbol) {
        _mint(
            baseParams.supplyRecipient,
            baseParams.totalSupply * 10 ** decimals()
        );
        _grantRole(DEFAULT_ADMIN_ROLE, baseParams.defaultAdmin);
        _tokenHasTax = _processTaxParams(taxParams);
        projectTaxRecipient = taxParams.projectTaxRecipient;
    }

    function _processTaxParams(
        ERC20TaxParameters memory erc20TaxParameters_
    ) internal returns (bool tokenHasTax_) {
        if (
            erc20TaxParameters_.projectBuyTaxBasisPoints == 0 &&
            erc20TaxParameters_.projectSellTaxBasisPoints == 0
        ) {
            return false;
        } else {
            projectBuyTaxBasisPoints = uint16(
                erc20TaxParameters_.projectBuyTaxBasisPoints
            );
            projectSellTaxBasisPoints = uint16(
                erc20TaxParameters_.projectSellTaxBasisPoints
            );
            return true;
        }
    }

    function addLiquidityPool(
        address newLiquidityPool_
    ) public onlyRole(DEFAULT_ADMIN_ROLE) {
        // Don't allow calls that didn't pass an address:
        if (newLiquidityPool_ == address(0)) {
            _revert(LiquidityPoolCannotBeAddressZero.selector);
        }
        // Only allow smart contract addresses to be added, as only these can be pools:
        if (newLiquidityPool_.code.length == 0) {
            _revert(LiquidityPoolMustBeAContractAddress.selector);
        }
        // Add this to the enumerated list:
        _liquidityPools.add(newLiquidityPool_);
        emit LiquidityPoolAdded(newLiquidityPool_);
    }

    function removeLiquidityPool(
        address removedLiquidityPool_
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        // Remove this from the enumerated list:
        _liquidityPools.remove(removedLiquidityPool_);
        emit LiquidityPoolRemoved(removedLiquidityPool_);
    }

    function transfer(
        address to,
        uint256 value
    ) public override returns (bool) {
        address owner = _msgSender();
        _transfer(
            owner,
            to,
            value,
            (isLiquidityPool(owner) || isLiquidityPool(to))
        );
        return true;
    }

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(
            from,
            to,
            amount,
            (isLiquidityPool(from) || isLiquidityPool(to))
        );
        return true;
    }

    function _transfer(
        address from,
        address to,
        uint256 amount,
        bool applyTax
    ) internal virtual {
        // Perform pre-tax validation (e.g. amount doesn't exceed balance, max txn amount)
        uint256 fromBalance = _pretaxValidationAndLimits(from, to, amount);

        // Process taxes
        uint256 amountMinusTax = _taxProcessing(applyTax, to, from, amount);

        _setBalance(from, fromBalance - amount);
        _increaseBalance(to, amountMinusTax);

        emit Transfer(from, to, amountMinusTax);
    }

    function _pretaxValidationAndLimits(
        address from_,
        address to_,
        uint256 amount_
    ) internal view returns (uint256 fromBalance_) {
        if (from_ == address(0)) {
            _revert(TransferFromZeroAddress.selector);
        }

        if (to_ == address(0)) {
            _revert(TransferToZeroAddress.selector);
        }

        fromBalance_ = balanceOf(from_);

        if (fromBalance_ < amount_) {
            _revert(TransferAmountExceedsBalance.selector);
        }

        return (fromBalance_);
    }

    function _taxProcessing(
        bool applyTax_,
        address to_,
        address from_,
        uint256 sentAmount_
    ) internal returns (uint256 amountLessTax_) {
        amountLessTax_ = sentAmount_;
        unchecked {
            if (_tokenHasTax && applyTax_) {
                uint256 tax;

                // on sell
                if (isLiquidityPool(to_) && totalSellTaxBasisPoints() > 0) {
                    uint256 projectTax = ((sentAmount_ *
                        projectSellTaxBasisPoints) / BP_DENOM);
                    projectTaxPendingSwap += uint128(projectTax);
                    tax += projectTax;
                }
                // on buy
                else if (
                    isLiquidityPool(from_) && totalBuyTaxBasisPoints() > 0
                ) {
                    uint256 projectTax = ((sentAmount_ *
                        projectBuyTaxBasisPoints) / BP_DENOM);
                    projectTaxPendingSwap += uint128(projectTax);
                    tax += projectTax;
                }

                if (tax > 0) {
                    _increaseBalance(address(this), tax);
                    emit Transfer(from_, address(this), tax);
                    amountLessTax_ -= tax;
                }
            }
        }
        return (amountLessTax_);
    }

    fallback() external {
        revert("Not supported");
    }

    function withdrawERC20(
        address token_,
        uint256 amount_
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (token_ == address(this)) {
            _revert(CannotWithdrawThisToken.selector);
        }
        IERC20(token_).safeTransfer(_msgSender(), amount_);
    }

    function isLiquidityPool(address queryAddress_) public view returns (bool) {
        return _liquidityPools.contains(queryAddress_);
    }

    function totalBuyTaxBasisPoints() public view returns (uint256) {
        return projectBuyTaxBasisPoints;
    }

    function totalSellTaxBasisPoints() public view returns (uint256) {
        return projectSellTaxBasisPoints;
    }

    function distributeTaxTokens() external {
        if (projectTaxPendingSwap > 0) {
            uint256 projectDistribution = projectTaxPendingSwap;
            projectTaxPendingSwap = 0;
            _transfer(
                address(this),
                projectTaxRecipient,
                projectDistribution,
                false
            );
        }
    }

    function setProjectTaxRecipient(
        address projectTaxRecipient_
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        projectTaxRecipient = projectTaxRecipient_;
        emit ProjectTaxRecipientUpdated(projectTaxRecipient_);
    }

    function setProjectTaxRates(
        uint16 newProjectBuyTaxBasisPoints_,
        uint16 newProjectSellTaxBasisPoints_
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        require(
            newProjectBuyTaxBasisPoints_ < BP_DENOM,
            "Buy tax basis points must be less than 10000"
        );
        require(
            newProjectSellTaxBasisPoints_ < BP_DENOM,
            "Sell tax basis points must be less than 10000"
        );

        uint16 oldBuyTaxBasisPoints = projectBuyTaxBasisPoints;
        uint16 oldSellTaxBasisPoints = projectSellTaxBasisPoints;

        _tokenHasTax =
            newProjectBuyTaxBasisPoints_ > 0 ||
            newProjectSellTaxBasisPoints_ > 0;

        projectBuyTaxBasisPoints = newProjectBuyTaxBasisPoints_;
        projectSellTaxBasisPoints = newProjectSellTaxBasisPoints_;

        emit ProjectTaxBasisPointsChanged(
            oldBuyTaxBasisPoints,
            newProjectBuyTaxBasisPoints_,
            oldSellTaxBasisPoints,
            newProjectSellTaxBasisPoints_
        );
    }
}

File 2 of 47 : AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {ERC165Upgradeable} from "../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.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 AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControl, ERC165Upgradeable {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;


    /// @custom:storage-location erc7201:openzeppelin.storage.AccessControl
    struct AccessControlStorage {
        mapping(bytes32 role => RoleData) _roles;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControl")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant AccessControlStorageLocation = 0x02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800;

    function _getAccessControlStorage() private pure returns (AccessControlStorage storage $) {
        assembly {
            $.slot := AccessControlStorageLocation
        }
    }

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

    function __AccessControl_init() internal onlyInitializing {
    }

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    /**
     * @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) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        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) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        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 {
        AccessControlStorage storage $ = _getAccessControlStorage();
        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) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        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) {
        AccessControlStorage storage $ = _getAccessControlStorage();
        if (hasRole(role, account)) {
            $._roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}

File 3 of 47 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reininitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint64) {
        return _getInitializableStorage()._initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        assembly {
            $.slot := INITIALIZABLE_STORAGE
        }
    }
}

File 4 of 47 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    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;
    }
}

File 5 of 47 : ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {Initializable} from "../../proxy/utils/Initializable.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 ERC165Upgradeable is Initializable, IERC165 {
    function __ERC165_init() internal onlyInitializing {
    }

    function __ERC165_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 6 of 47 : AccessControl.sol
// 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;
        }
    }
}

File 7 of 47 : IAccessControl.sol
// 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;
}

File 8 of 47 : draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;

/**
 * @dev Standard ERC20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}

File 9 of 47 : IERC1271.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1271.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC1271 standard signature validation method for
 * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
 */
interface IERC1271 {
    /**
     * @dev Should return whether the signature provided is valid for the provided data
     * @param hash      Hash of the data to be signed
     * @param signature Signature byte array associated with _data
     */
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}

File 10 of 47 : IERC5267.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)

pragma solidity ^0.8.20;

interface IERC5267 {
    /**
     * @dev MAY be emitted to signal that the domain could have changed.
     */
    event EIP712DomainChanged();

    /**
     * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
     * signature.
     */
    function eip712Domain()
        external
        view
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        );
}

File 11 of 47 : ERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/ERC1155.sol)

pragma solidity ^0.8.20;

import {IERC1155} from "./IERC1155.sol";
import {IERC1155Receiver} from "./IERC1155Receiver.sol";
import {IERC1155MetadataURI} from "./extensions/IERC1155MetadataURI.sol";
import {Context} from "../../utils/Context.sol";
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol";
import {Arrays} from "../../utils/Arrays.sol";
import {IERC1155Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the basic standard multi-token.
 * See https://eips.ethereum.org/EIPS/eip-1155
 * Originally based on code by Enjin: https://github.com/enjin/erc-1155
 */
abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IERC1155Errors {
    using Arrays for uint256[];
    using Arrays for address[];

    mapping(uint256 id => mapping(address account => uint256)) private _balances;

    mapping(address account => mapping(address operator => bool)) private _operatorApprovals;

    // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
    string private _uri;

    /**
     * @dev See {_setURI}.
     */
    constructor(string memory uri_) {
        _setURI(uri_);
    }

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

    /**
     * @dev See {IERC1155MetadataURI-uri}.
     *
     * This implementation returns the same URI for *all* token types. It relies
     * on the token type ID substitution mechanism
     * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
     *
     * Clients calling this function must replace the `\{id\}` substring with the
     * actual token type ID.
     */
    function uri(uint256 /* id */) public view virtual returns (string memory) {
        return _uri;
    }

    /**
     * @dev See {IERC1155-balanceOf}.
     */
    function balanceOf(address account, uint256 id) public view virtual returns (uint256) {
        return _balances[id][account];
    }

    /**
     * @dev See {IERC1155-balanceOfBatch}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(
        address[] memory accounts,
        uint256[] memory ids
    ) public view virtual returns (uint256[] memory) {
        if (accounts.length != ids.length) {
            revert ERC1155InvalidArrayLength(ids.length, accounts.length);
        }

        uint256[] memory batchBalances = new uint256[](accounts.length);

        for (uint256 i = 0; i < accounts.length; ++i) {
            batchBalances[i] = balanceOf(accounts.unsafeMemoryAccess(i), ids.unsafeMemoryAccess(i));
        }

        return batchBalances;
    }

    /**
     * @dev See {IERC1155-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual {
        _setApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC1155-isApprovedForAll}.
     */
    function isApprovedForAll(address account, address operator) public view virtual returns (bool) {
        return _operatorApprovals[account][operator];
    }

    /**
     * @dev See {IERC1155-safeTransferFrom}.
     */
    function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) public virtual {
        address sender = _msgSender();
        if (from != sender && !isApprovedForAll(from, sender)) {
            revert ERC1155MissingApprovalForAll(sender, from);
        }
        _safeTransferFrom(from, to, id, value, data);
    }

    /**
     * @dev See {IERC1155-safeBatchTransferFrom}.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory values,
        bytes memory data
    ) public virtual {
        address sender = _msgSender();
        if (from != sender && !isApprovedForAll(from, sender)) {
            revert ERC1155MissingApprovalForAll(sender, from);
        }
        _safeBatchTransferFrom(from, to, ids, values, data);
    }

    /**
     * @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`. Will mint (or burn) if `from`
     * (or `to`) is the zero address.
     *
     * Emits a {TransferSingle} event if the arrays contain one element, and {TransferBatch} otherwise.
     *
     * Requirements:
     *
     * - If `to` refers to a smart contract, it must implement either {IERC1155Receiver-onERC1155Received}
     *   or {IERC1155Receiver-onERC1155BatchReceived} and return the acceptance magic value.
     * - `ids` and `values` must have the same length.
     *
     * NOTE: The ERC-1155 acceptance check is not performed in this function. See {_updateWithAcceptanceCheck} instead.
     */
    function _update(address from, address to, uint256[] memory ids, uint256[] memory values) internal virtual {
        if (ids.length != values.length) {
            revert ERC1155InvalidArrayLength(ids.length, values.length);
        }

        address operator = _msgSender();

        for (uint256 i = 0; i < ids.length; ++i) {
            uint256 id = ids.unsafeMemoryAccess(i);
            uint256 value = values.unsafeMemoryAccess(i);

            if (from != address(0)) {
                uint256 fromBalance = _balances[id][from];
                if (fromBalance < value) {
                    revert ERC1155InsufficientBalance(from, fromBalance, value, id);
                }
                unchecked {
                    // Overflow not possible: value <= fromBalance
                    _balances[id][from] = fromBalance - value;
                }
            }

            if (to != address(0)) {
                _balances[id][to] += value;
            }
        }

        if (ids.length == 1) {
            uint256 id = ids.unsafeMemoryAccess(0);
            uint256 value = values.unsafeMemoryAccess(0);
            emit TransferSingle(operator, from, to, id, value);
        } else {
            emit TransferBatch(operator, from, to, ids, values);
        }
    }

    /**
     * @dev Version of {_update} that performs the token acceptance check by calling
     * {IERC1155Receiver-onERC1155Received} or {IERC1155Receiver-onERC1155BatchReceived} on the receiver address if it
     * contains code (eg. is a smart contract at the moment of execution).
     *
     * IMPORTANT: Overriding this function is discouraged because it poses a reentrancy risk from the receiver. So any
     * update to the contract state after this function would break the check-effect-interaction pattern. Consider
     * overriding {_update} instead.
     */
    function _updateWithAcceptanceCheck(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory values,
        bytes memory data
    ) internal virtual {
        _update(from, to, ids, values);
        if (to != address(0)) {
            address operator = _msgSender();
            if (ids.length == 1) {
                uint256 id = ids.unsafeMemoryAccess(0);
                uint256 value = values.unsafeMemoryAccess(0);
                _doSafeTransferAcceptanceCheck(operator, from, to, id, value, data);
            } else {
                _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, values, data);
            }
        }
    }

    /**
     * @dev Transfers a `value` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `from` must have a balance of tokens of type `id` of at least `value` amount.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function _safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) internal {
        if (to == address(0)) {
            revert ERC1155InvalidReceiver(address(0));
        }
        if (from == address(0)) {
            revert ERC1155InvalidSender(address(0));
        }
        (uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
        _updateWithAcceptanceCheck(from, to, ids, values, data);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     * - `ids` and `values` must have the same length.
     */
    function _safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory values,
        bytes memory data
    ) internal {
        if (to == address(0)) {
            revert ERC1155InvalidReceiver(address(0));
        }
        if (from == address(0)) {
            revert ERC1155InvalidSender(address(0));
        }
        _updateWithAcceptanceCheck(from, to, ids, values, data);
    }

    /**
     * @dev Sets a new URI for all token types, by relying on the token type ID
     * substitution mechanism
     * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
     *
     * By this mechanism, any occurrence of the `\{id\}` substring in either the
     * URI or any of the values in the JSON file at said URI will be replaced by
     * clients with the token type ID.
     *
     * For example, the `https://token-cdn-domain/\{id\}.json` URI would be
     * interpreted by clients as
     * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
     * for token type ID 0x4cce0.
     *
     * See {uri}.
     *
     * Because these URIs cannot be meaningfully represented by the {URI} event,
     * this function emits no events.
     */
    function _setURI(string memory newuri) internal virtual {
        _uri = newuri;
    }

    /**
     * @dev Creates a `value` amount of tokens of type `id`, and assigns them to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function _mint(address to, uint256 id, uint256 value, bytes memory data) internal {
        if (to == address(0)) {
            revert ERC1155InvalidReceiver(address(0));
        }
        (uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
        _updateWithAcceptanceCheck(address(0), to, ids, values, data);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `values` must have the same length.
     * - `to` cannot be the zero address.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function _mintBatch(address to, uint256[] memory ids, uint256[] memory values, bytes memory data) internal {
        if (to == address(0)) {
            revert ERC1155InvalidReceiver(address(0));
        }
        _updateWithAcceptanceCheck(address(0), to, ids, values, data);
    }

    /**
     * @dev Destroys a `value` amount of tokens of type `id` from `from`
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `from` must have at least `value` amount of tokens of type `id`.
     */
    function _burn(address from, uint256 id, uint256 value) internal {
        if (from == address(0)) {
            revert ERC1155InvalidSender(address(0));
        }
        (uint256[] memory ids, uint256[] memory values) = _asSingletonArrays(id, value);
        _updateWithAcceptanceCheck(from, address(0), ids, values, "");
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `from` must have at least `value` amount of tokens of type `id`.
     * - `ids` and `values` must have the same length.
     */
    function _burnBatch(address from, uint256[] memory ids, uint256[] memory values) internal {
        if (from == address(0)) {
            revert ERC1155InvalidSender(address(0));
        }
        _updateWithAcceptanceCheck(from, address(0), ids, values, "");
    }

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the zero address.
     */
    function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
        if (operator == address(0)) {
            revert ERC1155InvalidOperator(address(0));
        }
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Performs an acceptance check by calling {IERC1155-onERC1155Received} on the `to` address
     * if it contains code at the moment of execution.
     */
    function _doSafeTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256 id,
        uint256 value,
        bytes memory data
    ) private {
        if (to.code.length > 0) {
            try IERC1155Receiver(to).onERC1155Received(operator, from, id, value, data) returns (bytes4 response) {
                if (response != IERC1155Receiver.onERC1155Received.selector) {
                    // Tokens rejected
                    revert ERC1155InvalidReceiver(to);
                }
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    // non-ERC1155Receiver implementer
                    revert ERC1155InvalidReceiver(to);
                } else {
                    /// @solidity memory-safe-assembly
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        }
    }

    /**
     * @dev Performs a batch acceptance check by calling {IERC1155-onERC1155BatchReceived} on the `to` address
     * if it contains code at the moment of execution.
     */
    function _doSafeBatchTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory values,
        bytes memory data
    ) private {
        if (to.code.length > 0) {
            try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, values, data) returns (
                bytes4 response
            ) {
                if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
                    // Tokens rejected
                    revert ERC1155InvalidReceiver(to);
                }
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    // non-ERC1155Receiver implementer
                    revert ERC1155InvalidReceiver(to);
                } else {
                    /// @solidity memory-safe-assembly
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        }
    }

    /**
     * @dev Creates an array in memory with only one value for each of the elements provided.
     */
    function _asSingletonArrays(
        uint256 element1,
        uint256 element2
    ) private pure returns (uint256[] memory array1, uint256[] memory array2) {
        /// @solidity memory-safe-assembly
        assembly {
            // Load the free memory pointer
            array1 := mload(0x40)
            // Set array length to 1
            mstore(array1, 1)
            // Store the single element at the next word after the length (where content starts)
            mstore(add(array1, 0x20), element1)

            // Repeat for next array locating it right after the first array
            array2 := add(array1, 0x40)
            mstore(array2, 1)
            mstore(add(array2, 0x20), element2)

            // Update the free memory pointer by pointing after the second array
            mstore(0x40, add(array2, 0x40))
        }
    }
}

File 12 of 47 : ERC1155Burnable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/extensions/ERC1155Burnable.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Extension of {ERC1155} that allows token holders to destroy both their
 * own tokens and those that they have been approved to use.
 */
abstract contract ERC1155Burnable is ERC1155 {
    function burn(address account, uint256 id, uint256 value) public virtual {
        if (account != _msgSender() && !isApprovedForAll(account, _msgSender())) {
            revert ERC1155MissingApprovalForAll(_msgSender(), account);
        }

        _burn(account, id, value);
    }

    function burnBatch(address account, uint256[] memory ids, uint256[] memory values) public virtual {
        if (account != _msgSender() && !isApprovedForAll(account, _msgSender())) {
            revert ERC1155MissingApprovalForAll(_msgSender(), account);
        }

        _burnBatch(account, ids, values);
    }
}

File 13 of 47 : IERC1155MetadataURI.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/extensions/IERC1155MetadataURI.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Interface of the optional ERC1155MetadataExtension interface, as defined
 * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
 */
interface IERC1155MetadataURI is IERC1155 {
    /**
     * @dev Returns the URI for token type `id`.
     *
     * If the `\{id\}` substring is present in the URI, it must be replaced by
     * clients with the actual token type ID.
     */
    function uri(uint256 id) external view returns (string memory);
}

File 14 of 47 : IERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 */
interface IERC1155 is IERC165 {
    /**
     * @dev Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`.
     */
    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);

    /**
     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
     * transfers.
     */
    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    /**
     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
     * `approved`.
     */
    event ApprovalForAll(address indexed account, address indexed operator, bool approved);

    /**
     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
     *
     * If an {URI} event was emitted for `id`, the standard
     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
     * returned by {IERC1155MetadataURI-uri}.
     */
    event URI(string value, uint256 indexed id);

    /**
     * @dev Returns the value of tokens of token type `id` owned by `account`.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) external view returns (uint256);

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(
        address[] calldata accounts,
        uint256[] calldata ids
    ) external view returns (uint256[] memory);

    /**
     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the caller.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address account, address operator) external view returns (bool);

    /**
     * @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`.
     *
     * WARNING: This function can potentially allow a reentrancy attack when transferring tokens
     * to an untrusted contract, when invoking {onERC1155Received} on the receiver.
     * Ensure to follow the checks-effects-interactions pattern and consider employing
     * reentrancy guards when interacting with untrusted contracts.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `value` amount.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     *
     * WARNING: This function can potentially allow a reentrancy attack when transferring tokens
     * to an untrusted contract, when invoking {onERC1155BatchReceived} on the receiver.
     * Ensure to follow the checks-effects-interactions pattern and consider employing
     * reentrancy guards when interacting with untrusted contracts.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `values` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external;
}

File 15 of 47 : IERC1155Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155Receiver.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Interface that must be implemented by smart contracts in order to receive
 * ERC-1155 token transfers.
 */
interface IERC1155Receiver is IERC165 {
    /**
     * @dev Handles the receipt of a single ERC1155 token type. This function is
     * called at the end of a `safeTransferFrom` after the balance has been updated.
     *
     * NOTE: To accept the transfer, this must return
     * `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
     * (i.e. 0xf23a6e61, or its own function selector).
     *
     * @param operator The address which initiated the transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param id The ID of the token being transferred
     * @param value The amount of tokens being transferred
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
     */
    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external returns (bytes4);

    /**
     * @dev Handles the receipt of a multiple ERC1155 token types. This function
     * is called at the end of a `safeBatchTransferFrom` after the balances have
     * been updated.
     *
     * NOTE: To accept the transfer(s), this must return
     * `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
     * (i.e. 0xbc197c81, or its own function selector).
     *
     * @param operator The address which initiated the batch transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param ids An array containing ids of each token being transferred (order and length must match values array)
     * @param values An array containing amounts of each token being transferred (order and length must match ids array)
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
     */
    function onERC1155BatchReceived(
        address operator,
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external returns (bytes4);
}

File 16 of 47 : ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

    mapping(address account => mapping(address spender => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `value`.
     */
    function transfer(address to, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `value`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `value`.
     */
    function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, value);
        _transfer(from, to, value);
        return true;
    }

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
     * true using the following override:
     * ```
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `value`.
     *
     * Does not update the allowance value in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Does not emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            if (currentAllowance < value) {
                revert ERC20InsufficientAllowance(spender, currentAllowance, value);
            }
            unchecked {
                _approve(owner, spender, currentAllowance - value, false);
            }
        }
    }
}

File 17 of 47 : ERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Permit.sol)

pragma solidity ^0.8.20;

import {IERC20Permit} from "./IERC20Permit.sol";
import {ERC20} from "../ERC20.sol";
import {ECDSA} from "../../../utils/cryptography/ECDSA.sol";
import {EIP712} from "../../../utils/cryptography/EIP712.sol";
import {Nonces} from "../../../utils/Nonces.sol";

/**
 * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712, Nonces {
    bytes32 private constant PERMIT_TYPEHASH =
        keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");

    /**
     * @dev Permit deadline has expired.
     */
    error ERC2612ExpiredSignature(uint256 deadline);

    /**
     * @dev Mismatched signature.
     */
    error ERC2612InvalidSigner(address signer, address owner);

    /**
     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
     *
     * It's a good idea to use the same `name` that is defined as the ERC20 token name.
     */
    constructor(string memory name) EIP712(name, "1") {}

    /**
     * @inheritdoc IERC20Permit
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        if (block.timestamp > deadline) {
            revert ERC2612ExpiredSignature(deadline);
        }

        bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));

        bytes32 hash = _hashTypedDataV4(structHash);

        address signer = ECDSA.recover(hash, v, r, s);
        if (signer != owner) {
            revert ERC2612InvalidSigner(signer, owner);
        }

        _approve(owner, spender, value);
    }

    /**
     * @inheritdoc IERC20Permit
     */
    function nonces(address owner) public view virtual override(IERC20Permit, Nonces) returns (uint256) {
        return super.nonces(owner);
    }

    /**
     * @inheritdoc IERC20Permit
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view virtual returns (bytes32) {
        return _domainSeparatorV4();
    }
}

File 18 of 47 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 19 of 47 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 20 of 47 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the 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);
}

File 21 of 47 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 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 {
    using Address for address;

    /**
     * @dev An operation with an ERC20 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 Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    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.
     */
    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.
     */
    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 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).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            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 silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}

File 22 of 47 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
     *   {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the address zero.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

File 23 of 47 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}

File 24 of 47 : Arrays.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Arrays.sol)

pragma solidity ^0.8.20;

import {StorageSlot} from "./StorageSlot.sol";
import {Math} from "./math/Math.sol";

/**
 * @dev Collection of functions related to array types.
 */
library Arrays {
    using StorageSlot for bytes32;

    /**
     * @dev Searches a sorted `array` and returns the first index that contains
     * a value greater or equal to `element`. If no such index exists (i.e. all
     * values in the array are strictly less than `element`), the array length is
     * returned. Time complexity O(log n).
     *
     * `array` is expected to be sorted in ascending order, and to contain no
     * repeated elements.
     */
    function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
        uint256 low = 0;
        uint256 high = array.length;

        if (high == 0) {
            return 0;
        }

        while (low < high) {
            uint256 mid = Math.average(low, high);

            // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
            // because Math.average rounds towards zero (it does integer division with truncation).
            if (unsafeAccess(array, mid).value > element) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }

        // At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
        if (low > 0 && unsafeAccess(array, low - 1).value == element) {
            return low - 1;
        } else {
            return low;
        }
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlot.AddressSlot storage) {
        bytes32 slot;
        // We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
        // following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.

        /// @solidity memory-safe-assembly
        assembly {
            mstore(0, arr.slot)
            slot := add(keccak256(0, 0x20), pos)
        }
        return slot.getAddressSlot();
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlot.Bytes32Slot storage) {
        bytes32 slot;
        // We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
        // following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.

        /// @solidity memory-safe-assembly
        assembly {
            mstore(0, arr.slot)
            slot := add(keccak256(0, 0x20), pos)
        }
        return slot.getBytes32Slot();
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlot.Uint256Slot storage) {
        bytes32 slot;
        // We use assembly to calculate the storage slot of the element at index `pos` of the dynamic array `arr`
        // following https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays.

        /// @solidity memory-safe-assembly
        assembly {
            mstore(0, arr.slot)
            slot := add(keccak256(0, 0x20), pos)
        }
        return slot.getUint256Slot();
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeMemoryAccess(uint256[] memory arr, uint256 pos) internal pure returns (uint256 res) {
        assembly {
            res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
        }
    }

    /**
     * @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
     *
     * WARNING: Only use if you are certain `pos` is lower than the array length.
     */
    function unsafeMemoryAccess(address[] memory arr, uint256 pos) internal pure returns (address res) {
        assembly {
            res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
        }
    }
}

File 25 of 47 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (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;
    }
}

File 26 of 47 : ECDSA.sol
// 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);
        }
    }
}

File 27 of 47 : EIP712.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.20;

import {MessageHashUtils} from "./MessageHashUtils.sol";
import {ShortStrings, ShortString} from "../ShortStrings.sol";
import {IERC5267} from "../../interfaces/IERC5267.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose
 * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract
 * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to
 * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
 * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the
 * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
 *
 * @custom:oz-upgrades-unsafe-allow state-variable-immutable
 */
abstract contract EIP712 is IERC5267 {
    using ShortStrings for *;

    bytes32 private constant TYPE_HASH =
        keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _cachedDomainSeparator;
    uint256 private immutable _cachedChainId;
    address private immutable _cachedThis;

    bytes32 private immutable _hashedName;
    bytes32 private immutable _hashedVersion;

    ShortString private immutable _name;
    ShortString private immutable _version;
    string private _nameFallback;
    string private _versionFallback;

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        _name = name.toShortStringWithFallback(_nameFallback);
        _version = version.toShortStringWithFallback(_versionFallback);
        _hashedName = keccak256(bytes(name));
        _hashedVersion = keccak256(bytes(version));

        _cachedChainId = block.chainid;
        _cachedDomainSeparator = _buildDomainSeparator();
        _cachedThis = address(this);
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
            return _cachedDomainSeparator;
        } else {
            return _buildDomainSeparator();
        }
    }

    function _buildDomainSeparator() private view returns (bytes32) {
        return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
    }

    /**
     * @dev See {IERC-5267}.
     */
    function eip712Domain()
        public
        view
        virtual
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        )
    {
        return (
            hex"0f", // 01111
            _EIP712Name(),
            _EIP712Version(),
            block.chainid,
            address(this),
            bytes32(0),
            new uint256[](0)
        );
    }

    /**
     * @dev The name parameter for the EIP712 domain.
     *
     * NOTE: By default this function reads _name which is an immutable value.
     * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
     */
    // solhint-disable-next-line func-name-mixedcase
    function _EIP712Name() internal view returns (string memory) {
        return _name.toStringWithFallback(_nameFallback);
    }

    /**
     * @dev The version parameter for the EIP712 domain.
     *
     * NOTE: By default this function reads _version which is an immutable value.
     * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
     */
    // solhint-disable-next-line func-name-mixedcase
    function _EIP712Version() internal view returns (string memory) {
        return _version.toStringWithFallback(_versionFallback);
    }
}

File 28 of 47 : MessageHashUtils.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
 *
 * The library provides methods for generating a hash of a message that conforms to the
 * https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
 * specifications.
 */
library MessageHashUtils {
    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing a bytes32 `messageHash` with
     * `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
     * keccak256, although any bytes32 value can be safely used because the final digest will
     * be re-hashed.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
            mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
            digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
        }
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing an arbitrary `message` with
     * `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
        return
            keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x00` (data with intended validator).
     *
     * The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
     * `validator` address. Then hashing the result.
     *
     * See {ECDSA-recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(hex"19_00", validator, data));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).
     *
     * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
     * `\x19\x01` and hashing the result. It corresponds to the hash signed by the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
     *
     * See {ECDSA-recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, hex"19_01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            digest := keccak256(ptr, 0x42)
        }
    }
}

File 29 of 47 : SignatureChecker.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/SignatureChecker.sol)

pragma solidity ^0.8.20;

import {ECDSA} from "./ECDSA.sol";
import {IERC1271} from "../../interfaces/IERC1271.sol";

/**
 * @dev Signature verification helper that can be used instead of `ECDSA.recover` to seamlessly support both ECDSA
 * signatures from externally owned accounts (EOAs) as well as ERC1271 signatures from smart contract wallets like
 * Argent and Safe Wallet (previously Gnosis Safe).
 */
library SignatureChecker {
    /**
     * @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the
     * signature is validated against that smart contract using ERC1271, otherwise it's validated using `ECDSA.recover`.
     *
     * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
     * change through time. It could return true at block N and false at block N+1 (or the opposite).
     */
    function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
        (address recovered, ECDSA.RecoverError error, ) = ECDSA.tryRecover(hash, signature);
        return
            (error == ECDSA.RecoverError.NoError && recovered == signer) ||
            isValidERC1271SignatureNow(signer, hash, signature);
    }

    /**
     * @dev Checks if a signature is valid for a given signer and data hash. The signature is validated
     * against the signer smart contract using ERC1271.
     *
     * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
     * change through time. It could return true at block N and false at block N+1 (or the opposite).
     */
    function isValidERC1271SignatureNow(
        address signer,
        bytes32 hash,
        bytes memory signature
    ) internal view returns (bool) {
        (bool success, bytes memory result) = signer.staticcall(
            abi.encodeCall(IERC1271.isValidSignature, (hash, signature))
        );
        return (success &&
            result.length >= 32 &&
            abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector));
    }
}

File 30 of 47 : ERC165.sol
// 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;
    }
}

File 31 of 47 : IERC165.sol
// 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);
}

File 32 of 47 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
     * Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator.
            // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.

            uint256 twos = denominator & (0 - denominator);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
            // works in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}

File 33 of 47 : SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

File 34 of 47 : Nonces.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Nonces.sol)
pragma solidity ^0.8.20;

/**
 * @dev Provides tracking nonces for addresses. Nonces will only increment.
 */
abstract contract Nonces {
    /**
     * @dev The nonce used for an `account` is not the expected current nonce.
     */
    error InvalidAccountNonce(address account, uint256 currentNonce);

    mapping(address account => uint256) private _nonces;

    /**
     * @dev Returns the next unused nonce for an address.
     */
    function nonces(address owner) public view virtual returns (uint256) {
        return _nonces[owner];
    }

    /**
     * @dev Consumes a nonce.
     *
     * Returns the current value and increments nonce.
     */
    function _useNonce(address owner) internal virtual returns (uint256) {
        // For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be
        // decremented or reset. This guarantees that the nonce never overflows.
        unchecked {
            // It is important to do x++ and not ++x here.
            return _nonces[owner]++;
        }
    }

    /**
     * @dev Same as {_useNonce} but checking that `nonce` is the next valid for `owner`.
     */
    function _useCheckedNonce(address owner, uint256 nonce) internal virtual {
        uint256 current = _useNonce(owner);
        if (nonce != current) {
            revert InvalidAccountNonce(owner, current);
        }
    }
}

File 35 of 47 : ShortStrings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ShortStrings.sol)

pragma solidity ^0.8.20;

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

// | string  | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA   |
// | length  | 0x                                                              BB |
type ShortString is bytes32;

/**
 * @dev This library provides functions to convert short memory strings
 * into a `ShortString` type that can be used as an immutable variable.
 *
 * Strings of arbitrary length can be optimized using this library if
 * they are short enough (up to 31 bytes) by packing them with their
 * length (1 byte) in a single EVM word (32 bytes). Additionally, a
 * fallback mechanism can be used for every other case.
 *
 * Usage example:
 *
 * ```solidity
 * contract Named {
 *     using ShortStrings for *;
 *
 *     ShortString private immutable _name;
 *     string private _nameFallback;
 *
 *     constructor(string memory contractName) {
 *         _name = contractName.toShortStringWithFallback(_nameFallback);
 *     }
 *
 *     function name() external view returns (string memory) {
 *         return _name.toStringWithFallback(_nameFallback);
 *     }
 * }
 * ```
 */
library ShortStrings {
    // Used as an identifier for strings longer than 31 bytes.
    bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;

    error StringTooLong(string str);
    error InvalidShortString();

    /**
     * @dev Encode a string of at most 31 chars into a `ShortString`.
     *
     * This will trigger a `StringTooLong` error is the input string is too long.
     */
    function toShortString(string memory str) internal pure returns (ShortString) {
        bytes memory bstr = bytes(str);
        if (bstr.length > 31) {
            revert StringTooLong(str);
        }
        return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
    }

    /**
     * @dev Decode a `ShortString` back to a "normal" string.
     */
    function toString(ShortString sstr) internal pure returns (string memory) {
        uint256 len = byteLength(sstr);
        // using `new string(len)` would work locally but is not memory safe.
        string memory str = new string(32);
        /// @solidity memory-safe-assembly
        assembly {
            mstore(str, len)
            mstore(add(str, 0x20), sstr)
        }
        return str;
    }

    /**
     * @dev Return the length of a `ShortString`.
     */
    function byteLength(ShortString sstr) internal pure returns (uint256) {
        uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
        if (result > 31) {
            revert InvalidShortString();
        }
        return result;
    }

    /**
     * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
     */
    function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
        if (bytes(value).length < 32) {
            return toShortString(value);
        } else {
            StorageSlot.getStringSlot(store).value = value;
            return ShortString.wrap(FALLBACK_SENTINEL);
        }
    }

    /**
     * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
     */
    function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
        if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
            return toString(value);
        } else {
            return store;
        }
    }

    /**
     * @dev Return the length of a string that was encoded to `ShortString` or written to storage using
     * {setWithFallback}.
     *
     * WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
     * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
     */
    function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
        if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
            return byteLength(value);
        } else {
            return bytes(store).length;
        }
    }
}

File 36 of 47 : StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}

File 37 of 47 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)

pragma solidity ^0.8.20;

import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";

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

    /**
     * @dev The `value` string doesn't fit in the specified `length`.
     */
    error StringsInsufficientHexLength(uint256 value, uint256 length);

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toStringSigned(int256 value) internal pure returns (string memory) {
        return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

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

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

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

File 38 of 47 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

                // Move the lastValue to the index where the value to delete is
                set._values[valueIndex] = lastValue;
                // Update the tracked position of the lastValue (that was just moved)
                set._positions[lastValue] = position;
            }

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

            // Delete the tracked position for the deleted slot
            delete set._positions[value];

            return true;
        } else {
            return false;
        }
    }

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

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

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

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }
}

File 39 of 47 : IERC2981.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

/**
 * @dev Interface for the NFT Royalty Standard
 */
interface IERC2981 is IERC165 {
    /**
     * @notice Called with the sale price to determine how much royalty
     * is owed and to whom.
     * @param _tokenId - the NFT asset queried for royalty information
     * @param _salePrice - the sale price of the NFT asset specified by _tokenId
     * @return receiver - address of who should be sent the royalty payment
     * @return royaltyAmount - the royalty payment amount for _salePrice
     */
    function royaltyInfo(
        uint256 _tokenId,
        uint256 _salePrice
    ) external view returns (address receiver, uint256 royaltyAmount);
}

File 40 of 47 : IShop.sol
// SPDX-License-Identifier: MIT
// This contract is based off of the INiftyswapExchange20 from Niftyswap repository (https://github.com/0xsequence/niftyswap).
pragma solidity ^0.8.20;

interface IShop {
    event TokensPurchase(
        address indexed buyer,
        address indexed recipient,
        uint256[] tokensBoughtIds,
        uint256[] tokensBoughtAmounts,
        uint256[] currencySoldAmounts
    );

    event CurrencyPurchase(
        address indexed buyer,
        address indexed recipient,
        uint256[] tokensSoldIds,
        uint256[] tokensSoldAmounts,
        uint256[] currencyBoughtAmounts
    );

    event LiquidityAdded(
        address indexed provider, uint256[] tokenIds, uint256[] tokenAmounts, uint256[] currencyAmounts
    );

    struct LiquidityRemovedEventObj {
        uint256 currencyAmount;
        uint256 soldTokenNumerator;
        uint256 boughtCurrencyNumerator;
        uint256 totalSupply;
    }

    event LiquidityRemoved(
        address indexed provider, uint256[] tokenIds, uint256[] tokenAmounts, LiquidityRemovedEventObj[] details
    );

    event RoyaltyChanged(address indexed royaltyRecipient, uint256 royaltyFee);

    struct SellTokensObj {
        address recipient; // Who receives the currency
        uint256 minCurrency; // Total minimum number of currency  expected for all tokens sold
        uint256 deadline; // Timestamp after which the tx isn't valid anymore
    }

    struct AddLiquidityObj {
        uint256[] maxCurrency; // Maximum number of currency to deposit with tokens
        uint256 deadline; // Timestamp after which the tx isn't valid anymore
    }

    struct RemoveLiquidityObj {
        uint256[] minCurrency; // Minimum number of currency to withdraw
        uint256[] minTokens; // Minimum number of tokens to withdraw
        uint256 deadline; // Timestamp after which the tx isn't valid anymore
    }

    //
    // Purchasing Functions
    //

    /**
     * @notice Convert currency tokens to Tokens _id and transfers Tokens to recipient.
     * @dev User specifies MAXIMUM inputs (_maxCurrency) and EXACT outputs.
     * @dev Assumes that all trades will be successful, or revert the whole tx
     * @dev Exceeding currency tokens sent will be refunded to recipient
     * @dev Sorting IDs is mandatory for efficient way of preventing duplicated IDs (which would lead to exploit)
     * @param _tokenIds            Array of Tokens ID that are bought
     * @param _tokensBoughtAmounts Amount of Tokens id bought for each corresponding Token id in _tokenIds
     * @param _maxCurrency         Total maximum amount of currency tokens to spend for all Token ids
     * @param _deadline            Timestamp after which this transaction will be reverted
     * @param _recipient           The address that receives output Tokens and refund
     * @return currencySold How much currency was actually sold.
     */
    function buyTokens(
        uint256[] memory _tokenIds,
        uint256[] memory _tokensBoughtAmounts,
        uint256 _maxCurrency,
        uint256 _deadline,
        address _recipient
    ) external returns (uint256[] memory);

    //
    // OnReceive Functions
    //

    /**
     * @notice Handle which method is being called on Token transfer
     * @dev `_data` must be encoded as follow: abi.encode(bytes4, MethodObj)
     * where bytes4 argument is the MethodObj object signature passed as defined
     * in the `Signatures for onReceive control logic` section above
     * @param _operator The address which called the `safeTransferFrom` function
     * @param _from     The address which previously owned the token
     * @param _id       The id of the token being transferred
     * @param _amount   The amount of tokens being transferred
     * @param _data     Method signature and corresponding encoded arguments for method to call on *this* contract
     * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
     */
    function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _amount, bytes calldata _data)
        external
        returns (bytes4);

    /**
     * @notice Handle which method is being called on transfer
     * @dev `_data` must be encoded as follow: abi.encode(bytes4, MethodObj)
     * where bytes4 argument is the MethodObj object signature passed as defined
     * in the `Signatures for onReceive control logic` section above
     * @param _from     The address which previously owned the Token
     * @param _ids      An array containing ids of each Token being transferred
     * @param _amounts  An array containing amounts of each Token being transferred
     * @param _data     Method signature and corresponding encoded arguments for method to call on *this* contract
     * @return bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)")
     */
    function onERC1155BatchReceived(
        address,
        address _from,
        uint256[] calldata _ids,
        uint256[] calldata _amounts,
        bytes calldata _data
    ) external returns (bytes4);

    //
    // Getter Functions
    //

    /**
     * @dev Pricing function used for converting between currency token to Tokens.
     * @param _assetBoughtAmount  Amount of Tokens being bought.
     * @param _assetSoldReserve   Amount of currency tokens in exchange reserves.
     * @param _assetBoughtReserve Amount of Tokens (output type) in exchange reserves.
     * @return Amount of currency tokens to send to Niftyswap.
     */
    function getBuyPrice(uint256 _assetBoughtAmount, uint256 _assetSoldReserve, uint256 _assetBoughtReserve)
        external
        view
        returns (uint256);

   
    /**
     * @dev Pricing function used for converting Tokens to currency token.
     * @param _assetSoldAmount    Amount of Tokens being sold.
     * @param _assetSoldReserve   Amount of Tokens in exchange reserves.
     * @param _assetBoughtReserve Amount of currency tokens in exchange reserves.
     * @return Amount of currency tokens to receive from Niftyswap.
     */
    function getSellPrice(uint256 _assetSoldAmount, uint256 _assetSoldReserve, uint256 _assetBoughtReserve)
        external
        view
        returns (uint256);
    /**
     * @notice Get amount of currency in reserve for each Token _id in _ids
     * @param _ids Array of ID sto query currency reserve of
     * @return amount of currency in reserve for each Token _id
     */
    function getCurrencyReserves(uint256[] calldata _ids) external view returns (uint256[] memory);

    /**
     * @notice Return price for `currency => Token _id` trades with an exact token amount.
     * @param _ids          Array of ID of tokens bought.
     * @param _tokensBought Amount of Tokens bought.
     * @return Amount of currency needed to buy Tokens in _ids for amounts in _tokensBought
     */
    function getPrice_currencyToToken(uint256[] calldata _ids, uint256[] calldata _tokensBought)
        external
        view
        returns (uint256[] memory);

    /**
     * @notice Return price for `Token _id => currency` trades with an exact token amount.
     * @param _ids        Array of IDs  token sold.
     * @param _tokensSold Array of amount of each Token sold.
     * @return Amount of currency that can be bought for Tokens in _ids for amounts in _tokensSold
     */
    function getPrice_tokenToCurrency(uint256[] calldata _ids, uint256[] calldata _tokensSold)
        external
        view
        returns (uint256[] memory);

    /**
     * @notice Get total supply of liquidity tokens
     * @param _ids ID of the Tokens
     * @return The total supply of each liquidity token id provided in _ids
     */
    function getTotalSupply(uint256[] calldata _ids) external view returns (uint256[] memory);

    /**
     * @return Address of Token that is sold on this exchange.
     */
    function getTokenAddress() external view returns (address);

    /**
     * @return Address of the currency contract that is used as currency
     */
    function getCurrencyInfo() external view returns (address);

    /**
     * @return Address of factory that created this exchange.
     */
    function getFactoryAddress() external view returns (address);
}

File 41 of 47 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 42 of 47 : Shop.sol
// SPDX-License-Identifier: MIT
// This contract is based off of the ShopExchange20 from Shop repository (https://github.com/0xsequence/niftyswap).
// We removed the royalty portion as it is not needed for our use case.
pragma solidity ^0.8.20;

import {IShop} from "./IShop.sol";
import {ReentrancyGuard} from "./ReentrancyGuard.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC1155MetadataURI} from "@openzeppelin/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol";
import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {IERC1155Receiver} from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
import {TransferHelper} from "./TransferHelper.sol";
import {ERC1155Burnable} from "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
import {IERC2981} from "./IERC2981.sol";

/**
 * This Uniswap-like implementation supports ERC-1155 standard tokens
 * with an ERC-20 based token used as a currency instead of Ether.
 *
 * Liquidity tokens are also ERC-1155 tokens you can find the ERC-1155
 * implementation used here:
 * https://github.com/horizon-games/multi-token-standard/tree/master/contracts/tokens/ERC1155
 *
 * @dev Like Uniswap, tokens with 0 decimals and low supply are susceptible to significant rounding
 * errors when it comes to removing liquidity, possibly preventing them to be withdrawn without
 * some collaboration between liquidity providers.
 *
 * @dev ERC-777 tokens may be vulnerable if used as currency in Shop. Please review the code
 * carefully before using it with ERC-777 tokens.
 */
contract Shop is ReentrancyGuard, IShop, ERC1155, ERC1155Burnable {
    // Variables
    IERC1155 internal immutable token; // address of the ERC-1155 token contract
    address internal immutable currency; // address of the ERC-20 currency used for exchange
    address internal immutable factory; // address for the factory that created this contract

    // Royalty variables
    bool internal immutable IS_ERC2981; // whether token contract supports ERC-2981

    // onReceive function signatures
    bytes4 internal constant ERC1155_RECEIVED_VALUE = 0xf23a6e61;
    bytes4 internal constant ERC1155_BATCH_RECEIVED_VALUE = 0xbc197c81;

    // Mapping variables
    mapping(uint256 => uint256) internal totalSupplies; // Liquidity pool token supply per Token id
    mapping(uint256 => uint256) internal currencyReserves; // currency Token reserve per Token id
    mapping(address => uint256) internal royaltiesNumerator; // Mapping tracking how much royalties can be claimed per address

    uint256 internal constant ROYALTIES_DENOMINATOR = 10000;

    //
    // Constructor
    //

    /**
     * @notice Create instance of exchange contract with respective token and currency token
     * @dev If token supports ERC-2981, then royalty fee will be queried per token on the
     * token contract. Else royalty fee will need to be manually set by admin.
     * @param _tokenAddr     The address of the ERC-1155 Token
     * @param _currencyAddr  The address of the ERC-20 currency Token
     * @param _currencyAddr  Address of the admin, which should be the same as the factory owner
     * Number between 0 and 1000, where 10 is 1.0% and 100 is 10%.
     */
    constructor(
        address _tokenAddr,
        address _currencyAddr,
        string memory _uri
    ) ERC1155(_uri) {
        require(
            _tokenAddr != address(0) && _currencyAddr != address(0),
            "E#1" // Error#constructor:INVALID_INPUT
        );

        factory = msg.sender;
        token = IERC1155(_tokenAddr);
        currency = _currencyAddr;

        IS_ERC2981 = IERC1155(_tokenAddr).supportsInterface(
            type(IERC2981).interfaceId
        );
    }

    //
    // Exchange Functions
    //

    /**
     * @notice Convert currency tokens to Tokens _id and transfers Tokens to recipient.
     */
    function _currencyToToken(
        uint256[] memory _tokenIds,
        uint256[] memory _tokensBoughtAmounts,
        uint256 _maxCurrency,
        uint256 _deadline,
        address _recipient
    ) internal nonReentrant returns (uint256[] memory currencySold) {
        // Input validation
        // solhint-disable-next-line not-rely-on-time
        require(_deadline >= block.timestamp, "E#3"); // Error#_currencyToToken: DEADLINE_EXCEEDED
        require(_tokenIds.length == _tokensBoughtAmounts.length, "E#2"); // Error#_currencyToToken: INVALID_TOKENS_AMOUNT

        // Number of Token IDs to deposit
        uint256 nTokens = _tokenIds.length;
        uint256 totalRefundCurrency = _maxCurrency;

        // Initialize variables
        currencySold = new uint256[](nTokens); // Amount of currency tokens sold per ID

        // Get token reserves
        uint256[] memory tokenReserves = _getTokenReserves(_tokenIds);

        // Assumes the currency Tokens are already received by contract, but not
        // the Tokens Ids

        // Remove liquidity for each Token ID in _tokenIds
        for (uint256 i = 0; i < nTokens; i++) {
            // Store current id and amount from argument arrays
            uint256 idBought = _tokenIds[i];
            uint256 amountBought = _tokensBoughtAmounts[i];
            uint256 tokenReserve = tokenReserves[i];

            require(amountBought > 0, "E#4"); // Error#_currencyToToken: NULL_TOKENS_BOUGHT

            // Load currency token and Token _id reserves
            uint256 currencyReserve = currencyReserves[idBought];

            // Get amount of currency tokens to send for purchase
            // Neither reserves amount have been changed so far in this transaction, so
            // no adjustment to the inputs is needed
            uint256 currencyAmount = getBuyPrice(
                amountBought,
                currencyReserve,
                tokenReserve
            );

            // Calculate currency token amount to refund (if any) where whatever is not used will be returned
            // Will throw if total cost exceeds _maxCurrency
            totalRefundCurrency -= currencyAmount;

            // Append Token id, Token id amount and currency token amount to tracking arrays
            currencySold[i] = currencyAmount;

            // Update individual currency reseve amount (royalty is not added to liquidity)
            currencyReserves[idBought] = currencyReserve + currencyAmount;
        }

        // Send Tokens all tokens purchased
        token.safeBatchTransferFrom(
            address(this),
            _recipient,
            _tokenIds,
            _tokensBoughtAmounts,
            ""
        );

        // Refund currency token if any
        if (totalRefundCurrency > 0) {
            TransferHelper.safeTransfer(
                currency,
                _recipient,
                totalRefundCurrency
            );
        }

        return currencySold;
    }

    /**
     * @dev Pricing function used for converting between currency token to Tokens.
     * @param _assetBoughtAmount  Amount of Tokens being bought.
     * @param _assetSoldReserve   Amount of currency tokens in exchange reserves.
     * @param _assetBoughtReserve Amount of Tokens (output type) in exchange reserves.
     * @return price Amount of currency tokens to send to Shop.
     */
    function getBuyPrice(
        uint256 _assetBoughtAmount,
        uint256 _assetSoldReserve,
        uint256 _assetBoughtReserve
    ) public view override returns (uint256 price) {
        // Reserves must not be empty
        require(_assetSoldReserve > 0 && _assetBoughtReserve > 0, "E#5"); // Error#getBuyPrice: EMPTY_RESERVE

        // Calculate price with fee
        uint256 numerator = _assetSoldReserve * _assetBoughtAmount * 1000;
        uint256 denominator = (_assetBoughtReserve - _assetBoughtAmount) * 1000;
        (price, ) = divRound(numerator, denominator);
        return price; // Will add 1 if rounding error
    }

    /**
     * @notice Convert Tokens _id to currency tokens and transfers Tokens to recipient.
     * @dev User specifies EXACT Tokens _id sold and MINIMUM currency tokens received.
     * @dev Assumes that all trades will be valid, or the whole tx will fail
     * @dev Sorting _tokenIds is mandatory for efficient way of preventing duplicated IDs (which would lead to errors)
     * @param _tokenIds           Array of Token IDs that are sold
     * @param _tokensSoldAmounts  Array of Amount of Tokens sold for each id in _tokenIds.
     * @param _minCurrency        Minimum amount of currency tokens to receive
     * @param _deadline           Timestamp after which this transaction will be reverted
     * @param _recipient          The address that receives output currency tokens.
     * @return currencyBought How much currency was actually purchased.
     */
    function _tokenToCurrency(
        uint256[] memory _tokenIds,
        uint256[] memory _tokensSoldAmounts,
        uint256 _minCurrency,
        uint256 _deadline,
        address _recipient
    ) internal nonReentrant returns (uint256[] memory currencyBought) {
        // Number of Token IDs to deposit
        uint256 nTokens = _tokenIds.length;

        // Input validation
        // solhint-disable-next-line not-rely-on-time
        require(_deadline >= block.timestamp, "E#6"); // Error#_tokenToCurrency: DEADLINE_EXCEEDED
        require(_tokenIds.length == _tokensSoldAmounts.length, "E#33"); // Error#_tokenToCurrency: INVALID_TOKENS_AMOUNT

        // Initialize variables
        uint256 totalCurrency = 0; // Total amount of currency tokens to transfer
        currencyBought = new uint256[](nTokens);

        // Get token reserves
        uint256[] memory tokenReserves = _getTokenReserves(_tokenIds);

        // Assumes the Tokens ids are already received by contract, but not
        // the Tokens Ids. Will return cards not sold if invalid price.

        // Remove liquidity for each Token ID in _tokenIds
        for (uint256 i = 0; i < nTokens; i++) {
            // Store current id and amount from argument arrays
            uint256 idSold = _tokenIds[i];
            uint256 amountSold = _tokensSoldAmounts[i];
            uint256 tokenReserve = tokenReserves[i];

            // If 0 tokens send for this ID, revert
            require(amountSold > 0, "E#7"); // Error#_tokenToCurrency: NULL_TOKENS_SOLD

            // Load currency token and Token _id reserves
            uint256 currencyReserve = currencyReserves[idSold];

            // Get amount of currency that will be received
            // Need to sub amountSold because tokens already added in reserve, which would bias the calculation
            // Don't need to add it for currencyReserve because the amount is added after this calculation
            uint256 currencyAmount = getSellPrice(
                amountSold,
                tokenReserve - amountSold,
                currencyReserve
            );

            // If royalty, substract amount seller will receive after LP fees were calculated
            // Note: Royalty will be a bit lower since LF fees are substracted first
            (address royaltyRecipient, uint256 royaltyAmount) = getRoyaltyInfo(
                idSold,
                currencyAmount
            );
            if (royaltyAmount > 0) {
                royaltiesNumerator[royaltyRecipient] +=
                    royaltyAmount *
                    ROYALTIES_DENOMINATOR;
            }

            // Increase total amount of currency to receive (minus royalty to pay)
            totalCurrency += currencyAmount - royaltyAmount;

            // Update individual currency reseve amount
            currencyReserves[idSold] = currencyReserve - currencyAmount;

            // Append Token id, Token id amount and currency token amount to tracking arrays
            currencyBought[i] = currencyAmount;
        }

        // If minCurrency is not met
        require(totalCurrency >= _minCurrency, "E#8"); // Error#_tokenToCurrency: INSUFFICIENT_CURRENCY_AMOUNT

        // Transfer currency here
        TransferHelper.safeTransfer(currency, _recipient, totalCurrency);
        return currencyBought;
    }

    /**
     * @dev Pricing function used for converting Tokens to currency token.
     * @param _assetSoldAmount    Amount of Tokens being sold.
     * @param _assetSoldReserve   Amount of Tokens in exchange reserves.
     * @param _assetBoughtReserve Amount of currency tokens in exchange reserves.
     * @return price Amount of currency tokens to receive from Shop.
     */
    function getSellPrice(
        uint256 _assetSoldAmount,
        uint256 _assetSoldReserve,
        uint256 _assetBoughtReserve
    ) public view override returns (uint256 price) {
        //Reserves must not be empty
        require(_assetSoldReserve > 0 && _assetBoughtReserve > 0, "E#9"); // Error#getSellPrice: EMPTY_RESERVE

        // Calculate amount to receive (with fee) before royalty
        uint256 _assetSoldAmount_withFee = _assetSoldAmount * 1000;
        uint256 numerator = _assetSoldAmount_withFee * _assetBoughtReserve;
        uint256 denominator = (_assetSoldReserve * 1000) +
            _assetSoldAmount_withFee;
        return numerator / denominator; //Rounding errors will favor Shop, so nothing to do
    }

    //
    // Liquidity Functions
    //

    /**
     * @notice Deposit less than max currency tokens && exact Tokens (token ID) at current ratio to mint liquidity pool tokens.
     * @dev min_liquidity does nothing when total liquidity pool token supply is 0.
     * @dev Assumes that sender approved this contract on the currency
     * @dev Sorting _tokenIds is mandatory for efficient way of preventing duplicated IDs (which would lead to errors)
     * @param _provider      Address that provides liquidity to the reserve
     * @param _tokenIds      Array of Token IDs where liquidity is added
     * @param _tokenAmounts  Array of amount of Tokens deposited corresponding to each ID provided in _tokenIds
     * @param _maxCurrency   Array of maximum number of tokens deposited for each ID provided in _tokenIds.
     * Deposits max amount if total liquidity pool token supply is 0.
     * @param _deadline      Timestamp after which this transaction will be reverted
     */
    function _addLiquidity(
        address _provider,
        uint256[] memory _tokenIds,
        uint256[] memory _tokenAmounts,
        uint256[] memory _maxCurrency,
        uint256 _deadline
    ) internal nonReentrant {
        // Requirements
        // solhint-disable-next-line not-rely-on-time
        require(_deadline >= block.timestamp, "E#10"); // Error#_addLiquidity: DEADLINE_EXCEEDED

        // Initialize variables
        uint256 nTokens = _tokenIds.length; // Number of Token IDs to deposit
        uint256 totalCurrency = 0; // Total amount of currency tokens to transfer

        // Initialize arrays
        uint256[] memory liquiditiesToMint = new uint256[](nTokens);
        uint256[] memory currencyAmounts = new uint256[](nTokens);

        // Get token reserves
        uint256[] memory tokenReserves = _getTokenReserves(_tokenIds);

        // Assumes tokens _ids are deposited already, but not currency tokens
        // as this is calculated and executed below.

        // Loop over all Token IDs to deposit
        for (uint256 i = 0; i < nTokens; i++) {
            // Store current id and amount from argument arrays
            uint256 tokenId = _tokenIds[i];
            uint256 amount = _tokenAmounts[i];

            // Check if input values are acceptable
            require(_maxCurrency[i] > 0, "E#11"); // Error#_addLiquidity: NULL_MAX_CURRENCY
            require(amount > 0, "E#12"); // Error#_addLiquidity: NULL_TOKENS_AMOUNT

            // Current total liquidity calculated in currency token
            uint256 totalLiquidity = totalSupplies[tokenId];

            // When reserve for this token already exists
            if (totalLiquidity > 0) {
                // Load currency token and Token reserve's supply of Token id
                uint256 currencyReserve = currencyReserves[tokenId]; // Amount not yet in reserve
                uint256 tokenReserve = tokenReserves[i];

                /**
                 * Amount of currency tokens to send to token id reserve:
                 * X/Y = dx/dy
                 * dx = X*dy/Y
                 * where
                 * X:  currency total liquidity
                 * Y:  Token _id total liquidity (before tokens were received)
                 * dy: Amount of token _id deposited
                 * dx: Amount of currency to deposit
                 *
                 * Adding 1 if rounding errors so to not favor users incorrectly
                 */
                (uint256 currencyAmount, bool rounded) = divRound(
                    amount * currencyReserve,
                    tokenReserve - amount
                );
                require(_maxCurrency[i] >= currencyAmount, "E#13"); // Error#_addLiquidity: MAX_CURRENCY_AMOUNT_EXCEEDED

                // Update currency reserve size for Token id before transfer
                currencyReserves[tokenId] = currencyReserve + currencyAmount;

                // Update totalCurrency
                totalCurrency += currencyAmount;

                // Proportion of the liquidity pool to give to current liquidity provider
                // If rounding error occured, round down to favor previous liquidity providers
                // See https://github.com/0xsequence/niftyswap/issues/19
                liquiditiesToMint[i] =
                    ((currencyAmount - (rounded ? 1 : 0)) * totalLiquidity) /
                    currencyReserve;
                currencyAmounts[i] = currencyAmount;

                // Mint liquidity ownership tokens and increase liquidity supply accordingly
                totalSupplies[tokenId] = totalLiquidity + liquiditiesToMint[i];
            } else {
                uint256 maxCurrency = _maxCurrency[i];

                // Otherwise rounding error could end up being significant on second deposit
                require(maxCurrency >= 1000, "E#14"); // Error#_addLiquidity: INVALID_CURRENCY_AMOUNT

                // Update currency  reserve size for Token id before transfer
                currencyReserves[tokenId] = maxCurrency;

                // Update totalCurrency
                totalCurrency += maxCurrency;

                // Initial liquidity is amount deposited (Incorrect pricing will be arbitraged)
                // uint256 initialLiquidity = _maxCurrency;
                totalSupplies[tokenId] = maxCurrency;

                // Liquidity to mints
                liquiditiesToMint[i] = maxCurrency;
                currencyAmounts[i] = maxCurrency;
            }
        }

        // Transfer all currency to this contract
        TransferHelper.safeTransferFrom(
            currency,
            _provider,
            address(this),
            totalCurrency
        );

        // Mint liquidity pool tokens
        _mintBatch(_provider, _tokenIds, liquiditiesToMint, "");

        // Emit event
        emit LiquidityAdded(
            _provider,
            _tokenIds,
            _tokenAmounts,
            currencyAmounts
        );
    }

    /**
     * @dev Convert pool participation into amounts of token and currency.
     * @dev Rounding error of the asset with lower resolution is traded for the other asset.
     * @param _amountPool       Participation to be converted to tokens and currency.
     * @param _tokenReserve     Amount of tokens on the AMM reserve.
     * @param _currencyReserve  Amount of currency on the AMM reserve.
     * @param _totalLiquidity   Total liquidity on the pool.
     *
     * @return currencyAmount Currency corresponding to pool amount plus rounded tokens.
     * @return tokenAmount    Token corresponding to pool amount plus rounded currency.
     */
    function _toRoundedLiquidity(
        uint256 _tokenId,
        uint256 _amountPool,
        uint256 _tokenReserve,
        uint256 _currencyReserve,
        uint256 _totalLiquidity
    )
        internal
        view
        returns (
            uint256 currencyAmount,
            uint256 tokenAmount,
            uint256 soldTokenNumerator,
            uint256 boughtCurrencyNumerator
        )
    {
        uint256 currencyNumerator = _amountPool * _currencyReserve;
        uint256 tokenNumerator = _amountPool * _tokenReserve;

        // Convert all tokenProduct rest to currency
        soldTokenNumerator = tokenNumerator % _totalLiquidity;

        if (soldTokenNumerator != 0) {
            // The trade happens "after" funds are out of the pool
            // so we need to remove these funds before computing the rate
            uint256 virtualTokenReserve = (_tokenReserve -
                (tokenNumerator / _totalLiquidity)) * _totalLiquidity;
            uint256 virtualCurrencyReserve = (_currencyReserve -
                (currencyNumerator / _totalLiquidity)) * _totalLiquidity;

            // Skip process if any of the two reserves is left empty
            // this step is important to avoid an error withdrawing all left liquidity
            if (virtualCurrencyReserve != 0 && virtualTokenReserve != 0) {
                boughtCurrencyNumerator = getSellPrice(
                    soldTokenNumerator,
                    virtualTokenReserve,
                    virtualCurrencyReserve
                );

                currencyNumerator += boughtCurrencyNumerator;
            }
        }

        // Calculate amounts
        currencyAmount = currencyNumerator / _totalLiquidity;
        tokenAmount = tokenNumerator / _totalLiquidity;
    }

    /**
     * @dev Burn liquidity pool tokens to withdraw currency  && Tokens at current ratio.
     * @dev Sorting _tokenIds is mandatory for efficient way of preventing duplicated IDs (which would lead to errors)
     * @param _provider         Address that removes liquidity to the reserve
     * @param _tokenIds         Array of Token IDs where liquidity is removed
     * @param _poolTokenAmounts Array of Amount of liquidity pool tokens burned for each Token id in _tokenIds.
     * @param _minCurrency      Minimum currency withdrawn for each Token id in _tokenIds.
     * @param _minTokens        Minimum Tokens id withdrawn for each Token id in _tokenIds.
     * @param _deadline         Timestamp after which this transaction will be reverted
     */
    function _removeLiquidity(
        address _provider,
        uint256[] memory _tokenIds,
        uint256[] memory _poolTokenAmounts,
        uint256[] memory _minCurrency,
        uint256[] memory _minTokens,
        uint256 _deadline
    ) internal nonReentrant {
        // Input validation
        // solhint-disable-next-line not-rely-on-time
        require(_deadline > block.timestamp, "E#15"); // Error#_removeLiquidity: DEADLINE_EXCEEDED

        // Initialize variables
        uint256 nTokens = _tokenIds.length; // Number of Token IDs to deposit
        uint256 totalCurrency = 0; // Total amount of currency  to transfer
        uint256[] memory tokenAmounts = new uint256[](nTokens); // Amount of Tokens to transfer for each id

        // Structs contain most information for the event
        // notice: tokenAmounts and tokenIds are absent because we already
        // either have those arrays constructed or we need to construct them for other reasons
        LiquidityRemovedEventObj[]
            memory eventObjs = new LiquidityRemovedEventObj[](nTokens);

        // Get token reserves
        uint256[] memory tokenReserves = _getTokenReserves(_tokenIds);

        // Assumes NIFTY liquidity tokens are already received by contract, but not
        // the currency nor the Tokens Ids

        // Remove liquidity for each Token ID in _tokenIds
        for (uint256 i = 0; i < nTokens; i++) {
            // Store current id and amount from argument arrays
            uint256 id = _tokenIds[i];
            uint256 amountPool = _poolTokenAmounts[i];

            // Load total liquidity pool token supply for Token _id
            uint256 totalLiquidity = totalSupplies[id];
            require(totalLiquidity > 0, "E#16"); // Error#_removeLiquidity: NULL_TOTAL_LIQUIDITY

            // Load currency and Token reserve's supply of Token id
            uint256 currencyReserve = currencyReserves[id];

            // Calculate amount to withdraw for currency  and Token _id
            uint256 currencyAmount;
            uint256 tokenAmount;

            {
                uint256 tokenReserve = tokenReserves[i];
                uint256 soldTokenNumerator;
                uint256 boughtCurrencyNumerator;

                (
                    currencyAmount,
                    tokenAmount,
                    soldTokenNumerator,
                    boughtCurrencyNumerator
                ) = _toRoundedLiquidity(
                    id,
                    amountPool,
                    tokenReserve,
                    currencyReserve,
                    totalLiquidity
                );

                // Add trade info to event
                eventObjs[i].soldTokenNumerator = soldTokenNumerator;
                eventObjs[i].boughtCurrencyNumerator = boughtCurrencyNumerator;
                eventObjs[i].totalSupply = totalLiquidity;
            }

            // Verify if amounts to withdraw respect minimums specified
            require(currencyAmount >= _minCurrency[i], "E#17"); // Error#_removeLiquidity: INSUFFICIENT_CURRENCY_AMOUNT
            require(tokenAmount >= _minTokens[i], "E#18"); // Error#_removeLiquidity: INSUFFICIENT_TOKENS

            // Update total liquidity pool token supply of Token _id
            totalSupplies[id] = totalLiquidity - amountPool;

            // Update currency reserve size for Token id
            currencyReserves[id] = currencyReserve - currencyAmount;

            // Update totalCurrency and tokenAmounts
            totalCurrency += currencyAmount;
            tokenAmounts[i] = tokenAmount;

            eventObjs[i].currencyAmount = currencyAmount;
        }

        // Burn liquidity pool tokens for offchain supplies
        _burnBatch(address(this), _tokenIds, _poolTokenAmounts);

        // Transfer total currency and all Tokens ids
        TransferHelper.safeTransfer(currency, _provider, totalCurrency);
        token.safeBatchTransferFrom(
            address(this),
            _provider,
            _tokenIds,
            tokenAmounts,
            ""
        );

        // Emit event
        emit LiquidityRemoved(_provider, _tokenIds, tokenAmounts, eventObjs);
    }

    //
    // Receive Method Handlers
    //

    // Method signatures for onReceive control logic

    // bytes4(keccak256(
    //   "_tokenToCurrency(uint256[],uint256[],uint256,uint256,address,address[],uint256[])"
    // ));
    bytes4 internal constant SELLTOKENS_SIG = 0xade79c7a;

    //  bytes4(keccak256(
    //   "_addLiquidity(address,uint256[],uint256[],uint256[],uint256)"
    // ));
    bytes4 internal constant ADDLIQUIDITY_SIG = 0x82da2b73;

    // bytes4(keccak256(
    //    "_removeLiquidity(address,uint256[],uint256[],uint256[],uint256[],uint256)"
    // ));
    bytes4 internal constant REMOVELIQUIDITY_SIG = 0x5c0bf259;


    //
    // Buying Tokens
    //

    /**
     * @notice Convert currency tokens to Tokens _id and transfers Tokens to recipient.
     * @dev User specifies MAXIMUM inputs (_maxCurrency) and EXACT outputs.
     * @dev Assumes that all trades will be successful, or revert the whole tx
     * @dev Exceeding currency tokens sent will be refunded to recipient
     * @dev Sorting IDs is mandatory for efficient way of preventing duplicated IDs (which would lead to exploit)
     * @param _tokenIds            Array of Tokens ID that are bought
     * @param _tokensBoughtAmounts Amount of Tokens id bought for each corresponding Token id in _tokenIds
     * @param _maxCurrency         Total maximum amount of currency tokens to spend for all Token ids
     * @param _deadline            Timestamp after which this transaction will be reverted
     * @param _recipient           The address that receives output Tokens and refund
     * @return currencySold How much currency was actually sold.
     */
    function buyTokens(
        uint256[] memory _tokenIds,
        uint256[] memory _tokensBoughtAmounts,
        uint256 _maxCurrency,
        uint256 _deadline,
        address _recipient
    ) external returns (uint256[] memory) {
        // solhint-disable-next-line not-rely-on-time
        require(_deadline >= block.timestamp, "E#19"); // Error#buyTokens: DEADLINE_EXCEEDED
        require(_tokenIds.length > 0, "E#20"); // Error#buyTokens: INVALID_CURRENCY_IDS_AMOUNT
        require(_tokenIds.length == _tokensBoughtAmounts.length, "E#21"); // Error#buyTokens: INVALID_TOKENS_AMOUNT

        // Transfer the tokens for purchase
        TransferHelper.safeTransferFrom(
            currency,
            msg.sender,
            address(this),
            _maxCurrency
        );

        address recipient = _recipient == address(0x0)
            ? msg.sender
            : _recipient;

        uint256 maxCurrency = _maxCurrency;

        // Execute trade and retrieve amount of currency spent
        uint256[] memory currencySold = _currencyToToken(
            _tokenIds,
            _tokensBoughtAmounts,
            maxCurrency,
            _deadline,
            recipient
        );
        emit TokensPurchase(
            msg.sender,
            recipient,
            _tokenIds,
            _tokensBoughtAmounts,
            currencySold
        );

        return currencySold;
    }

    /**
     * @notice Handle which method is being called on transfer
     * @dev `_data` must be encoded as follow: abi.encode(bytes4, MethodObj)
     * where bytes4 argument is the MethodObj object signature passed as defined
     * in the `Signatures for onReceive control logic` section above
     * @param _from     The address which previously owned the Token
     * @param _ids      An array containing ids of each Token being transferred
     * @param _amounts  An array containing amounts of each Token being transferred
     * @param _data     Method signature and corresponding encoded arguments for method to call on *this* contract
     * @return bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)")
     */
    function onERC1155BatchReceived(
        address, // _operator,
        address _from,
        uint256[] memory _ids,
        uint256[] memory _amounts,
        bytes memory _data
    ) public override returns (bytes4) {
        // This function assumes that the ERC-1155 token contract can
        // only call `onERC1155BatchReceived()` via a valid token transfer.
        // Users must be responsible and only use this Shop exchange
        // contract with ERC-1155 compliant token contracts.

        // Obtain method to call via object signature
        bytes4 functionSignature = abi.decode(_data, (bytes4));

        //
        // Selling Tokens
        //
        if (functionSignature == SELLTOKENS_SIG) {
            // Tokens received need to be Token contract
            require(msg.sender == address(token), "E#22"); // Error#onERC1155BatchReceived: INVALID_TOKENS_TRANSFERRED

            // Decode SellTokensObj from _data to call _tokenToCurrency()
            SellTokensObj memory obj;
            (, obj) = abi.decode(_data, (bytes4, SellTokensObj));
            address recipient = obj.recipient == address(0x0)
                ? _from
                : obj.recipient;

            // Execute trade and retrieve amount of currency received
            uint256[] memory currencyBought = _tokenToCurrency(
                _ids,
                _amounts,
                obj.minCurrency,
                obj.deadline,
                recipient
            );
            emit CurrencyPurchase(
                _from,
                recipient,
                _ids,
                _amounts,
                currencyBought
            );

            //
            // Adding Liquidity Tokens
            //
        } else if (functionSignature == ADDLIQUIDITY_SIG) {
            // Only allow to receive ERC-1155 tokens from `token` contract
            require(msg.sender == address(token), "E#24"); // Error#onERC1155BatchReceived: INVALID_TOKEN_TRANSFERRED

            // Decode AddLiquidityObj from _data to call _addLiquidity()
            AddLiquidityObj memory obj;
            (, obj) = abi.decode(_data, (bytes4, AddLiquidityObj));
            _addLiquidity(_from, _ids, _amounts, obj.maxCurrency, obj.deadline);

            //
            // Removing Liquidity Tokens
            //
        } else if (functionSignature == REMOVELIQUIDITY_SIG) {
            // Tokens received need to be NIFTY-1155 tokens
            require(msg.sender == address(this), "E#25"); // Error#onERC1155BatchReceived: INVALID_NIFTY_TOKENS_TRANSFERRED

            // Decode RemoveLiquidityObj from _data to call _removeLiquidity()
            RemoveLiquidityObj memory obj;
            (, obj) = abi.decode(_data, (bytes4, RemoveLiquidityObj));
            _removeLiquidity(
                _from,
                _ids,
                _amounts,
                obj.minCurrency,
                obj.minTokens,
                obj.deadline
            );

            //
            // Deposits & Invalid Calls
            //
        } else {
            revert("E#27"); // Error#onERC1155BatchReceived: INVALID_METHOD
        }

        return ERC1155_BATCH_RECEIVED_VALUE;
    }

    /**
     * @dev Will pass to onERC115Batch5Received
     */
    function onERC1155Received(
        address _operator,
        address _from,
        uint256 _id,
        uint256 _amount,
        bytes memory _data
    ) public override returns (bytes4) {
        uint256[] memory ids = new uint256[](1);
        uint256[] memory amounts = new uint256[](1);

        ids[0] = _id;
        amounts[0] = _amount;

        require(
            ERC1155_BATCH_RECEIVED_VALUE ==
                onERC1155BatchReceived(_operator, _from, ids, amounts, _data),
            "E#28" // Error#onERC1155Received: INVALID_ONRECEIVED_MESSAGE
        );

        return ERC1155_RECEIVED_VALUE;
    }

    /**
     * @notice Will send the royalties that _royaltyRecipient can claim, if any
     * @dev Anyone can call this function such that payout could be distributed
     * regularly instead of being claimed.
     * @param _royaltyRecipient Address that is able to claim royalties
     */
    function sendRoyalties(address _royaltyRecipient) external {
        uint256 royaltyAmount = royaltiesNumerator[_royaltyRecipient] /
            ROYALTIES_DENOMINATOR;
        royaltiesNumerator[_royaltyRecipient] =
            royaltiesNumerator[_royaltyRecipient] %
            ROYALTIES_DENOMINATOR;
        TransferHelper.safeTransfer(currency, _royaltyRecipient, royaltyAmount);
    }

    /**
     * @notice Will return how much of currency need to be paid for the royalty
     * @notice Royalty is capped at 25% of the total amount of currency
     * @param _tokenId ID of the erc-1155 token being traded
     * @param _cost    Amount of currency sent/received for the trade
     * @return recipient Address that will be able to claim the royalty
     * @return royalty Amount of currency that will be sent to royalty recipient
     */
    function getRoyaltyInfo(
        uint256 _tokenId,
        uint256 _cost
    ) public view returns (address recipient, uint256 royalty) {
        if (IS_ERC2981) {
            return IERC2981(address(token)).royaltyInfo(_tokenId, _cost);
        } else {
            return (address(0), 0);
        }
    }

    /**
     * @notice Prevents receiving Ether or calls to unsuported methods
     */
    fallback() external {
        revert("E#29"); // ShopExchange20:UNSUPPORTED_METHOD
    }

    //
    // Getter Functions
    //

    /**
     * @notice Get amount of currency in reserve for each Token _id in _ids
     * @param _ids Array of ID sto query currency reserve of
     * @return amount of currency in reserve for each Token _id
     */
    function getCurrencyReserves(
        uint256[] calldata _ids
    ) external view override returns (uint256[] memory) {
        uint256 nIds = _ids.length;
        uint256[] memory currencyReservesReturn = new uint256[](nIds);
        for (uint256 i = 0; i < nIds; i++) {
            currencyReservesReturn[i] = currencyReserves[_ids[i]];
        }
        return currencyReservesReturn;
    }

    /**
     * @notice Return price for `currency => Token _id` trades with an exact token amount.
     * @param _ids           Array of ID of tokens bought.
     * @param _tokensBought Amount of Tokens bought.
     * @return Amount of currency needed to buy Tokens in _ids for amounts in _tokensBought
     */
    function getPrice_currencyToToken(
        uint256[] calldata _ids,
        uint256[] calldata _tokensBought
    ) external view override returns (uint256[] memory) {
        uint256 nIds = _ids.length;
        uint256[] memory prices = new uint256[](nIds);

        require(_ids.length == _tokensBought.length, "E#30"); // Error#getPrice_currencyToToken: INVALID_INPUTS_LENGTH

        for (uint256 i = 0; i < nIds; i++) {
            // Load Token id reserve
            uint256 tokenReserve = token.balanceOf(address(this), _ids[i]);
            prices[i] = getBuyPrice(
                _tokensBought[i],
                currencyReserves[_ids[i]],
                tokenReserve
            );
        }

        // Return prices
        return prices;
    }

    /**
     * @notice Return price for `Token _id => currency` trades with an exact token amount.
     * @param _ids        Array of IDs  token sold.
     * @param _tokensSold Array of amount of each Token sold.
     * @return Amount of currency that can be bought for Tokens in _ids for amounts in _tokensSold
     */
    function getPrice_tokenToCurrency(
        uint256[] calldata _ids,
        uint256[] calldata _tokensSold
    ) external view override returns (uint256[] memory) {
        uint256 nIds = _ids.length;
        uint256[] memory prices = new uint256[](nIds);

        require(_ids.length == _tokensSold.length, "E#31"); // Error#getPrice_tokenToCurrency: INVALID_INPUTS_LENGTH

        for (uint256 i = 0; i < nIds; i++) {
            // Load Token id reserve
            uint256 tokenReserve = token.balanceOf(address(this), _ids[i]);
            prices[i] = getSellPrice(
                _tokensSold[i],
                tokenReserve,
                currencyReserves[_ids[i]]
            );
        }

        // Return price
        return prices;
    }

    /**
     * @return Address of Token that is sold on this exchange.
     */
    function getTokenAddress() external view override returns (address) {
        return address(token);
    }

    /**
     * @return Address of the currency contract that is used as currency
     */
    function getCurrencyInfo() external view override returns (address) {
        return (address(currency));
    }

    /**
     * @notice Get total supply of liquidity tokens
     * @param _ids ID of the Tokens
     * @return The total supply of each liquidity token id provided in _ids
     */
    function getTotalSupply(
        uint256[] calldata _ids
    ) external view override returns (uint256[] memory) {
        // Number of ids
        uint256 nIds = _ids.length;

        // Variables
        uint256[] memory batchTotalSupplies = new uint256[](nIds);

        // Iterate over each owner and token ID
        for (uint256 i = 0; i < nIds; i++) {
            batchTotalSupplies[i] = totalSupplies[_ids[i]];
        }

        return batchTotalSupplies;
    }

    /**
     * @return Address of factory that created this exchange.
     */
    function getFactoryAddress() external view override returns (address) {
        return factory;
    }

    //
    // Utility Functions
    //

    /**
     * @notice Divides two numbers and add 1 if there is a rounding error
     * @param a Numerator
     * @param b Denominator
     */
    function divRound(
        uint256 a,
        uint256 b
    ) internal pure returns (uint256, bool) {
        return a % b == 0 ? (a / b, false) : ((a / b) + 1, true);
    }

    /**
     * @notice Return Token reserves for given Token ids
     * @dev Assumes that ids are sorted from lowest to highest with no duplicates.
     * This assumption allows for checking the token reserves only once, otherwise
     * token reserves need to be re-checked individually or would have to do more expensive
     * duplication checks.
     * @param _tokenIds Array of IDs to query their Reserve balance.
     * @return Array of Token ids' reserves
     */
    function _getTokenReserves(
        uint256[] memory _tokenIds
    ) internal view returns (uint256[] memory) {
        uint256 nTokens = _tokenIds.length;

        // Regular balance query if only 1 token, otherwise batch query
        if (nTokens == 1) {
            uint256[] memory tokenReserves = new uint256[](1);
            tokenReserves[0] = token.balanceOf(address(this), _tokenIds[0]);
            return tokenReserves;
        } else {
            // Lazy check preventing duplicates & build address array for query
            address[] memory thisAddressArray = new address[](nTokens);
            thisAddressArray[0] = address(this);

            for (uint256 i = 1; i < nTokens; i++) {
                require(_tokenIds[i - 1] < _tokenIds[i], "E#32"); // Error#_getTokenReserves: UNSORTED_OR_DUPLICATE_TOKEN_IDS
                thisAddressArray[i] = address(this);
            }
            return token.balanceOfBatch(thisAddressArray, _tokenIds);
        }
    }

    /**
     * @notice Indicates whether a contract implements the `ERC1155TokenReceiver` functions and so can accept ERC1155 token types.
     * @param  interfaceID The ERC-165 interface ID that is queried for support.s
     * @dev This function MUST return true if it implements the ERC1155TokenReceiver interface and ERC-165 interface.
     * This function MUST NOT consume more thsan 5,000 gas.
     * @return Whether a given interface is supported
     */
    function supportsInterface(
        bytes4 interfaceID
    ) public pure override returns (bool) {
        return
            interfaceID == type(IERC20).interfaceId ||
            interfaceID == type(IERC165).interfaceId ||
            interfaceID == type(IERC1155).interfaceId ||
            interfaceID == type(IERC1155Receiver).interfaceId ||
            interfaceID == type(IERC1155MetadataURI).interfaceId;
    }
}

File 43 of 47 : TransferHelper.sol
// SPDX-License-Identifier: GPL-3.0-or-later
// Taken from https://github.com/Uniswap/solidity-lib/blob/master/contracts/libraries/TransferHelper.sol
pragma solidity >=0.6.0;

// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('approve(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            'TransferHelper::safeApprove: approve failed'
        );
    }

    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('transfer(address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            'TransferHelper::safeTransfer: transfer failed'
        );
    }

    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            'TransferHelper::transferFrom: transferFrom failed'
        );
    }

    function safeTransferETH(address to, uint256 value) internal {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
    }
}

File 44 of 47 : GameManager.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import "./IAIWaifu.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

contract GameManager is Initializable, AccessControlUpgradeable {
    using SafeERC20 for IERC20;

    bytes32 public constant ORACLE_ROLE = keccak256("ORACLE_ROLE");

    address public ingredientNft;
    address public waifuNft;
    address public token;

    struct LevelCost {
        uint256 ingredients;
        uint256 tokens;
        uint24 duration;
    }

    mapping(uint256 ingredientId => uint256 updradeId) public levelUpMap;
    mapping(uint8 level => LevelCost) public levelCosts;
    mapping(uint256 waifuId => uint256 levelCompleteAt) private _levelCooldown;

    // Prevent double spending of food and gifts
    mapping(bytes32 hash => bool) private _waifuHashes;

    uint8 public maxLevel;
    uint256 private _nextFoodId;
    uint256 private _nextGiftId;

    modifier isActive(uint256 tokenId) {
        require(IAIWaifu(waifuNft).isAlive(tokenId), "Waifu is not dead");
        require(
            block.timestamp > _levelCooldown[tokenId],
            "Waifu is leveling up"
        );
        _;
    }

    event LevelUpMapUpdated(uint256 ingredientId, uint256 updradeId);
    event LevelUpCostUpdated(
        uint8 level,
        uint256 ingredients,
        uint256 tokens,
        uint24 duration
    );
    event MaxLevelUpdated(uint8 maxLevel);
    event Feed(uint256 waifuId, uint256 foodId);
    event Gift(uint256 waifuId, uint256 giftId);
    event Eaten(
        uint256 waifuId,
        uint256 foodId,
        uint256 amount,
        uint256 replenishAmount
    );
    event GiftOpened(
        uint256 waifuId,
        uint256 giftId,
        uint256 amount,
        uint256 replenishAmount
    );
    event WithdrawnToken(address indexed receiver, uint256 amount);
    event WithdrawnIngredient(
        address indexed receiver,
        uint256 id,
        uint256 amount
    );
    event LevelUp(uint256 waifuId, uint8 level);

    uint256 private _nextTemptId;
    mapping(uint256 ingredientId => uint256 temptIngredientId) public temptMap;
    mapping(uint256 waifuId => uint256 cooldown) private _cooldownByWaifu;
    mapping (address => uint256 cooldown) private _cooldownByAddress;
    uint16 public defendCooldown;
    uint16 public temptCooldown;
    event TemptCooldownUpdated(uint16 defendCooldown, uint16 temptCooldown);
    event TemptMapUpdated(uint256 ingredientId, uint256 temptIngredientId);
    event Tempted(
        address indexed account,
        uint256 waifuId,
        uint256 temptId,
        uint256 wager,
        uint256 defendAmount
    );
    event TemptResult(
        uint256 temptId,
        uint256 waifuId,
        bool success,
        uint16 ingredientScore,
        uint16 flirtScore
    );

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    function initialize(
        address defaultAdmin,
        uint8 maxLevel_,
        address token_,
        address ingredientNft_,
        address waifuNft_
    ) public initializer {
        __AccessControl_init();
        _grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
        _nextFoodId = 1;
        _nextGiftId = 1;
        _nextTemptId = 1;
        maxLevel = maxLevel_;
        token = token_;
        waifuNft = waifuNft_;
        ingredientNft = ingredientNft_;
    }

    function updateLevelMap(
        uint8[] memory ingredients,
        uint8[] memory updrades
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        require(ingredients.length == updrades.length, "Invalid input");
        for (uint8 i = 0; i < ingredients.length; i++) {
            levelUpMap[ingredients[i]] = updrades[i];
            emit LevelUpMapUpdated(ingredients[i], updrades[i]);
        }
    }

    function updateTemptMap(
        uint8[] memory ingredients,
        uint8[] memory tempts
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        require(ingredients.length == tempts.length, "Invalid input");
        for (uint8 i = 0; i < ingredients.length; i++) {
            temptMap[ingredients[i]] = tempts[i];
            emit TemptMapUpdated(ingredients[i], tempts[i]);
        }
    }

    function updateLevelCost(
        uint8[] memory levels,
        LevelCost[] memory costs
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        require(levels.length == costs.length, "Invalid input");
        for (uint8 i = 0; i < levels.length; i++) {
            levelCosts[levels[i]] = costs[i];
            emit LevelUpCostUpdated(
                levels[i],
                costs[i].ingredients,
                costs[i].tokens,
                costs[i].duration
            );
        }
    }

    function updateMaxLevel(
        uint8 _maxLevel
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        maxLevel = _maxLevel;
        emit MaxLevelUpdated(_maxLevel);
    }

    function updateTemptCooldown(
        uint16 defendCooldown_,
        uint16 temptCooldown_
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        defendCooldown = defendCooldown_;
        temptCooldown = temptCooldown_;
        emit TemptCooldownUpdated(defendCooldown_, temptCooldown_);
    }

    function _feed(uint256 waifuId) internal isActive(waifuId) {
        uint256 foodId = _nextFoodId++;
        emit Feed(waifuId, foodId);
    }

    function feed(uint256 waifuId) public {
        require(
            _msgSender() == IERC721(waifuNft).ownerOf(waifuId),
            "Not the owner of the waifu"
        );
        return _feed(waifuId);
    }

    function feedBySig(
        uint256 waifuId,
        uint256 nonce,
        bytes memory signature
    ) public {
        bytes32 hash = keccak256(abi.encodePacked(waifuId, "f", nonce));
        require(!_waifuHashes[hash], "Nonce already used");
        SignatureChecker.isValidSignatureNow(
            IERC721(waifuNft).ownerOf(waifuId),
            hash,
            signature
        );
        _waifuHashes[hash] = true;
        return _feed(waifuId);
    }

    function _gift(uint256 waifuId) internal isActive(waifuId) {
        uint256 giftId = _nextGiftId++;
        emit Gift(waifuId, giftId);
    }

    function gift(uint256 waifuId) public {
        require(
            _msgSender() == IERC721(waifuNft).ownerOf(waifuId),
            "Not the owner of the waifu"
        );
        return _gift(waifuId);
    }

    function giftBySig(
        uint256 waifuId,
        uint256 nonce,
        bytes memory signature
    ) public {
        bytes32 hash = keccak256(abi.encodePacked(waifuId, "g", nonce));
        require(!_waifuHashes[hash], "Nonce already used");
        SignatureChecker.isValidSignatureNow(
            IERC721(waifuNft).ownerOf(waifuId),
            hash,
            signature
        );
        _waifuHashes[hash] = true;
        return _gift(waifuId);
    }

    function eat(
        uint256 waifuId,
        uint256 foodId,
        uint256 amount,
        uint256 replenishAmount
    ) public isActive(waifuId) onlyRole(ORACLE_ROLE) {
        address account = IERC721(waifuNft).ownerOf(waifuId);
        require(
            IERC20(token).balanceOf(account) >= amount,
            "Insufficient token balance"
        );
        require(amount > 0, "Invalid amount");
        IERC20(token).safeTransferFrom(account, address(this), amount);
        emit Eaten(waifuId, foodId, amount, replenishAmount);
    }

    function openGift(
        uint256 waifuId,
        uint256 giftId,
        uint256 amount,
        uint256 replenishAmount
    ) public isActive(waifuId) onlyRole(ORACLE_ROLE) {
        address account = IERC721(waifuNft).ownerOf(waifuId);
        require(
            IERC20(token).balanceOf(account) >= amount,
            "Insufficient token balance"
        );
        require(amount > 0, "Invalid amount");
        IERC20(token).safeTransferFrom(account, address(this), amount);
        emit GiftOpened(waifuId, giftId, amount, replenishAmount);
    }

    function withdrawToken(
        address receiver,
        uint256 amount
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        IERC20(token).safeTransfer(receiver, amount);
        emit WithdrawnToken(receiver, amount);
    }

    function levelUp(uint256 waifuId) external isActive(waifuId) {
        address sender = _msgSender();
        require(
            sender == IERC721(waifuNft).ownerOf(waifuId),
            "Not the owner of the waifu"
        );

        IAIWaifu.Waifu memory waifu = IAIWaifu(waifuNft).waifu(waifuId);
        require(waifu.level < maxLevel, "Max level reached");
        uint8 nextLevel = waifu.level + 1;
        LevelCost memory levelCost = levelCosts[nextLevel];

        // Spend token
        require(
            IERC20(token).balanceOf(sender) >= levelCost.tokens,
            "Insufficient token balance"
        );
        IERC20(token).safeTransferFrom(sender, address(this), levelCost.tokens);

        // Spend ingredients
        uint256 levelUpIngredientId = levelUpMap[waifu.ingredientId];
        require(
            ERC1155Burnable(ingredientNft).balanceOf(
                sender,
                levelUpIngredientId
            ) >= levelCost.ingredients,
            "Insufficient ingredients"
        );
        ERC1155Burnable(ingredientNft).burn(
            sender,
            levelUpIngredientId,
            levelCost.ingredients
        );

        // Level up
        IAIWaifu(waifuNft).setLevel(waifuId, nextLevel);
        _levelCooldown[waifuId] = uint256(block.timestamp + levelCost.duration);
        emit LevelUp(waifuId, nextLevel);
    }

    // Admin functions to save any accidentally sent tokens
    function withdrawETH(
        uint256 amount_
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        (bool success, ) = _msgSender().call{value: amount_}("");
        if (!success) {
            revert("Transfer failed");
        }
    }

    function withdrawERC20(
        address token_,
        uint256 amount_
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        IERC20(token_).safeTransfer(_msgSender(), amount_);
    }

    function tempt(uint256 waifuId, uint256 wager) external isActive(waifuId) {
        address account = _msgSender();
        require(
            _cooldownByWaifu[waifuId] < block.timestamp,
            "Waifu is on cooldown"
        );
        require(
            _cooldownByAddress[account] < block.timestamp,
            "Account is on cooldown"
        );
        IAIWaifu.Waifu memory waifu = IAIWaifu(waifuNft).waifu(waifuId);
        ERC1155Burnable ingredientContract = ERC1155Burnable(ingredientNft);
        uint256 temptIngredientId = temptMap[waifu.ingredientId];
        require(
            ingredientContract.balanceOf(account, temptIngredientId) >= wager,
            "Insufficient ingredient"
        );
        uint256 temptId = _nextTemptId++;
        ingredientContract.burn(account, temptIngredientId, wager);

        address defender = IERC721(waifuNft).ownerOf(waifuId);
        uint256 defendAmount = ingredientContract.isApprovedForAll(
            defender,
            address(this)
        )
            ? ingredientContract.balanceOf(defender, waifu.ingredientId)
            : 0;
        if (defendAmount > 0) {
            ingredientContract.burn(
                defender,
                waifu.ingredientId,
                Math.min(defendAmount, wager)
            );
        }

        _cooldownByWaifu[waifuId] = block.timestamp + defendCooldown;
        _cooldownByAddress[account] = block.timestamp + temptCooldown;

        emit Tempted(account, waifuId, temptId, wager, defendAmount);
    }

    function temptResult(
        uint256 temptId,
        uint256 waifuId,
        bool success,
        uint16 ingredientScore,
        uint16 flirtScore
    ) external onlyRole(ORACLE_ROLE) {
        if (success) {
            IAIWaifu waifuContract = IAIWaifu(waifuNft);
            IAIWaifu.Waifu memory waifu = waifuContract.waifu(waifuId);
            waifuContract.setHealth(waifuId, waifu.health - 1, waifu.maxHealth);
        }
        emit TemptResult(
            temptId,
            waifuId,
            success,
            ingredientScore,
            flirtScore
        );
    }
}

File 45 of 47 : IAIWaifu.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

interface IAIWaifu {
    struct Waifu {
        uint8 health;
        uint8 maxHealth;
        uint8 level;
        uint256 ingredientId;
    }

    event HealthUpdated(uint256 tokenId, uint8 health, uint8 maxHealth);
    event LevelUp(uint256 tokenId, uint8 level);

    function isAlive(uint256 tokenId) external view returns (bool);

    function waifu(uint256 tokenId) external view returns (Waifu memory);

    function setHealth(uint256 tokenId, uint8 health, uint8 maxHealth) external;

    function setLevel(uint256 tokenId, uint8 level) external;
}

File 46 of 47 : ERC20Custom.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {Context} from "@openzeppelin/contracts/utils/Context.sol";
import {IERC20Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import "./IErrors.sol";

/*
This is a custom implementation of the OpenZeppelin ERC20 contract.
*/
abstract contract ERC20Custom is
    IErrors,
    Context,
    IERC20,
    IERC20Metadata,
    IERC20Errors
{
    mapping(address account => uint256) private _balances;

    mapping(address account => mapping(address spender => uint256))
        private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(
        address owner,
        address spender
    ) public view virtual returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(
        address spender,
        uint256 value
    ) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }

    function transfer(address to, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `value`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `value`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 value
    ) public virtual returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, value);
        _transfer(from, to, value);
        return true;
    }

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
     * true using the following override:
     * ```
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(
        address owner,
        address spender,
        uint256 value,
        bool emitEvent
    ) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `value`.
     *
     * Does not update the allowance value in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Does not emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 value
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            if (currentAllowance < value) {
                revert ERC20InsufficientAllowance(
                    spender,
                    currentAllowance,
                    value
                );
            }
            unchecked {
                _approve(owner, spender, currentAllowance - value, false);
            }
        }
    }

    function _revert(bytes4 errorSelector) internal pure {
        assembly {
            mstore(0x00, errorSelector)
            revert(0x00, 0x04)
        }
    }

    function _setBalance(address account, uint256 newBalance) internal {
        _balances[account] = newBalance;
    }

    function _increaseBalance(address account, uint256 value) internal {
        unchecked {
            _balances[account] += value;
        }
    }

    function burn(uint256 value) public virtual {
        _burn(_msgSender(), value);
    }
}

File 47 of 47 : IErrors.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IErrors {
    error CannotWithdrawThisToken();
    error LiquidityPoolMustBeAContractAddress();

    error LiquidityPoolCannotBeAddressZero();

    error TransferAmountExceedsBalance();

    error TransferFailed();

    error TransferFromZeroAddress();

    error TransferToZeroAddress();
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  }
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"components":[{"internalType":"address","name":"defaultAdmin","type":"address"},{"internalType":"address","name":"supplyRecipient","type":"address"},{"internalType":"uint256","name":"totalSupply","type":"uint256"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"}],"internalType":"struct WaifuToken.BaseParameters","name":"baseParams","type":"tuple"},{"components":[{"internalType":"uint256","name":"projectBuyTaxBasisPoints","type":"uint256"},{"internalType":"uint256","name":"projectSellTaxBasisPoints","type":"uint256"},{"internalType":"address","name":"projectTaxRecipient","type":"address"}],"internalType":"struct WaifuToken.ERC20TaxParameters","name":"taxParams","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"CannotWithdrawThisToken","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC20InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC20InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC20InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"}],"name":"ERC20InvalidSpender","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"LiquidityPoolCannotBeAddressZero","type":"error"},{"inputs":[],"name":"LiquidityPoolMustBeAContractAddress","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"TransferAmountExceedsBalance","type":"error"},{"inputs":[],"name":"TransferFailed","type":"error"},{"inputs":[],"name":"TransferFromZeroAddress","type":"error"},{"inputs":[],"name":"TransferToZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addedPool","type":"address"}],"name":"LiquidityPoolAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"removedPool","type":"address"}],"name":"LiquidityPoolRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldBuyBasisPoints","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newBuyBasisPoints","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"oldSellBasisPoints","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newSellBasisPoints","type":"uint256"}],"name":"ProjectTaxBasisPointsChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"treasury","type":"address"}],"name":"ProjectTaxRecipientUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"stateMutability":"nonpayable","type":"fallback"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newLiquidityPool_","type":"address"}],"name":"addLiquidityPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"distributeTaxTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"queryAddress_","type":"address"}],"name":"isLiquidityPool","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"projectBuyTaxBasisPoints","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"projectSellTaxBasisPoints","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"projectTaxPendingSwap","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"projectTaxRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"removedLiquidityPool_","type":"address"}],"name":"removeLiquidityPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"callerConfirmation","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"newProjectBuyTaxBasisPoints_","type":"uint16"},{"internalType":"uint16","name":"newProjectSellTaxBasisPoints_","type":"uint16"}],"name":"setProjectTaxRates","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"projectTaxRecipient_","type":"address"}],"name":"setProjectTaxRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalBuyTaxBasisPoints","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSellTaxBasisPoints","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"withdrawERC20","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60806040523480156200001157600080fd5b5060405162001fc538038062001fc5833981016040819052620000349162000505565b6060820151608083015160036200004c838262000675565b5060046200005b828262000675565b50505060208201516200008d90620000766012600a62000854565b84604001516200008791906200086c565b620000f5565b81516200009d9060009062000137565b50620000a981620001ea565b600880546040909301516001600160a01b03166501000000000002600160281b600160c81b03199215159290921664ffffffff01600160c81b031990931692909217179055506200089c565b6001600160a01b038216620001255760405163ec442f0560e01b8152600060048201526024015b60405180910390fd5b620001336000838362000251565b5050565b60008281526005602090815260408083206001600160a01b038516845290915281205460ff16620001e05760008381526005602090815260408083206001600160a01b03861684529091529020805460ff19166001179055620001973390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a4506001620001e4565b5060005b92915050565b8051600090158015620001ff57506020820151155b156200020d57506000919050565b5080516008805460209093015161ffff90811663010000000264ffff0000001991909316610100021664ffffffff001990931692909217179055600190565b919050565b6001600160a01b0383166200028057806002600082825462000274919062000886565b90915550620002f49050565b6001600160a01b03831660009081526020819052604090205481811015620002d55760405163391434e360e21b81526001600160a01b038516600482015260248101829052604481018390526064016200011c565b6001600160a01b03841660009081526020819052604090209082900390555b6001600160a01b038216620003125760028054829003905562000331565b6001600160a01b03821660009081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516200037791815260200190565b60405180910390a3505050565b634e487b7160e01b600052604160045260246000fd5b60405160a081016001600160401b0381118282101715620003bf57620003bf62000384565b60405290565b604051601f8201601f191681016001600160401b0381118282101715620003f057620003f062000384565b604052919050565b80516001600160a01b03811681146200024c57600080fd5b600082601f8301126200042257600080fd5b81516001600160401b038111156200043e576200043e62000384565b602062000454601f8301601f19168201620003c5565b82815285828487010111156200046957600080fd5b60005b83811015620004895785810183015182820184015282016200046c565b506000928101909101919091529392505050565b600060608284031215620004b057600080fd5b604051606081016001600160401b0381118282101715620004d557620004d562000384565b80604052508091508251815260208301516020820152620004f960408401620003f8565b60408201525092915050565b600080608083850312156200051957600080fd5b82516001600160401b03808211156200053157600080fd5b9084019060a082870312156200054657600080fd5b620005506200039a565b6200055b83620003f8565b81526200056b60208401620003f8565b6020820152604083015160408201526060830151828111156200058d57600080fd5b6200059b8882860162000410565b606083015250608083015182811115620005b457600080fd5b620005c28882860162000410565b608083015250809450505050620005dd84602085016200049d565b90509250929050565b600181811c90821680620005fb57607f821691505b6020821081036200061c57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200067057600081815260208120601f850160051c810160208610156200064b5750805b601f850160051c820191505b818110156200066c5782815560010162000657565b5050505b505050565b81516001600160401b0381111562000691576200069162000384565b620006a981620006a28454620005e6565b8462000622565b602080601f831160018114620006e15760008415620006c85750858301515b600019600386901b1c1916600185901b1785556200066c565b600085815260208120601f198616915b828110156200071257888601518255948401946001909101908401620006f1565b5085821015620007315787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b600181815b80851115620007985781600019048211156200077c576200077c62000741565b808516156200078a57918102915b93841c93908002906200075c565b509250929050565b600082620007b157506001620001e4565b81620007c057506000620001e4565b8160018114620007d95760028114620007e45762000804565b6001915050620001e4565b60ff841115620007f857620007f862000741565b50506001821b620001e4565b5060208310610133831016604e8410600b841016171562000829575081810a620001e4565b62000835838362000757565b80600019048211156200084c576200084c62000741565b029392505050565b60006200086560ff841683620007a0565b9392505050565b8082028115828204841417620001e457620001e462000741565b80820180821115620001e457620001e462000741565b61171980620008ac6000396000f3fe608060405234801561001057600080fd5b50600436106101da5760003560e01c806395d89b4111610104578063b0d75097116100a2578063e85455d711610071578063e85455d714610471578063ea8b242414610484578063ee6a934c146104b8578063eeae0f97146104cb576101da565b8063b0d75097146103e5578063b2c5c9eb14610410578063d547741f14610425578063dd62ed3e14610438576101da565b8063a217fddf116100de578063a217fddf14610391578063a45cae0214610399578063a9059cbb146103bf578063ae22107f146103d2576101da565b806395d89b41146103635780639808751d1461036b578063a1db97821461037e576101da565b80632ead09551161017c57806342966c681161014b57806342966c681461030157806370a082311461031457806391d148541461033d578063936b293414610350576101da565b80632ead0955146102c25780632f2ff15d146102cc578063313ce567146102df57806336568abe146102ee576101da565b8063095ea7b3116101b8578063095ea7b31461027157806318160ddd1461028457806323b872dd1461028c578063248a9ca31461029f576101da565b806301ffc9a714610217578063038272b61461023f57806306fdde031461025c575b60405162461bcd60e51b815260206004820152600d60248201526c139bdd081cdd5c1c1bdc9d1959609a1b60448201526064015b60405180910390fd5b61022a61022536600461143a565b6104dc565b60405190151581526020015b60405180910390f35b6008546301000000900461ffff165b604051908152602001610236565b610264610513565b6040516102369190611488565b61022a61027f3660046114d7565b6105a5565b60025461024e565b61022a61029a366004611501565b6105bd565b61024e6102ad36600461153d565b60009081526005602052604090206001015490565b6102ca6105fb565b005b6102ca6102da366004611556565b610651565b60405160128152602001610236565b6102ca6102fc366004611556565b61067c565b6102ca61030f36600461153d565b6106b4565b61024e610322366004611582565b6001600160a01b031660009081526020819052604090205490565b61022a61034b366004611556565b6106be565b6102ca61035e3660046115af565b6106e9565b61026461088c565b6102ca610379366004611582565b61089b565b6102ca61038c3660046114d7565b61090c565b61024e600081565b6008546103ac90610100900461ffff1681565b60405161ffff9091168152602001610236565b61022a6103cd3660046114d7565b61094b565b6102ca6103e0366004611582565b61095d565b6009546103f8906001600160801b031681565b6040516001600160801b039091168152602001610236565b6008546103ac906301000000900461ffff1681565b6102ca610433366004611556565b6109ad565b61024e6104463660046115d9565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b61022a61047f366004611582565b6109d2565b6008546104a0906501000000000090046001600160a01b031681565b6040516001600160a01b039091168152602001610236565b6102ca6104c6366004611582565b6109df565b600854610100900461ffff1661024e565b60006001600160e01b03198216637965db0b60e01b148061050d57506301ffc9a760e01b6001600160e01b03198316145b92915050565b60606003805461052290611603565b80601f016020809104026020016040519081016040528092919081815260200182805461054e90611603565b801561059b5780601f106105705761010080835404028352916020019161059b565b820191906000526020600020905b81548152906001019060200180831161057e57829003601f168201915b5050505050905090565b6000336105b3818585610a6f565b5060019392505050565b6000336105cb858285610a7c565b6105ee8585856105da896109d2565b806105e957506105e9886109d2565b610af4565b60019150505b9392505050565b6009546001600160801b03161561064f57600980546001600160801b031981169091556008546001600160801b039091169061064d9030906501000000000090046001600160a01b0316836000610af4565b505b565b60008281526005602052604090206001015461066c81610bb0565b6106768383610bba565b50505050565b6001600160a01b03811633146106a55760405163334bd91960e11b815260040160405180910390fd5b6106af8282610c4e565b505050565b61064d3382610cbb565b60009182526005602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60006106f481610bb0565b6127108361ffff161061075e5760405162461bcd60e51b815260206004820152602c60248201527f4275792074617820626173697320706f696e7473206d757374206265206c657360448201526b073207468616e2031303030360a41b606482015260840161020e565b6127108261ffff16106107c95760405162461bcd60e51b815260206004820152602d60248201527f53656c6c2074617820626173697320706f696e7473206d757374206265206c6560448201526c07373207468616e20313030303609c1b606482015260840161020e565b60085461ffff61010082048116916301000000900481169085161515806107f4575060008461ffff16115b6008805462ffffff191691151562ffff0019169190911761010061ffff8881169182029290921764ffff000000191663010000008884169081029190911790935560408051868416815260208101929092529184169181019190915260608101919091527f8da1f77a22734510b762a9625e69e737d7c0cc48984e810e5802fb341eb80a3e9060800160405180910390a15050505050565b60606004805461052290611603565b60006108a681610bb0565b6008805465010000000000600160c81b031916650100000000006001600160a01b038516908102919091179091556040519081527fa4eea51cd2f21eac6612ba054a363ae2fd59698fc258ab414313cd73f69f2b85906020015b60405180910390a15050565b600061091781610bb0565b306001600160a01b038416036109375761093763992501b360e01b610cf5565b6106af6001600160a01b0384163384610cff565b6000336105b38185856105da836109d2565b600061096881610bb0565b610973600683610d51565b506040516001600160a01b03831681527f59c3fbcae88f30e9b0e35c132a7f68c53231dffa4722f197c7ecb0ee013eee6090602001610900565b6000828152600560205260409020600101546109c881610bb0565b6106768383610c4e565b600061050d600683610d66565b60006109ea81610bb0565b6001600160a01b038216610a0857610a0863b47cdee560e01b610cf5565b816001600160a01b03163b600003610a2a57610a2a630f9da0c760e41b610cf5565b610a35600683610d88565b506040516001600160a01b03831681527fb893f883ef734b712208a877459424ee509832c57e0461fb1ac99ed4d42f2d8990602001610900565b6106af8383836001610d9d565b6001600160a01b0383811660009081526001602090815260408083209386168352929052205460001981146106765781811015610ae557604051637dc7a0d960e11b81526001600160a01b0384166004820152602481018290526044810183905260640161020e565b61067684848484036000610d9d565b6000610b01858585610e72565b90506000610b1183868887610ee2565b9050610b3d86610b218685611653565b6001600160a01b03909116600090815260208190526040902055565b6001600160a01b0385166000908152602081905260409020805482019055846001600160a01b0316866001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051610ba091815260200190565b60405180910390a3505050505050565b61064d8133611033565b6000610bc683836106be565b610c465760008381526005602090815260408083206001600160a01b03861684529091529020805460ff19166001179055610bfe3390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a450600161050d565b50600061050d565b6000610c5a83836106be565b15610c465760008381526005602090815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a450600161050d565b6001600160a01b038216610ce557604051634b637e8f60e11b81526000600482015260240161020e565b610cf18260008361106c565b5050565b8060005260046000fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526106af908490611196565b60006105f4836001600160a01b0384166111f9565b6001600160a01b038116600090815260018301602052604081205415156105f4565b60006105f4836001600160a01b0384166112ec565b6001600160a01b038416610dc75760405163e602df0560e01b81526000600482015260240161020e565b6001600160a01b038316610df157604051634a1406b160e11b81526000600482015260240161020e565b6001600160a01b038085166000908152600160209081526040808320938716835292905220829055801561067657826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92584604051610e6491815260200190565b60405180910390a350505050565b60006001600160a01b038416610e9257610e92630b07e54560e11b610cf5565b6001600160a01b038316610eb057610eb0633a954ecd60e21b610cf5565b506001600160a01b038316600090815260208190526040902054818110156105f4576105f4635dd58b8b60e01b610cf5565b600854819060ff168015610ef35750845b1561102b576000610f03856109d2565b8015610f1d57506008546000906301000000900461ffff16115b15610f6557600854600980546001600160801b0380821661271061ffff630100000090960495909516880294909404938401166001600160801b031990911617905501610fc8565b610f6e846109d2565b8015610f865750600854600090610100900461ffff16115b15610fc857600854600980546001600160801b0380821661271061ffff61010090960495909516880294909404938401166001600160801b0319909116179055015b80156110295730600090815260208190526040902080548201905560405181815230906001600160a01b038616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a380820391505b505b949350505050565b61103d82826106be565b610cf15760405163e2517d3f60e01b81526001600160a01b03821660048201526024810183905260440161020e565b6001600160a01b03831661109757806002600082825461108c9190611666565b909155506111099050565b6001600160a01b038316600090815260208190526040902054818110156110ea5760405163391434e360e21b81526001600160a01b0385166004820152602481018290526044810183905260640161020e565b6001600160a01b03841660009081526020819052604090209082900390555b6001600160a01b03821661112557600280548290039055611144565b6001600160a01b03821660009081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161118991815260200190565b60405180910390a3505050565b60006111ab6001600160a01b03841683611333565b905080516000141580156111d05750808060200190518101906111ce9190611679565b155b156106af57604051635274afe760e01b81526001600160a01b038416600482015260240161020e565b600081815260018301602052604081205480156112e257600061121d600183611653565b855490915060009061123190600190611653565b90508082146112965760008660000182815481106112515761125161169b565b90600052602060002001549050808760000184815481106112745761127461169b565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806112a7576112a76116b1565b60019003818190600052602060002001600090559055856001016000868152602001908152602001600020600090556001935050505061050d565b600091505061050d565b6000818152600183016020526040812054610c465750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561050d565b60606105f48383600084600080856001600160a01b0316848660405161135991906116c7565b60006040518083038185875af1925050503d8060008114611396576040519150601f19603f3d011682016040523d82523d6000602084013e61139b565b606091505b50915091506113ab8683836113b5565b9695505050505050565b6060826113ca576113c582611411565b6105f4565b81511580156113e157506001600160a01b0384163b155b1561140a57604051639996b31560e01b81526001600160a01b038516600482015260240161020e565b50806105f4565b8051156114215780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b60006020828403121561144c57600080fd5b81356001600160e01b0319811681146105f457600080fd5b60005b8381101561147f578181015183820152602001611467565b50506000910152565b60208152600082518060208401526114a7816040850160208701611464565b601f01601f19169190910160400192915050565b80356001600160a01b03811681146114d257600080fd5b919050565b600080604083850312156114ea57600080fd5b6114f3836114bb565b946020939093013593505050565b60008060006060848603121561151657600080fd5b61151f846114bb565b925061152d602085016114bb565b9150604084013590509250925092565b60006020828403121561154f57600080fd5b5035919050565b6000806040838503121561156957600080fd5b82359150611579602084016114bb565b90509250929050565b60006020828403121561159457600080fd5b6105f4826114bb565b803561ffff811681146114d257600080fd5b600080604083850312156115c257600080fd5b6115cb8361159d565b91506115796020840161159d565b600080604083850312156115ec57600080fd5b6115f5836114bb565b9150611579602084016114bb565b600181811c9082168061161757607f821691505b60208210810361163757634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561050d5761050d61163d565b8082018082111561050d5761050d61163d565b60006020828403121561168b57600080fd5b815180151581146105f457600080fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b600082516116d9818460208701611464565b919091019291505056fea26469706673582212201ea1ff3445b90230b568ccdef04e56a4a0e53ad0c1870f54fdc2ddb42e488a3e64736f6c63430008140033000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001f400000000000000000000000000000000000000000000000000000000000001f40000000000000000000000000fd4ecd1e6d302d989e0d2724e37e645f523da8b0000000000000000000000000fd4ecd1e6d302d989e0d2724e37e645f523da8b0000000000000000000000000fd4ecd1e6d302d989e0d2724e37e645f523da8b0000000000000000000000000000000000000000000000000000000005f5e10000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000007414957414946550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000042457414900000000000000000000000000000000000000000000000000000000

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101da5760003560e01c806395d89b4111610104578063b0d75097116100a2578063e85455d711610071578063e85455d714610471578063ea8b242414610484578063ee6a934c146104b8578063eeae0f97146104cb576101da565b8063b0d75097146103e5578063b2c5c9eb14610410578063d547741f14610425578063dd62ed3e14610438576101da565b8063a217fddf116100de578063a217fddf14610391578063a45cae0214610399578063a9059cbb146103bf578063ae22107f146103d2576101da565b806395d89b41146103635780639808751d1461036b578063a1db97821461037e576101da565b80632ead09551161017c57806342966c681161014b57806342966c681461030157806370a082311461031457806391d148541461033d578063936b293414610350576101da565b80632ead0955146102c25780632f2ff15d146102cc578063313ce567146102df57806336568abe146102ee576101da565b8063095ea7b3116101b8578063095ea7b31461027157806318160ddd1461028457806323b872dd1461028c578063248a9ca31461029f576101da565b806301ffc9a714610217578063038272b61461023f57806306fdde031461025c575b60405162461bcd60e51b815260206004820152600d60248201526c139bdd081cdd5c1c1bdc9d1959609a1b60448201526064015b60405180910390fd5b61022a61022536600461143a565b6104dc565b60405190151581526020015b60405180910390f35b6008546301000000900461ffff165b604051908152602001610236565b610264610513565b6040516102369190611488565b61022a61027f3660046114d7565b6105a5565b60025461024e565b61022a61029a366004611501565b6105bd565b61024e6102ad36600461153d565b60009081526005602052604090206001015490565b6102ca6105fb565b005b6102ca6102da366004611556565b610651565b60405160128152602001610236565b6102ca6102fc366004611556565b61067c565b6102ca61030f36600461153d565b6106b4565b61024e610322366004611582565b6001600160a01b031660009081526020819052604090205490565b61022a61034b366004611556565b6106be565b6102ca61035e3660046115af565b6106e9565b61026461088c565b6102ca610379366004611582565b61089b565b6102ca61038c3660046114d7565b61090c565b61024e600081565b6008546103ac90610100900461ffff1681565b60405161ffff9091168152602001610236565b61022a6103cd3660046114d7565b61094b565b6102ca6103e0366004611582565b61095d565b6009546103f8906001600160801b031681565b6040516001600160801b039091168152602001610236565b6008546103ac906301000000900461ffff1681565b6102ca610433366004611556565b6109ad565b61024e6104463660046115d9565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b61022a61047f366004611582565b6109d2565b6008546104a0906501000000000090046001600160a01b031681565b6040516001600160a01b039091168152602001610236565b6102ca6104c6366004611582565b6109df565b600854610100900461ffff1661024e565b60006001600160e01b03198216637965db0b60e01b148061050d57506301ffc9a760e01b6001600160e01b03198316145b92915050565b60606003805461052290611603565b80601f016020809104026020016040519081016040528092919081815260200182805461054e90611603565b801561059b5780601f106105705761010080835404028352916020019161059b565b820191906000526020600020905b81548152906001019060200180831161057e57829003601f168201915b5050505050905090565b6000336105b3818585610a6f565b5060019392505050565b6000336105cb858285610a7c565b6105ee8585856105da896109d2565b806105e957506105e9886109d2565b610af4565b60019150505b9392505050565b6009546001600160801b03161561064f57600980546001600160801b031981169091556008546001600160801b039091169061064d9030906501000000000090046001600160a01b0316836000610af4565b505b565b60008281526005602052604090206001015461066c81610bb0565b6106768383610bba565b50505050565b6001600160a01b03811633146106a55760405163334bd91960e11b815260040160405180910390fd5b6106af8282610c4e565b505050565b61064d3382610cbb565b60009182526005602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60006106f481610bb0565b6127108361ffff161061075e5760405162461bcd60e51b815260206004820152602c60248201527f4275792074617820626173697320706f696e7473206d757374206265206c657360448201526b073207468616e2031303030360a41b606482015260840161020e565b6127108261ffff16106107c95760405162461bcd60e51b815260206004820152602d60248201527f53656c6c2074617820626173697320706f696e7473206d757374206265206c6560448201526c07373207468616e20313030303609c1b606482015260840161020e565b60085461ffff61010082048116916301000000900481169085161515806107f4575060008461ffff16115b6008805462ffffff191691151562ffff0019169190911761010061ffff8881169182029290921764ffff000000191663010000008884169081029190911790935560408051868416815260208101929092529184169181019190915260608101919091527f8da1f77a22734510b762a9625e69e737d7c0cc48984e810e5802fb341eb80a3e9060800160405180910390a15050505050565b60606004805461052290611603565b60006108a681610bb0565b6008805465010000000000600160c81b031916650100000000006001600160a01b038516908102919091179091556040519081527fa4eea51cd2f21eac6612ba054a363ae2fd59698fc258ab414313cd73f69f2b85906020015b60405180910390a15050565b600061091781610bb0565b306001600160a01b038416036109375761093763992501b360e01b610cf5565b6106af6001600160a01b0384163384610cff565b6000336105b38185856105da836109d2565b600061096881610bb0565b610973600683610d51565b506040516001600160a01b03831681527f59c3fbcae88f30e9b0e35c132a7f68c53231dffa4722f197c7ecb0ee013eee6090602001610900565b6000828152600560205260409020600101546109c881610bb0565b6106768383610c4e565b600061050d600683610d66565b60006109ea81610bb0565b6001600160a01b038216610a0857610a0863b47cdee560e01b610cf5565b816001600160a01b03163b600003610a2a57610a2a630f9da0c760e41b610cf5565b610a35600683610d88565b506040516001600160a01b03831681527fb893f883ef734b712208a877459424ee509832c57e0461fb1ac99ed4d42f2d8990602001610900565b6106af8383836001610d9d565b6001600160a01b0383811660009081526001602090815260408083209386168352929052205460001981146106765781811015610ae557604051637dc7a0d960e11b81526001600160a01b0384166004820152602481018290526044810183905260640161020e565b61067684848484036000610d9d565b6000610b01858585610e72565b90506000610b1183868887610ee2565b9050610b3d86610b218685611653565b6001600160a01b03909116600090815260208190526040902055565b6001600160a01b0385166000908152602081905260409020805482019055846001600160a01b0316866001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef83604051610ba091815260200190565b60405180910390a3505050505050565b61064d8133611033565b6000610bc683836106be565b610c465760008381526005602090815260408083206001600160a01b03861684529091529020805460ff19166001179055610bfe3390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a450600161050d565b50600061050d565b6000610c5a83836106be565b15610c465760008381526005602090815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a450600161050d565b6001600160a01b038216610ce557604051634b637e8f60e11b81526000600482015260240161020e565b610cf18260008361106c565b5050565b8060005260046000fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526106af908490611196565b60006105f4836001600160a01b0384166111f9565b6001600160a01b038116600090815260018301602052604081205415156105f4565b60006105f4836001600160a01b0384166112ec565b6001600160a01b038416610dc75760405163e602df0560e01b81526000600482015260240161020e565b6001600160a01b038316610df157604051634a1406b160e11b81526000600482015260240161020e565b6001600160a01b038085166000908152600160209081526040808320938716835292905220829055801561067657826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92584604051610e6491815260200190565b60405180910390a350505050565b60006001600160a01b038416610e9257610e92630b07e54560e11b610cf5565b6001600160a01b038316610eb057610eb0633a954ecd60e21b610cf5565b506001600160a01b038316600090815260208190526040902054818110156105f4576105f4635dd58b8b60e01b610cf5565b600854819060ff168015610ef35750845b1561102b576000610f03856109d2565b8015610f1d57506008546000906301000000900461ffff16115b15610f6557600854600980546001600160801b0380821661271061ffff630100000090960495909516880294909404938401166001600160801b031990911617905501610fc8565b610f6e846109d2565b8015610f865750600854600090610100900461ffff16115b15610fc857600854600980546001600160801b0380821661271061ffff61010090960495909516880294909404938401166001600160801b0319909116179055015b80156110295730600090815260208190526040902080548201905560405181815230906001600160a01b038616907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a380820391505b505b949350505050565b61103d82826106be565b610cf15760405163e2517d3f60e01b81526001600160a01b03821660048201526024810183905260440161020e565b6001600160a01b03831661109757806002600082825461108c9190611666565b909155506111099050565b6001600160a01b038316600090815260208190526040902054818110156110ea5760405163391434e360e21b81526001600160a01b0385166004820152602481018290526044810183905260640161020e565b6001600160a01b03841660009081526020819052604090209082900390555b6001600160a01b03821661112557600280548290039055611144565b6001600160a01b03821660009081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161118991815260200190565b60405180910390a3505050565b60006111ab6001600160a01b03841683611333565b905080516000141580156111d05750808060200190518101906111ce9190611679565b155b156106af57604051635274afe760e01b81526001600160a01b038416600482015260240161020e565b600081815260018301602052604081205480156112e257600061121d600183611653565b855490915060009061123190600190611653565b90508082146112965760008660000182815481106112515761125161169b565b90600052602060002001549050808760000184815481106112745761127461169b565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806112a7576112a76116b1565b60019003818190600052602060002001600090559055856001016000868152602001908152602001600020600090556001935050505061050d565b600091505061050d565b6000818152600183016020526040812054610c465750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561050d565b60606105f48383600084600080856001600160a01b0316848660405161135991906116c7565b60006040518083038185875af1925050503d8060008114611396576040519150601f19603f3d011682016040523d82523d6000602084013e61139b565b606091505b50915091506113ab8683836113b5565b9695505050505050565b6060826113ca576113c582611411565b6105f4565b81511580156113e157506001600160a01b0384163b155b1561140a57604051639996b31560e01b81526001600160a01b038516600482015260240161020e565b50806105f4565b8051156114215780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b60006020828403121561144c57600080fd5b81356001600160e01b0319811681146105f457600080fd5b60005b8381101561147f578181015183820152602001611467565b50506000910152565b60208152600082518060208401526114a7816040850160208701611464565b601f01601f19169190910160400192915050565b80356001600160a01b03811681146114d257600080fd5b919050565b600080604083850312156114ea57600080fd5b6114f3836114bb565b946020939093013593505050565b60008060006060848603121561151657600080fd5b61151f846114bb565b925061152d602085016114bb565b9150604084013590509250925092565b60006020828403121561154f57600080fd5b5035919050565b6000806040838503121561156957600080fd5b82359150611579602084016114bb565b90509250929050565b60006020828403121561159457600080fd5b6105f4826114bb565b803561ffff811681146114d257600080fd5b600080604083850312156115c257600080fd5b6115cb8361159d565b91506115796020840161159d565b600080604083850312156115ec57600080fd5b6115f5836114bb565b9150611579602084016114bb565b600181811c9082168061161757607f821691505b60208210810361163757634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561050d5761050d61163d565b8082018082111561050d5761050d61163d565b60006020828403121561168b57600080fd5b815180151581146105f457600080fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b600082516116d9818460208701611464565b919091019291505056fea26469706673582212201ea1ff3445b90230b568ccdef04e56a4a0e53ad0c1870f54fdc2ddb42e488a3e64736f6c63430008140033

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

000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001f400000000000000000000000000000000000000000000000000000000000001f40000000000000000000000000fd4ecd1e6d302d989e0d2724e37e645f523da8b0000000000000000000000000fd4ecd1e6d302d989e0d2724e37e645f523da8b0000000000000000000000000fd4ecd1e6d302d989e0d2724e37e645f523da8b0000000000000000000000000000000000000000000000000000000005f5e10000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000007414957414946550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000042457414900000000000000000000000000000000000000000000000000000000

-----Decoded View---------------
Arg [0] : baseParams (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
Arg [1] : taxParams (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]

-----Encoded View---------------
13 Constructor Arguments found :
Arg [0] : 0000000000000000000000000000000000000000000000000000000000000080
Arg [1] : 00000000000000000000000000000000000000000000000000000000000001f4
Arg [2] : 00000000000000000000000000000000000000000000000000000000000001f4
Arg [3] : 0000000000000000000000000fd4ecd1e6d302d989e0d2724e37e645f523da8b
Arg [4] : 0000000000000000000000000fd4ecd1e6d302d989e0d2724e37e645f523da8b
Arg [5] : 0000000000000000000000000fd4ecd1e6d302d989e0d2724e37e645f523da8b
Arg [6] : 0000000000000000000000000000000000000000000000000000000005f5e100
Arg [7] : 00000000000000000000000000000000000000000000000000000000000000a0
Arg [8] : 00000000000000000000000000000000000000000000000000000000000000e0
Arg [9] : 0000000000000000000000000000000000000000000000000000000000000007
Arg [10] : 4149574149465500000000000000000000000000000000000000000000000000
Arg [11] : 0000000000000000000000000000000000000000000000000000000000000004
Arg [12] : 2457414900000000000000000000000000000000000000000000000000000000


Deployed Bytecode Sourcemap

408:8691:46:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6728:23;;-1:-1:-1;;;6728:23:46;;216:2:47;6728:23:46;;;198:21:47;255:2;235:18;;;228:30;-1:-1:-1;;;274:18:47;;;267:43;327:18;;6728:23:46;;;;;;;;2565:202:4;;;;;;:::i;:::-;;:::i;:::-;;;812:14:47;;805:22;787:41;;775:2;760:18;2565:202:4;;;;;;;;7319:114:46;7401:25;;;;;;;7319:114;;;985:25:47;;;973:2;958:18;7319:114:46;839:177:47;1266:89:44;;;:::i;:::-;;;;;;;:::i;3134:208::-;;;;;;:::i;:::-;;:::i;2336:97::-;2414:12;;2336:97;;3876:384:46;;;;;;:::i;:::-;;:::i;3810:120:4:-;;;;;;:::i;:::-;3875:7;3901:12;;;:6;:12;;;;;:22;;;;3810:120;7439:367:46;;;:::i;:::-;;4226:136:4;;;;;;:::i;:::-;;:::i;2194:82:44:-;;;2267:2;3215:36:47;;3203:2;3188:18;2194:82:44;3073:184:47;5328:245:4;;;;;;:::i;:::-;;:::i;10807:87:44:-;;;;;;:::i;:::-;;:::i;2491:116::-;;;;;;:::i;:::-;-1:-1:-1;;;;;2582:18:44;2556:7;2582:18;;;;;;;;;;;;2491:116;2854:136:4;;;;;;:::i;:::-;;:::i;8054:1043:46:-;;;;;;:::i;:::-;;:::i;1468:93:44:-;;;:::i;7812:236:46:-;;;;;;:::i;:::-;;:::i;6764:287::-;;;;;;:::i;:::-;;:::i;2187:49:4:-;;2232:4;2187:49;;1019:38:46;;;;;;;;;;;;;;;4237:6:47;4225:19;;;4207:38;;4195:2;4180:18;1019:38:46;4063:188:47;3562:308:46;;;;;;:::i;:::-;;:::i;3275:281::-;;;;;;:::i;:::-;;:::i;1496:36::-;;;;;-1:-1:-1;;;;;1496:36:46;;;;;;-1:-1:-1;;;;;4420:47:47;;;4402:66;;4390:2;4375:18;1496:36:46;4256:218:47;1063:39:46;;;;;;;;;;;;4642:138:4;;;;;;:::i;:::-;;:::i;2665:162:44:-;;;;;;:::i;:::-;-1:-1:-1;;;;;2793:18:44;;;2767:7;2793:18;;;:11;:18;;;;;;;;:27;;;;;;;;;;;;;2665:162;7057:138:46;;;;;;:::i;:::-;;:::i;1108:34::-;;;;;;;;-1:-1:-1;;;;;1108:34:46;;;;;;-1:-1:-1;;;;;4908:32:47;;;4890:51;;4878:2;4863:18;1108:34:46;4744:203:47;2621:648:46;;;;;;:::i;:::-;;:::i;7201:112::-;7282:24;;;;;;;7201:112;;2565:202:4;2650:4;-1:-1:-1;;;;;;2673:47:4;;-1:-1:-1;;;2673:47:4;;:87;;-1:-1:-1;;;;;;;;;;861:40:32;;;2724:36:4;2666:94;2565:202;-1:-1:-1;;2565:202:4:o;1266:89:44:-;1311:13;1343:5;1336:12;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1266:89;:::o;3134:208::-;3229:4;735:10:23;3283:31:44;735:10:23;3299:7:44;3308:5;3283:8;:31::i;:::-;-1:-1:-1;3331:4:44;;3134:208;-1:-1:-1;;;3134:208:44:o;3876:384:46:-;3995:4;735:10:23;4051:38:46;4067:4;735:10:23;4082:6:46;4051:15;:38::i;:::-;4099:133;4122:4;4140:2;4156:6;4177:21;4193:4;4177:15;:21::i;:::-;:44;;;;4202:19;4218:2;4202:15;:19::i;:::-;4099:9;:133::i;:::-;4249:4;4242:11;;;3876:384;;;;;;:::o;7439:367::-;7493:21;;-1:-1:-1;;;;;7493:21:46;:25;7489:311;;7564:21;;;-1:-1:-1;;;;;;7599:25:46;;;;;7696:19;;-1:-1:-1;;;;;7564:21:46;;;;7638:151;;7673:4;;7696:19;;;-1:-1:-1;;;;;7696:19:46;7564:21;-1:-1:-1;7638:9:46;:151::i;:::-;7520:280;7489:311;7439:367::o;4226:136:4:-;3875:7;3901:12;;;:6;:12;;;;;:22;;;2464:16;2475:4;2464:10;:16::i;:::-;4330:25:::1;4341:4;4347:7;4330:10;:25::i;:::-;;4226:136:::0;;;:::o;5328:245::-;-1:-1:-1;;;;;5421:34:4;;735:10:23;5421:34:4;5417:102;;5478:30;;-1:-1:-1;;;5478:30:4;;;;;;;;;;;5417:102;5529:37;5541:4;5547:18;5529:11;:37::i;:::-;;5328:245;;:::o;10807:87:44:-;10861:26;735:10:23;10881:5:44;10861;:26::i;2854:136:4:-;2931:4;2954:12;;;:6;:12;;;;;;;;-1:-1:-1;;;;;2954:29:4;;;;;;;;;;;;;;;2854:136::o;8054:1043:46:-;2232:4:4;2464:16;2232:4;2464:10;:16::i;:::-;920:5:46::1;8248:28;:39;;;8227:130;;;::::0;-1:-1:-1;;;8227:130:46;;5539:2:47;8227:130:46::1;::::0;::::1;5521:21:47::0;5578:2;5558:18;;;5551:30;5617:34;5597:18;;;5590:62;-1:-1:-1;;;5668:18:47;;;5661:42;5720:19;;8227:130:46::1;5337:408:47::0;8227:130:46::1;920:5;8388:29;:40;;;8367:132;;;::::0;-1:-1:-1;;;8367:132:46;;5952:2:47;8367:132:46::1;::::0;::::1;5934:21:47::0;5991:2;5971:18;;;5964:30;6030:34;6010:18;;;6003:62;-1:-1:-1;;;6081:18:47;;;6074:43;6134:19;;8367:132:46::1;5750:409:47::0;8367:132:46::1;8540:24;::::0;::::1;;::::0;::::1;::::0;::::1;::::0;8605:25;;::::1;::::0;::::1;::::0;8668:32;::::1;::::0;;;:81:::1;;;8748:1;8716:29;:33;;;8668:81;8641:12;:108:::0;;-1:-1:-1;;8760:55:46;8641:108;::::1;;-1:-1:-1::0;;8760:55:46;;;;;8641:108:::1;8760:55;::::0;;::::1;::::0;;::::1;::::0;;;::::1;-1:-1:-1::0;;8825:57:46::1;::::0;;;::::1;::::0;;::::1;::::0;;;::::1;::::0;;;8898:192:::1;::::0;;6434:15:47;;;6416:34;;6481:2;6466:18;;6459:43;;;;6538:15;;;6518:18;;;6511:43;;;;6585:2;6570:18;;6563:43;;;;8898:192:46::1;::::0;6378:3:47;6363:19;8898:192:46::1;;;;;;;8217:880;;8054:1043:::0;;;:::o;1468:93:44:-;1515:13;1547:7;1540:14;;;;;:::i;7812:236:46:-;2232:4:4;2464:16;2232:4;2464:10;:16::i;:::-;7936:19:46::1;:42:::0;;-1:-1:-1;;;;;;7936:42:46::1;::::0;-1:-1:-1;;;;;7936:42:46;::::1;::::0;;::::1;::::0;;;::::1;::::0;;;7993:48:::1;::::0;4890:51:47;;;7993:48:46::1;::::0;4878:2:47;4863:18;7993:48:46::1;;;;;;;;7812:236:::0;;:::o;6764:287::-;2232:4:4;2464:16;2232:4;2464:10;:16::i;:::-;6912:4:46::1;-1:-1:-1::0;;;;;6894:23:46;::::1;::::0;6890:95:::1;;6933:41;-1:-1:-1::0;;;6933:7:46::1;:41::i;:::-;6994:50;-1:-1:-1::0;;;;;6994:27:46;::::1;735:10:23::0;7036:7:46;6994:27:::1;:50::i;3562:308::-:0;3654:4;735:10:23;3708:134:46;735:10:23;3750:2:46;3766:5;3786:22;735:10:23;3786:15:46;:22::i;3275:281::-;2232:4:4;2464:16;2232:4;2464:10;:16::i;:::-;3446:45:46::1;:15;3469:21:::0;3446:22:::1;:45::i;:::-;-1:-1:-1::0;3506:43:46::1;::::0;-1:-1:-1;;;;;4908:32:47;;4890:51;;3506:43:46::1;::::0;4878:2:47;4863:18;3506:43:46::1;4744:203:47::0;4642:138:4;3875:7;3901:12;;;:6;:12;;;;;:22;;;2464:16;2475:4;2464:10;:16::i;:::-;4747:26:::1;4759:4;4765:7;4747:11;:26::i;7057:138:46:-:0;7126:4;7149:39;:15;7174:13;7149:24;:39::i;2621:648::-;2232:4:4;2464:16;2232:4;2464:10;:16::i;:::-;-1:-1:-1;;;;;2796:31:46;::::1;2792:112;;2843:50;-1:-1:-1::0;;;2843:7:46::1;:50::i;:::-;3005:17;-1:-1:-1::0;;;;;3005:29:46::1;;3038:1;3005:34:::0;3001:118:::1;;3055:53;-1:-1:-1::0;;;3055:7:46::1;:53::i;:::-;3172:38;:15;3192:17:::0;3172:19:::1;:38::i;:::-;-1:-1:-1::0;3225:37:46::1;::::0;-1:-1:-1;;;;;4908:32:47;;4890:51;;3225:37:46::1;::::0;4878:2:47;4863:18;3225:37:46::1;4744:203:47::0;8066:128:44;8150:37;8159:5;8166:7;8175:5;8182:4;8150:8;:37::i;9778:585::-;-1:-1:-1;;;;;2793:18:44;;;9907:24;2793:18;;;:11;:18;;;;;;;;:27;;;;;;;;;;-1:-1:-1;;9973:37:44;;9969:388;;10049:5;10030:16;:24;10026:208;;;10081:138;;-1:-1:-1;;;10081:138:44;;-1:-1:-1;;;;;6837:32:47;;10081:138:44;;;6819:51:47;6886:18;;;6879:34;;;6929:18;;;6922:34;;;6792:18;;10081:138:44;6617:345:47;10026:208:44;10275:57;10284:5;10291:7;10319:5;10300:16;:24;10326:5;10275:8;:57::i;4266:554:46:-;4498:19;4520:44;4547:4;4553:2;4557:6;4520:26;:44::i;:::-;4498:66;;4600:22;4625:42;4640:8;4650:2;4654:4;4660:6;4625:14;:42::i;:::-;4600:67;-1:-1:-1;4678:39:46;4690:4;4696:20;4710:6;4696:11;:20;:::i;:::-;-1:-1:-1;;;;;10612:18:44;;;:9;:18;;;;;;;;;;:31;10535:115;4678:39:46;-1:-1:-1;;;;;10757:18:44;;:9;:18;;;;;;;;;;:27;;;;;;4794:2:46;-1:-1:-1;;;;;4779:34:46;4788:4;-1:-1:-1;;;;;4779:34:46;;4798:14;4779:34;;;;985:25:47;;973:2;958:18;;839:177;4779:34:46;;;;;;;;4397:423;;4266:554;;;;:::o;3199:103:4:-;3265:30;3276:4;735:10:23;3265::4;:30::i;6179:316::-;6256:4;6277:22;6285:4;6291:7;6277;:22::i;:::-;6272:217;;6315:12;;;;:6;:12;;;;;;;;-1:-1:-1;;;;;6315:29:4;;;;;;;;;:36;;-1:-1:-1;;6315:36:4;6347:4;6315:36;;;6397:12;735:10:23;;656:96;6397:12:4;-1:-1:-1;;;;;6370:40:4;6388:7;-1:-1:-1;;;;;6370:40:4;6382:4;6370:40;;;;;;;;;;-1:-1:-1;6431:4:4;6424:11;;6272:217;-1:-1:-1;6473:5:4;6466:12;;6730:317;6808:4;6828:22;6836:4;6842:7;6828;:22::i;:::-;6824:217;;;6898:5;6866:12;;;:6;:12;;;;;;;;-1:-1:-1;;;;;6866:29:4;;;;;;;;;;:37;;-1:-1:-1;;6866:37:4;;;6922:40;735:10:23;;6866:12:4;;6922:40;;6898:5;6922:40;-1:-1:-1;6983:4:4;6976:11;;7324:206:44;-1:-1:-1;;;;;7394:21:44;;7390:89;;7438:30;;-1:-1:-1;;;7438:30:44;;7465:1;7438:30;;;4890:51:47;4863:18;;7438:30:44;4744:203:47;7390:89:44;7488:35;7496:7;7513:1;7517:5;7488:7;:35::i;:::-;7324:206;;:::o;10369:160::-;10468:13;10462:4;10455:27;10508:4;10502;10495:18;1303:160:19;1412:43;;;-1:-1:-1;;;;;7424:32:47;;1412:43:19;;;7406:51:47;7473:18;;;;7466:34;;;1412:43:19;;;;;;;;;;7379:18:47;;;;1412:43:19;;;;;;;;-1:-1:-1;;;;;1412:43:19;-1:-1:-1;;;1412:43:19;;;1385:71;;1405:5;;1385:19;:71::i;8634:156:36:-;8707:4;8730:53;8738:3;-1:-1:-1;;;;;8758:23:36;;8730:7;:53::i;8871:165::-;-1:-1:-1;;;;;9004:23:36;;8951:4;4360:21;;;:14;;;:21;;;;;;:26;;8974:55;4264:129;8316:150;8386:4;8409:50;8414:3;-1:-1:-1;;;;;8434:23:36;;8409:4;:50::i;9026:470:44:-;-1:-1:-1;;;;;9176:19:44;;9172:89;;9218:32;;-1:-1:-1;;;9218:32:44;;9247:1;9218:32;;;4890:51:47;4863:18;;9218:32:44;4744:203:47;9172:89:44;-1:-1:-1;;;;;9274:21:44;;9270:90;;9318:31;;-1:-1:-1;;;9318:31:44;;9346:1;9318:31;;;4890:51:47;4863:18;;9318:31:44;4744:203:47;9270:90:44;-1:-1:-1;;;;;9369:18:44;;;;;;;:11;:18;;;;;;;;:27;;;;;;;;;:35;;;9414:76;;;;9464:7;-1:-1:-1;;;;;9448:31:44;9457:5;-1:-1:-1;;;;;9448:31:44;;9473:5;9448:31;;;;985:25:47;;973:2;958:18;;839:177;9448:31:44;;;;;;;;9026:470;;;;:::o;4826:543:46:-;4960:20;-1:-1:-1;;;;;4996:19:46;;4992:91;;5031:41;-1:-1:-1;;;5031:7:46;:41::i;:::-;-1:-1:-1;;;;;5097:17:46;;5093:87;;5130:39;-1:-1:-1;;;5130:7:46;:39::i;:::-;-1:-1:-1;;;;;;2582:18:44;;2556:7;2582:18;;;;;;;;;;;5236:22:46;;;5232:99;;;5274:46;-1:-1:-1;;;5274:7:46;:46::i;5375:1317::-;5620:12;;5571:11;;5620:12;;:25;;;;;5636:9;5620:25;5616:1027;;;5665:11;5726:20;5742:3;5726:15;:20::i;:::-;:53;;;;-1:-1:-1;7401:25:46;;5778:1;;7401:25;;;;;5750:29;5726:53;5722:694;;;5864:25;;5924:21;:44;;-1:-1:-1;;;;;5924:44:46;;;920:5;5864:25;;;;;;;;;5826:63;;5825:76;;;;5924:44;;;;-1:-1:-1;;;;;;5924:44:46;;;;;;5990:17;5722:694;;;6099:22;6115:5;6099:15;:22::i;:::-;:54;;;;-1:-1:-1;7282:24:46;;6152:1;;7282:24;;;;;6125:28;6099:54;6074:342;;;6255:24;;6314:21;:44;;-1:-1:-1;;;;;6314:44:46;;;920:5;6255:24;;;;;;;;;6217:62;;6216:75;;;;6314:44;;;;-1:-1:-1;;;;;;6314:44:46;;;;;;6380:17;6074:342;6438:7;;6434:195;;6494:4;10757:9:44;:18;;;;;;;;;;:27;;;;;;6532:35:46;;985:25:47;;;6556:4:46;;-1:-1:-1;;;;;6532:35:46;;;;;973:2:47;958:18;6532:35:46;;;;;;;6607:3;6589:21;;;;6434:195;5647:996;5616:1027;5375:1317;;;;;;:::o;3432:197:4:-;3520:22;3528:4;3534:7;3520;:22::i;:::-;3515:108;;3565:47;;-1:-1:-1;;;3565:47:4;;-1:-1:-1;;;;;7424:32:47;;3565:47:4;;;7406:51:47;7473:18;;;7466:34;;;7379:18;;3565:47:4;7232:274:47;5348:1107:44;-1:-1:-1;;;;;5437:18:44;;5433:540;;5589:5;5573:12;;:21;;;;;;;:::i;:::-;;;;-1:-1:-1;5433:540:44;;-1:-1:-1;5433:540:44;;-1:-1:-1;;;;;5647:15:44;;5625:19;5647:15;;;;;;;;;;;5680:19;;;5676:115;;;5726:50;;-1:-1:-1;;;5726:50:44;;-1:-1:-1;;;;;6837:32:47;;5726:50:44;;;6819:51:47;6886:18;;;6879:34;;;6929:18;;;6922:34;;;6792:18;;5726:50:44;6617:345:47;5676:115:44;-1:-1:-1;;;;;5911:15:44;;:9;:15;;;;;;;;;;5929:19;;;;5911:37;;5433:540;-1:-1:-1;;;;;5987:16:44;;5983:425;;6150:12;:21;;;;;;;5983:425;;;-1:-1:-1;;;;;6361:13:44;;:9;:13;;;;;;;;;;:22;;;;;;5983:425;6438:2;-1:-1:-1;;;;;6423:25:44;6432:4;-1:-1:-1;;;;;6423:25:44;;6442:5;6423:25;;;;985::47;;973:2;958:18;;839:177;6423:25:44;;;;;;;;5348:1107;;;:::o;4059:629:19:-;4478:23;4504:33;-1:-1:-1;;;;;4504:27:19;;4532:4;4504:27;:33::i;:::-;4478:59;;4551:10;:17;4572:1;4551:22;;:57;;;;;4589:10;4578:30;;;;;;;;;;;;:::i;:::-;4577:31;4551:57;4547:135;;;4631:40;;-1:-1:-1;;;4631:40:19;;-1:-1:-1;;;;;4908:32:47;;4631:40:19;;;4890:51:47;4863:18;;4631:40:19;4744:203:47;2815:1368:36;2881:4;3010:21;;;:14;;;:21;;;;;;3046:13;;3042:1135;;3413:18;3434:12;3445:1;3434:8;:12;:::i;:::-;3480:18;;3413:33;;-1:-1:-1;3460:17:36;;3480:22;;3501:1;;3480:22;:::i;:::-;3460:42;;3535:9;3521:10;:23;3517:378;;3564:17;3584:3;:11;;3596:9;3584:22;;;;;;;;:::i;:::-;;;;;;;;;3564:42;;3731:9;3705:3;:11;;3717:10;3705:23;;;;;;;;:::i;:::-;;;;;;;;;;;;:35;;;;3844:25;;;:14;;;:25;;;;;:36;;;3517:378;3973:17;;:3;;:17;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;4076:3;:14;;:21;4091:5;4076:21;;;;;;;;;;;4069:28;;;4119:4;4112:11;;;;;;;3042:1135;4161:5;4154:12;;;;;2241:406;2304:4;4360:21;;;:14;;;:21;;;;;;2320:321;;-1:-1:-1;2362:23:36;;;;;;;;:11;:23;;;;;;;;;;;;;2544:18;;2520:21;;;:14;;;:21;;;;;;:42;;;;2576:11;;2705:151:21;2780:12;2811:38;2833:6;2841:4;2847:1;2780:12;3421;3435:23;3462:6;-1:-1:-1;;;;;3462:11:21;3481:5;3488:4;3462:31;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3420:73;;;;3510:55;3537:6;3545:7;3554:10;3510:26;:55::i;:::-;3503:62;3180:392;-1:-1:-1;;;;;;3180:392:21:o;4625:582::-;4769:12;4798:7;4793:408;;4821:19;4829:10;4821:7;:19::i;:::-;4793:408;;;5045:17;;:22;:49;;;;-1:-1:-1;;;;;;5071:18:21;;;:23;5045:49;5041:119;;;5121:24;;-1:-1:-1;;;5121:24:21;;-1:-1:-1;;;;;4908:32:47;;5121:24:21;;;4890:51:47;4863:18;;5121:24:21;4744:203:47;5041:119:21;-1:-1:-1;5180:10:21;5173:17;;5743:516;5874:17;;:21;5870:383;;6102:10;6096:17;6158:15;6145:10;6141:2;6137:19;6130:44;5870:383;6225:17;;-1:-1:-1;;;6225:17:21;;;;;;;;;;;356:286:47;414:6;467:2;455:9;446:7;442:23;438:32;435:52;;;483:1;480;473:12;435:52;509:23;;-1:-1:-1;;;;;;561:32:47;;551:43;;541:71;;608:1;605;598:12;1021:250;1106:1;1116:113;1130:6;1127:1;1124:13;1116:113;;;1206:11;;;1200:18;1187:11;;;1180:39;1152:2;1145:10;1116:113;;;-1:-1:-1;;1263:1:47;1245:16;;1238:27;1021:250::o;1276:396::-;1425:2;1414:9;1407:21;1388:4;1457:6;1451:13;1500:6;1495:2;1484:9;1480:18;1473:34;1516:79;1588:6;1583:2;1572:9;1568:18;1563:2;1555:6;1551:15;1516:79;:::i;:::-;1656:2;1635:15;-1:-1:-1;;1631:29:47;1616:45;;;;1663:2;1612:54;;1276:396;-1:-1:-1;;1276:396:47:o;1677:173::-;1745:20;;-1:-1:-1;;;;;1794:31:47;;1784:42;;1774:70;;1840:1;1837;1830:12;1774:70;1677:173;;;:::o;1855:254::-;1923:6;1931;1984:2;1972:9;1963:7;1959:23;1955:32;1952:52;;;2000:1;1997;1990:12;1952:52;2023:29;2042:9;2023:29;:::i;:::-;2013:39;2099:2;2084:18;;;;2071:32;;-1:-1:-1;;;1855:254:47:o;2114:328::-;2191:6;2199;2207;2260:2;2248:9;2239:7;2235:23;2231:32;2228:52;;;2276:1;2273;2266:12;2228:52;2299:29;2318:9;2299:29;:::i;:::-;2289:39;;2347:38;2381:2;2370:9;2366:18;2347:38;:::i;:::-;2337:48;;2432:2;2421:9;2417:18;2404:32;2394:42;;2114:328;;;;;:::o;2447:180::-;2506:6;2559:2;2547:9;2538:7;2534:23;2530:32;2527:52;;;2575:1;2572;2565:12;2527:52;-1:-1:-1;2598:23:47;;2447:180;-1:-1:-1;2447:180:47:o;2814:254::-;2882:6;2890;2943:2;2931:9;2922:7;2918:23;2914:32;2911:52;;;2959:1;2956;2949:12;2911:52;2995:9;2982:23;2972:33;;3024:38;3058:2;3047:9;3043:18;3024:38;:::i;:::-;3014:48;;2814:254;;;;;:::o;3447:186::-;3506:6;3559:2;3547:9;3538:7;3534:23;3530:32;3527:52;;;3575:1;3572;3565:12;3527:52;3598:29;3617:9;3598:29;:::i;3638:159::-;3705:20;;3765:6;3754:18;;3744:29;;3734:57;;3787:1;3784;3777:12;3802:256;3868:6;3876;3929:2;3917:9;3908:7;3904:23;3900:32;3897:52;;;3945:1;3942;3935:12;3897:52;3968:28;3986:9;3968:28;:::i;:::-;3958:38;;4015:37;4048:2;4037:9;4033:18;4015:37;:::i;4479:260::-;4547:6;4555;4608:2;4596:9;4587:7;4583:23;4579:32;4576:52;;;4624:1;4621;4614:12;4576:52;4647:29;4666:9;4647:29;:::i;:::-;4637:39;;4695:38;4729:2;4718:9;4714:18;4695:38;:::i;4952:380::-;5031:1;5027:12;;;;5074;;;5095:61;;5149:4;5141:6;5137:17;5127:27;;5095:61;5202:2;5194:6;5191:14;5171:18;5168:38;5165:161;;5248:10;5243:3;5239:20;5236:1;5229:31;5283:4;5280:1;5273:15;5311:4;5308:1;5301:15;5165:161;;4952:380;;;:::o;6967:127::-;7028:10;7023:3;7019:20;7016:1;7009:31;7059:4;7056:1;7049:15;7083:4;7080:1;7073:15;7099:128;7166:9;;;7187:11;;;7184:37;;;7201:18;;:::i;7922:125::-;7987:9;;;8008:10;;;8005:36;;;8021:18;;:::i;8052:277::-;8119:6;8172:2;8160:9;8151:7;8147:23;8143:32;8140:52;;;8188:1;8185;8178:12;8140:52;8220:9;8214:16;8273:5;8266:13;8259:21;8252:5;8249:32;8239:60;;8295:1;8292;8285:12;8334:127;8395:10;8390:3;8386:20;8383:1;8376:31;8426:4;8423:1;8416:15;8450:4;8447:1;8440:15;8466:127;8527:10;8522:3;8518:20;8515:1;8508:31;8558:4;8555:1;8548:15;8582:4;8579:1;8572:15;8598:287;8727:3;8765:6;8759:13;8781:66;8840:6;8835:3;8828:4;8820:6;8816:17;8781:66;:::i;:::-;8863:16;;;;;8598:287;-1:-1:-1;;8598:287:47:o

Swarm Source

ipfs://1ea1ff3445b90230b568ccdef04e56a4a0e53ad0c1870f54fdc2ddb42e488a3e

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

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

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