Contract Address Details

0x6cadb0b3C2D1a0F46DC998E800AA2AD74D59066E

Creator
0x0f1bb1–c34de6 at 0xedc804–b5dbbd
Balance
0 ADIL ( )
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
14335033
Contract is not verified. However, we found a verified contract with the same bytecode in AdilScan DB 0x38ee2fb4a4c55a66913ae986be5c21dcffb7b554.
All metadata displayed below is from that contract. In order to verify current contract, click Verify & Publish button
Verify & Publish
Contract name:
SwapTicket




Optimization enabled
true
Compiler version
v0.8.2+commit.661d1103




Optimization runs
200
Verified at
2025-06-23 10:17:02.301303Z

contracts/SwapTicket.sol

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

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "./abstracts/OwnerOperator.sol";
import "./interfaces/IHorseItemNFT.sol";
import "./interfaces/ITicket.sol";
import "./libraries/StringLibrary.sol";
import "./libraries/BytesLibrary.sol";

contract SwapTicket is Initializable, OwnerOperator, ERC721HolderUpgradeable {
    using StringLibrary for string;
    using BytesLibrary for bytes32;
    using EnumerableSet for EnumerableSet.UintSet;
    struct SwapData {
        uint256 uniqueId;
        uint8 tokenId;
        uint256 tokenAmount;
        uint256 horseItemAmount;
        string userId;
        uint256 timestamp;
        uint8 v;
        bytes32 r;
        bytes32 s;
    }

    struct SwappedItems {
        address horseItemAddress;
        uint256[] horseItemIds;
    }

    ITicket private ticket;
    IHorseItemNFT private horseItemNFT;

    uint8 public horseForTicket;
    uint256 public timeExpiredSignature;

    mapping(uint8 => EnumerableSet.UintSet) private horseItems;
    mapping(uint256 => SwappedItems) private swappedItemIds;

    address public signerAddress;

    event HorseItemSet(uint8 indexed ticketType, uint256 indexed horseId);
    event HorseItemRemoved(uint8 indexed ticketType, uint256 indexed horseId);
    event HorseItemsSwapped(
        uint256 uniqueIds,
        address ticketSwapped,
        uint8 ticketIdSwapped,
        uint256 ticketBurnedAmount,
        address indexed to,
        uint256[] horseItemIds,
        string userId
    );

    function init(
        ITicket _ticket,
        IHorseItemNFT _horseItemNFT
    ) public initializer {
        require(address(_ticket) != address(0), "Zero Ticket address");
        require(
            address(_horseItemNFT) != address(0),
            "Zero HorseItemNFT address"
        );

        super.initialize();
        __ERC721Holder_init();

        ticket = _ticket;
        horseItemNFT = _horseItemNFT;
    }

    function removeSwappedItemIds(
        uint256[] memory _ids
    ) external operatorOrOwner {
        for (uint256 i = 0; i < _ids.length; i++) {
            delete swappedItemIds[_ids[i]];
        }
    }

    function setSignerAddress(address _signerAddress) external operatorOrOwner {
        require(_signerAddress != address(0), "Zero signer address");
        signerAddress = _signerAddress;
    }

    function setTimeExpiredSignature(
        uint256 _timeExpiredSignature
    ) external operatorOrOwner {
        timeExpiredSignature = _timeExpiredSignature;
    }

    function setHorseForTicket(uint8 _horseForTicket) external operatorOrOwner {
        horseForTicket = _horseForTicket;
    }

    function setHorseItems(
        uint8 _ticketId,
        uint256[] calldata _ids
    ) external operatorOrOwner {
        for (uint256 i = 0; i < _ids.length; i++) {
            setHorseItem(_ticketId, _ids[i]);
        }
    }

    function setHorseItem(uint8 _ticketId, uint256 _id) internal {
        require(
            horseItemNFT.ownerOf(_id) == address(this),
            "SwapTicket: Horse not owned by contract"
        );
        horseItems[_ticketId].add(_id);
        emit HorseItemSet(_ticketId, _id);
    }

    function setTicket(ITicket _ticket) external operatorOrOwner {
        require(address(_ticket) != address(0), "Zero Ticket address");
        ticket = _ticket;
    }

    function setHorseItemNFT(
        IHorseItemNFT _horseItemNFT
    ) external operatorOrOwner {
        require(address(_horseItemNFT) != address(0), "Zero HorseNFT address");
        horseItemNFT = _horseItemNFT;
    }

    function removeHorseItems(
        uint8 _ticketId,
        uint256[] calldata _ids
    ) external operatorOrOwner {
        for (uint256 i = 0; i < _ids.length; i++) {
            horseItems[_ticketId].remove(_ids[i]);
            emit HorseItemRemoved(_ticketId, _ids[i]);
        }
    }

    function removeAllHorseItems(uint8 _ticketId) external operatorOrOwner {
        delete horseItems[_ticketId];
    }

    function swap(SwapData memory _data) external {
        require(
            swappedItemIds[_data.uniqueId].horseItemIds.length == 0,
            "SwapTicket: Unique ID already used"
        );
        verifySwap(msg.sender, _data);

        uint256[] memory horseItemIds = new uint256[](_data.horseItemAmount);

        for (uint8 i = 0; i < _data.horseItemAmount; i++) {
            uint256 horseId = getRandomHorseId(
                _data.uniqueId,
                _data.tokenId,
                i
            );
            horseItems[_data.tokenId].remove(horseId);
            horseItemIds[i] = horseId;
        }

        ticket.burn(msg.sender, _data.tokenId, _data.tokenAmount);
        horseItemNFT.multiTransfer(msg.sender, horseItemIds);
        swappedItemIds[_data.uniqueId] = SwappedItems({
            horseItemAddress: address(horseItemNFT),
            horseItemIds: horseItemIds
        });

        emit HorseItemsSwapped(
            _data.uniqueId,
            address(ticket),
            _data.tokenId,
            _data.tokenAmount,
            msg.sender,
            horseItemIds,
            _data.userId
        );
    }

    function withdrawHorseItems(
        uint8 _ticketLength,
        uint256[] calldata _ids,
        address _to
    ) external operatorOrOwner {
        require(_to != address(0), "SwapTicket: zero address");
        uint256 limitHorseItem = 50;
        require(
            _ids.length <= limitHorseItem,
            "SwapTicket: Exceeds limit of horse items"
        );

        for (uint256 i = 0; i < _ids.length; ++i) {
            for (uint8 j = 1; j <= _ticketLength; ++j) {
                horseItems[j].remove(_ids[i]);
            }
        }

        horseItemNFT.multiTransfer(_to, _ids);
    }

    function getRandomHorseId(
        uint256 _uniqueId,
        uint8 _tokenId,
        uint8 _randomIndex
    ) internal view returns (uint256) {
        require(
            horseItems[_tokenId].length() > 0,
            "SwapTicket: No horse items available for type"
        );
        uint256 index = uint256(
            keccak256(
                abi.encodePacked(_uniqueId, block.timestamp, _randomIndex)
            )
        ) % horseItems[_tokenId].length();
        return horseItems[_tokenId].at(index);
    }

    // View functions
    function getHorseItemNFT() external view returns (IHorseItemNFT) {
        return horseItemNFT;
    }

    function getTicket() external view returns (ITicket) {
        return ticket;
    }

    function getTotalHorseNFT(uint8 _ticketId) external view returns (uint256) {
        return horseItems[_ticketId].length();
    }

    function getHorseItems(
        uint8 _ticketId
    ) external view returns (uint256[] memory) {
        return horseItems[_ticketId].values();
    }

    function getSwappedItemIds(
        uint256 _uniqueId
    ) external view returns (SwappedItems memory) {
        return swappedItemIds[_uniqueId];
    }

    function getMultipleSwappedItemIds(
        uint256[] memory _uniqueIds
    ) external view returns (SwappedItems[] memory) {
        SwappedItems[] memory items = new SwappedItems[](_uniqueIds.length);
        for (uint256 i = 0; i < _uniqueIds.length; i++) {
            items[i] = swappedItemIds[_uniqueIds[i]];
        }
        return items;
    }

    function verifySwap(address _sender, SwapData memory _data) internal view {
        bytes32 message = keccak256(
            abi.encode(
                _sender,
                _data.uniqueId,
                _data.tokenId,
                _data.tokenAmount,
                _data.horseItemAmount,
                _data.userId,
                _data.timestamp
            )
        );
        address signer = message.toString().recover(_data.v, _data.r, _data.s);
        require(
            block.timestamp <= _data.timestamp + timeExpiredSignature,
            "SwapTicket: signature expired"
        );
        require(signer == signerAddress, "SwapTicket: Invalid signature");
    }

    function multiTransfer(
        address to,
        uint256[] memory tokenIds
    ) external operatorOrOwner {
        require(to != address(0), "SwapTicket: zero address");
        for (uint256 i = 0; i < tokenIds.length; i++) {
            require(
                horseItemNFT.ownerOf(tokenIds[i]) == address(this),
                "SwapTicket: contract does not own the token"
            );
            horseItemNFT.safeTransferFrom(address(this), to, tokenIds[i]);
        }
    }

    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) public override returns (bytes4) {
        setHorseItem(horseForTicket, tokenId);

        return this.onERC721Received.selector;
    }
}
        

@openzeppelin/contracts-upgradeable/token/ERC721/IERC721ReceiverUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721ReceiverUpgradeable {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}
          

@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}
          

@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "../../utils/AddressUpgradeable.sol";

/**
 * @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]
 * ```
 * 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 Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 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 functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _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 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _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() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @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 {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized < type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initialized`
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Internal function that returns the initialized version. Returns `_initializing`
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}
          

@openzeppelin/contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol)

pragma solidity ^0.8.0;

import "../IERC721ReceiverUpgradeable.sol";
import "../../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC721Receiver} interface.
 *
 * Accepts all token transfers.
 * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.
 */
contract ERC721HolderUpgradeable is Initializable, IERC721ReceiverUpgradeable {
    function __ERC721Holder_init() internal onlyInitializing {
    }

    function __ERC721Holder_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC721Receiver-onERC721Received}.
     *
     * Always returns `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address,
        address,
        uint256,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC721Received.selector;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
          

@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @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, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * 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.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @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`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

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

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage);
        }
    }
}
          

@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../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;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}
          

@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/MathUpgradeable.sol";

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

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = MathUpgradeable.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), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, MathUpgradeable.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) {
        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] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

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

@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library MathUpgradeable {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @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 up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (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; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

            ///////////////////////////////////////////////
            // 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.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            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 (rounding == Rounding.Up && 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 down.
     *
     * 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * 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 + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * 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 + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * 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 10, 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 + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
        }
    }
}
          

@openzeppelin/contracts/token/ERC721/IERC721.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../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 caller.
     *
     * 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);
}
          

@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}
          

@openzeppelin/contracts/utils/introspection/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

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

@openzeppelin/contracts/utils/math/SafeMath.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    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.
     *
     * _Available since v3.4._
     */
    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.
     *
     * _Available since v3.4._
     */
    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.
     *
     * _Available since v3.4._
     */
    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.
     *
     * _Available since v3.4._
     */
    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 addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}
          

@openzeppelin/contracts/utils/structs/EnumerableSet.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

            return true;
        } else {
            return false;
        }
    }

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

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

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

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

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

contracts/abstracts/OwnerOperator.sol

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

abstract contract OwnerOperator is OwnableUpgradeable {
    mapping(address => bool) public operators;

    function initialize() public initializer {
        __Context_init_unchained();
        __Ownable_init_unchained();
    }

    modifier operatorOrOwner() {
        require(
            operators[msg.sender] || owner() == msg.sender,
            "OwnerOperator: !operator, !owner"
        );
        _;
    }

    modifier onlyOperator() {
        require(operators[msg.sender], "OwnerOperator: !operator");
        _;
    }

    function addOperator(address operator) external virtual onlyOwner {
        require(
            operator != address(0),
            "OwnerOperator: operator is the zero address"
        );
        operators[operator] = true;
    }

    function removeOperator(address operator) external virtual onlyOwner {
        require(
            operator != address(0),
            "OwnerOperator: operator is the zero address"
        );
        operators[operator] = false;
    }
}
          

contracts/interfaces/IHorseItemNFT.sol

// SPDX-License-Identifier: MIT

import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";

pragma solidity ^0.8.2;

interface IHorseItemNFT is IERC721Enumerable {
    function mint(
        address to,
        uint256 tokenId,
        string memory metaUrl
    ) external;

    function mintBatch(
        address to,
        uint256[] memory ids,
        string[] memory metaUrls
    ) external;

    function multiTransfer(
        address to,
        uint256[] memory tokenIds
    ) external;

    function burn(uint256 tokenId) external;

    function burnBatch(uint256[] memory ids) external;
}
          

contracts/interfaces/ITicket.sol

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

interface ITicket {
    function mint(address to, uint256 id, uint256 amount, bytes calldata data) external;
    function mintBatch(address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data) external;

    function burn(address from, uint256 id, uint256 amount) external;
    function burnBatch(address from, uint256[] calldata ids, uint256[] calldata amounts) external;

    function balanceOf(address account, uint256 id) external view returns (uint256);
    function isApprovedForAll(address account, address operator) external view returns (bool);

    function pause() external;
    function unpause() external;
}
          

contracts/libraries/BytesLibrary.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev BytesLibrary operations.
 */
library BytesLibrary {
    function toString(bytes32 value) internal pure returns (string memory) {
        bytes memory alphabet = "0123456789abcdef";
        bytes memory str = new bytes(64);
        for (uint256 i = 0; i < 32; i++) {
            str[i * 2] = alphabet[uint8(value[i] >> 4)];
            str[1 + i * 2] = alphabet[uint8(value[i] & 0x0f)];
        }
        return string(str);
    }
}
          

contracts/libraries/StringLibrary.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./UintLibrary.sol";

library StringLibrary {
    using UintLibrary for uint256;

    function append(string memory a, string memory b) internal pure returns (string memory) {
        bytes memory ba = bytes(a);
        bytes memory bb = bytes(b);
        bytes memory bab = new bytes(ba.length + bb.length);
        uint256 k = 0;
        for (uint256 i = 0; i < ba.length; i++) bab[k++] = ba[i];
        for (uint256 i = 0; i < bb.length; i++) bab[k++] = bb[i];
        return string(bab);
    }

    function append(
        string memory a,
        string memory b,
        string memory c
    ) internal pure returns (string memory) {
        bytes memory ba = bytes(a);
        bytes memory bb = bytes(b);
        bytes memory bc = bytes(c);
        bytes memory bbb = new bytes(ba.length + bb.length + bc.length);
        uint256 k = 0;
        for (uint256 i = 0; i < ba.length; i++) bbb[k++] = ba[i];
        for (uint256 i = 0; i < bb.length; i++) bbb[k++] = bb[i];
        for (uint256 i = 0; i < bc.length; i++) bbb[k++] = bc[i];
        return string(bbb);
    }

    function recover(
        string memory message,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address) {
        bytes memory msgBytes = bytes(message);
        bytes memory fullMessage = concat(
            bytes("\x19Ethereum Signed Message:\n"),
            bytes(msgBytes.length.toString()),
            msgBytes,
            new bytes(0),
            new bytes(0),
            new bytes(0),
            new bytes(0)
        );
        return ecrecover(keccak256(fullMessage), v, r, s);
    }

    function concat(
        bytes memory ba,
        bytes memory bb,
        bytes memory bc,
        bytes memory bd,
        bytes memory be,
        bytes memory bf,
        bytes memory bg
    ) internal pure returns (bytes memory) {
        bytes memory resultBytes = new bytes(ba.length + bb.length + bc.length + bd.length + be.length + bf.length + bg.length);
        uint256 k = 0;
        for (uint256 i = 0; i < ba.length; i++) resultBytes[k++] = ba[i];
        for (uint256 i = 0; i < bb.length; i++) resultBytes[k++] = bb[i];
        for (uint256 i = 0; i < bc.length; i++) resultBytes[k++] = bc[i];
        for (uint256 i = 0; i < bd.length; i++) resultBytes[k++] = bd[i];
        for (uint256 i = 0; i < be.length; i++) resultBytes[k++] = be[i];
        for (uint256 i = 0; i < bf.length; i++) resultBytes[k++] = bf[i];
        for (uint256 i = 0; i < bg.length; i++) resultBytes[k++] = bg[i];
        return resultBytes;
    }
}
          

contracts/libraries/UintLibrary.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";

library UintLibrary {
    using SafeMath for uint256;

    function toString(uint256 i) internal pure returns (string memory) {
        if (i == 0) {
            return "0";
        }

        uint256 j = i;
        uint256 len;

        while (j != 0) {
            len++;
            j /= 10;
        }

        bytes memory bstr = new bytes(len);

        for (uint256 k = len; k > 0; k--) {
            bstr[k - 1] = bytes1(uint8(48 + (i % 10)));
            i /= 10;
        }

        return string(bstr);
    }

    function bp(uint256 value, uint256 bpValue) internal pure returns (uint256) {
        return value.mul(bpValue).div(10000);
    }
}
          

Contract ABI

[{"type":"event","name":"HorseItemRemoved","inputs":[{"type":"uint8","name":"ticketType","internalType":"uint8","indexed":true},{"type":"uint256","name":"horseId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"HorseItemSet","inputs":[{"type":"uint8","name":"ticketType","internalType":"uint8","indexed":true},{"type":"uint256","name":"horseId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"HorseItemsSwapped","inputs":[{"type":"uint256","name":"uniqueIds","internalType":"uint256","indexed":false},{"type":"address","name":"ticketSwapped","internalType":"address","indexed":false},{"type":"uint8","name":"ticketIdSwapped","internalType":"uint8","indexed":false},{"type":"uint256","name":"ticketBurnedAmount","internalType":"uint256","indexed":false},{"type":"address","name":"to","internalType":"address","indexed":true},{"type":"uint256[]","name":"horseItemIds","internalType":"uint256[]","indexed":false},{"type":"string","name":"userId","internalType":"string","indexed":false}],"anonymous":false},{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","internalType":"uint8","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addOperator","inputs":[{"type":"address","name":"operator","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IHorseItemNFT"}],"name":"getHorseItemNFT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256[]","name":"","internalType":"uint256[]"}],"name":"getHorseItems","inputs":[{"type":"uint8","name":"_ticketId","internalType":"uint8"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"","internalType":"struct SwapTicket.SwappedItems[]","components":[{"type":"address","name":"horseItemAddress","internalType":"address"},{"type":"uint256[]","name":"horseItemIds","internalType":"uint256[]"}]}],"name":"getMultipleSwappedItemIds","inputs":[{"type":"uint256[]","name":"_uniqueIds","internalType":"uint256[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct SwapTicket.SwappedItems","components":[{"type":"address","name":"horseItemAddress","internalType":"address"},{"type":"uint256[]","name":"horseItemIds","internalType":"uint256[]"}]}],"name":"getSwappedItemIds","inputs":[{"type":"uint256","name":"_uniqueId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract ITicket"}],"name":"getTicket","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getTotalHorseNFT","inputs":[{"type":"uint8","name":"_ticketId","internalType":"uint8"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint8","name":"","internalType":"uint8"}],"name":"horseForTicket","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"init","inputs":[{"type":"address","name":"_ticket","internalType":"contract ITicket"},{"type":"address","name":"_horseItemNFT","internalType":"contract IHorseItemNFT"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"multiTransfer","inputs":[{"type":"address","name":"to","internalType":"address"},{"type":"uint256[]","name":"tokenIds","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes4","name":"","internalType":"bytes4"}],"name":"onERC721Received","inputs":[{"type":"address","name":"operator","internalType":"address"},{"type":"address","name":"from","internalType":"address"},{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"operators","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeAllHorseItems","inputs":[{"type":"uint8","name":"_ticketId","internalType":"uint8"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeHorseItems","inputs":[{"type":"uint8","name":"_ticketId","internalType":"uint8"},{"type":"uint256[]","name":"_ids","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeOperator","inputs":[{"type":"address","name":"operator","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeSwappedItemIds","inputs":[{"type":"uint256[]","name":"_ids","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setHorseForTicket","inputs":[{"type":"uint8","name":"_horseForTicket","internalType":"uint8"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setHorseItemNFT","inputs":[{"type":"address","name":"_horseItemNFT","internalType":"contract IHorseItemNFT"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setHorseItems","inputs":[{"type":"uint8","name":"_ticketId","internalType":"uint8"},{"type":"uint256[]","name":"_ids","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setSignerAddress","inputs":[{"type":"address","name":"_signerAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setTicket","inputs":[{"type":"address","name":"_ticket","internalType":"contract ITicket"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setTimeExpiredSignature","inputs":[{"type":"uint256","name":"_timeExpiredSignature","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"signerAddress","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"swap","inputs":[{"type":"tuple","name":"_data","internalType":"struct SwapTicket.SwapData","components":[{"type":"uint256","name":"uniqueId","internalType":"uint256"},{"type":"uint8","name":"tokenId","internalType":"uint8"},{"type":"uint256","name":"tokenAmount","internalType":"uint256"},{"type":"uint256","name":"horseItemAmount","internalType":"uint256"},{"type":"string","name":"userId","internalType":"string"},{"type":"uint256","name":"timestamp","internalType":"uint256"},{"type":"uint8","name":"v","internalType":"uint8"},{"type":"bytes32","name":"r","internalType":"bytes32"},{"type":"bytes32","name":"s","internalType":"bytes32"}]}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"timeExpiredSignature","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdrawHorseItems","inputs":[{"type":"uint8","name":"_ticketLength","internalType":"uint8"},{"type":"uint256[]","name":"_ids","internalType":"uint256[]"},{"type":"address","name":"_to","internalType":"address"}]}]
            

Deployed ByteCode

Verify & Publish
0x608060405234801561001057600080fd5b50600436106101da5760003560e01c80639870d7fe11610104578063dd032d34116100a2578063f703b9d511610071578063f703b9d514610447578063fbd502391461045a578063fcfdccc61461046d578063fdb9e8af14610480576101da565b8063dd032d34146103f8578063e07d516c14610401578063f09a401614610421578063f2fde38b14610434576101da565b8063af51462b116100de578063af51462b146103a1578063c002c4d6146103b4578063cd8aadfa146103c5578063daa11a6b146103d8576101da565b80639870d7fe1461035b578063aa84e9f81461036e578063ac8a584a1461038e576101da565b80631c65c78b1161017c578063715018a61161014b578063715018a6146103275780638129fc1c1461032f5780638da5cb5b1461033757806396f3e3cc14610348576101da565b80631c65c78b146102b757806345dadac9146102ca5780635b7633d0146102eb5780635ff80beb14610316576101da565b806314b62858116101b857806314b628581461023f578063150b7a02146102525780631b85436d1461027e5780631c1fdcec14610291576101da565b8063046dc166146101df578063131ef2b8146101f457806313e7c9d814610207575b600080fd5b6101f26101ed366004612937565b610493565b005b6101f2610202366004612c18565b61055d565b61022a610215366004612937565b60656020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b6101f261024d366004612bc8565b610753565b61026561026036600461296f565b610865565b6040516001600160e01b03199091168152602001610236565b6101f261028c366004612bae565b610891565b6099546102a590600160a01b900460ff1681565b60405160ff9091168152602001610236565b6101f26102c5366004612937565b61090a565b6102dd6102d8366004612bae565b6109cb565b604051908152602001610236565b609d546102fe906001600160a01b031681565b6040516001600160a01b039091168152602001610236565b6099546001600160a01b03166102fe565b6101f26109ee565b6101f2610a02565b6033546001600160a01b03166102fe565b6101f2610356366004612a55565b610ad4565b6101f2610369366004612937565b610ba8565b61038161037c366004612a55565b610bfa565b6040516102369190612de6565b6101f261039c366004612937565b610d6c565b6101f26103af366004612b96565b610dbb565b6098546001600160a01b03166102fe565b6101f26103d3366004612ac7565b610e13565b6103eb6103e6366004612b96565b611110565b6040516102369190612f72565b6102dd609a5481565b61041461040f366004612bae565b6111a9565b6040516102369190612e46565b6101f261042f366004612a8f565b6111c7565b6101f2610442366004612937565b61136d565b6101f2610455366004612bae565b6113e3565b6101f2610468366004612bc8565b611456565b6101f261047b366004612a08565b6114f6565b6101f261048e366004612937565b61177d565b3360009081526065602052604090205460ff16806104ca5750336104bf6033546001600160a01b031690565b6001600160a01b0316145b6104ef5760405162461bcd60e51b81526004016104e690612ef2565b60405180910390fd5b6001600160a01b03811661053b5760405162461bcd60e51b81526020600482015260136024820152725a65726f207369676e6572206164647265737360681b60448201526064016104e6565b609d80546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526065602052604090205460ff16806105945750336105896033546001600160a01b031690565b6001600160a01b0316145b6105b05760405162461bcd60e51b81526004016104e690612ef2565b6001600160a01b0381166106015760405162461bcd60e51b8152602060048201526018602482015277537761705469636b65743a207a65726f206164647265737360401b60448201526064016104e6565b6032808311156106645760405162461bcd60e51b815260206004820152602860248201527f537761705469636b65743a2045786365656473206c696d6974206f6620686f726044820152677365206974656d7360c01b60648201526084016104e6565b60005b838110156106e55760015b8660ff168160ff16116106d4576106c38686848181106106a257634e487b7160e01b600052603260045260246000fd5b60ff85166000908152609b6020908152604090912093910201359050611840565b506106cd8161309e565b9050610672565b506106de81613083565b9050610667565b50609954604051637e7ee66360e11b81526001600160a01b039091169063fcfdccc69061071a90859088908890600401612d27565b600060405180830381600087803b15801561073457600080fd5b505af1158015610748573d6000803e3d6000fd5b505050505050505050565b3360009081526065602052604090205460ff168061078a57503361077f6033546001600160a01b031690565b6001600160a01b0316145b6107a65760405162461bcd60e51b81526004016104e690612ef2565b60005b8181101561085f576107f58383838181106107d457634e487b7160e01b600052603260045260246000fd5b60ff88166000908152609b6020908152604090912093910201359050611840565b5082828281811061081657634e487b7160e01b600052603260045260246000fd5b905060200201358460ff167f296fea0325ea74736c419d97d6e85d622ced6cbccb14418b93393f81f48b920160405160405180910390a38061085781613083565b9150506107a9565b50505050565b60995460009061087f90600160a01b900460ff1685611855565b50630a85bd0160e11b95945050505050565b3360009081526065602052604090205460ff16806108c85750336108bd6033546001600160a01b031690565b6001600160a01b0316145b6108e45760405162461bcd60e51b81526004016104e690612ef2565b60ff81166000908152609b602052604081209081816109038282612775565b5050505050565b3360009081526065602052604090205460ff16806109415750336109366033546001600160a01b031690565b6001600160a01b0316145b61095d5760405162461bcd60e51b81526004016104e690612ef2565b6001600160a01b0381166109a95760405162461bcd60e51b81526020600482015260136024820152725a65726f205469636b6574206164647265737360681b60448201526064016104e6565b609880546001600160a01b0319166001600160a01b0392909216919091179055565b60ff81166000908152609b602052604081206109e690611988565b90505b919050565b6109f6611992565b610a0060006119ec565b565b600054610100900460ff1615808015610a225750600054600160ff909116105b80610a3c5750303b158015610a3c575060005460ff166001145b610a585760405162461bcd60e51b81526004016104e690612ea4565b6000805460ff191660011790558015610a7b576000805461ff0019166101001790555b610a83611a3e565b610a8b611a65565b8015610ad1576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b50565b3360009081526065602052604090205460ff1680610b0b575033610b006033546001600160a01b031690565b6001600160a01b0316145b610b275760405162461bcd60e51b81526004016104e690612ef2565b60005b8151811015610ba457609c6000838381518110610b5757634e487b7160e01b600052603260045260246000fd5b6020908102919091018101518252810191909152604001600090812080546001600160a01b031916815590610b8f6001830182612775565b50508080610b9c90613083565b915050610b2a565b5050565b610bb0611992565b6001600160a01b038116610bd65760405162461bcd60e51b81526004016104e690612e59565b6001600160a01b03166000908152606560205260409020805460ff19166001179055565b6060600082516001600160401b03811115610c2557634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610c6b57816020015b604080518082019091526000815260606020820152815260200190600190039081610c435790505b50905060005b8351811015610d6557609c6000858381518110610c9e57634e487b7160e01b600052603260045260246000fd5b60209081029190910181015182528181019290925260409081016000208151808301835281546001600160a01b031681526001820180548451818702810187019095528085529194929385840193909290830182828015610d1e57602002820191906000526020600020905b815481526020019060010190808311610d0a575b505050505081525050828281518110610d4757634e487b7160e01b600052603260045260246000fd5b60200260200101819052508080610d5d90613083565b915050610c71565b5092915050565b610d74611992565b6001600160a01b038116610d9a5760405162461bcd60e51b81526004016104e690612e59565b6001600160a01b03166000908152606560205260409020805460ff19169055565b3360009081526065602052604090205460ff1680610df2575033610de76033546001600160a01b031690565b6001600160a01b0316145b610e0e5760405162461bcd60e51b81526004016104e690612ef2565b609a55565b80516000908152609c602052604090206001015415610e7f5760405162461bcd60e51b815260206004820152602260248201527f537761705469636b65743a20556e6971756520494420616c7265616479207573604482015261195960f21b60648201526084016104e6565b610e893382611a95565b600081606001516001600160401b03811115610eb557634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610ede578160200160208202803683370190505b50905060005b82606001518160ff161015610f6f576000610f088460000151856020015184611bca565b60208086015160ff166000908152609b90915260409020909150610f2c9082611840565b5080838360ff1681518110610f5157634e487b7160e01b600052603260045260246000fd5b60209081029190910101525080610f678161309e565b915050610ee4565b5060985460208301516040808501519051637a94c56560e11b815233600482015260ff909216602483015260448201526001600160a01b039091169063f5298aca90606401600060405180830381600087803b158015610fce57600080fd5b505af1158015610fe2573d6000803e3d6000fd5b5050609954604051637e7ee66360e11b81526001600160a01b03909116925063fcfdccc691506110189033908590600401612d72565b600060405180830381600087803b15801561103257600080fd5b505af1158015611046573d6000803e3d6000fd5b50506040805180820182526099546001600160a01b039081168252602080830187815288516000908152609c835294909420835181546001600160a01b0319169316929092178255925180519295509093506110a9926001850192910190612793565b505082516098546020850151604080870151608088015191513396507f2c7563cf9e2566cbed33b352e043d23198cc031a1ca2ea629c4c9981cd8a7258956111049590946001600160a01b0390911693909291899190612f85565b60405180910390a25050565b6040805180820190915260008152606060208201526000828152609c60209081526040918290208251808401845281546001600160a01b031681526001820180548551818602810186019096528086529194929385810193929083018282801561119957602002820191906000526020600020905b815481526020019060010190808311611185575b5050505050815250509050919050565b60ff81166000908152609b602052604090206060906109e690611cd3565b600054610100900460ff16158080156111e75750600054600160ff909116105b806112015750303b158015611201575060005460ff166001145b61121d5760405162461bcd60e51b81526004016104e690612ea4565b6000805460ff191660011790558015611240576000805461ff0019166101001790555b6001600160a01b03831661128c5760405162461bcd60e51b81526020600482015260136024820152725a65726f205469636b6574206164647265737360681b60448201526064016104e6565b6001600160a01b0382166112e25760405162461bcd60e51b815260206004820152601960248201527f5a65726f20486f7273654974656d4e465420616464726573730000000000000060448201526064016104e6565b6112ea610a02565b6112f2611a3e565b609880546001600160a01b038086166001600160a01b03199283161790925560998054928516929091169190911790558015611368576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050565b611375611992565b6001600160a01b0381166113da5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016104e6565b610ad1816119ec565b3360009081526065602052604090205460ff168061141a57503361140f6033546001600160a01b031690565b6001600160a01b0316145b6114365760405162461bcd60e51b81526004016104e690612ef2565b6099805460ff909216600160a01b0260ff60a01b19909216919091179055565b3360009081526065602052604090205460ff168061148d5750336114826033546001600160a01b031690565b6001600160a01b0316145b6114a95760405162461bcd60e51b81526004016104e690612ef2565b60005b8181101561085f576114e4848484848181106114d857634e487b7160e01b600052603260045260246000fd5b90506020020135611855565b806114ee81613083565b9150506114ac565b3360009081526065602052604090205460ff168061152d5750336115226033546001600160a01b031690565b6001600160a01b0316145b6115495760405162461bcd60e51b81526004016104e690612ef2565b6001600160a01b03821661159a5760405162461bcd60e51b8152602060048201526018602482015277537761705469636b65743a207a65726f206164647265737360401b60448201526064016104e6565b60005b815181101561136857609954825130916001600160a01b031690636352211e908590859081106115dd57634e487b7160e01b600052603260045260246000fd5b60200260200101516040518263ffffffff1660e01b815260040161160391815260200190565b60206040518083038186803b15801561161b57600080fd5b505afa15801561162f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116539190612953565b6001600160a01b0316146116bd5760405162461bcd60e51b815260206004820152602b60248201527f537761705469636b65743a20636f6e747261637420646f6573206e6f74206f7760448201526a37103a3432903a37b5b2b760a91b60648201526084016104e6565b60995482516001600160a01b03909116906342842e0e90309086908690869081106116f857634e487b7160e01b600052603260045260246000fd5b60209081029190910101516040516001600160e01b031960e086901b1681526001600160a01b0393841660048201529290911660248301526044820152606401600060405180830381600087803b15801561175257600080fd5b505af1158015611766573d6000803e3d6000fd5b50505050808061177590613083565b91505061159d565b3360009081526065602052604090205460ff16806117b45750336117a96033546001600160a01b031690565b6001600160a01b0316145b6117d05760405162461bcd60e51b81526004016104e690612ef2565b6001600160a01b03811661181e5760405162461bcd60e51b81526020600482015260156024820152745a65726f20486f7273654e4654206164647265737360581b60448201526064016104e6565b609980546001600160a01b0319166001600160a01b0392909216919091179055565b600061184c8383611ce7565b90505b92915050565b6099546040516331a9108f60e11b81526004810183905230916001600160a01b031690636352211e9060240160206040518083038186803b15801561189957600080fd5b505afa1580156118ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118d19190612953565b6001600160a01b0316146119375760405162461bcd60e51b815260206004820152602760248201527f537761705469636b65743a20486f727365206e6f74206f776e656420627920636044820152661bdb9d1c9858dd60ca1b60648201526084016104e6565b60ff82166000908152609b602052604090206119539082611e04565b50604051819060ff8416907fb3e0f24acd3d9a73bc606c838a51d42f1964209acc43f5421adb7ad3cea0bf3e90600090a35050565b60006109e6825490565b6033546001600160a01b03163314610a005760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016104e6565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff16610a005760405162461bcd60e51b81526004016104e690612f27565b600054610100900460ff16611a8c5760405162461bcd60e51b81526004016104e690612f27565b610a00336119ec565b600082826000015183602001518460400151856060015186608001518760a00151604051602001611acc9796959493929190612d96565b6040516020818303038152906040528051906020012090506000611b0a8360c001518460e00151856101000151611b0286611e10565b929190611fc4565b9050609a548360a00151611b1e919061300a565b421115611b6d5760405162461bcd60e51b815260206004820152601d60248201527f537761705469636b65743a207369676e6174757265206578706972656400000060448201526064016104e6565b609d546001600160a01b0382811691161461085f5760405162461bcd60e51b815260206004820152601d60248201527f537761705469636b65743a20496e76616c6964207369676e617475726500000060448201526064016104e6565b60ff82166000908152609b602052604081208190611be790611988565b11611c4a5760405162461bcd60e51b815260206004820152602d60248201527f537761705469636b65743a204e6f20686f727365206974656d7320617661696c60448201526c61626c6520666f72207479706560981b60648201526084016104e6565b60ff83166000908152609b60205260408120611c6590611988565b604080516020808201899052428284015260f887901b6001600160f81b03191660608301528251604181840301815260619092019092528051910120611cab91906130be565b60ff85166000908152609b60205260409020909150611cca90826120b9565b95945050505050565b60606000611ce0836120c5565b9392505050565b60008181526001830160205260408120548015611dfa576000611d0b600183613055565b8554909150600090611d1f90600190613055565b9050818114611da0576000866000018281548110611d4d57634e487b7160e01b600052603260045260246000fd5b9060005260206000200154905080876000018481548110611d7e57634e487b7160e01b600052603260045260246000fd5b6000918252602080832090910192909255918252600188019052604090208390555b8554869080611dbf57634e487b7160e01b600052603160045260246000fd5b60019003818190600052602060002001600090559055856001016000868152602001908152602001600020600090556001935050505061184f565b600091505061184f565b600061184c8383612121565b604080518082018252601081526f181899199a1a9b1b9c1cb0b131b232b360811b6020820152815182815260608181018452926000919060208201818036833701905050905060005b6020811015611fbc57826004868360208110611e8557634e487b7160e01b600052603260045260246000fd5b1a60f81b6001600160f81b031916901c60f81c60ff1681518110611eb957634e487b7160e01b600052603260045260246000fd5b01602001516001600160f81b03191682611ed4836002613036565b81518110611ef257634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a90535082858260208110611f2a57634e487b7160e01b600052603260045260246000fd5b825191901a600f16908110611f4f57634e487b7160e01b600052603260045260246000fd5b01602001516001600160f81b03191682611f6a836002613036565b611f7590600161300a565b81518110611f9357634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a90535080611fb481613083565b915050611e59565b509392505050565b600080859050600061203c6040518060400160405280601a81526020017f19457468657265756d205369676e6564204d6573736167653a0a00000000000081525061200f8451612170565b6040805160008082526020820181815282840182815260608401928352608084019094528893909161229e565b90506001818051906020012087878760405160008152602001604052604051612081949392919093845260ff9290921660208401526040830152606082015260800190565b6020604051602081039080840390855afa1580156120a3573d6000803e3d6000fd5b5050604051601f19015198975050505050505050565b600061184c838361273d565b60608160000180548060200260200160405190810160405280929190818152602001828054801561211557602002820191906000526020600020905b815481526020019060010190808311612101575b50505050509050919050565b60008181526001830160205260408120546121685750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561184f565b50600061184f565b60608161219557506040805180820190915260018152600360fc1b60208201526109e9565b8160005b81156121bf57806121a981613083565b91506121b89050600a83613022565b9150612199565b6000816001600160401b038111156121e757634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f191660200182016040528015612211576020820181803683370190505b509050815b801561229557612227600a876130be565b61223290603061300a565b60f81b82612241600184613055565b8151811061225f57634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350612281600a87613022565b95508061228d8161306c565b915050612216565b50949350505050565b6060600082518451865188518a518c518e516122ba919061300a565b6122c4919061300a565b6122ce919061300a565b6122d8919061300a565b6122e2919061300a565b6122ec919061300a565b6001600160401b0381111561231157634e487b7160e01b600052604160045260246000fd5b6040519080825280601f01601f19166020018201604052801561233b576020820181803683370190505b5090506000805b8a518110156123ce578a818151811061236b57634e487b7160e01b600052603260045260246000fd5b01602001516001600160f81b031916838361238581613083565b9450815181106123a557634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350806123c681613083565b915050612342565b5060005b895181101561245e578981815181106123fb57634e487b7160e01b600052603260045260246000fd5b01602001516001600160f81b031916838361241581613083565b94508151811061243557634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053508061245681613083565b9150506123d2565b5060005b88518110156124ee5788818151811061248b57634e487b7160e01b600052603260045260246000fd5b01602001516001600160f81b03191683836124a581613083565b9450815181106124c557634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a905350806124e681613083565b915050612462565b5060005b875181101561257e5787818151811061251b57634e487b7160e01b600052603260045260246000fd5b01602001516001600160f81b031916838361253581613083565b94508151811061255557634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053508061257681613083565b9150506124f2565b5060005b865181101561260e578681815181106125ab57634e487b7160e01b600052603260045260246000fd5b01602001516001600160f81b03191683836125c581613083565b9450815181106125e557634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053508061260681613083565b915050612582565b5060005b855181101561269e5785818151811061263b57634e487b7160e01b600052603260045260246000fd5b01602001516001600160f81b031916838361265581613083565b94508151811061267557634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053508061269681613083565b915050612612565b5060005b845181101561272e578481815181106126cb57634e487b7160e01b600052603260045260246000fd5b01602001516001600160f81b03191683836126e581613083565b94508151811061270557634e487b7160e01b600052603260045260246000fd5b60200101906001600160f81b031916908160001a9053508061272681613083565b9150506126a2565b50909998505050505050505050565b600082600001828154811061276257634e487b7160e01b600052603260045260246000fd5b9060005260206000200154905092915050565b5080546000825590600052602060002090810190610ad191906127de565b8280548282559060005260206000209081019282156127ce579160200282015b828111156127ce5782518255916020019190600101906127b3565b506127da9291506127de565b5090565b5b808211156127da57600081556001016127df565b60008083601f840112612804578182fd5b5081356001600160401b0381111561281a578182fd5b602083019150836020808302850101111561283457600080fd5b9250929050565b600082601f83011261284b578081fd5b813560206001600160401b03821115612866576128666130fe565b808202612874828201612fda565b83815282810190868401838801850189101561288e578687fd5b8693505b858410156128b0578035835260019390930192918401918401612892565b50979650505050505050565b600082601f8301126128cc578081fd5b81356001600160401b038111156128e5576128e56130fe565b6128f8601f8201601f1916602001612fda565b81815284602083860101111561290c578283fd5b816020850160208301379081016020019190915292915050565b803560ff811681146109e957600080fd5b600060208284031215612948578081fd5b8135611ce081613114565b600060208284031215612964578081fd5b8151611ce081613114565b600080600080600060808688031215612986578081fd5b853561299181613114565b945060208601356129a181613114565b93506040860135925060608601356001600160401b03808211156129c3578283fd5b818801915088601f8301126129d6578283fd5b8135818111156129e4578384fd5b8960208285010111156129f5578384fd5b9699959850939650602001949392505050565b60008060408385031215612a1a578182fd5b8235612a2581613114565b915060208301356001600160401b03811115612a3f578182fd5b612a4b8582860161283b565b9150509250929050565b600060208284031215612a66578081fd5b81356001600160401b03811115612a7b578182fd5b612a878482850161283b565b949350505050565b60008060408385031215612aa1578182fd5b8235612aac81613114565b91506020830135612abc81613114565b809150509250929050565b600060208284031215612ad8578081fd5b81356001600160401b0380821115612aee578283fd5b8184019150610120808387031215612b04578384fd5b612b0d81612fda565b905082358152612b1f60208401612926565b60208201526040830135604082015260608301356060820152608083013582811115612b49578485fd5b612b55878286016128bc565b60808301525060a083013560a0820152612b7160c08401612926565b60c082015260e083810135908201526101009283013592810192909252509392505050565b600060208284031215612ba7578081fd5b5035919050565b600060208284031215612bbf578081fd5b61184c82612926565b600080600060408486031215612bdc578081fd5b612be584612926565b925060208401356001600160401b03811115612bff578182fd5b612c0b868287016127f3565b9497909650939450505050565b60008060008060608587031215612c2d578182fd5b612c3685612926565b935060208501356001600160401b03811115612c50578283fd5b612c5c878288016127f3565b9094509250506040850135612c7081613114565b939692955090935050565b6000815180845260208085019450808401835b83811015612caa57815187529582019590820190600101612c8e565b509495945050505050565b60008151808452815b81811015612cda57602081850181015186830182015201612cbe565b81811115612ceb5782602083870101525b50601f01601f19169290920160200192915050565b600060018060a01b038251168352602082015160406020850152612a876040850182612c7b565b6001600160a01b0384168152604060208201819052810182905260006001600160fb1b03831115612d56578081fd5b6020830280856060850137919091016060019081529392505050565b6001600160a01b0383168152604060208201819052600090612a8790830184612c7b565b600060018060a01b038916825287602083015260ff8716604083015285606083015284608083015260e060a0830152612dd260e0830185612cb5565b90508260c083015298975050505050505050565b6000602080830181845280855180835260408601915060408482028701019250838701855b82811015612e3957603f19888603018452612e27858351612d00565b94509285019290850190600101612e0b565b5092979650505050505050565b60006020825261184c6020830184612c7b565b6020808252602b908201527f4f776e65724f70657261746f723a206f70657261746f7220697320746865207a60408201526a65726f206164647265737360a81b606082015260800190565b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b6020808252818101527f4f776e65724f70657261746f723a20216f70657261746f722c20216f776e6572604082015260600190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60006020825261184c6020830184612d00565b600087825260018060a01b038716602083015260ff8616604083015284606083015260c06080830152612fbb60c0830185612c7b565b82810360a0840152612fcd8185612cb5565b9998505050505050505050565b604051601f8201601f191681016001600160401b0381118282101715613002576130026130fe565b604052919050565b6000821982111561301d5761301d6130d2565b500190565b600082613031576130316130e8565b500490565b6000816000190483118215151615613050576130506130d2565b500290565b600082821015613067576130676130d2565b500390565b60008161307b5761307b6130d2565b506000190190565b6000600019821415613097576130976130d2565b5060010190565b600060ff821660ff8114156130b5576130b56130d2565b60010192915050565b6000826130cd576130cd6130e8565b500690565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114610ad157600080fdfea2646970667358221220bbb7d59ddc8ffc534d2cde0305ad605bcd40e8bf47a59826a44acc515cceb94064736f6c63430008020033