ETH Price: $3,131.17 (-0.57%)
Gas: 0.08 Gwei

Contract

0xFc411152fa7A1ed6DD3E2EC4C62579810Ad9f6aB
 

Overview

ETH Balance

0.98427 ETH

Eth Value

$3,081.91 (@ $3,131.17/ETH)

Token Holdings

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Set Approval For...237558232025-11-08 16:46:358 days ago1762620395IN
0xFc411152...10Ad9f6aB
0 ETH0.00009942.12453886
Safe Transfer Fr...237141882025-11-02 21:00:3514 days ago1762117235IN
0xFc411152...10Ad9f6aB
0 ETH0.000004590.08807872
Set Approval For...236944862025-10-31 2:52:5916 days ago1761879179IN
0xFc411152...10Ad9f6aB
0 ETH0.000004850.10369481
Set Approval For...235178812025-10-06 9:37:1141 days ago1759743431IN
0xFc411152...10Ad9f6aB
0 ETH0.000005290.1131128
Safe Transfer Fr...235107372025-10-05 9:41:5942 days ago1759657319IN
0xFc411152...10Ad9f6aB
0 ETH0.000063931.22618014
Set Approval For...235107022025-10-05 9:34:5942 days ago1759656899IN
0xFc411152...10Ad9f6aB
0 ETH0.000030671.14085209
Set Approval For...235106712025-10-05 9:28:4742 days ago1759656527IN
0xFc411152...10Ad9f6aB
0 ETH0.000052191.11554598
Set Approval For...234993752025-10-03 19:34:4744 days ago1759520087IN
0xFc411152...10Ad9f6aB
0 ETH0.000020370.43543048
Safe Transfer Fr...232771632025-09-02 18:18:5975 days ago1756837139IN
0xFc411152...10Ad9f6aB
0 ETH0.000030810.59107428
Set Approval For...232119482025-08-24 15:49:2384 days ago1756050563IN
0xFc411152...10Ad9f6aB
0 ETH0.000089211.90659327
Set Approval For...231846292025-08-20 20:18:1188 days ago1755721091IN
0xFc411152...10Ad9f6aB
0 ETH0.00002820.60276599
Set Approval For...231796912025-08-20 3:46:1188 days ago1755661571IN
0xFc411152...10Ad9f6aB
0 ETH0.000106242.27071913
Safe Transfer Fr...231609522025-08-17 13:03:1191 days ago1755435791IN
0xFc411152...10Ad9f6aB
0 ETH0.000112852.16447268
Set Approval For...231384012025-08-14 9:29:3594 days ago1755163775IN
0xFc411152...10Ad9f6aB
0 ETH0.000059851.27920148
Set Approval For...231372502025-08-14 5:37:1194 days ago1755149831IN
0xFc411152...10Ad9f6aB
0 ETH0.000132022.82154331
Set Approval For...230879602025-08-07 8:22:23101 days ago1754554943IN
0xFc411152...10Ad9f6aB
0 ETH0.000108782.32489945
Set Approval For...230629612025-08-03 20:35:23105 days ago1754253323IN
0xFc411152...10Ad9f6aB
0 ETH0.000104032.22340975
Set Royalty Addr...230626822025-08-03 19:39:23105 days ago1754249963IN
0xFc411152...10Ad9f6aB
0 ETH0.000006790.23510683
Set Approval For...230437742025-08-01 4:13:59107 days ago1754021639IN
0xFc411152...10Ad9f6aB
0 ETH0.000017470.37350463
Set Approval For...230255032025-07-29 14:51:23110 days ago1753800683IN
0xFc411152...10Ad9f6aB
0 ETH0.000343517.34153563
Set Approval For...230238482025-07-29 9:17:35110 days ago1753780655IN
0xFc411152...10Ad9f6aB
0 ETH0.000110212.35550995
Safe Transfer Fr...226261532025-06-03 19:15:35166 days ago1748978135IN
0xFc411152...10Ad9f6aB
0 ETH0.000169453.2500558
Safe Transfer Fr...224766102025-05-13 20:16:23187 days ago1747167383IN
0xFc411152...10Ad9f6aB
0 ETH0.0008907717.08863636
Set Approval For...224765982025-05-13 20:13:59187 days ago1747167239IN
0xFc411152...10Ad9f6aB
0 ETH0.0005184919.28125453
Set Approval For...224765952025-05-13 20:13:23187 days ago1747167203IN
0xFc411152...10Ad9f6aB
0 ETH0.0009841621.03311052
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Method Block
From
To
Transfer219383802025-02-27 14:50:11262 days ago1740667811
0xFc411152...10Ad9f6aB
0.0663 ETH
Transfer219383802025-02-27 14:50:11262 days ago1740667811
0xFc411152...10Ad9f6aB
0.0117 ETH
Transfer216829962025-01-22 22:24:47298 days ago1737584687
0xFc411152...10Ad9f6aB
0.07 ETH
Transfer215304142025-01-01 15:07:59319 days ago1735744079
0xFc411152...10Ad9f6aB
0.02 ETH
Transfer215159042024-12-30 14:31:35321 days ago1735569095
0xFc411152...10Ad9f6aB
0.085 ETH
Transfer215138892024-12-30 7:46:35321 days ago1735544795
0xFc411152...10Ad9f6aB
0.05 ETH
Transfer214739072024-12-24 17:46:23327 days ago1735062383
0xFc411152...10Ad9f6aB
0.1 ETH
Transfer214612232024-12-22 23:09:47329 days ago1734908987
0xFc411152...10Ad9f6aB
0.1 ETH
Transfer214584172024-12-22 13:44:59329 days ago1734875099
0xFc411152...10Ad9f6aB
0.1551 ETH
Transfer214521672024-12-21 16:45:59330 days ago1734799559
0xFc411152...10Ad9f6aB
0.12 ETH
Transfer214507302024-12-21 11:57:23330 days ago1734782243
0xFc411152...10Ad9f6aB
0.1 ETH
Transfer214489452024-12-21 5:58:47330 days ago1734760727
0xFc411152...10Ad9f6aB
0.1395 ETH
Transfer214477982024-12-21 2:06:23330 days ago1734746783
0xFc411152...10Ad9f6aB
0.02 ETH
Transfer214470392024-12-20 23:32:47331 days ago1734737567
0xFc411152...10Ad9f6aB
0.061 ETH
Transfer214464872024-12-20 21:41:59331 days ago1734730919
0xFc411152...10Ad9f6aB
0.045 ETH
Transfer214461402024-12-20 20:32:35331 days ago1734726755
0xFc411152...10Ad9f6aB
12.193675 ETH
Transfer214461402024-12-20 20:32:35331 days ago1734726755
0xFc411152...10Ad9f6aB
2.151825 ETH
Transfer214461322024-12-20 20:30:59331 days ago1734726659
0xFc411152...10Ad9f6aB
0.05 ETH
Transfer214460402024-12-20 20:12:23331 days ago1734725543
0xFc411152...10Ad9f6aB
0.03 ETH
Transfer214453202024-12-20 17:47:47331 days ago1734716867
0xFc411152...10Ad9f6aB
0.08 ETH
Transfer214448882024-12-20 16:21:11331 days ago1734711671
0xFc411152...10Ad9f6aB
0.0701 ETH
Transfer214443872024-12-20 14:40:23331 days ago1734705623
0xFc411152...10Ad9f6aB
0.0265 ETH
Transfer214426242024-12-20 8:45:47331 days ago1734684347
0xFc411152...10Ad9f6aB
0.0495 ETH
Transfer214424232024-12-20 8:05:11331 days ago1734681911
0xFc411152...10Ad9f6aB
0.07 ETH
Transfer214421662024-12-20 7:13:23331 days ago1734678803
0xFc411152...10Ad9f6aB
0.18 ETH
View All Internal Transactions
Loading...
Loading
Cross-Chain Transactions

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
GmStudioRankedAuction

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 50 runs

Other Settings:
paris EvmVersion
File 1 of 32 : GmStudioRankedAuction.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import "./helpers/OwnableUpgradeable.sol";
import "./helpers/ERC721EnumerableUpgradeable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

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

interface IDelegateRegistry {
    /**
     * @notice Checks if a delegate has been granted permission for an ERC721 token.
     * @param delegate The address of the delegate.
     * @param vault The address of the vault (original owner).
     * @param contract_ The address of the ERC721 contract.
     * @param tokenId The ID of the token.
     * @param role The role assigned to the delegate.
     * @return True if the delegate has permission, false otherwise.
     */
    function checkDelegateForERC721(
        address delegate,
        address vault,
        address contract_,
        uint256 tokenId,
        bytes32 role
    ) external view returns (bool);
}

/// @title GmStudioRankedAuction
/// @notice A ranked auction contract for gmDAO NFTs with allowlist and discount functionalities.
contract GmStudioRankedAuction is
    ERC721EnumerableUpgradeable,
    OwnableUpgradeable,
    IERC2981,
    ReentrancyGuard
{
    // Mapping of bid IDs to BidNode structs representing the bids.
    mapping(uint32 => BidNode) public bidNodes;

    // Tracks whether an address has claimed their allowlist mint.
    mapping(address => bool) private _addressToAllowlistClaimed;

    // Bitmap to track used gmDAO tokens for discounts (supports up to 1024 tokens).
    uint256[4] private _gmDaoDiscountFlags;

    // Ether amount available for withdrawal by the owner.
    uint256 private _withdrawable;

    // The final clearing price after the auction ends.
    uint96 private finalClearingPrice;

    // Timestamp when the auction ends.
    uint56 public auctionEndTimeStamp;

    // ID of the lowest winning bid (tail of the winning bids linked list).
    uint32 private winningTail;

    // Counter for generating unique bid IDs.
    uint32 public bidCount;

    // Number of winning bids in the auction.
    uint32 private numberOfWinningBids;

    // Number of winning bids that claimed an NFT
    uint32 private numberOfClaimedWinningBids;

    // Amount minted before auction
    uint32 private mintedBeforeAuction;

    // Bool for public mint
    bool private allowPublic;

    /// @notice Struct representing the project configuration and parameters.
    struct Project {
        string name; // Name of the project/token
        string symbol; // symbol of the project/token
        string tokenBase; // Base URI for token metadata
        bytes32 merkleRoot; // Merkle root for the allowlist (used for allowlist minting)
        address gmV3Contract; // Address of the gmV3Contract (for gmDAO tokens)
        uint96 royalty; // Royalty percentage (in basis points, out of 10000)
        address payable ownerAddress; // Address of the contract owner
        uint96 gmDiscount; // Discount percentage for gmDAO token holders (in basis points, out of 10000)
        address payable royaltyAddress; // Address to receive royalty payments
        uint96 minBid; // Minimum bid amount (in wei)
        address payable artistAddress; // Address of the artist
        uint96 allowListPrice; // Price for allowlist minting (in wei)
        address payable gmDaoAddress; // gmDAO address
        uint56 auctionStartTimeStamp; // Auction start time (UNIX timestamp in seconds)
        uint32 maxSupply; // Maximum number of tokens to mint
        address delegateRegistry; // Address of delegate registry
        uint56 allowListStartTimeStamp; // Allowlist minting start time (UNIX timestamp in seconds)
        uint32 auctionDuration; // Duration of the auction (in seconds)
        uint32 auctionExtension; // Time added when a bid is placed near the end (in seconds)
        uint32 auctionExtenderTimeFrame; // Timeframe near the end during which bids extend the auction (in seconds)
        uint32 maxAuctionExtension; // Maximum total time the auction can be extended (in seconds)
        uint24 gmDaoShare; // Share of proceeds for gmDAO (in basis points, out of 10000)
    }

    /**
     * @notice Struct representing a bid in the auction.
     * @dev Contains bidder address and packed data for:
     *      - 96 bits: amount
     *      - 32 bits: next
     *      - 32 bits: prev
     *      - bit 0: isWinning
     *      - bit 1: isClaimed
     * (Total = 96+32+32+2 bits used, fits in 256 bits).
     */
    struct BidNode {
        address bidder; // 20 bytes
        uint256 data; // Packed data for amount, next, prev, flags
    }

    // Instance of the project configuration.
    Project private project;

    // Event emitted when a bid is submitted.
    event BidSubmitted(
        address indexed bidder,
        uint32 bidId,
        uint256 amount,
        uint256 timestamp
    );

    // Event emitted when a bid is updated.
    event BidUpdated(
        address indexed bidder,
        uint32 bidId,
        uint256 newAmount,
        uint256 timestamp
    );

    // Event emitted when the auction is extended.
    event AuctionExtended(uint256 newEndTime);

    /**
     * @notice Initializes the project with the provided project data.
     * @dev This function initializes the ERC721 and Ownable contracts, sets up the project data, and calculates the auction end timestamp.
     * @param _p The project data struct containing all configuration parameters.
     */
    function initProject(Project calldata _p) public initializer {
        // Initialize the ERC721 contract with the project name and symbol.
        __ERC721_init(_p.name, _p.symbol);
        // Initialize the Ownable contract with the owner's address.
        __Ownable_init(_p.ownerAddress);
        // Store the project data.
        project = _p;
        // Calculate the auction end timestamp based on the start time and duration.
        auctionEndTimeStamp =
            project.auctionStartTimeStamp +
            project.auctionDuration;
    }

    /**
     * @notice Mint tokens to a specified address (owner only).
     * @dev Allows the owner to mint a specified number of tokens to a given address, subject to certain conditions.
     * @param count The number of tokens to mint.
     * @param a The address to receive the minted tokens.
     */
    function ownerMint(uint24 count, address a) external onlyOwner {
        // If the auction is currently in progress, the owner cannot mint.
        if (
            block.timestamp >= project.auctionStartTimeStamp &&
            block.timestamp <= auctionEndTimeStamp
        ) {
            revert("Auction in progress");
        }

        // If the auction has ended but not yet finalized, finalize it.
        if (block.timestamp > auctionEndTimeStamp && finalClearingPrice == 0) {
            _finalizeAuction();
        }

        uint256 totalSupply = _owners.length;

        uint32 unclaimedWinningBids = 0;

        // If the auction has been finalized, calculate unclaimed winning bids.
        if (finalClearingPrice != 0) {
            unclaimedWinningBids =
                numberOfWinningBids -
                numberOfClaimedWinningBids;
        }

        // Calculate the number of tokens available for the owner to mint.
        uint32 availableForOwner = project.maxSupply -
            uint32(totalSupply) -
            unclaimedWinningBids;

        // Ensure the owner does not mint more tokens than allowed.
        require(count <= availableForOwner, "Too many");

        // Mint the specified number of tokens to the address 'a'.
        for (uint256 i; i < count; ) {
            unchecked {
                uint256 tokenId = totalSupply + i;
                _mint(a, tokenId);
                i++;
            }
        }
    }

    /**
     * @notice Mint a token to an allowlisted address if conditions are met.
     * @dev Mints a token to the specified address 'a' if they are on the allowlist and haven't already claimed.
     * @param proof The Merkle proof verifying the address is on the allowlist.
     * @param a The address to mint the token to.
     */
    function allowListMint(
        bytes32[] calldata proof,
        address a
    ) external payable {
        // Ensure the allowlist minting has started.
        require(
            block.timestamp >= project.allowListStartTimeStamp,
            "AL not started"
        );
        // Ensure the allowlist minting has not ended.
        require(block.timestamp < project.auctionStartTimeStamp, "AL ended");
        // Verify that the address 'a' is on the allowlist using the Merkle proof.
        require(
            MerkleProof.verify(
                proof,
                project.merkleRoot,
                keccak256(abi.encodePacked(a))
            ),
            "Not on AL"
        );
        // Ensure the address hasn't already claimed their allowlist mint.
        require(_addressToAllowlistClaimed[a] == false, "Claimed");

        uint256 totalSupply = _owners.length;

        // Ensure the total supply doesn't exceed the maximum supply.
        require(totalSupply + 1 <= project.maxSupply, "Minted out");
        // Ensure the correct amount of Ether is provided.
        require(project.allowListPrice <= msg.value, "Invalid funds");
        // Prevent contracts from minting.
        require(msg.sender == tx.origin, "No contracts");

        unchecked {
            uint256 tokenId = totalSupply;
            // Mark the address as having claimed their allowlist mint.
            _addressToAllowlistClaimed[a] = true;
            // Add the funds to the withdrawable balance.
            _withdrawable += msg.value;
            // Mint the token to address 'a'.
            _mint(a, tokenId);
        }
    }

    function publicMint(uint24 count, address a) external payable {
        require(block.timestamp > auctionEndTimeStamp, "Auction ongoing");
        require(allowPublic, "Public not allowed");
        require(count > 0, "Must mint at least one");
        require(msg.sender == tx.origin, "No contracts");

        if (finalClearingPrice == 0) {
            _finalizeAuction();
        }

        uint256 totalSupply = _owners.length;

        // Calculate the number of unclaimed winning bids.
        uint32 unclaimedWinningBids = numberOfWinningBids -
            numberOfClaimedWinningBids;

        // Calculate the number of tokens available for public minting.
        uint32 availableForPublic = project.maxSupply -
            uint32(totalSupply) -
            unclaimedWinningBids;

        // Ensure the public does not mint more tokens than allowed.
        require(count <= availableForPublic, "Too many");

        // Ensure the correct amount of Ether is provided.
        uint256 totalPrice = count * project.minBid;
        require(msg.value >= totalPrice, "Insufficient funds");

        // Mint the specified number of tokens to the address 'a'.
        for (uint256 i; i < count; ) {
            unchecked {
                uint256 tokenId = totalSupply + i;
                _mint(a, tokenId);
                i++;
            }
        }

        // Add funds to withdrawable balance
        _withdrawable += totalPrice;
    }

    /**
     * @notice Places a new bid into the auction.
     * @dev Users can place multiple bids. The bid is inserted into the ordered linked list of bids.
     * @param estimatedNodePositionId The estimated position in the linked list for optimization.
     */
    function placeBid(
        uint32 estimatedNodePositionId
    ) external payable nonReentrant {
        // Ensure the auction has started.
        require(
            block.timestamp >= project.auctionStartTimeStamp,
            "Not started"
        );
        // Ensure the estimated node position is valid.
        require(estimatedNodePositionId <= bidCount, "Bad estimate");
        // Ensure the auction has not ended.
        require(block.timestamp <= auctionEndTimeStamp, "Auction ended");
        // Ensure the bid amount meets the minimum bid requirement.
        require(msg.value >= project.minBid, "Bid too low");
        // Prevent contracts from placing bids.
        require(msg.sender == tx.origin, "No contracts");

        // Get the cutoff bid amount required to be a winning bid.
        uint96 cutoffAmount = getCutoffBidAmount();
        // Calculate the maximum number of winning bids.
        uint256 maxWinners = project.maxSupply - _owners.length;

        if (bidCount >= maxWinners) {
            // If the list of bids is full, the new bid must be strictly greater than the cutoff amount.
            require(msg.value > cutoffAmount, "Bid too low");
        } else {
            // If the list is not full, the bid must be at least the cutoff amount (minimum bid).
            require(msg.value >= cutoffAmount, "Bid too low");
        }
        // Generate a new bid ID.
        uint32 newBidId = ++bidCount;

        // Insert the new bid into the ordered linked list.
        _insertNode(
            estimatedNodePositionId,
            newBidId,
            uint96(msg.value),
            msg.sender
        );

        // If the number of bids exceeds the maximum number of winners, adjust the winning tail.
        if (bidCount > maxWinners) {
            _adjustWinningTail();
        }

        // Extend the auction if the bid was placed near the end.
        _extendAuctionIfNeeded();

        // Emit an event for the new bid.
        emit BidSubmitted(msg.sender, newBidId, msg.value, block.timestamp);
    }

    /**
     * @notice Inserts a bid node into the ordered linked list of bids.
     * @dev The list is ordered by bid amount in descending order.
     * @param estimatedNodeId The estimated node position for optimization.
     * @param newNodeId The ID of the new bid node.
     * @param bid The amount of the bid.
     * @param bidder The address of the bidder.
     */
    function _insertNode(
        uint32 estimatedNodeId,
        uint32 newNodeId,
        uint96 bid,
        address bidder
    ) internal {
        // isNewNode = true when first creating the node;
        // but we reuse the same storage slot if the node already existed
        // (though that generally doesn't happen for a brand new bidId).
        bool isNewNode = (bidder != address(0));

        // Data packing structure (256 bits):
        // bits [160..255]: bid amount (96 bits)
        // bits [72..103]: next (32 bits)
        // bits [40..71]: prev (32 bits)
        // bit 0: isWinning
        // bit 1: isClaimed
        // The rest bits [2..39] remain unused.
        uint256 newNodeData = (uint256(bid) << 160) |
            (uint256(0) << 72) | // next
            (uint256(0) << 40) | // prev
            uint256(1); // isWinning=1, isClaimed=0

        if (winningTail == 0) {
            // Initialize the list with the new node
            winningTail = newNodeId;
            bidNodes[newNodeId] = BidNode({bidder: bidder, data: newNodeData});
            return;
        }

        uint32 currentId = (estimatedNodeId != 0 && estimatedNodeId <= bidCount)
            ? estimatedNodeId
            : winningTail;

        uint96 currentAmount = uint96(bidNodes[currentId].data >> 160);

        // Traverse the list to find the correct position for the new bid
        if (bid > currentAmount) {
            // Traverse backward to find the insertion point
            bool isHead = false;
            while (
                currentId != 0 &&
                (uint96(bidNodes[currentId].data >> 160) < bid)
            ) {
                uint32 prevId = uint32(bidNodes[currentId].data >> 40);
                if (prevId == 0) {
                    isHead = true;
                    break;
                }
                currentId = prevId;
            }
            if (isHead) {
                // Inserting at the head of the list
                uint32 headId = currentId;

                // newNode.next = headId
                newNodeData |= uint256(headId) << 72;
                // newNode.prev = 0
                newNodeData |= uint256(0) << 40;

                // Update the previous head's prev pointer to point to the new node
                uint256 headData = bidNodes[headId].data;
                headData =
                    (headData & ~((uint256(0xFFFFFFFF) << 40))) |
                    (uint256(newNodeId) << 40); // head.prev = newNodeId

                bidNodes[headId].data = headData;
            } else {
                // Inserting between currentId and its next node
                uint32 nextId = uint32(bidNodes[currentId].data >> 72);

                // Set new node's prev and next pointers
                newNodeData |= uint256(nextId) << 72; // newNode.next
                newNodeData |= uint256(currentId) << 40; // newNode.prev

                // Update currentId's next pointer to newNodeId
                uint256 currentNodeData = bidNodes[currentId].data;
                currentNodeData =
                    (currentNodeData & ~((uint256(0xFFFFFFFF) << 72))) |
                    (uint256(newNodeId) << 72);
                bidNodes[currentId].data = currentNodeData;

                // Update next node's prev pointer to newNodeId if nextId != 0
                if (nextId != 0) {
                    uint256 nextNodeData = bidNodes[nextId].data;
                    nextNodeData =
                        (nextNodeData & ~((uint256(0xFFFFFFFF) << 40))) |
                        (uint256(newNodeId) << 40);
                    bidNodes[nextId].data = nextNodeData;
                } else {
                    // If nextId is zero, update the winningTail to the new node
                    winningTail = newNodeId;
                }
            }
        } else {
            // Traverse forward to find the insertion point
            bool isWinningTail = false;
            while (
                currentId != 0 &&
                (uint96(bidNodes[currentId].data >> 160) >= bid)
            ) {
                if (currentId == winningTail) {
                    isWinningTail = true;
                    break;
                }
                uint32 nextId = uint32(bidNodes[currentId].data >> 72);
                currentId = nextId;
            }
            if (isWinningTail) {
                // Inserting at the tail of the list
                uint32 oldTail = winningTail;
                winningTail = newNodeId;

                // newNode.next = 0
                newNodeData |= uint256(0) << 72;
                // newNode.prev = oldTail
                newNodeData |= uint256(oldTail) << 40;

                uint256 oldTailData = bidNodes[oldTail].data;

                // Update the old tail's next pointer to point to the new node
                oldTailData =
                    (oldTailData & ~((uint256(0xFFFFFFFF) << 72))) |
                    (uint256(newNodeId) << 72);

                // If the max number of winners is reached, clear the isWinning flag
                if (bidCount >= (project.maxSupply - uint32(_owners.length))) {
                    oldTailData &= ~uint256(1); // Clear isWinning flag
                }

                bidNodes[oldTail].data = oldTailData;
            } else {
                // Inserting between two nodes
                uint32 prevId = uint32(bidNodes[currentId].data >> 40);

                // newNode.next = currentId
                newNodeData |= uint256(currentId) << 72;
                // newNode.prev = prevId
                newNodeData |= uint256(prevId) << 40;

                // Update current node's prev pointer to new node
                uint256 currentNodeData = bidNodes[currentId].data;
                currentNodeData =
                    (currentNodeData & ~((uint256(0xFFFFFFFF) << 40))) |
                    (uint256(newNodeId) << 40);
                bidNodes[currentId].data = currentNodeData;

                // Update previous node's next pointer to new node if prevId != 0
                if (prevId != 0) {
                    uint256 prevNodeData = bidNodes[prevId].data;
                    prevNodeData =
                        (prevNodeData & ~((uint256(0xFFFFFFFF) << 72))) |
                        (uint256(newNodeId) << 72);
                    bidNodes[prevId].data = prevNodeData;
                }
            }
        }

        // Insert the new node into the mapping
        if (isNewNode) {
            bidNodes[newNodeId] = BidNode({bidder: bidder, data: newNodeData});
        } else {
            bidNodes[newNodeId].data = newNodeData;
        }
    }

    /**
     * @notice Updates an existing bid by increasing the bid amount.
     * @dev Users can only increase their bids. The bid is re-inserted into the ordered linked list if necessary.
     * @param bidId The ID of the bid to update.
     * @param estimatedNodePositionId The estimated node ID for reordering.
     */
    function updateBid(
        uint32 bidId,
        uint32 estimatedNodePositionId
    ) external payable nonReentrant {
        // Ensure the auction has started.
        require(
            block.timestamp >= project.auctionStartTimeStamp,
            "Not started"
        );
        // Ensure the estimated node position is valid.
        require(estimatedNodePositionId <= bidCount, "Bad estimate");
        // Ensure the auction has not ended.
        require(block.timestamp <= auctionEndTimeStamp, "Auction ended");
        // Ensure the caller is increasing the bid amount.
        require(msg.value > 0, "No ETH sent");
        // Prevent contracts from updating bids.
        require(msg.sender == tx.origin, "No contracts");

        BidNode storage node = bidNodes[bidId];
        require(node.bidder == msg.sender, "Not your bid");

        // Decode the current data
        uint256 nodeData = node.data;
        uint96 currentAmount = uint96(nodeData >> 160);
        uint96 newAmount = currentAmount + uint96(msg.value);

        // Compute the cutoff amount and max winners
        uint32 maxWinners = project.maxSupply - uint32(_owners.length);
        uint96 cutoffAmount = getCutoffBidAmount();

        // Check if the updated bid meets the required conditions
        if (bidCount >= maxWinners) {
            require(newAmount > cutoffAmount, "Bid too low");
        } else {
            require(newAmount >= project.minBid, "Bid too low");
        }

        bool wasWinning = (nodeData & uint256(1)) != 0;

        // Update the bid amount (preserve 'isWinning' + 'isClaimed' bits)
        // bit[0]: isWinning, bit[1]: isClaimed
        // We only want to replace the amount bits [160..255].
        // So we mask out the old amount, then set the new amount:
        uint256 flagsMask = nodeData &
            0x000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
        // This keeps bits [0..159] intact, which includes isWinning, isClaimed, prev, next
        // Then we put newAmount in bits [160..255].
        node.data = flagsMask | (uint256(newAmount) << 160);

        // If previously not winning or we updated the tail, re-check tail
        if (bidId == winningTail || !wasWinning) {
            _adjustWinningTail();
        }

        // Adjust the position of the node in the linked list if necessary
        _adjustNodePosition(bidId, newAmount, estimatedNodePositionId);

        // Extend auction if needed
        _extendAuctionIfNeeded();

        emit BidUpdated(msg.sender, bidId, newAmount, block.timestamp);
    }

    /**
     * @notice Adjusts the position of a bid node after updating its amount.
     * @dev Detaches the node and re-inserts it into the correct position in the ordered linked list.
     * @param bidId The ID of the bid node to adjust.
     * @param newAmount The new bid amount.
     * @param estimatedNodePositionId The estimated node position for optimization.
     */
    function _adjustNodePosition(
        uint32 bidId,
        uint96 newAmount,
        uint32 estimatedNodePositionId
    ) internal {
        _detachNode(bidId);
        _insertNode(estimatedNodePositionId, bidId, newAmount, address(0));
    }

    /**
     * @notice Detaches a bid node from the linked list.
     * @dev Updates the previous and next nodes to bypass the detached node.
     * @param bidId The ID of the bid node to detach.
     */
    function _detachNode(uint32 bidId) internal {
        uint256 nodeData = bidNodes[bidId].data;
        uint32 prevId = uint32(nodeData >> 40);
        uint32 nextId = uint32(nodeData >> 72);

        // Update previous node's next pointer
        if (prevId != 0) {
            uint256 prevData = bidNodes[prevId].data;
            bidNodes[prevId].data =
                (prevData & ~(uint256(0xFFFFFFFF) << 72)) |
                (uint256(nextId) << 72);
        }

        // Update next node's prev pointer
        if (nextId != 0) {
            uint256 nextData = bidNodes[nextId].data;
            bidNodes[nextId].data =
                (nextData & ~(uint256(0xFFFFFFFF) << 40)) |
                (uint256(prevId) << 40);
        }
    }

    /**
     * @notice Adjusts the winning tail of the linked list when necessary.
     * @dev Updates the 'isWinning' flag of the old winning tail and moves the winning tail to the previous node.
     */
    function _adjustWinningTail() internal {
        if (winningTail == 0) return;
        // Clear the `isWinning` flag for the old winningTail
        uint256 oldTailData = bidNodes[winningTail].data;
        // bit[0] = isWinning -> set to 0
        bidNodes[winningTail].data = oldTailData & ~uint256(1);

        // Update the winningTail to the previous node
        winningTail = uint32(bidNodes[winningTail].data >> 40); // Get `prev`
    }

    /**
     * @notice Returns the estimated node ID for a given bid amount.
     * @dev Navigates the linked list to find the appropriate position for the bid.
     * @param bid The amount of the bid for which to find the estimated position.
     * @return The estimated node ID.
     */
    function getEstimatedNodeId(uint96 bid) external view returns (uint32) {
        uint32 currentId = winningTail;
        if (currentId == 0) return 0;

        uint96 currentAmount = uint96(bidNodes[currentId].data >> 160);
        if (bid > currentAmount) {
            while (
                currentId != 0 &&
                (uint96(bidNodes[currentId].data >> 160) < bid)
            ) {
                uint32 prevId = uint32(bidNodes[currentId].data >> 40);
                if (prevId == 0) {
                    break;
                }
                currentId = prevId;
            }
            return currentId;
        } else {
            return winningTail;
        }
    }

    /**
     * @notice Returns the cutoff bid amount required to be a winning bid.
     * @dev Determines the bid amount of the `winningTail` or the minimum bid if the auction is undersubscribed.
     * @return cutoffAmount The minimum amount required to be a winning bid.
     */
    function getCutoffBidAmount() public view returns (uint96 cutoffAmount) {
        uint32 maxWinners = project.maxSupply - uint32(_owners.length);

        if (bidCount >= maxWinners && winningTail != 0) {
            // If there are enough bids to fill all available tokens, return the `winningTail` amount
            uint256 tailData = bidNodes[winningTail].data;
            return uint96(tailData >> 160);
        } else {
            // If there are fewer bids than tokens, any bid can win
            return project.minBid;
        }
    }

    /**
     * @notice Internal function to extend the auction if a bid is placed near the end.
     * @dev Extends the auction end time by 'auctionExtension' if within 'auctionExtenderTimeFrame', up to 'maxAuctionExtension'.
     */
    function _extendAuctionIfNeeded() internal {
        uint256 timeRemaining = auctionEndTimeStamp > block.timestamp
            ? auctionEndTimeStamp - block.timestamp
            : 0;

        if (timeRemaining < project.auctionExtenderTimeFrame) {
            uint56 totalExtendedTime = auctionEndTimeStamp -
                (project.auctionStartTimeStamp + project.auctionDuration);
            if (totalExtendedTime < project.maxAuctionExtension) {
                uint56 extensionTime = project.auctionExtension;

                // Adjust extension time if it exceeds maxAuctionExtension
                if (
                    totalExtendedTime + extensionTime >
                    project.maxAuctionExtension
                ) {
                    extensionTime =
                        project.maxAuctionExtension -
                        totalExtendedTime;
                }

                auctionEndTimeStamp += extensionTime;

                emit AuctionExtended(auctionEndTimeStamp);
            }
        }
    }

    /**
     * @notice Allows users to claim their NFTs and refunds after the auction ends.
     *         Now it sets `isClaimed` = 1 instead of deleting the bid node.
     * @param bidIds The array of bid IDs to claim.
     * @param gmDaoTokenIds The array of gmDAO token IDs for discount eligibility.
     * @param a The address to receive the NFTs and refunds.
     */
    function claim(
        uint32[] calldata bidIds,
        uint256[] calldata gmDaoTokenIds,
        address a
    ) external nonReentrant {
        require(block.timestamp > auctionEndTimeStamp, "Auction not ended");
        require(bidIds.length > 0, "No bids");

        if (finalClearingPrice == 0) {
            _finalizeAuction();
        }

        uint256 totalRefund = 0;
        uint256 gmTokenIndex = 0; // Tracks which gmDAO token to use for discounts

        for (uint256 i = 0; i < bidIds.length; i++) {
            uint32 bidId = bidIds[i];
            BidNode storage node = bidNodes[bidId];
            require(node.bidder == msg.sender, "Not your bid");

            uint256 nodeData = node.data;
            bool isWinning = ((nodeData & uint256(1)) != 0);
            bool isAlreadyClaimed = ((nodeData & uint256(2)) != 0); // bit[1] = isClaimed
            require(!isAlreadyClaimed, "Already claimed");

            uint256 bidAmount = uint96(nodeData >> 160);
            uint256 discount = 0;

            if (isWinning) {
                // Winning bid: apply discount logic
                if (gmTokenIndex < gmDaoTokenIds.length) {
                    uint256 gmDaoTokenId = gmDaoTokenIds[gmTokenIndex];

                    address gmTokenOwner = ERC721Upgradeable(
                        project.gmV3Contract
                    ).ownerOf(gmDaoTokenId);

                    // Check ownership or delegation
                    if (
                        gmTokenOwner == msg.sender || // Direct ownership
                        IDelegateRegistry(project.delegateRegistry)
                            .checkDelegateForERC721(
                                msg.sender,
                                gmTokenOwner,
                                address(project.gmV3Contract),
                                gmDaoTokenId,
                                ""
                            )
                    ) {
                        require(
                            !_isDiscountUsed(gmDaoTokenId),
                            "Discount used"
                        );
                        _setDiscountUsed(gmDaoTokenId); // Mark discount as used
                        discount =
                            (finalClearingPrice * project.gmDiscount) /
                            10000;
                        gmTokenIndex++;
                    }
                }

                uint256 effectivePrice = finalClearingPrice - discount;
                uint256 refundAmount = bidAmount > effectivePrice
                    ? bidAmount - effectivePrice
                    : 0;

                // Add unused discount portion back to withdrawable if discount was not used
                if (discount == 0) {
                    _withdrawable +=
                        (finalClearingPrice * project.gmDiscount) /
                        10000;
                }

                // Mint the NFT to address 'a'.
                _mint(a, _owners.length);
                totalRefund += refundAmount;
                numberOfClaimedWinningBids += 1;
            } else {
                // Losing bid: full refund
                totalRefund += bidAmount;
            }

            // Set isClaimed = 1 (bit[1])
            // preserve the rest of nodeData, just set bit 1:
            node.data = nodeData | uint256(2); // set bit[1]

            // Instead of deleting the node, we keep it with isClaimed = true
        }

        // Transfer any refunds to the address 'a'.
        if (totalRefund > 0) {
            _safeTransferEther(payable(a), totalRefund);
        }
    }

    /**
     * @notice Finalizes the auction by determining the final clearing price and the number of winning bids.
     * @dev Calculates the final clearing price based on the bids and marks the auction as finalized.
     */
    function _finalizeAuction() internal {
        mintedBeforeAuction = uint32(_owners.length);
        uint32 maxAvailableTokens = uint32(
            project.maxSupply - mintedBeforeAuction
        );

        if (bidCount >= maxAvailableTokens) {
            numberOfWinningBids = maxAvailableTokens;
            finalClearingPrice = uint96(bidNodes[winningTail].data >> 160);
        } else {
            numberOfWinningBids = uint32(bidCount);
            finalClearingPrice = project.minBid;
        }

        // Calculate instant withdrawable amount
        uint256 totalProceeds = numberOfWinningBids *
            uint256(finalClearingPrice);
        uint256 instantWithdrawable = (totalProceeds *
            (10000 - project.gmDiscount)) / 10000;

        // Reserve the discount portion
        _withdrawable += instantWithdrawable; // Add to withdrawable funds
    }

    /**
     * @notice Checks if a gmDAO token has been used for a discount.
     * @param tokenId The gmDAO token ID to check.
     * @return True if the token has been used, false otherwise.
     */
    function _isDiscountUsed(uint256 tokenId) internal view returns (bool) {
        uint256 index = tokenId / 256; // Determine which uint256 to use
        uint256 bit = 1 << (tokenId % 256); // Determine the specific bit within the uint256
        return (_gmDaoDiscountFlags[index] & bit) != 0;
    }

    /**
     * @notice Marks a gmDAO token as used for a discount.
     * @param tokenId The gmDAO token ID to mark.
     */
    function _setDiscountUsed(uint256 tokenId) internal {
        uint256 index = tokenId / 256;
        uint256 bit = 1 << (tokenId % 256);
        _gmDaoDiscountFlags[index] |= bit;
    }

    /**
     * @notice Public function returning an array of booleans indicating whether each gmDAO token’s discount was used.
     * @param gmDaoTokenIds The array of gmDAO token IDs to check.
     * @return A boolean array parallel to gmDaoTokenIds where `true` means discount was used.
     */
    function areDiscountsUsed(
        uint256[] calldata gmDaoTokenIds
    ) external view returns (bool[] memory) {
        bool[] memory used = new bool[](gmDaoTokenIds.length);
        for (uint256 i = 0; i < gmDaoTokenIds.length; i++) {
            used[i] = _isDiscountUsed(gmDaoTokenIds[i]);
        }
        return used;
    }

    /**
     * @notice Public function that returns an array of BidNode data starting from `startId` of length `count`.
     * @dev If you pass (0, 5), you'll get bidNodes[0..4].
     *      Watch out for existence: if a node was never created or is out of range, it might just contain default values.
     * @param startId The starting bid ID
     * @param count How many nodes to fetch
     */
    function getBidNodes(
        uint32 startId,
        uint32 count
    ) external view returns (BidNode[] memory) {
        BidNode[] memory result = new BidNode[](count);
        for (uint32 i = 0; i < count; i++) {
            uint32 bidId = startId + i;
            result[i] = bidNodes[bidId];
        }
        return result;
    }

    /**
     * @notice Internal function to safely transfer Ether.
     * @param to The recipient address.
     * @param amount The amount of Ether to transfer.
     */
    function _safeTransferEther(address payable to, uint256 amount) internal {
        (bool sent, ) = to.call{value: amount}("");
        require(sent, "Ether transfer failed");
    }

    /**
     * @notice Returns a list of token IDs owned by the specified address.
     * @param _owner The address to query.
     * @return An array of token IDs owned by the address.
     */
    function walletOfOwner(
        address _owner
    ) public view returns (uint256[] memory) {
        uint256 tokenCount = balanceOf(_owner);
        if (tokenCount == 0) return new uint256[](0);

        uint256[] memory tokensId = new uint256[](tokenCount);
        for (uint256 i; i < tokenCount; i++) {
            tokensId[i] = tokenOfOwnerByIndex(_owner, i);
        }
        return tokensId;
    }

    /**
     * @notice Returns the royalty information for a given token ID and sale price.
     * @dev This function is required by the ERC2981 standard.
     * @param _salePrice The sale price of the token.
     * @return receiver The address to receive the royalties.
     * @return royaltyAmount The amount of royalties owed.
     */
    function royaltyInfo(
        uint256,
        uint256 _salePrice
    ) external view override returns (address receiver, uint256 royaltyAmount) {
        receiver = project.royaltyAddress;
        royaltyAmount = (_salePrice * project.royalty) / 10000;
    }

    /**
     * @notice Returns the metadata of the token with the given ID.
     * @dev It returns a JSON object which conforms to the ERC721 metadata standard.
     * @param _tokenId The ID of the token to retrieve metadata for.
     * @return A JSON object that contains the metadata of the given token.
     */
    function tokenURI(
        uint256 _tokenId
    ) public view override returns (string memory) {
        require(_exists(_tokenId), "Token not found");
        return string.concat(project.tokenBase, Strings.toString(_tokenId));
    }

    /**
     * @notice Returns the maximum supply of tokens.
     * @return The maximum supply of tokens.
     */
    function maxSupply() public view returns (uint32) {
        return project.maxSupply;
    }

    /**
     * @notice Allows the owner to set the metadata base URL for the project.
     * @dev Only callable by the owner.
     * @param _tokenBase String representing the base URL for tokens.
     */
    function setTokenBase(string calldata _tokenBase) public onlyOwner {
        project.tokenBase = _tokenBase;
    }

    /**
     * @notice Sets the address to receive royalties.
     * @param _royaltyAddress The new royalty recipient address.
     */
    function setRoyaltyAddress(
        address payable _royaltyAddress
    ) public onlyOwner {
        require(_royaltyAddress != address(0), "Invalid address");
        project.royaltyAddress = _royaltyAddress;
    }

    /**
     * @notice Sets the royalty percentage.
     * @param _royalty The new royalty percentage (out of 10000).
     */
    function setRoyalty(uint96 _royalty) public onlyOwner {
        require(_royalty <= 10000, "Royalty percentage too high");
        project.royalty = _royalty;
    }

    /**
     * @notice Allows the owner to set the Merkle root for the allowlist.
     * @dev Only callable by the owner.
     * @param _merkleRoot The new Merkle root.
     */
    function setMerkleRoot(bytes32 _merkleRoot) external onlyOwner {
        project.merkleRoot = _merkleRoot;
    }

    /**
     * @notice Allows the owner to set the gmDAO token holder discount percentage.
     * @dev Only callable by the owner and not after the auction has started.
     *      The discount cannot exceed 10000 (100%).
     * @param _gmDiscount The new discount percentage (in basis points out of 10000).
     */
    function setGmDiscount(uint96 _gmDiscount) external onlyOwner {
        require(_gmDiscount <= 10000, "Discount percentage too high");
        // Disallow after auction start
        require(
            block.timestamp < project.auctionStartTimeStamp,
            "Cannot set discount after auction starts"
        );
        project.gmDiscount = _gmDiscount;
    }

    /**
     * @notice Allows the owner to set the minimum bid amount.
     * @dev Only callable by the owner before we have enough winning bids.
     * @param _minBid The new minimum bid amount (in wei).
     */
    function setMinBid(uint96 _minBid) external onlyOwner {
        // If we already have enough winning bids, disallow change.
        uint32 maxWinners = project.maxSupply - uint32(_owners.length);
        require(bidCount < maxWinners, "Enough winning bids exist");
        project.minBid = _minBid;
    }

    /**
     * @notice Allows the owner to set the allowlist minting price.
     * @dev Only callable by the owner before the allowlist minting starts.
     * @param _allowListPrice The new price for allowlist minting (in wei).
     */
    function setALPrice(uint96 _allowListPrice) external onlyOwner {
        require(
            block.timestamp < project.allowListStartTimeStamp,
            "Allowlist mint already started"
        );
        project.allowListPrice = _allowListPrice;
    }

    /**
     * @notice Allows the owner to set the auction start timestamp.
     * @dev Only callable by the owner if the auction hasn't started yet.
     * @param _auctionStartTimeStamp The new auction start timestamp (UNIX time in seconds).
     */
    function setAuctionStart(uint56 _auctionStartTimeStamp) external onlyOwner {
        require(
            block.timestamp < project.auctionStartTimeStamp,
            "Auction already started"
        );
        require(
            _auctionStartTimeStamp >= project.allowListStartTimeStamp,
            "Start cannot be before AL"
        );
        project.auctionStartTimeStamp = _auctionStartTimeStamp;
        // Recalculate the auction end timestamp
        auctionEndTimeStamp =
            project.auctionStartTimeStamp +
            project.auctionDuration;
    }

    /**
     * @notice Allows the owner to increase the auction duration.
     * @dev Only callable by the owner before the auction starts. Can only increase the auctionDuration.
     * @param _auctionDuration The new auction duration in seconds.
     */
    function setAuctionDuration(uint32 _auctionDuration) external onlyOwner {
        require(
            block.timestamp < project.auctionStartTimeStamp,
            "Auction already started"
        );
        require(
            _auctionDuration > project.auctionDuration,
            "Must increase duration"
        );
        project.auctionDuration = _auctionDuration;
        // Recalculate the auction end timestamp
        auctionEndTimeStamp =
            project.auctionStartTimeStamp +
            project.auctionDuration;
    }

    /**
     * @notice Allows the owner to set the allowlist minting start timestamp.
     * @dev Only callable by the owner if the allowlist minting hasn't started yet. Must be before the auction start time.
     * @param _allowListStartTimeStamp The new allowlist minting start timestamp (UNIX time in seconds).
     */
    function setALStart(uint56 _allowListStartTimeStamp) external onlyOwner {
        require(
            block.timestamp < project.allowListStartTimeStamp,
            "AL mint started"
        );
        require(
            _allowListStartTimeStamp <= project.auctionStartTimeStamp,
            "AL after auction"
        );
        project.allowListStartTimeStamp = _allowListStartTimeStamp;
    }

    /**
     * @notice Allows the owner to decrease the maximum supply of tokens.
     * @dev Only callable by the owner. Can only decrease the maxSupply, and cannot set it lower than the current total supply + unclaimed winning bids.
     * @param _maxSupply The new maximum supply of tokens.
     */
    function setMaxSupply(uint32 _maxSupply) external onlyOwner {
        require(_maxSupply < project.maxSupply, "Only decrease");

        uint256 totalSupply = _owners.length;

        // Check the current auction status
        if (block.timestamp < project.auctionStartTimeStamp) {
            // Before auction starts
            require(_maxSupply >= uint32(totalSupply), "maxSupply too low");
        } else if (
            block.timestamp >= project.auctionStartTimeStamp &&
            block.timestamp <= auctionEndTimeStamp
        ) {
            // During the auction
            revert("Cannot change maxSupply during the auction");
        } else {
            // After auction ends
            if (finalClearingPrice == 0) {
                // Auction not finalized, finalize it
                _finalizeAuction();
            }
            // After finalization, calculate unclaimed winning bids
            uint32 unclaimedWinningBids = numberOfWinningBids -
                numberOfClaimedWinningBids;

            uint32 minimumMaxSupply = uint32(totalSupply) +
                unclaimedWinningBids;

            require(_maxSupply >= minimumMaxSupply, "maxSupply too low");
        }

        project.maxSupply = _maxSupply;
    }

    /**
     * @notice Allows the owner to set whether public mint should be open.
     * @dev Only callable by the owner.
     * @param _allowPublic Public open or closed.
     */
    function setAllowPublic(bool _allowPublic) external onlyOwner {
        allowPublic = _allowPublic;
    }

    /**
     * @notice Allows the contract owner to withdraw accumulated Ether.
     * @dev Can withdraw allowlist funds at any time and auction funds after the auction ends.
     *      Ensures funds cannot be withdrawn more than once.
     */
    function withdraw() external onlyOwner nonReentrant {
        // Finalize the auction if it's ended but not yet finalized
        if (block.timestamp > auctionEndTimeStamp && finalClearingPrice == 0) {
            _finalizeAuction();
        }

        uint256 amountToWithdraw = _withdrawable;
        require(amountToWithdraw > 0, "No funds");

        // Reset withdrawable amount to prevent re-entrancy
        _withdrawable = 0;

        // Calculate gmDAO's share (in basis points out of 10000)
        uint256 gmDaoAmount = (amountToWithdraw * project.gmDaoShare) / 10000;
        // Calculate artist's share as the remaining amount
        uint256 artistAmount = amountToWithdraw - gmDaoAmount;

        // Transfer gmDAO's share to the gmDAO address
        if (gmDaoAmount > 0) {
            _safeTransferEther(project.gmDaoAddress, gmDaoAmount);
        }

        // Transfer the artist's share to the artist's address
        if (artistAmount > 0) {
            _safeTransferEther(project.artistAddress, artistAmount);
        }
    }

    function supportsInterface(
        bytes4 interfaceId
    ) public view virtual override(ERC721EnumerableUpgradeable) returns (bool) {
        return
            interfaceId == type(IERC2981).interfaceId || // ERC2981 Royalties
            super.supportsInterface(interfaceId);
    }

    // Override _msgSender to resolve conflict between base classes.
    function _msgSender()
        internal
        view
        virtual
        override(ContextUpgradeable, ERC721C)
        returns (address)
    {
        return super._msgSender();
    }

    // Override _msgData to resolve conflict between base classes.
    function _msgData()
        internal
        view
        virtual
        override(ContextUpgradeable, ERC721C)
        returns (bytes calldata)
    {
        return super._msgData();
    }

    function _contextSuffixLength()
        internal
        view
        virtual
        override(ContextUpgradeable, ERC721C)
        returns (uint256)
    {
        return 0;
    }

    function _requireCallerIsContractOwner() internal view virtual override {
        require(owner() == _msgSender(), "Ownable: Caller is not the owner");
    }
}

File 2 of 32 : OwnablePermissions.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/utils/Context.sol";

abstract contract OwnablePermissions is Context {
    function _requireCallerIsContractOwner() internal view virtual;
}

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

interface ICreatorToken {
    event TransferValidatorUpdated(address oldValidator, address newValidator);
    function getTransferValidator() external view returns (address validator);
    function setTransferValidator(address validator) external;
    function getTransferValidationFunction() external view returns (bytes4 functionSignature, bool isViewFunction);
}

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

interface ICreatorTokenLegacy {
    event TransferValidatorUpdated(address oldValidator, address newValidator);
    function getTransferValidator() external view returns (address validator);
    function setTransferValidator(address validator) external;
}

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

interface ITransferValidator {
    function applyCollectionTransferPolicy(address caller, address from, address to) external view;
    function validateTransfer(address caller, address from, address to) external view;
    function validateTransfer(address caller, address from, address to, uint256 tokenId) external view;
    function validateTransfer(address caller, address from, address to, uint256 tokenId, uint256 amount) external;

    function beforeAuthorizedTransfer(address operator, address token, uint256 tokenId) external;
    function afterAuthorizedTransfer(address token, uint256 tokenId) external;
    function beforeAuthorizedTransfer(address operator, address token) external;
    function afterAuthorizedTransfer(address token) external;
    function beforeAuthorizedTransfer(address token, uint256 tokenId) external;
    function beforeAuthorizedTransferWithAmount(address token, uint256 tokenId, uint256 amount) external;
    function afterAuthorizedTransferWithAmount(address token, uint256 tokenId) external;
}

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

interface ITransferValidatorSetTokenType {
    function setTokenTypeOfCollection(address collection, uint16 tokenType) external;
}

File 7 of 32 : AutomaticValidatorTransferApproval.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "../access/OwnablePermissions.sol";

/**
 * @title AutomaticValidatorTransferApproval
 * @author Limit Break, Inc.
 * @notice Base contract mix-in that provides boilerplate code giving the contract owner the
 *         option to automatically approve a 721-C transfer validator implementation for transfers.
 */
abstract contract AutomaticValidatorTransferApproval is OwnablePermissions {

    /// @dev Emitted when the automatic approval flag is modified by the creator.
    event AutomaticApprovalOfTransferValidatorSet(bool autoApproved);

    /// @dev If true, the collection's transfer validator is automatically approved to transfer holder's tokens.
    bool public autoApproveTransfersFromValidator;

    /**
     * @notice Sets if the transfer validator is automatically approved as an operator for all token owners.
     * 
     * @dev    Throws when the caller is not the contract owner.
     * 
     * @param autoApprove If true, the collection's transfer validator will be automatically approved to
     *                    transfer holder's tokens.
     */
    function setAutomaticApprovalOfTransfersFromValidator(bool autoApprove) external {
        _requireCallerIsContractOwner();
        autoApproveTransfersFromValidator = autoApprove;
        emit AutomaticApprovalOfTransferValidatorSet(autoApprove);
    }
}

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

import "../access/OwnablePermissions.sol";
import "../interfaces/ICreatorToken.sol";
import "../interfaces/ICreatorTokenLegacy.sol";
import "../interfaces/ITransferValidator.sol";
import "./TransferValidation.sol";
import "../interfaces/ITransferValidatorSetTokenType.sol";

/**
 * @title CreatorTokenBase
 * @author Limit Break, Inc.
 * @notice CreatorTokenBaseV3 is an abstract contract that provides basic functionality for managing token 
 * transfer policies through an implementation of ICreatorTokenTransferValidator/ICreatorTokenTransferValidatorV2/ICreatorTokenTransferValidatorV3. 
 * This contract is intended to be used as a base for creator-specific token contracts, enabling customizable transfer 
 * restrictions and security policies.
 *
 * <h4>Features:</h4>
 * <ul>Ownable: This contract can have an owner who can set and update the transfer validator.</ul>
 * <ul>TransferValidation: Implements the basic token transfer validation interface.</ul>
 *
 * <h4>Benefits:</h4>
 * <ul>Provides a flexible and modular way to implement custom token transfer restrictions and security policies.</ul>
 * <ul>Allows creators to enforce policies such as account and codehash blacklists, whitelists, and graylists.</ul>
 * <ul>Can be easily integrated into other token contracts as a base contract.</ul>
 *
 * <h4>Intended Usage:</h4>
 * <ul>Use as a base contract for creator token implementations that require advanced transfer restrictions and 
 *   security policies.</ul>
 * <ul>Set and update the ICreatorTokenTransferValidator implementation contract to enforce desired policies for the 
 *   creator token.</ul>
 *
 * <h4>Compatibility:</h4>
 * <ul>Backward and Forward Compatible - V1/V2/V3 Creator Token Base will work with V1/V2/V3 Transfer Validators.</ul>
 */
abstract contract CreatorTokenBase is OwnablePermissions, TransferValidation, ICreatorToken {

    /// @dev Thrown when setting a transfer validator address that has no deployed code.
    error CreatorTokenBase__InvalidTransferValidatorContract();

    /// @dev The default transfer validator that will be used if no transfer validator has been set by the creator.
    address public constant DEFAULT_TRANSFER_VALIDATOR = address(0x721C002B0059009a671D00aD1700c9748146cd1B);

    /// @dev Used to determine if the default transfer validator is applied.
    /// @dev Set to true when the creator sets a transfer validator address.
    bool private isValidatorInitialized;
    /// @dev Address of the transfer validator to apply to transactions.
    address private transferValidator;

    constructor() {
        _emitDefaultTransferValidator();
        _registerTokenType(DEFAULT_TRANSFER_VALIDATOR);
    }

    /**
     * @notice Sets the transfer validator for the token contract.
     *
     * @dev    Throws when provided validator contract is not the zero address and does not have code.
     * @dev    Throws when the caller is not the contract owner.
     *
     * @dev    <h4>Postconditions:</h4>
     *         1. The transferValidator address is updated.
     *         2. The `TransferValidatorUpdated` event is emitted.
     *
     * @param transferValidator_ The address of the transfer validator contract.
     */
    function setTransferValidator(address transferValidator_) public {
        _requireCallerIsContractOwner();

        bool isValidTransferValidator = transferValidator_.code.length > 0;

        if(transferValidator_ != address(0) && !isValidTransferValidator) {
            revert CreatorTokenBase__InvalidTransferValidatorContract();
        }

        emit TransferValidatorUpdated(address(getTransferValidator()), transferValidator_);

        isValidatorInitialized = true;
        transferValidator = transferValidator_;

        _registerTokenType(transferValidator_);
    }

    /**
     * @notice Returns the transfer validator contract address for this token contract.
     */
    function getTransferValidator() public view override returns (address validator) {
        validator = transferValidator;

        if (validator == address(0)) {
            if (!isValidatorInitialized) {
                validator = DEFAULT_TRANSFER_VALIDATOR;
            }
        }
    }

    /**
     * @dev Pre-validates a token transfer, reverting if the transfer is not allowed by this token's security policy.
     *      Inheriting contracts are responsible for overriding the _beforeTokenTransfer function, or its equivalent
     *      and calling _validateBeforeTransfer so that checks can be properly applied during token transfers.
     *
     * @dev Be aware that if the msg.sender is the transfer validator, the transfer is automatically permitted, as the
     *      transfer validator is expected to pre-validate the transfer.
     *
     * @dev Throws when the transfer doesn't comply with the collection's transfer policy, if the transferValidator is
     *      set to a non-zero address.
     *
     * @param caller  The address of the caller.
     * @param from    The address of the sender.
     * @param to      The address of the receiver.
     * @param tokenId The token id being transferred.
     */
    function _preValidateTransfer(
        address caller, 
        address from, 
        address to, 
        uint256 tokenId, 
        uint256 /*value*/) internal virtual override {
        address validator = getTransferValidator();

        if (validator != address(0)) {
            if (msg.sender == validator) {
                return;
            }

            ITransferValidator(validator).validateTransfer(caller, from, to, tokenId);
        }
    }

    /**
     * @dev Pre-validates a token transfer, reverting if the transfer is not allowed by this token's security policy.
     *      Inheriting contracts are responsible for overriding the _beforeTokenTransfer function, or its equivalent
     *      and calling _validateBeforeTransfer so that checks can be properly applied during token transfers.
     *
     * @dev Be aware that if the msg.sender is the transfer validator, the transfer is automatically permitted, as the
     *      transfer validator is expected to pre-validate the transfer.
     * 
     * @dev Used for ERC20 and ERC1155 token transfers which have an amount value to validate in the transfer validator.
     * @dev The `tokenId` for ERC20 tokens should be set to `0`.
     *
     * @dev Throws when the transfer doesn't comply with the collection's transfer policy, if the transferValidator is
     *      set to a non-zero address.
     *
     * @param caller  The address of the caller.
     * @param from    The address of the sender.
     * @param to      The address of the receiver.
     * @param tokenId The token id being transferred.
     * @param amount  The amount of token being transferred.
     */
    function _preValidateTransfer(
        address caller, 
        address from, 
        address to, 
        uint256 tokenId, 
        uint256 amount,
        uint256 /*value*/) internal virtual override {
        address validator = getTransferValidator();

        if (validator != address(0)) {
            if (msg.sender == validator) {
                return;
            }

            ITransferValidator(validator).validateTransfer(caller, from, to, tokenId, amount);
        }
    }

    function _tokenType() internal virtual pure returns(uint16);

    function _registerTokenType(address validator) internal {
        if (validator != address(0)) {
            uint256 validatorCodeSize;
            assembly {
                validatorCodeSize := extcodesize(validator)
            }
            if(validatorCodeSize > 0) {
                try ITransferValidatorSetTokenType(validator).setTokenTypeOfCollection(address(this), _tokenType()) {
                } catch { }
            }
        }
    }

    /**
     * @dev  Used during contract deployment for constructable and cloneable creator tokens
     * @dev  to emit the `TransferValidatorUpdated` event signaling the validator for the contract
     * @dev  is the default transfer validator.
     */
    function _emitDefaultTransferValidator() internal {
        emit TransferValidatorUpdated(address(0), DEFAULT_TRANSFER_VALIDATOR);
    }
}

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

import "@openzeppelin/contracts/utils/Context.sol";

/**
 * @title TransferValidation
 * @author Limit Break, Inc.
 * @notice A mix-in that can be combined with ERC-721 contracts to provide more granular hooks.
 * Openzeppelin's ERC721 contract only provides hooks for before and after transfer.  This allows
 * developers to validate or customize transfers within the context of a mint, a burn, or a transfer.
 */
abstract contract TransferValidation is Context {
    
    /// @dev Thrown when the from and to address are both the zero address.
    error ShouldNotMintToBurnAddress();

    /*************************************************************************/
    /*                      Transfers Without Amounts                        */
    /*************************************************************************/

    /// @dev Inheriting contracts should call this function in the _beforeTokenTransfer function to get more granular hooks.
    function _validateBeforeTransfer(address from, address to, uint256 tokenId) internal virtual {
        bool fromZeroAddress = from == address(0);
        bool toZeroAddress = to == address(0);

        if(fromZeroAddress && toZeroAddress) {
            revert ShouldNotMintToBurnAddress();
        } else if(fromZeroAddress) {
            _preValidateMint(_msgSender(), to, tokenId, msg.value);
        } else if(toZeroAddress) {
            _preValidateBurn(_msgSender(), from, tokenId, msg.value);
        } else {
            _preValidateTransfer(_msgSender(), from, to, tokenId, msg.value);
        }
    }

    /// @dev Inheriting contracts should call this function in the _afterTokenTransfer function to get more granular hooks.
    function _validateAfterTransfer(address from, address to, uint256 tokenId) internal virtual {
        bool fromZeroAddress = from == address(0);
        bool toZeroAddress = to == address(0);

        if(fromZeroAddress && toZeroAddress) {
            revert ShouldNotMintToBurnAddress();
        } else if(fromZeroAddress) {
            _postValidateMint(_msgSender(), to, tokenId, msg.value);
        } else if(toZeroAddress) {
            _postValidateBurn(_msgSender(), from, tokenId, msg.value);
        } else {
            _postValidateTransfer(_msgSender(), from, to, tokenId, msg.value);
        }
    }

    /// @dev Optional validation hook that fires before a mint
    function _preValidateMint(address caller, address to, uint256 tokenId, uint256 value) internal virtual {}

    /// @dev Optional validation hook that fires after a mint
    function _postValidateMint(address caller, address to, uint256 tokenId, uint256 value) internal virtual {}

    /// @dev Optional validation hook that fires before a burn
    function _preValidateBurn(address caller, address from, uint256 tokenId, uint256 value) internal virtual {}

    /// @dev Optional validation hook that fires after a burn
    function _postValidateBurn(address caller, address from, uint256 tokenId, uint256 value) internal virtual {}

    /// @dev Optional validation hook that fires before a transfer
    function _preValidateTransfer(address caller, address from, address to, uint256 tokenId, uint256 value) internal virtual {}

    /// @dev Optional validation hook that fires after a transfer
    function _postValidateTransfer(address caller, address from, address to, uint256 tokenId, uint256 value) internal virtual {}

    /*************************************************************************/
    /*                         Transfers With Amounts                        */
    /*************************************************************************/

    /// @dev Inheriting contracts should call this function in the _beforeTokenTransfer function to get more granular hooks.
    function _validateBeforeTransfer(address from, address to, uint256 tokenId, uint256 amount) internal virtual {
        bool fromZeroAddress = from == address(0);
        bool toZeroAddress = to == address(0);

        if(fromZeroAddress && toZeroAddress) {
            revert ShouldNotMintToBurnAddress();
        } else if(fromZeroAddress) {
            _preValidateMint(_msgSender(), to, tokenId, amount, msg.value);
        } else if(toZeroAddress) {
            _preValidateBurn(_msgSender(), from, tokenId, amount, msg.value);
        } else {
            _preValidateTransfer(_msgSender(), from, to, tokenId, amount, msg.value);
        }
    }

    /// @dev Inheriting contracts should call this function in the _afterTokenTransfer function to get more granular hooks.
    function _validateAfterTransfer(address from, address to, uint256 tokenId, uint256 amount) internal virtual {
        bool fromZeroAddress = from == address(0);
        bool toZeroAddress = to == address(0);

        if(fromZeroAddress && toZeroAddress) {
            revert ShouldNotMintToBurnAddress();
        } else if(fromZeroAddress) {
            _postValidateMint(_msgSender(), to, tokenId, amount, msg.value);
        } else if(toZeroAddress) {
            _postValidateBurn(_msgSender(), from, tokenId, amount, msg.value);
        } else {
            _postValidateTransfer(_msgSender(), from, to, tokenId, amount, msg.value);
        }
    }

    /// @dev Optional validation hook that fires before a mint
    function _preValidateMint(address caller, address to, uint256 tokenId, uint256 amount, uint256 value) internal virtual {}

    /// @dev Optional validation hook that fires after a mint
    function _postValidateMint(address caller, address to, uint256 tokenId, uint256 amount, uint256 value) internal virtual {}

    /// @dev Optional validation hook that fires before a burn
    function _preValidateBurn(address caller, address from, uint256 tokenId, uint256 amount, uint256 value) internal virtual {}

    /// @dev Optional validation hook that fires after a burn
    function _postValidateBurn(address caller, address from, uint256 tokenId, uint256 amount, uint256 value) internal virtual {}

    /// @dev Optional validation hook that fires before a transfer
    function _preValidateTransfer(address caller, address from, address to, uint256 tokenId, uint256 amount, uint256 value) internal virtual {}

    /// @dev Optional validation hook that fires after a transfer
    function _postValidateTransfer(address caller, address from, address to, uint256 tokenId, uint256 amount, uint256 value) internal virtual {}
}

File 10 of 32 : Constants.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @dev Constant bytes32 value of 0x000...000
bytes32 constant ZERO_BYTES32 = bytes32(0);

/// @dev Constant value of 0
uint256 constant ZERO = 0;
/// @dev Constant value of 1
uint256 constant ONE = 1;

/// @dev Constant value representing an open order in storage
uint8 constant ORDER_STATE_OPEN = 0;
/// @dev Constant value representing a filled order in storage
uint8 constant ORDER_STATE_FILLED = 1;
/// @dev Constant value representing a cancelled order in storage
uint8 constant ORDER_STATE_CANCELLED = 2;

/// @dev Constant value representing the ERC721 token type for signatures and transfer hooks
uint256 constant TOKEN_TYPE_ERC721 = 721;
/// @dev Constant value representing the ERC1155 token type for signatures and transfer hooks
uint256 constant TOKEN_TYPE_ERC1155 = 1155;
/// @dev Constant value representing the ERC20 token type for signatures and transfer hooks
uint256 constant TOKEN_TYPE_ERC20 = 20;

/// @dev Constant value to mask the upper bits of a signature that uses a packed `vs` value to extract `s`
bytes32 constant UPPER_BIT_MASK = 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;

/// @dev EIP-712 typehash used for validating signature based stored approvals
bytes32 constant UPDATE_APPROVAL_TYPEHASH =
    keccak256("UpdateApprovalBySignature(uint256 tokenType,address token,uint256 id,uint256 amount,uint256 nonce,address operator,uint256 approvalExpiration,uint256 sigDeadline,uint256 masterNonce)");

/// @dev EIP-712 typehash used for validating a single use permit without additional data
bytes32 constant SINGLE_USE_PERMIT_TYPEHASH =
    keccak256("PermitTransferFrom(uint256 tokenType,address token,uint256 id,uint256 amount,uint256 nonce,address operator,uint256 expiration,uint256 masterNonce)");

/// @dev EIP-712 typehash used for validating a single use permit with additional data
string constant SINGLE_USE_PERMIT_TRANSFER_ADVANCED_TYPEHASH_STUB =
    "PermitTransferFromWithAdditionalData(uint256 tokenType,address token,uint256 id,uint256 amount,uint256 nonce,address operator,uint256 expiration,uint256 masterNonce,";

/// @dev EIP-712 typehash used for validating an order permit that updates storage as it fills
string constant PERMIT_ORDER_ADVANCED_TYPEHASH_STUB =
    "PermitOrderWithAdditionalData(uint256 tokenType,address token,uint256 id,uint256 amount,uint256 salt,address operator,uint256 expiration,uint256 masterNonce,";

/// @dev Pausable flag for stored approval transfers of ERC721 assets
uint256 constant PAUSABLE_APPROVAL_TRANSFER_FROM_ERC721 = 1 << 0;
/// @dev Pausable flag for stored approval transfers of ERC1155 assets
uint256 constant PAUSABLE_APPROVAL_TRANSFER_FROM_ERC1155 = 1 << 1;
/// @dev Pausable flag for stored approval transfers of ERC20 assets
uint256 constant PAUSABLE_APPROVAL_TRANSFER_FROM_ERC20 = 1 << 2;

/// @dev Pausable flag for single use permit transfers of ERC721 assets
uint256 constant PAUSABLE_PERMITTED_TRANSFER_FROM_ERC721 = 1 << 3;
/// @dev Pausable flag for single use permit transfers of ERC1155 assets
uint256 constant PAUSABLE_PERMITTED_TRANSFER_FROM_ERC1155 = 1 << 4;
/// @dev Pausable flag for single use permit transfers of ERC20 assets
uint256 constant PAUSABLE_PERMITTED_TRANSFER_FROM_ERC20 = 1 << 5;

/// @dev Pausable flag for order fill transfers of ERC1155 assets
uint256 constant PAUSABLE_ORDER_TRANSFER_FROM_ERC1155 = 1 << 6;
/// @dev Pausable flag for order fill transfers of ERC20 assets
uint256 constant PAUSABLE_ORDER_TRANSFER_FROM_ERC20 = 1 << 7;

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

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

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

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165Upgradeable is Initializable, IERC165 {
    function __ERC165_init() internal onlyInitializing {
    }

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

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

pragma solidity ^0.8.20;

import {IERC721} from "../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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity ^0.8.20;

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

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

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

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

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

pragma solidity ^0.8.20;

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

/**
 * @dev Required interface of an ERC-721 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 ERC-721 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 ERC-721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

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

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

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

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

File 17 of 32 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.20;

/**
 * @title ERC-721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC-721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

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

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/Hashes.sol)

pragma solidity ^0.8.20;

/**
 * @dev Library of standard hash functions.
 *
 * _Available since v5.1._
 */
library Hashes {
    /**
     * @dev Commutative Keccak256 hash of a sorted pair of bytes32. Frequently used when working with merkle proofs.
     *
     * NOTE: Equivalent to the `standardNodeHash` in our https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
     */
    function commutativeKeccak256(bytes32 a, bytes32 b) internal pure returns (bytes32) {
        return a < b ? _efficientKeccak256(a, b) : _efficientKeccak256(b, a);
    }

    /**
     * @dev Implementation of keccak256(abi.encode(a, b)) that doesn't allocate or expand memory.
     */
    function _efficientKeccak256(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
        assembly ("memory-safe") {
            mstore(0x00, a)
            mstore(0x20, b)
            value := keccak256(0x00, 0x40)
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/MerkleProof.sol)
// This file was procedurally generated from scripts/generate/templates/MerkleProof.js.

pragma solidity ^0.8.20;

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

/**
 * @dev These functions deal with verification of Merkle Tree proofs.
 *
 * The tree and the proofs can be generated using our
 * https://github.com/OpenZeppelin/merkle-tree[JavaScript library].
 * You will find a quickstart guide in the readme.
 *
 * WARNING: You should avoid using leaf values that are 64 bytes long prior to
 * hashing, or use a hash function other than keccak256 for hashing leaves.
 * This is because the concatenation of a sorted pair of internal nodes in
 * the Merkle tree could be reinterpreted as a leaf value.
 * OpenZeppelin's JavaScript library generates Merkle trees that are safe
 * against this attack out of the box.
 *
 * IMPORTANT: Consider memory side-effects when using custom hashing functions
 * that access memory in an unsafe way.
 *
 * NOTE: This library supports proof verification for merkle trees built using
 * custom _commutative_ hashing functions (i.e. `H(a, b) == H(b, a)`). Proving
 * leaf inclusion in trees built using non-commutative hashing functions requires
 * additional logic that is not supported by this library.
 */
library MerkleProof {
    /**
     *@dev The multiproof provided is not valid.
     */
    error MerkleProofInvalidMultiproof();

    /**
     * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
     * defined by `root`. For this, a `proof` must be provided, containing
     * sibling hashes on the branch from the leaf to the root of the tree. Each
     * pair of leaves and each pair of pre-images are assumed to be sorted.
     *
     * This version handles proofs in memory with the default hashing function.
     */
    function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
        return processProof(proof, leaf) == root;
    }

    /**
     * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
     * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
     * hash matches the root of the tree. When processing the proof, the pairs
     * of leaves & pre-images are assumed to be sorted.
     *
     * This version handles proofs in memory with the default hashing function.
     */
    function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = Hashes.commutativeKeccak256(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
     * defined by `root`. For this, a `proof` must be provided, containing
     * sibling hashes on the branch from the leaf to the root of the tree. Each
     * pair of leaves and each pair of pre-images are assumed to be sorted.
     *
     * This version handles proofs in memory with a custom hashing function.
     */
    function verify(
        bytes32[] memory proof,
        bytes32 root,
        bytes32 leaf,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bool) {
        return processProof(proof, leaf, hasher) == root;
    }

    /**
     * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
     * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
     * hash matches the root of the tree. When processing the proof, the pairs
     * of leaves & pre-images are assumed to be sorted.
     *
     * This version handles proofs in memory with a custom hashing function.
     */
    function processProof(
        bytes32[] memory proof,
        bytes32 leaf,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = hasher(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
     * defined by `root`. For this, a `proof` must be provided, containing
     * sibling hashes on the branch from the leaf to the root of the tree. Each
     * pair of leaves and each pair of pre-images are assumed to be sorted.
     *
     * This version handles proofs in calldata with the default hashing function.
     */
    function verifyCalldata(bytes32[] calldata proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
        return processProofCalldata(proof, leaf) == root;
    }

    /**
     * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
     * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
     * hash matches the root of the tree. When processing the proof, the pairs
     * of leaves & pre-images are assumed to be sorted.
     *
     * This version handles proofs in calldata with the default hashing function.
     */
    function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = Hashes.commutativeKeccak256(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
     * defined by `root`. For this, a `proof` must be provided, containing
     * sibling hashes on the branch from the leaf to the root of the tree. Each
     * pair of leaves and each pair of pre-images are assumed to be sorted.
     *
     * This version handles proofs in calldata with a custom hashing function.
     */
    function verifyCalldata(
        bytes32[] calldata proof,
        bytes32 root,
        bytes32 leaf,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bool) {
        return processProofCalldata(proof, leaf, hasher) == root;
    }

    /**
     * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
     * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
     * hash matches the root of the tree. When processing the proof, the pairs
     * of leaves & pre-images are assumed to be sorted.
     *
     * This version handles proofs in calldata with a custom hashing function.
     */
    function processProofCalldata(
        bytes32[] calldata proof,
        bytes32 leaf,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = hasher(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a Merkle tree defined by
     * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
     *
     * This version handles multiproofs in memory with the default hashing function.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
     * The `leaves` must be validated independently. See {processMultiProof}.
     */
    function multiProofVerify(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProof(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
     * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
     * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
     * respectively.
     *
     * This version handles multiproofs in memory with the default hashing function.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
     * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
     * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
     *
     * NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
     * and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
     * validating the leaves elsewhere.
     */
    function processMultiProof(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the Merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 proofFlagsLen = proofFlags.length;

        // Check proof validity.
        if (leavesLen + proof.length != proofFlagsLen + 1) {
            revert MerkleProofInvalidMultiproof();
        }

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](proofFlagsLen);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < proofFlagsLen; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = Hashes.commutativeKeccak256(a, b);
        }

        if (proofFlagsLen > 0) {
            if (proofPos != proof.length) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[proofFlagsLen - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a Merkle tree defined by
     * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
     *
     * This version handles multiproofs in memory with a custom hashing function.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
     * The `leaves` must be validated independently. See {processMultiProof}.
     */
    function multiProofVerify(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32 root,
        bytes32[] memory leaves,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bool) {
        return processMultiProof(proof, proofFlags, leaves, hasher) == root;
    }

    /**
     * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
     * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
     * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
     * respectively.
     *
     * This version handles multiproofs in memory with a custom hashing function.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
     * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
     * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
     *
     * NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
     * and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
     * validating the leaves elsewhere.
     */
    function processMultiProof(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32[] memory leaves,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bytes32 merkleRoot) {
        // This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the Merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 proofFlagsLen = proofFlags.length;

        // Check proof validity.
        if (leavesLen + proof.length != proofFlagsLen + 1) {
            revert MerkleProofInvalidMultiproof();
        }

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](proofFlagsLen);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < proofFlagsLen; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = hasher(a, b);
        }

        if (proofFlagsLen > 0) {
            if (proofPos != proof.length) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[proofFlagsLen - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a Merkle tree defined by
     * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
     *
     * This version handles multiproofs in calldata with the default hashing function.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
     * The `leaves` must be validated independently. See {processMultiProofCalldata}.
     */
    function multiProofVerifyCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProofCalldata(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
     * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
     * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
     * respectively.
     *
     * This version handles multiproofs in calldata with the default hashing function.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
     * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
     * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
     *
     * NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
     * and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
     * validating the leaves elsewhere.
     */
    function processMultiProofCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the Merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 proofFlagsLen = proofFlags.length;

        // Check proof validity.
        if (leavesLen + proof.length != proofFlagsLen + 1) {
            revert MerkleProofInvalidMultiproof();
        }

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](proofFlagsLen);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < proofFlagsLen; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = Hashes.commutativeKeccak256(a, b);
        }

        if (proofFlagsLen > 0) {
            if (proofPos != proof.length) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[proofFlagsLen - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @dev Returns true if the `leaves` can be simultaneously proven to be a part of a Merkle tree defined by
     * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
     *
     * This version handles multiproofs in calldata with a custom hashing function.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * NOTE: Consider the case where `root == proof[0] && leaves.length == 0` as it will return `true`.
     * The `leaves` must be validated independently. See {processMultiProofCalldata}.
     */
    function multiProofVerifyCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32 root,
        bytes32[] memory leaves,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bool) {
        return processMultiProofCalldata(proof, proofFlags, leaves, hasher) == root;
    }

    /**
     * @dev Returns the root of a tree reconstructed from `leaves` and sibling nodes in `proof`. The reconstruction
     * proceeds by incrementally reconstructing all inner nodes by combining a leaf/inner node with either another
     * leaf/inner node or a proof sibling node, depending on whether each `proofFlags` item is true or false
     * respectively.
     *
     * This version handles multiproofs in calldata with a custom hashing function.
     *
     * CAUTION: Not all Merkle trees admit multiproofs. To use multiproofs, it is sufficient to ensure that: 1) the tree
     * is complete (but not necessarily perfect), 2) the leaves to be proven are in the opposite order they are in the
     * tree (i.e., as seen from right to left starting at the deepest layer and continuing at the next layer).
     *
     * NOTE: The _empty set_ (i.e. the case where `proof.length == 1 && leaves.length == 0`) is considered a no-op,
     * and therefore a valid multiproof (i.e. it returns `proof[0]`). Consider disallowing this case if you're not
     * validating the leaves elsewhere.
     */
    function processMultiProofCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32[] memory leaves,
        function(bytes32, bytes32) view returns (bytes32) hasher
    ) internal view returns (bytes32 merkleRoot) {
        // This function rebuilds the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the Merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 proofFlagsLen = proofFlags.length;

        // Check proof validity.
        if (leavesLen + proof.length != proofFlagsLen + 1) {
            revert MerkleProofInvalidMultiproof();
        }

        // The xxxPos values are "pointers" to the next value to consume in each array. All accesses are done using
        // `xxx[xxxPos++]`, which return the current value and increment the pointer, thus mimicking a queue's "pop".
        bytes32[] memory hashes = new bytes32[](proofFlagsLen);
        uint256 leafPos = 0;
        uint256 hashPos = 0;
        uint256 proofPos = 0;
        // At each step, we compute the next hash using two values:
        // - a value from the "main queue". If not all leaves have been consumed, we get the next leaf, otherwise we
        //   get the next hash.
        // - depending on the flag, either another value from the "main queue" (merging branches) or an element from the
        //   `proof` array.
        for (uint256 i = 0; i < proofFlagsLen; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = hasher(a, b);
        }

        if (proofFlagsLen > 0) {
            if (proofPos != proof.length) {
                revert MerkleProofInvalidMultiproof();
            }
            unchecked {
                return hashes[proofFlagsLen - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

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

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

pragma solidity ^0.8.20;

import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

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

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

    /**
     * @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        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 success flag (no division by zero).
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

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

    /**
     * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
     *
     * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
     * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
     * one branch when needed, making this function more expensive.
     */
    function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
        unchecked {
            // branchless ternary works because:
            // b ^ (a ^ b) == a
            // b ^ 0 == b
            return b ^ ((a ^ b) * SafeCast.toUint(condition));
        }
    }

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

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

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

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

        // The following calculation ensures accurate ceiling division without overflow.
        // Since a is non-zero, (a - 1) / b will not overflow.
        // The largest possible result occurs when (a - 1) / b is type(uint256).max,
        // but the largest value we can obtain is type(uint256).max - 1, which happens
        // when a = type(uint256).max and b = 1.
        unchecked {
            return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
        }
    }

    /**
     * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     *
     * 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²⁵⁶ and mod 2²⁵⁶ - 1, then use
            // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2²⁵⁶ + prod0.
            uint256 prod0 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

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

            // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
            if (denominator <= prod1) {
                Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
            }

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

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

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

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

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

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

                // Flip twos such that it is 2²⁵⁶ / 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²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
            // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv ≡ 1 mod 2⁴.
            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⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
            inverse *= 2 - denominator * inverse; // inverse mod 2³²
            inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
            inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶

            // 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²⁵⁶. Since the preconditions guarantee that the outcome is
            // less than 2²⁵⁶, 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;
        }
    }

    /**
     * @dev 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) {
        return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
    }

    /**
     * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
     *
     * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
     * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
     *
     * If the input value is not inversible, 0 is returned.
     *
     * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
     * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
     */
    function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
        unchecked {
            if (n == 0) return 0;

            // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
            // Used to compute integers x and y such that: ax + ny = gcd(a, n).
            // When the gcd is 1, then the inverse of a modulo n exists and it's x.
            // ax + ny = 1
            // ax = 1 + (-y)n
            // ax ≡ 1 (mod n) # x is the inverse of a modulo n

            // If the remainder is 0 the gcd is n right away.
            uint256 remainder = a % n;
            uint256 gcd = n;

            // Therefore the initial coefficients are:
            // ax + ny = gcd(a, n) = n
            // 0a + 1n = n
            int256 x = 0;
            int256 y = 1;

            while (remainder != 0) {
                uint256 quotient = gcd / remainder;

                (gcd, remainder) = (
                    // The old remainder is the next gcd to try.
                    remainder,
                    // Compute the next remainder.
                    // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
                    // where gcd is at most n (capped to type(uint256).max)
                    gcd - remainder * quotient
                );

                (x, y) = (
                    // Increment the coefficient of a.
                    y,
                    // Decrement the coefficient of n.
                    // Can overflow, but the result is casted to uint256 so that the
                    // next value of y is "wrapped around" to a value between 0 and n - 1.
                    x - y * int256(quotient)
                );
            }

            if (gcd != 1) return 0; // No inverse exists.
            return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
        }
    }

    /**
     * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
     *
     * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
     * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
     * `a**(p-2)` is the modular multiplicative inverse of a in Fp.
     *
     * NOTE: this function does NOT check that `p` is a prime greater than `2`.
     */
    function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
        unchecked {
            return Math.modExp(a, p - 2, p);
        }
    }

    /**
     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
     *
     * Requirements:
     * - modulus can't be zero
     * - underlying staticcall to precompile must succeed
     *
     * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
     * sure the chain you're using it on supports the precompiled contract for modular exponentiation
     * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
     * the underlying function will succeed given the lack of a revert, but the result may be incorrectly
     * interpreted as 0.
     */
    function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
        (bool success, uint256 result) = tryModExp(b, e, m);
        if (!success) {
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }
        return result;
    }

    /**
     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
     * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
     * to operate modulo 0 or if the underlying precompile reverted.
     *
     * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
     * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
     * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
     * of a revert, but the result may be incorrectly interpreted as 0.
     */
    function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
        if (m == 0) return (false, 0);
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            // | Offset    | Content    | Content (Hex)                                                      |
            // |-----------|------------|--------------------------------------------------------------------|
            // | 0x00:0x1f | size of b  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x20:0x3f | size of e  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x40:0x5f | size of m  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x60:0x7f | value of b | 0x<.............................................................b> |
            // | 0x80:0x9f | value of e | 0x<.............................................................e> |
            // | 0xa0:0xbf | value of m | 0x<.............................................................m> |
            mstore(ptr, 0x20)
            mstore(add(ptr, 0x20), 0x20)
            mstore(add(ptr, 0x40), 0x20)
            mstore(add(ptr, 0x60), b)
            mstore(add(ptr, 0x80), e)
            mstore(add(ptr, 0xa0), m)

            // Given the result < m, it's guaranteed to fit in 32 bytes,
            // so we can use the memory scratch space located at offset 0.
            success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
            result := mload(0x00)
        }
    }

    /**
     * @dev Variant of {modExp} that supports inputs of arbitrary length.
     */
    function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
        (bool success, bytes memory result) = tryModExp(b, e, m);
        if (!success) {
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }
        return result;
    }

    /**
     * @dev Variant of {tryModExp} that supports inputs of arbitrary length.
     */
    function tryModExp(
        bytes memory b,
        bytes memory e,
        bytes memory m
    ) internal view returns (bool success, bytes memory result) {
        if (_zeroBytes(m)) return (false, new bytes(0));

        uint256 mLen = m.length;

        // Encode call args in result and move the free memory pointer
        result = abi.encodePacked(b.length, e.length, mLen, b, e, m);

        assembly ("memory-safe") {
            let dataPtr := add(result, 0x20)
            // Write result on top of args to avoid allocating extra memory.
            success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
            // Overwrite the length.
            // result.length > returndatasize() is guaranteed because returndatasize() == m.length
            mstore(result, mLen)
            // Set the memory pointer after the returned data.
            mstore(0x40, add(dataPtr, mLen))
        }
    }

    /**
     * @dev Returns whether the provided byte array is zero.
     */
    function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
        for (uint256 i = 0; i < byteArray.length; ++i) {
            if (byteArray[i] != 0) {
                return false;
            }
        }
        return true;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * This method is based on Newton's method for computing square roots; the algorithm is restricted to only
     * using integer operations.
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        unchecked {
            // Take care of easy edge cases when a == 0 or a == 1
            if (a <= 1) {
                return a;
            }

            // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
            // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
            // the current value as `ε_n = | x_n - sqrt(a) |`.
            //
            // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
            // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
            // bigger than any uint256.
            //
            // By noticing that
            // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
            // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
            // to the msb function.
            uint256 aa = a;
            uint256 xn = 1;

            if (aa >= (1 << 128)) {
                aa >>= 128;
                xn <<= 64;
            }
            if (aa >= (1 << 64)) {
                aa >>= 64;
                xn <<= 32;
            }
            if (aa >= (1 << 32)) {
                aa >>= 32;
                xn <<= 16;
            }
            if (aa >= (1 << 16)) {
                aa >>= 16;
                xn <<= 8;
            }
            if (aa >= (1 << 8)) {
                aa >>= 8;
                xn <<= 4;
            }
            if (aa >= (1 << 4)) {
                aa >>= 4;
                xn <<= 2;
            }
            if (aa >= (1 << 2)) {
                xn <<= 1;
            }

            // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
            //
            // We can refine our estimation by noticing that the middle of that interval minimizes the error.
            // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
            // This is going to be our x_0 (and ε_0)
            xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)

            // From here, Newton's method give us:
            // x_{n+1} = (x_n + a / x_n) / 2
            //
            // One should note that:
            // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
            //              = ((x_n² + a) / (2 * x_n))² - a
            //              = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
            //              = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
            //              = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
            //              = (x_n² - a)² / (2 * x_n)²
            //              = ((x_n² - a) / (2 * x_n))²
            //              ≥ 0
            // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
            //
            // This gives us the proof of quadratic convergence of the sequence:
            // ε_{n+1} = | x_{n+1} - sqrt(a) |
            //         = | (x_n + a / x_n) / 2 - sqrt(a) |
            //         = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
            //         = | (x_n - sqrt(a))² / (2 * x_n) |
            //         = | ε_n² / (2 * x_n) |
            //         = ε_n² / | (2 * x_n) |
            //
            // For the first iteration, we have a special case where x_0 is known:
            // ε_1 = ε_0² / | (2 * x_0) |
            //     ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
            //     ≤ 2**(2*e-4) / (3 * 2**(e-1))
            //     ≤ 2**(e-3) / 3
            //     ≤ 2**(e-3-log2(3))
            //     ≤ 2**(e-4.5)
            //
            // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
            // ε_{n+1} = ε_n² / | (2 * x_n) |
            //         ≤ (2**(e-k))² / (2 * 2**(e-1))
            //         ≤ 2**(2*e-2*k) / 2**e
            //         ≤ 2**(e-2*k)
            xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5)  -- special case, see above
            xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9)    -- general case with k = 4.5
            xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18)   -- general case with k = 9
            xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36)   -- general case with k = 18
            xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72)   -- general case with k = 36
            xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144)  -- general case with k = 72

            // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
            // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
            // sqrt(a) or sqrt(a) + 1.
            return xn - SafeCast.toUint(xn > a / xn);
        }
    }

    /**
     * @dev 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        uint256 exp;
        unchecked {
            exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
            value >>= exp;
            result += exp;

            exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
            value >>= exp;
            result += exp;

            exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
            value >>= exp;
            result += exp;

            exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
            value >>= exp;
            result += exp;

            exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
            value >>= exp;
            result += exp;

            exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
            value >>= exp;
            result += exp;

            exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
            value >>= exp;
            result += exp;

            result += SafeCast.toUint(value > 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 + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
        }
    }

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

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

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

            isGt = SafeCast.toUint(value > (1 << 64) - 1);
            value >>= isGt * 64;
            result += isGt * 8;

            isGt = SafeCast.toUint(value > (1 << 32) - 1);
            value >>= isGt * 32;
            result += isGt * 4;

            isGt = SafeCast.toUint(value > (1 << 16) - 1);
            value >>= isGt * 16;
            result += isGt * 2;

            result += SafeCast.toUint(value > (1 << 8) - 1);
        }
        return result;
    }

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

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

File 23 of 32 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.20;

/**
 * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeCast {
    /**
     * @dev Value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

    /**
     * @dev An int value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedIntToUint(int256 value);

    /**
     * @dev Value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);

    /**
     * @dev An uint value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedUintToInt(uint256 value);

    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        if (value > type(uint248).max) {
            revert SafeCastOverflowedUintDowncast(248, value);
        }
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        if (value > type(uint240).max) {
            revert SafeCastOverflowedUintDowncast(240, value);
        }
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        if (value > type(uint232).max) {
            revert SafeCastOverflowedUintDowncast(232, value);
        }
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        if (value > type(uint224).max) {
            revert SafeCastOverflowedUintDowncast(224, value);
        }
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        if (value > type(uint216).max) {
            revert SafeCastOverflowedUintDowncast(216, value);
        }
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        if (value > type(uint208).max) {
            revert SafeCastOverflowedUintDowncast(208, value);
        }
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        if (value > type(uint200).max) {
            revert SafeCastOverflowedUintDowncast(200, value);
        }
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        if (value > type(uint192).max) {
            revert SafeCastOverflowedUintDowncast(192, value);
        }
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        if (value > type(uint184).max) {
            revert SafeCastOverflowedUintDowncast(184, value);
        }
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        if (value > type(uint176).max) {
            revert SafeCastOverflowedUintDowncast(176, value);
        }
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        if (value > type(uint168).max) {
            revert SafeCastOverflowedUintDowncast(168, value);
        }
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        if (value > type(uint160).max) {
            revert SafeCastOverflowedUintDowncast(160, value);
        }
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        if (value > type(uint152).max) {
            revert SafeCastOverflowedUintDowncast(152, value);
        }
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        if (value > type(uint144).max) {
            revert SafeCastOverflowedUintDowncast(144, value);
        }
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        if (value > type(uint136).max) {
            revert SafeCastOverflowedUintDowncast(136, value);
        }
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        if (value > type(uint128).max) {
            revert SafeCastOverflowedUintDowncast(128, value);
        }
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        if (value > type(uint120).max) {
            revert SafeCastOverflowedUintDowncast(120, value);
        }
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        if (value > type(uint112).max) {
            revert SafeCastOverflowedUintDowncast(112, value);
        }
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        if (value > type(uint104).max) {
            revert SafeCastOverflowedUintDowncast(104, value);
        }
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        if (value > type(uint96).max) {
            revert SafeCastOverflowedUintDowncast(96, value);
        }
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        if (value > type(uint88).max) {
            revert SafeCastOverflowedUintDowncast(88, value);
        }
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        if (value > type(uint80).max) {
            revert SafeCastOverflowedUintDowncast(80, value);
        }
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        if (value > type(uint72).max) {
            revert SafeCastOverflowedUintDowncast(72, value);
        }
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        if (value > type(uint64).max) {
            revert SafeCastOverflowedUintDowncast(64, value);
        }
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        if (value > type(uint56).max) {
            revert SafeCastOverflowedUintDowncast(56, value);
        }
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        if (value > type(uint48).max) {
            revert SafeCastOverflowedUintDowncast(48, value);
        }
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        if (value > type(uint40).max) {
            revert SafeCastOverflowedUintDowncast(40, value);
        }
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        if (value > type(uint32).max) {
            revert SafeCastOverflowedUintDowncast(32, value);
        }
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        if (value > type(uint24).max) {
            revert SafeCastOverflowedUintDowncast(24, value);
        }
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        if (value > type(uint16).max) {
            revert SafeCastOverflowedUintDowncast(16, value);
        }
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        if (value > type(uint8).max) {
            revert SafeCastOverflowedUintDowncast(8, value);
        }
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        if (value < 0) {
            revert SafeCastOverflowedIntToUint(value);
        }
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(248, value);
        }
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(240, value);
        }
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(232, value);
        }
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(224, value);
        }
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(216, value);
        }
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(208, value);
        }
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(200, value);
        }
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(192, value);
        }
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(184, value);
        }
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(176, value);
        }
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(168, value);
        }
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(160, value);
        }
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(152, value);
        }
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(144, value);
        }
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(136, value);
        }
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(128, value);
        }
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(120, value);
        }
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(112, value);
        }
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(104, value);
        }
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(96, value);
        }
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(88, value);
        }
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(80, value);
        }
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(72, value);
        }
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(64, value);
        }
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(56, value);
        }
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(48, value);
        }
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(40, value);
        }
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(32, value);
        }
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(24, value);
        }
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(16, value);
        }
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(8, value);
        }
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        if (value > uint256(type(int256).max)) {
            revert SafeCastOverflowedUintToInt(value);
        }
        return int256(value);
    }

    /**
     * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
     */
    function toUint(bool b) internal pure returns (uint256 u) {
        assembly ("memory-safe") {
            u := iszero(iszero(b))
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
     *
     * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
     * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
     * one branch when needed, making this function more expensive.
     */
    function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
        unchecked {
            // branchless ternary works because:
            // b ^ (a ^ b) == a
            // b ^ 0 == b
            return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
        }
    }

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

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

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

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
            // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
            // taking advantage of the most significant (or "sign" bit) in two's complement representation.
            // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
            // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
            int256 mask = n >> 255;

            // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
            return uint256((n + mask) ^ mask);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)

pragma solidity ^0.8.20;

/**
 * @dev Helper library for emitting standardized panic codes.
 *
 * ```solidity
 * contract Example {
 *      using Panic for uint256;
 *
 *      // Use any of the declared internal constants
 *      function foo() { Panic.GENERIC.panic(); }
 *
 *      // Alternatively
 *      function foo() { Panic.panic(Panic.GENERIC); }
 * }
 * ```
 *
 * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
 *
 * _Available since v5.1._
 */
// slither-disable-next-line unused-state
library Panic {
    /// @dev generic / unspecified error
    uint256 internal constant GENERIC = 0x00;
    /// @dev used by the assert() builtin
    uint256 internal constant ASSERT = 0x01;
    /// @dev arithmetic underflow or overflow
    uint256 internal constant UNDER_OVERFLOW = 0x11;
    /// @dev division or modulo by zero
    uint256 internal constant DIVISION_BY_ZERO = 0x12;
    /// @dev enum conversion error
    uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
    /// @dev invalid encoding in storage
    uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
    /// @dev empty array pop
    uint256 internal constant EMPTY_ARRAY_POP = 0x31;
    /// @dev array out of bounds access
    uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
    /// @dev resource error (too large allocation or too large array)
    uint256 internal constant RESOURCE_ERROR = 0x41;
    /// @dev calling invalid internal function
    uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;

    /// @dev Reverts with a panic code. Recommended to use with
    /// the internal constants with predefined codes.
    function panic(uint256 code) internal pure {
        assembly ("memory-safe") {
            mstore(0x00, 0x4e487b71)
            mstore(0x20, code)
            revert(0x1c, 0x24)
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

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

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

    uint256 private _status;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

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

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

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
     * representation, according to EIP-55.
     */
    function toChecksumHexString(address addr) internal pure returns (string memory) {
        bytes memory buffer = bytes(toHexString(addr));

        // hash the hex part of buffer (skip length + 2 bytes, length 40)
        uint256 hashValue;
        assembly ("memory-safe") {
            hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
        }

        for (uint256 i = 41; i > 1; --i) {
            // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
            if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
                // case shift by xoring with 0x20
                buffer[i] ^= 0x20;
            }
            hashValue >>= 4;
        }
        return string(buffer);
    }

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

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

library Address {
    function isContract(address account) internal view returns (bool) {
        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }
}

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

import "@limitbreak/creator-token-standards/src/utils/AutomaticValidatorTransferApproval.sol";
import "@limitbreak/creator-token-standards/src/utils/CreatorTokenBase.sol";
import "./ERC721Upgradeable.sol";
import "@limitbreak/creator-token-standards/src/interfaces/ITransferValidatorSetTokenType.sol";
import {TOKEN_TYPE_ERC721} from "@limitbreak/permit-c/src/Constants.sol";

/**
 * @title ERC721C
 * @author Limit Break, Inc.
 * @notice Extends OpenZeppelin's ERC721 implementation with Creator Token functionality, which
 *         allows the contract owner to update the transfer validation logic by managing a security policy in
 *         an external transfer validation security policy registry.  See {CreatorTokenTransferValidator}.
 */
abstract contract ERC721C is
    ERC721Upgradeable,
    CreatorTokenBase,
    AutomaticValidatorTransferApproval
{
    /**
     * @dev Override _msgData to resolve conflict between base classes.
     */
    function _msgData()
        internal
        view
        virtual
        override(Context, ContextUpgradeable)
        returns (bytes calldata)
    {
        return super._msgData(); // You can choose either ContextUpgradeable._msgData() or OwnableUpgradeable._msgData().
    }

    /**
     * @dev Override _msgSender to resolve conflict between base classes.
     */
    function _msgSender()
        internal
        view
        virtual
        override(Context, ContextUpgradeable)
        returns (address)
    {
        return super._msgSender(); // You can choose ContextUpgradeable._msgSender() or OwnableUpgradeable._msgSender().
    }

    function _contextSuffixLength()
        internal
        view
        virtual
        override(ContextUpgradeable, Context)
        returns (uint256)
    {
        return 0;
    }

    /**
     * @notice Overrides behavior of isApprovedFor all such that if an operator is not explicitly approved
     *         for all, the contract owner can optionally auto-approve the 721-C transfer validator for transfers.
     */
    function isApprovedForAll(
        address owner,
        address operator
    ) public view virtual override returns (bool isApproved) {
        isApproved = super.isApprovedForAll(owner, operator);

        if (!isApproved) {
            if (autoApproveTransfersFromValidator) {
                isApproved = operator == address(getTransferValidator());
            }
        }
    }

    /**
     * @notice Indicates whether the contract implements the specified interface.
     * @dev Overrides supportsInterface in ERC165.
     * @param interfaceId The interface id
     * @return true if the contract implements the specified interface, false otherwise
     */
    function supportsInterface(
        bytes4 interfaceId
    ) public view virtual override returns (bool) {
        return
            interfaceId == type(ICreatorToken).interfaceId ||
            interfaceId == type(ICreatorTokenLegacy).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @notice Returns the function selector for the transfer validator's validation function to be called
     * @notice for transaction simulation.
     */
    function getTransferValidationFunction()
        external
        pure
        returns (bytes4 functionSignature, bool isViewFunction)
    {
        functionSignature = bytes4(
            keccak256("validateTransfer(address,address,address,uint256)")
        );
        isViewFunction = true;
    }

    /// @dev Ties the _beforeTokenTransfer hook to transfer validation logic.
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 firstTokenId,
        uint256 batchSize
    ) internal virtual override {
        super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
        for (uint256 i = 0; i < batchSize; ) {
            _validateBeforeTransfer(from, to, firstTokenId + i);
            unchecked {
                ++i;
            }
        }
    }

    /// @dev Ties the _afterTokenTransfer hook to transfer validation logic.
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 firstTokenId,
        uint256 batchSize
    ) internal virtual override {
        super._afterTokenTransfer(from, to, firstTokenId, batchSize);
        for (uint256 i = 0; i < batchSize; ) {
            _validateAfterTransfer(from, to, firstTokenId + i);
            unchecked {
                ++i;
            }
        }
    }

    function _tokenType() internal pure override returns (uint16) {
        return uint16(TOKEN_TYPE_ERC721);
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.13;

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

/**
 * @dev This implements an optional extension of {ERC721} defined in the EIP that adds
 * enumerability of all the token ids in the contract as well as all token ids owned by each
 * account but rips out the core of the gas-wasting processing that comes from OpenZeppelin.
 */
abstract contract ERC721EnumerableUpgradeable is ERC721C, IERC721Enumerable {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(
        bytes4 interfaceId
    ) public view virtual override(ERC721C, IERC165) returns (bool) {
        return
            interfaceId == type(IERC721Enumerable).interfaceId || // ERC721 Enumerable
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721Enumerable-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _owners.length;
    }

    /**
     * @dev See {IERC721Enumerable-tokenByIndex}.
     */
    function tokenByIndex(
        uint256 index
    ) public view virtual override returns (uint256) {
        require(
            index < totalSupply(),
            "ERC721Enumerable: global index out of bounds"
        );

        uint256 tokenId;
        uint256 count = 0;

        // Iterate over normal token range
        for (tokenId = 0; tokenId < _owners.length; tokenId++) {
            if (_exists(tokenId)) {
                if (count == index) {
                    return tokenId;
                }
                count++;
            }
        }

        revert("ERC721Enumerable: global index out of bounds");
    }

    /**
     * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
     */
    function tokenOfOwnerByIndex(
        address owner,
        uint256 index
    ) public view virtual override returns (uint256 tokenId) {
        require(
            index < balanceOf(owner),
            "ERC721Enumerable: owner index out of bounds"
        );

        uint256 count;
        for (uint256 i = 0; i < _owners.length; i++) {
            if (owner == _owners[i]) {
                if (count == index) return i;
                // Token ID for normal tokens
                else count++;
            }
        }

        revert("ERC721Enumerable: owner index out of bounds");
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol";
import "./Address.sol";

/**
 * @dev Implementation of the {IERC721} interface.
 * This is an upgradeable version of the ERC721 contract.
 */
abstract contract ERC721Upgradeable is
    ContextUpgradeable,
    ERC165Upgradeable,
    IERC721,
    IERC721Metadata
{
    using Address for address;
    using Strings for uint256;

    string private _name;
    string private _symbol;

    // Mapping from token ID to owner address
    address[] internal _owners;

    mapping(uint256 => address) private _tokenApprovals;
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     * @param name_ The name of the token.
     * @param symbol_ The symbol of the token.
     */
    function __ERC721_init(
        string memory name_,
        string memory symbol_
    ) internal onlyInitializing {
        __ERC721_init_unchained(name_, symbol_);
    }

    function __ERC721_init_unchained(
        string memory name_,
        string memory symbol_
    ) internal onlyInitializing {
        _name = name_;
        _symbol = symbol_;
    }

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

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(
        address owner
    ) public view virtual override returns (uint256) {
        require(
            owner != address(0),
            "ERC721: balance query for the zero address"
        );

        uint256 count;
        for (uint256 i; i < _owners.length; ++i) {
            if (owner == _owners[i]) ++count;
        }

        return count;
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(
        uint256 tokenId
    ) public view virtual override returns (address) {
        require(_exists(tokenId), "ERC721: owner query for nonexistent token");
        return _owners[tokenId];
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(
            _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not owner nor approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(
        uint256 tokenId
    ) public view virtual override returns (address) {
        require(
            _exists(tokenId),
            "ERC721: approved query for nonexistent token"
        );

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(
        address operator,
        bool approved
    ) public virtual override {
        require(operator != _msgSender(), "ERC721: approve to caller");

        _operatorApprovals[_msgSender()][operator] = approved;
        emit ApprovalForAll(_msgSender(), operator, approved);
    }

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

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        //solhint-disable-next-line max-line-length
        require(
            _isApprovedOrOwner(_msgSender(), tokenId),
            "ERC721: transfer caller is not owner nor approved"
        );

        _transfer(from, to, tokenId);
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) public virtual override {
        require(
            _isApprovedOrOwner(_msgSender(), tokenId),
            "ERC721: transfer caller is not owner nor approved"
        );
        _safeTransfer(from, to, tokenId, _data);
    }

    /**
     * @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.
     *
     * `_data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) internal virtual {
        _transfer(from, to, tokenId);
        require(
            _checkOnERC721Received(from, to, tokenId, _data),
            "ERC721: transfer to non ERC721Receiver implementer"
        );
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 tokenId) internal view virtual returns (bool) {
        return tokenId < _owners.length && _owners[tokenId] != address(0);
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(
        address spender,
        uint256 tokenId
    ) internal view virtual returns (bool) {
        require(
            _exists(tokenId),
            "ERC721: operator query for nonexistent token"
        );
        address owner = ownerOf(tokenId);
        return (spender == owner ||
            getApproved(tokenId) == spender ||
            isApprovedForAll(owner, spender));
    }

    /**
     * @dev Safely mints `tokenId` and transfers it to `to`.
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal virtual {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(
        address to,
        uint256 tokenId,
        bytes memory _data
    ) internal virtual {
        _mint(to, tokenId);
        require(
            _checkOnERC721Received(address(0), to, tokenId, _data),
            "ERC721: transfer to non ERC721Receiver implementer"
        );
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId, 1);

        _owners.push(to);

        emit Transfer(address(0), to, tokenId);

        _afterTokenTransfer(address(0), to, tokenId, 1);
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {
        require(
            ERC721Upgradeable.ownerOf(tokenId) == from,
            "ERC721: transfer of token that is not own"
        );
        require(to != address(0), "ERC721: transfer to the zero address");

        _beforeTokenTransfer(from, to, tokenId, 1);

        // Clear approvals from the previous owner
        _approve(address(0), tokenId);

        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);

        _afterTokenTransfer(from, to, tokenId, 1);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits a {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(ERC721Upgradeable.ownerOf(tokenId), to, tokenId);
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
     * The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param _data bytes optional data to send along with the call
     * @return bool whether the call correctly returned the expected magic value
     */
    function _checkOnERC721Received(
        address from,
        address to,
        uint256 tokenId,
        bytes memory _data
    ) private returns (bool) {
        if (to.isContract()) {
            try
                IERC721Receiver(to).onERC721Received(
                    _msgSender(),
                    from,
                    tokenId,
                    _data
                )
            returns (bytes4 retval) {
                return retval == IERC721Receiver.onERC721Received.selector;
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert(
                        "ERC721: transfer to non ERC721Receiver implementer"
                    );
                } else {
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        } else {
            return true;
        }
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, ``from``'s `tokenId` will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 firstTokenId,
        uint256 batchSize
    ) internal virtual {}

    function _afterTokenTransfer(
        address from,
        address to,
        uint256 firstTokenId,
        uint256 batchSize
    ) internal virtual {}
}

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

pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.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(address _ownerOnInit) internal onlyInitializing {
        __Ownable_init_unchained(_ownerOnInit);
    }

    function __Ownable_init_unchained(
        address _ownerOnInit
    ) internal onlyInitializing {
        _transferOwnership(_ownerOnInit);
    }

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        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;
}

Settings
{
  "viaIR": true,
  "optimizer": {
    "enabled": true,
    "runs": 50,
    "details": {
      "yul": true
    }
  },
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[],"name":"CreatorTokenBase__InvalidTransferValidatorContract","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[],"name":"ShouldNotMintToBurnAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newEndTime","type":"uint256"}],"name":"AuctionExtended","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"autoApproved","type":"bool"}],"name":"AutomaticApprovalOfTransferValidatorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"bidder","type":"address"},{"indexed":false,"internalType":"uint32","name":"bidId","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"BidSubmitted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"bidder","type":"address"},{"indexed":false,"internalType":"uint32","name":"bidId","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"newAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"BidUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldValidator","type":"address"},{"indexed":false,"internalType":"address","name":"newValidator","type":"address"}],"name":"TransferValidatorUpdated","type":"event"},{"inputs":[],"name":"DEFAULT_TRANSFER_VALIDATOR","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"},{"internalType":"address","name":"a","type":"address"}],"name":"allowListMint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"gmDaoTokenIds","type":"uint256[]"}],"name":"areDiscountsUsed","outputs":[{"internalType":"bool[]","name":"","type":"bool[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"auctionEndTimeStamp","outputs":[{"internalType":"uint56","name":"","type":"uint56"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"autoApproveTransfersFromValidator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bidCount","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"}],"name":"bidNodes","outputs":[{"internalType":"address","name":"bidder","type":"address"},{"internalType":"uint256","name":"data","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32[]","name":"bidIds","type":"uint32[]"},{"internalType":"uint256[]","name":"gmDaoTokenIds","type":"uint256[]"},{"internalType":"address","name":"a","type":"address"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"startId","type":"uint32"},{"internalType":"uint32","name":"count","type":"uint32"}],"name":"getBidNodes","outputs":[{"components":[{"internalType":"address","name":"bidder","type":"address"},{"internalType":"uint256","name":"data","type":"uint256"}],"internalType":"struct GmStudioRankedAuction.BidNode[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCutoffBidAmount","outputs":[{"internalType":"uint96","name":"cutoffAmount","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint96","name":"bid","type":"uint96"}],"name":"getEstimatedNodeId","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTransferValidationFunction","outputs":[{"internalType":"bytes4","name":"functionSignature","type":"bytes4"},{"internalType":"bool","name":"isViewFunction","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getTransferValidator","outputs":[{"internalType":"address","name":"validator","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"string","name":"tokenBase","type":"string"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"},{"internalType":"address","name":"gmV3Contract","type":"address"},{"internalType":"uint96","name":"royalty","type":"uint96"},{"internalType":"address payable","name":"ownerAddress","type":"address"},{"internalType":"uint96","name":"gmDiscount","type":"uint96"},{"internalType":"address payable","name":"royaltyAddress","type":"address"},{"internalType":"uint96","name":"minBid","type":"uint96"},{"internalType":"address payable","name":"artistAddress","type":"address"},{"internalType":"uint96","name":"allowListPrice","type":"uint96"},{"internalType":"address payable","name":"gmDaoAddress","type":"address"},{"internalType":"uint56","name":"auctionStartTimeStamp","type":"uint56"},{"internalType":"uint32","name":"maxSupply","type":"uint32"},{"internalType":"address","name":"delegateRegistry","type":"address"},{"internalType":"uint56","name":"allowListStartTimeStamp","type":"uint56"},{"internalType":"uint32","name":"auctionDuration","type":"uint32"},{"internalType":"uint32","name":"auctionExtension","type":"uint32"},{"internalType":"uint32","name":"auctionExtenderTimeFrame","type":"uint32"},{"internalType":"uint32","name":"maxAuctionExtension","type":"uint32"},{"internalType":"uint24","name":"gmDaoShare","type":"uint24"}],"internalType":"struct GmStudioRankedAuction.Project","name":"_p","type":"tuple"}],"name":"initProject","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"isApproved","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSupply","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint24","name":"count","type":"uint24"},{"internalType":"address","name":"a","type":"address"}],"name":"ownerMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"estimatedNodePositionId","type":"uint32"}],"name":"placeBid","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint24","name":"count","type":"uint24"},{"internalType":"address","name":"a","type":"address"}],"name":"publicMint","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"_salePrice","type":"uint256"}],"name":"royaltyInfo","outputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"royaltyAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint96","name":"_allowListPrice","type":"uint96"}],"name":"setALPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint56","name":"_allowListStartTimeStamp","type":"uint56"}],"name":"setALStart","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_allowPublic","type":"bool"}],"name":"setAllowPublic","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_auctionDuration","type":"uint32"}],"name":"setAuctionDuration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint56","name":"_auctionStartTimeStamp","type":"uint56"}],"name":"setAuctionStart","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"autoApprove","type":"bool"}],"name":"setAutomaticApprovalOfTransfersFromValidator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint96","name":"_gmDiscount","type":"uint96"}],"name":"setGmDiscount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_maxSupply","type":"uint32"}],"name":"setMaxSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_merkleRoot","type":"bytes32"}],"name":"setMerkleRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint96","name":"_minBid","type":"uint96"}],"name":"setMinBid","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint96","name":"_royalty","type":"uint96"}],"name":"setRoyalty","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_royaltyAddress","type":"address"}],"name":"setRoyaltyAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_tokenBase","type":"string"}],"name":"setTokenBase","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"transferValidator_","type":"address"}],"name":"setTransferValidator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"bidId","type":"uint32"},{"internalType":"uint32","name":"estimatedNodePositionId","type":"uint32"}],"name":"updateBid","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"walletOfOwner","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60808060405234620000d5576000908181527fcc5dc080ff977b3c3a211fa63ab74f90f658f5ba9d3236e92c8f59570f442aac604073721c002b0059009a671d00ad1700c9748146cd1b92836020820152a1803b6200006e575b6001603855604051615d649081620000db8239f35b8082913b15620000d257819060446040518095819363fb2de5d760e01b83523060048401526102d160248401525af11562000059576001600160401b038211620000be5750604052388062000059565b634e487b7160e01b81526041600452602490fd5b50fd5b600080fdfe6080604052600436101561001257600080fd5b60003560e01c8063014635461461038757806301ffc9a71461038257806306d254da1461037d57806306fdde0314610378578063081812fc14610373578063095ea7b31461036e578063098144d4146103695780630d705df6146103645780630e910d391461035f57806318160ddd1461035a57806323b872dd146103555780632a55205a146103505780632ed56f361461034b5780632f745c591461034657806335a83013146103415780633a7cb0861461033c5780633ccfd60b1461033757806342842e0e14610332578063438b63001461032d578063455d9ac4146103285780634f6ccce7146103235780634f808dc21461031e5780635077ee24146103195780636221d13c146103145780636352211e1461030f578063665155c01461030a57806370a0823114610305578063715018a614610300578063738cba9a146102fb57806378491b1b146102f65780637cb64759146102f15780637fd67d49146102ec578063816403a1146102e7578063881c632c146102e25780638da5cb5b146102dd578063916358a3146102d857806393803fdf146102d357806395d89b41146102ce5780639df742d7146102c95780639e05d240146102c4578063a22cb465146102bf578063a9fc664e146102ba578063b0153d5e146102b5578063b40a5627146102b0578063b88d4fde146102ab578063c87b56dd146102a6578063cac92669146102a1578063ccb1038a1461029c578063d5abeb0114610297578063d8d472d814610292578063e985e9c51461028d578063f2fde38b14610288578063f9da322414610283578063fafe3a201461027e5763fdca172e1461027957600080fd5b612707565b6125f8565b612493565b6123f9565b6123bb565b612386565b61235f565b61221e565b61218e565b611ff0565b611f89565b611e7c565b611caa565b611be9565b611afd565b611a91565b61191a565b611895565b611840565b611703565b6116da565b611604565b61156e565b6114a6565b611400565b611276565b61119c565b61113b565b611114565b6110ea565b6110cc565b6110a6565b610f9e565b610ee6565b610ec8565b610d1e565b610ca7565b610c7f565b610b70565b610ac9565b610a0b565b6109ce565b610903565b6108a5565b61087c565b610832565b610805565b6107dd565b6107c2565b6106a3565b610673565b6105b6565b6104cf565b6103dd565b61039c565b600091031261039757565b600080fd5b3461039757600036600319011261039757602060405173721c002b0059009a671d00ad1700c9748146cd1b8152f35b6001600160e01b031981160361039757565b346103975760203660031901126103975761042b6004356103fd816103cb565b63ffffffff60e01b1663152a902d60e11b811490811561042f575b5060405190151581529081906020820190565b0390f35b63780e9d6360e01b811491508115610449575b5038610418565b632b435fdb60e21b8114915081156104ad575b811561046a575b5038610442565b6380ac58cd60e01b81149150811561049c575b811561048b575b5038610463565b6301ffc9a760e01b14905038610484565b635b5e139f60e01b8114915061047d565b63503e914d60e11b8114915061045c565b6001600160a01b0381160361039757565b34610397576020366003190112610397576004356104ec816104be565b6006546001600160a01b03919061050690831633146135df565b16801561052357604880546001600160a01b031916919091179055005b60405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b6044820152606490fd5b60005b83811061056d5750506000910152565b818101518382015260200161055d565b906020916105968151809281855285808601910161055a565b601f01601f1916010190565b9060206105b392818152019061057d565b90565b3461039757600080600319360112610670576040518180546105d781612be2565b80845290600190818116908115610648575060011461060d575b61042b8461060181880382611f07565b604051918291826105a2565b93508180526020938483205b828410610635575050508161042b9361060192820101936105f1565b8054858501870152928501928101610619565b61042b96506106019450602092508593915060ff191682840152151560051b820101936105f1565b80fd5b34610397576020366003190112610397576020610691600435615401565b6040516001600160a01b039091168152f35b34610397576040366003190112610397576004356106c0816104be565b6024356106cc81615370565b6001600160a01b038181169084168114610773573314908115610761575b50156106fb576106f991615acd565b005b60405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f776044820152771b995c881b9bdc88185c1c1c9bdd995908199bdc88185b1b60421b6064820152608490fd5b61076d91503390614f55565b386106ea565b60405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608490fd5b34610397576000366003190112610397576020610691612b02565b34610397576000366003190112610397576040805163657711f560e11b815260016020820152f35b34610397576000366003190112610397576020610820614698565b6040516001600160601b039091168152f35b34610397576000366003190112610397576020600254604051908152f35b606090600319011261039757600435610868816104be565b90602435610875816104be565b9060443590565b34610397576106f961088d36610850565b916108a061089b84336155ae565b615484565b615937565b346103975760403660031901126103975760018060a01b03604854166127106108d560465460a01c602435614995565b604080516001600160a01b03949094168452919004602083015290f35b6001600160601b0381160361039757565b3461039757602036600319011261039757600435610920816108f2565b61093560018060a01b036006541633146135df565b6127106001600160601b03821611610989576106f99061096466ffffffffffffff604a5460a01c164210614d68565b604780546001600160a01b031660a09290921b6001600160a01b031916919091179055565b60405162461bcd60e51b815260206004820152601c60248201527f446973636f756e742070657263656e7461676520746f6f2068696768000000006044820152606490fd5b346103975760403660031901126103975760206109f96004356109f0816104be565b602435906150ef565b604051908152f35b8015150361039757565b3461039757602036600319011261039757600435610a2881610a01565b610a3d60018060a01b036006541633146135df565b6041805460ff60401b191691151560401b60ff60401b16919091179055005b9181601f84011215610397578235916001600160401b038311610397576020808501948460051b01011161039757565b6020908160408183019282815285518094520193019160005b828110610ab3575050505090565b8351151585529381019392810192600101610aa5565b34610397576020366003190112610397576004356001600160401b03811161039757610af9903690600401610a5c565b90610b03826136eb565b91610b116040519384611f07565b808352601f19610b20826136eb565b0136602085013760005b818110610b3f576040518061042b8682610a8c565b80610b57610b51610b6b9385876148b4565b35614ae4565b610b61828761390a565b90151590526138e5565b610b2a565b3461039757600036600319011261039757610b9660018060a01b036006541633146135df565b610b9e613b51565b60405466ffffffffffffff8160601c1642119081610c6d575b50610c60575b603f54610bcb811515614ec6565b610bd56000603f55565b610c10610c09610c01610bfb610bf3604c5462ffffff9060601c1690565b62ffffff1690565b84614995565b612710900490565b8092613b2f565b9080610c44575b5080610c28575b6106f96001603855565b604954610c3e91906001600160a01b0316614b7a565b38610c1e565b604a54610c5a91906001600160a01b0316614b7a565b38610c17565b610c686149c1565b610bbd565b6001600160601b031615905038610bb7565b34610397576106f9610c9036610850565b9060405192610c9e84611eec565b600084526154ea565b346103975760208060031936011261039757610ccd600435610cc8816104be565b614bdb565b906040519181839283018184528251809152816040850193019160005b828110610cf957505050500390f35b835185528695509381019392810192600101610cea565b63ffffffff81160361039757565b602036600319011261039757600435610d3681610d10565b610d3e613b51565b604a54610e2e610dfa66ffffffffffffff92610d61848260a01c16421015613a44565b610dd960405491610d9263ffffffff96878560b81c1694610d86868a8c161115613a7e565b60601c16421115613ab9565b610db8610db0610da460485460a01c90565b6001600160601b031690565b341015613af5565b610dc332331461384e565b610dcb614698565b956002549160d81c16613b2f565b93848210610eb357610df5906001600160601b03163411613af5565b613b3c565b6040805463ffffffff60b81b191660b883901b63ffffffff60b81b16179055923390346001600160601b0316908590613ff1565b604054610e489060b81c63ffffffff165b63ffffffff1690565b11610ea6575b610e56614718565b6040805163ffffffff9092168252346020830152429082015233907f025ecfc771110b33a5a72dd787c154336f05caa0447910a403028333139b75ec9080606081015b0390a26106f96001603855565b610eae614571565b610e4e565b610df5906001600160601b0316341015613af5565b346103975760203660031901126103975760206109f9600435614ffe565b3461039757602036600319011261039757600435610f03816108f2565b610f1860018060a01b036006541633146135df565b63ffffffff610f3381604a5460d81c1682600254169061362a565b60405460b81c821691161115610f4c576106f99061306b565b60405162461bcd60e51b8152602060048201526019602482015278115b9bdd59da081dda5b9b9a5b99c8189a591cc8195e1a5cdd603a1b6044820152606490fd5b66ffffffffffffff81160361039757565b3461039757602036600319011261039757600435610fbb81610f8d565b610fd060018060a01b036006541633146135df565b66ffffffffffffff610fea81604a5460a01c164210614dc5565b80604b5460a01c169082161061106557611003906130e4565b6106f961103a61101f604a5466ffffffffffffff9060a01c1690565b604b546110349060d81c63ffffffff16610e3f565b9061344a565b6040805466ffffffffffffff60601b191660609290921b66ffffffffffffff60601b16919091179055565b60405162461bcd60e51b815260206004820152601960248201527814dd185c9d0818d85b9b9bdd081899481899599bdc99481053603a1b6044820152606490fd5b3461039757600036600319011261039757602060ff60055460a81c166040519015158152f35b34610397576020366003190112610397576020610691600435615370565b3461039757600036600319011261039757602066ffffffffffffff60405460601c16604051908152f35b346103975760203660031901126103975760206109f9600435611136816104be565b6152bb565b34610397576000806003193601126106705760065481906001600160a01b038116906111683383146135df565b6001600160a01b0319166006557f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b34610397576020366003190112610397576004356111b981610d10565b6111ce60018060a01b036006541633146135df565b6111e766ffffffffffffff604a5460a01c164210614dc5565b63ffffffff80604b5460d81c1690821611156112065761100390613119565b60405162461bcd60e51b815260206004820152601660248201527526bab9ba1034b731b932b0b9b290323ab930ba34b7b760511b6044820152606490fd5b62ffffff81160361039757565b60409060031901126103975760043561126981611244565b906024356105b3816104be565b346103975761128436611251565b9061129a60018060a01b036006541633146135df565b604a546112ba9060a01c66ffffffffffffff165b66ffffffffffffff1690565b421015806113df575b6113a05760405466ffffffffffffff8160601c164211908161138e575b50611381575b60025461133762ffffff61132c610e3f600060405460018060601b038116611358575b50604a546113279060d81c63ffffffff1663ffffffff88169061362a565b61362a565b931692831115613640565b60005b82811061134357005b806113526001928401866156a7565b0161133a565b61137b915063ffffffff61137160415463ffffffff1690565b9160d81c1661362a565b38611309565b6113896149c1565b6112e6565b6001600160601b0316159050386112e0565b60405162461bcd60e51b815260206004820152601360248201527241756374696f6e20696e2070726f677265737360681b6044820152606490fd5b0390fd5b506040546113f89060601c66ffffffffffffff166112ae565b4211156112c3565b346103975760203660031901126103975761142660018060a01b036006541633146135df565b600435604555005b60409060031901126103975760043561144681610d10565b906024356105b381610d10565b60208082019080835283518092528060408094019401926000905b83821061147d57505050505090565b845180516001600160a01b0316875283015186840152948501949382019360019091019061146e565b34610397576114b43661142e565b63ffffffff809116916114c6836136eb565b9060406114d581519384611f07565b848352601f196114e4866136eb565b0160005b81811061154a57505060005b8481168681101561153d57906115326115389261152161151c611517858961497d565b61182a565b614b23565b61152b828961390a565b528661390a565b50613b3c565b6114f4565b82518061042b8782611453565b602090835161155881611eb9565b60008152826000818301528288010152016114e8565b346103975760203660031901126103975760043561158b816108f2565b6115a060018060a01b036006541633146135df565b66ffffffffffffff604b5460a01c164210156115bf576106f990613090565b60405162461bcd60e51b815260206004820152601e60248201527f416c6c6f776c697374206d696e7420616c7265616479207374617274656400006044820152606490fd5b346103975760203660031901126103975760043561162181610f8d565b61163660018060a01b036006541633146135df565b66ffffffffffffff9081604b5460a01c164210156116a3576116786106f99261166e6112ae604a5466ffffffffffffff9060a01c1690565b9083161115614e0b565b604b805466ffffffffffffff60a01b191660a09290921b66ffffffffffffff60a01b16919091179055565b60405162461bcd60e51b815260206004820152600f60248201526e1053081b5a5b9d081cdd185c9d1959608a1b6044820152606490fd5b34610397576000366003190112610397576006546040516001600160a01b039091168152602090f35b3461039757602080600319360112610397576001600160401b03600435818111610397573660238201121561039757806004013591821161039757602490368284830101116103975761176160018060a01b036006541633146135df565b61177583611770604454612be2565b612c6f565b600093601f84116001146117b657509282936000936117a9575b505050600019600383901b1c191660019190911b17604455005b010135905038808061178f565b6044600052601f19841694600080516020615cef833981519152939181905b87821061181057505084600196106117f4575b50505050811b01604455005b60001960f88660031b161c1992010135169055388080806117e8565b8060018497868395968901013581550196019201906117d5565b63ffffffff166000526039602052604060002090565b346103975760203660031901126103975763ffffffff60043561186281610d10565b16600090815260396020908152604091829020805460019091015483516001600160a01b03909216825291810191909152f35b3461039757600080600319360112610670576040518160018054906118b982612be2565b8085529181811690811561064857506001146118df5761042b8461060181880382611f07565b80945082526020938483205b828410611907575050508161042b9361060192820101936105f1565b80548585018701529285019281016118eb565b6040366003190112610397576004356001600160401b038111610397576119486106f9913690600401610a5c565b6119e26119dd6024359261195b846104be565b61197f6119776112ae604b5466ffffffffffffff9060a01c1690565b421015613677565b604a549461199a66ffffffffffffff8760a01c1642106136b4565b6045546040516001600160601b0319606088901b16602082019081526014825291926119d89290916119cd603482611f07565b519020933691613702565b613889565b613750565b6001600160a01b0381166000908152603a6020526040902054611a089060ff1615613788565b611a296002549263ffffffff611a1d856137be565b9160d81c1610156137d9565b611a4b611a3860495460a01c90565b346001600160601b039091161115613812565b611a5632331461384e565b6001600160a01b0381166000908152603a60205260409020611a7f90805460ff19166001179055565b611a8c34603f5401603f55565b6156a7565b34610397576020366003190112610397577f6787c7f9a80aa0f5ceddab2c54f1f5169c0b88e75dd5e19d5e858a64144c7dbc6020600435611ad181610a01565b611ad9614efd565b151560055460ff60a81b8260a81b169060ff60a81b191617600555604051908152a1005b3461039757604036600319011261039757600435611b1a816104be565b602435611b2681610a01565b6001600160a01b03821691338314611ba85781611b65611b769233600052600460205260406000209060018060a01b0316600052602052604060002090565b9060ff801983541691151516179055565b604051901515815233907f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3190602090a3005b60405162461bcd60e51b815260206004820152601960248201527822a9219b99189d1030b8383937bb32903a379031b0b63632b960391b6044820152606490fd5b3461039757602036600319011261039757600435611c06816104be565b611c0e614efd565b6001600160a01b038082169190821515823b1581611ca2575b50611c905760407fcc5dc080ff977b3c3a211fa63ab74f90f658f5ba9d3236e92c8f59570f442aac916106f994611c5c612b02565b8351921682526020820152a1600580546001600160a81b031916600883901b610100600160a81b0316176001179055612b4d565b6040516332483afb60e01b8152600490fd5b905038611c27565b610e997f3ab706acce053a4246886a2268a3fe0f7bac19ed2df0f36286da4936a0654c7a611cd73661142e565b9290611ce1613b51565b611e06604a549466ffffffffffffff611d01818860a01c16421015613a44565b60405490611d2363ffffffff91828460b81c1693610d86858588161115613a7e565b611d2e341515614440565b611d3932331461384e565b6001611d448661182a565b8054611d6c903390611d66906001600160a01b03165b6001600160a01b031690565b1461447a565b018054926001600160601b03611d9c611d8b34831660a088901c6144b5565b9b8561137160025463ffffffff1690565b9184611da6614698565b931611611e595780611dbc9216908b1611613af5565b6001600160f01b03831660a08a901b6001600160a01b031916179055604054611ded9060981c63ffffffff16610e3f565b90851614908115611e4d575b50611e40575b85836144ce565b611e0e614718565b6040805163ffffffff90921682526001600160601b039094166020820152429381019390935233929081906060820190565b611e48614571565b611dff565b60019150161538611df9565b611e779150611e6d610da460485460a01c90565b908b161015613af5565b611dbc565b3461039757600036600319011261039757602063ffffffff60405460b81c16604051908152f35b634e487b7160e01b600052604160045260246000fd5b604081019081106001600160401b03821117611ed457604052565b611ea3565b6001600160401b038111611ed457604052565b602081019081106001600160401b03821117611ed457604052565b90601f801991011681019081106001600160401b03821117611ed457604052565b60405190611f3582611eb9565b565b6001600160401b038111611ed457601f01601f191660200190565b929192611f5e82611f37565b91611f6c6040519384611f07565b829481845281830111610397578281602093846000960137010152565b3461039757608036600319011261039757600435611fa6816104be565b602435611fb2816104be565b606435916001600160401b038311610397573660238401121561039757611fe66106f9933690602481600401359101611f52565b91604435916154ea565b346103975760203660031901126103975760043561200d81615575565b15612157576000908072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8181811015612149575b50506d04ee2d6d415b85acef81000000008083101561213a575b50662386f26fc100008083101561212b575b506305f5e1008083101561211c575b506127108083101561210d575b5060648210156120fd575b600a809210156120f3575b6001908160216120a6828701614d36565b95860101905b6120bd575b61042b61060186614c7e565b600019019083906f181899199a1a9b1b9c1cb0b131b232b360811b8282061a8353049182156120ee579190826120ac565b6120b1565b9160010191612095565b919060646002910491019161208a565b6004919392049101913861207f565b60089193920491019138612072565b60109193920491019138612063565b60209193920491019138612051565b604094500491503880612037565b60405162461bcd60e51b815260206004820152600f60248201526e151bdad95b881b9bdd08199bdd5b99608a1b6044820152606490fd5b34610397576020366003190112610397576004356121ab816108f2565b6121c060018060a01b036006541633146135df565b6127106001600160601b038216116121db576106f9906130b5565b60405162461bcd60e51b815260206004820152601b60248201527a0a4def2c2d8e8f240e0cae4c6cadce8c2ceca40e8dede40d0d2ced602b1b6044820152606490fd5b3461039757600319602036820112610397576004356001600160401b0391828211610397576102c090823603011261039757600080516020615d0f833981519152549160ff8360401c1615921680159081612357575b600114908161234d575b159081612344575b5061233257600080516020615d0f833981519152805467ffffffffffffffff191660011790556122be908261230d575b60040161346a565b6122c457005b600080516020615d0f833981519152805460ff60401b19169055604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a1005b600080516020615d0f833981519152805460ff60401b1916600160401b1790556122b6565b60405163f92ee8a960e01b8152600490fd5b90501538612286565b303b15915061227e565b839150612274565b3461039757600036600319011261039757602063ffffffff604a5460d81c16604051908152f35b346103975760203660031901126103975760206123ad6004356123a8816108f2565b6145cb565b63ffffffff60405191168152f35b346103975760403660031901126103975760206123ef6004356123dd816104be565b602435906123ea826104be565b614f55565b6040519015158152f35b3461039757602036600319011261039757600435612416816104be565b6006546001600160a01b039061242f90821633146135df565b81161561243f576106f990615c85565b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b34610397576020366003190112610397576004356124b081610d10565b6124c560018060a01b036006541633146135df565b604a549063ffffffff808216926124e2828260d81c168510614e4a565b6002549066ffffffffffffff9060a01c811642101561253257509261250d916106f994161115614e86565b604a805463ffffffff60d81b191660d89290921b63ffffffff60d81b16919091179055565b60405494919290606086901c16421161259d5760405162461bcd60e51b815260206004820152602a60248201527f43616e6e6f74206368616e6765206d6178537570706c7920647572696e67207460448201526934329030bab1ba34b7b760b11b6064820152608490fd5b6106f99461250d936125e492610e3f926001600160601b0316156125eb575b6040546125dd9060d81c63ffffffff165b60415463ffffffff165b9061362a565b911661497d565b1115614e86565b6125f36149c1565b6125bc565b61260136611251565b9062ffffff6040549161262166ffffffffffffff8460601c164211613923565b6041546126339060401c60ff16613961565b16906126408215156139a2565b61264b32331461384e565b6001600160601b0316156126fa575b600254916126a261269a610e3f61267d6125cd60405463ffffffff9060d81c1690565b604a546113279060d81c63ffffffff1663ffffffff89169061362a565b831115613640565b6126ba610da46126b460485460a01c90565b846139e7565b926126c784341015613a03565b60005b8381106126e5576106f96126e086603f546137cc565b603f55565b806126f46001928401856156a7565b016126ca565b6127026149c1565b61265a565b34610397576060366003190112610397576001600160401b0360043581811161039757612738903690600401610a5c565b909160243590811161039757612752903690600401610a5c565b929061275f6044356104be565b612767613b51565b60405461278166ffffffffffffff8260601c16421161483e565b61278c84151561487e565b6001600160601b031615612af5575b6000938493855b8181106127d45786806127b9576106f96001603855565b6127ce906044356001600160a01b0316614b7a565b80610c1e565b6127ea6115176127e58385896148b4565b61310f565b8054612804903390611d66906001600160a01b0316611d5a565b600181015497600290612819828b16156148c4565b60009060a08b901c60018c1615612adb57878b1061291c575b6001926128cd969594926128939261285160405460018060601b031690565b9061286384888060601b038416613b2f565b60009181811115612914576128789250613b2f565b925b156128d2575b5061288e84546044356156a7565b6137cc565b9a6128c46128ae6128a960415463ffffffff1690565b614968565b63ffffffff1663ffffffff196041541617604155565b179101556138e5565b6127a2565b6126e0612906610da46128f461290e946128ee60475460a01c90565b906139e7565b6127106001600160601b039091160490565b603f546137cc565b38612880565b50509261287a565b6129278b898b6148b4565b6046546040516331a9108f60e11b8152913560048301819052916001600160a01b0391821691906020908181602481875afa928315612aa75785918994612aac575b50831633149283156129f3575b5050509050612986575b50612832565b600193509a6128cd969594926129b88d6129b3612893959f6129aa6129ae91614ae4565b1590565b61492c565b614b04565b6040546129e5906129df90610da4906128f4906001600160601b031660475460a01c6128ee565b926138e5565b9c9250929495965092612980565b604b549294612a5d94508593612a1390611d5a906001600160a01b031681565b604051632e7cda1d60e21b81523360048201526001600160a01b039384166024820152929091166044830152606482019290925260006084820152928391908290819060a4820190565b03915afa918215612aa7578692612a7a575b505080388381612976565b612a999250803d10612aa0575b612a918183611f07565b810190614917565b3880612a6f565b503d612a87565b612b41565b612acd919450833d8511612ad4575b612ac58183611f07565b810190614902565b9238612969565b503d612abb565b60019250612aef906128cd969594926137cc565b9a6128c4565b612afd6149c1565b61279b565b600554600881901c6001600160a01b031691908215612b1e5750565b60ff1615612b2857565b73721c002b0059009a671d00ad1700c9748146cd1b9150565b6040513d6000823e3d90fd5b6001600160a01b0381169081612b61575050565b3b612b6a575b50565b803b15610397576000809160446040518094819363fb2de5d760e01b83523060048401526102d160248401525af115612b6757611f3590611ed9565b903590601e198136030182121561039757018035906001600160401b0382116103975760200191813603831361039757565b356105b3816104be565b90600182811c92168015612c12575b6020831014612bfc57565b634e487b7160e01b600052602260045260246000fd5b91607f1691612bf1565b601f8111612c28575050565b60009081805260208220906020601f850160051c83019410612c65575b601f0160051c01915b828110612c5a57505050565b818155600101612c4e565b9092508290612c45565b601f8111612c7b575050565b6000906044825260208220906020601f850160051c83019410612cb9575b601f0160051c01915b828110612cae57505050565b818155600101612ca2565b9092508290612c99565b90601f8211612cd0575050565b60019160009083825260208220906020601f850160051c83019410612d10575b601f0160051c01915b828110612d065750505050565b8181558301612cf9565b9092508290612cf0565b601f8111612d26575050565b6000906042825260208220906020601f850160051c83019410612d64575b601f0160051c01915b828110612d5957505050565b818155600101612d4d565b9092508290612d44565b601f8111612d7a575050565b6000906043825260208220906020601f850160051c83019410612db8575b601f0160051c01915b828110612dad57505050565b818155600101612da1565b9092508290612d98565b91906001600160401b038111611ed457612de681612de1604254612be2565b612d1a565b6000601f8211600114612e2057819293600092612e15575b50508160011b916000199060031b1c191617604255565b013590503880612dfe565b6042600052601f198216937f38dfe4635b27babeca8be38d3b448cb5161a639b899a14825ba9c8d7892eb8c391805b868110612e875750836001959610612e6d575b505050811b01604255565b0135600019600384901b60f8161c19169055388080612e62565b90926020600181928686013581550194019101612e4f565b91906001600160401b038111611ed457612ec381612ebe604354612be2565b612d6e565b6000601f8211600114612efd57819293600092612ef2575b50508160011b916000199060031b1c191617604355565b013590503880612edb565b6043600052601f198216937f9690ad99d6ce244efa8a0f6c2d04036d3b33a9474db32a71b71135c69510279391805b868110612f645750836001959610612f4a575b505050811b01604355565b0135600019600384901b60f8161c19169055388080612f3f565b90926020600181928686013581550194019101612f2c565b91906001600160401b038111611ed457612f9b81611770604454612be2565b6000601f8211600114612fd557819293600092612fca575b50508160011b916000199060031b1c191617604455565b013590503880612fb3565b6044600052601f19821693600080516020615cef83398151915291805b86811061302a5750836001959610613010575b505050811b01604455565b0135600019600384901b60f8161c19169055388080613005565b90926020600181928686013581550194019101612ff2565b80546001600160a01b0319166001600160a01b03909216919091179055565b356105b3816108f2565b604880546001600160a01b031660a09290921b6001600160a01b031916919091179055565b604980546001600160a01b031660a09290921b6001600160a01b031916919091179055565b604680546001600160a01b031660a09290921b6001600160a01b031916919091179055565b356105b381610f8d565b604a805466ffffffffffffff60a01b191660a09290921b66ffffffffffffff60a01b16919091179055565b356105b381610d10565b604b805463ffffffff60d81b191660d89290921b63ffffffff60d81b16919091179055565b6040805463ffffffff60d81b191660d89290921b63ffffffff60d81b16919091179055565b356105b381611244565b6134116102a0611f359261318a6131848280612ba6565b90612dc2565b6131a061319a6020830183612ba6565b90612e9f565b6131b66131b06040830183612ba6565b90612f7c565b60608101356045556131ef6131cd60808301612bd8565b604680546001600160a01b0319166001600160a01b0392909216919091179055565b6132036131fe60a08301613061565b6130b5565b61323461321260c08301612bd8565b604780546001600160a01b0319166001600160a01b0392909216919091179055565b61324361096460e08301613061565b6132756132536101008301612bd8565b604880546001600160a01b0319166001600160a01b0392909216919091179055565b61328a6132856101208301613061565b61306b565b6132bc61329a6101408301612bd8565b604980546001600160a01b0319166001600160a01b0392909216919091179055565b6132d16132cc6101608301613061565b613090565b6133036132e16101808301612bd8565b604a80546001600160a01b0319166001600160a01b0392909216919091179055565b6133186133136101a083016130da565b6130e4565b61332861250d6101c0830161310f565b61335a6133386101e08301612bd8565b604b80546001600160a01b0319166001600160a01b0392909216919091179055565b61336a61167861020083016130da565b61337f61337a610220830161310f565b613119565b6133a561338f610240830161310f565b63ffffffff1663ffffffff19604c541617604c55565b6133d66133b5610260830161310f565b63ffffffff60201b604c549160201b169063ffffffff60201b191617604c55565b61340b6133e6610280830161310f565b604c805463ffffffff60401b191660409290921b63ffffffff60401b16919091179055565b01613163565b604c805462ffffff60601b191660609290921b62ffffff60601b16919091179055565b634e487b7160e01b600052601160045260246000fd5b91909166ffffffffffffff8080941691160191821161346557565b613434565b6134748180612ba6565b9061349c60209261349461348a85870187612ba6565b9490923691611f52565b923691611f52565b916134a56151a9565b6134ad6151a9565b8151906001600160401b038211611ed4576000926134d4836134cf8654612be2565b612c1c565b81601f841160011461355157509180849261352a97969461350e9692613546575b50508160011b916000199060031b1c19161790556151d8565b613525613520611d5a60c08401612bd8565b615c71565b61316d565b611f3561103a61101f604a5466ffffffffffffff9060a01c1690565b0151905038806134f5565b600080529190601f1984167f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5639386905b8282106135c757505092600192859261352a99989661350e9896106135ae575b505050811b0190556151d8565b015160001960f88460031b161c191690553880806135a1565b80600186978294978701518155019601940190613581565b156135e657565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b63ffffffff918216908216039190821161346557565b1561364757565b60405162461bcd60e51b8152602060048201526008602482015267546f6f206d616e7960c01b6044820152606490fd5b1561367e57565b60405162461bcd60e51b815260206004820152600e60248201526d1053081b9bdd081cdd185c9d195960921b6044820152606490fd5b156136bb57565b60405162461bcd60e51b8152602060048201526008602482015267105308195b99195960c21b6044820152606490fd5b6001600160401b038111611ed45760051b60200190565b929161370d826136eb565b9161371b6040519384611f07565b829481845260208094019160051b810192831161039757905b8282106137415750505050565b81358152908301908301613734565b1561375757565b60405162461bcd60e51b8152602060048201526009602482015268139bdd081bdb88105360ba1b6044820152606490fd5b1561378f57565b60405162461bcd60e51b815260206004820152600760248201526610db185a5b595960ca1b6044820152606490fd5b906001820180921161346557565b9190820180921161346557565b156137e057565b60405162461bcd60e51b815260206004820152600a602482015269135a5b9d1959081bdd5d60b21b6044820152606490fd5b1561381957565b60405162461bcd60e51b815260206004820152600d60248201526c496e76616c69642066756e647360981b6044820152606490fd5b1561385557565b60405162461bcd60e51b815260206004820152600c60248201526b4e6f20636f6e74726163747360a01b6044820152606490fd5b929091906000915b84518310156138dd576138a4838661390a565b51906000828210156138cb57506000526020526138c56040600020926138e5565b91613891565b6040916138c5938252602052206129df565b915092501490565b60001981146134655760010190565b634e487b7160e01b600052603260045260246000fd5b805182101561391e5760209160051b010190565b6138f4565b1561392a57565b60405162461bcd60e51b815260206004820152600f60248201526e41756374696f6e206f6e676f696e6760881b6044820152606490fd5b1561396857565b60405162461bcd60e51b8152602060048201526012602482015271141d589b1a58c81b9bdd08185b1b1bddd95960721b6044820152606490fd5b156139a957565b60405162461bcd60e51b81526020600482015260166024820152754d757374206d696e74206174206c65617374206f6e6560501b6044820152606490fd5b6001600160601b03918216908216029081169190820361346557565b15613a0a57565b60405162461bcd60e51b8152602060048201526012602482015271496e73756666696369656e742066756e647360701b6044820152606490fd5b15613a4b57565b60405162461bcd60e51b815260206004820152600b60248201526a139bdd081cdd185c9d195960aa1b6044820152606490fd5b15613a8557565b60405162461bcd60e51b815260206004820152600c60248201526b42616420657374696d61746560a01b6044820152606490fd5b15613ac057565b60405162461bcd60e51b815260206004820152600d60248201526c105d58dd1a5bdb88195b991959609a1b6044820152606490fd5b15613afc57565b60405162461bcd60e51b815260206004820152600b60248201526a42696420746f6f206c6f7760a81b6044820152606490fd5b9190820391821161346557565b63ffffffff8091169081146134655760010190565b600260385414613b62576002603855565b604051633ee5aeb560e01b8152600490fd5b6040805463ffffffff60981b191660989290921b63ffffffff60981b16919091179055565b906020600191613bb1838060a01b0382511685613042565b0151910155565b6040805460a085901b6001600160a01b03191694600194938587179363ffffffff936001600160601b039093169290919060981c841615613fbd578381168015159081613f9e575b5015613f8c57965b613c23610da4610da489613c1b8c61182a565b015460a01c90565b831115613d9357505084906000915b613d31575b5015613c8c5750604884901b63ffffffff60481b161792613c88919083613c8163ffffffff60281b1982613c6a8561182a565b01541663ffffffff60281b8560281b16179261182a565b015561182a565b0155565b8385613cab610e3f83613ca3613c8898979a61182a565b015460481c90565b9263ffffffff60281b9183613cf563ffffffff60481b9a858460281b16908c8960481b1617179a63ffffffff60481b1983613ce58661182a565b015416908960481b16179261182a565b0155831615613d2557613c819063ffffffff60281b1983613d158661182a565b015416908560281b16179261182a565b50505061151781613b74565b828716151580613d78575b15613d7357613d59610e3f87613d518a61182a565b015460281c90565b83811615613d6957965085613c32565b5050508338613c37565b613c37565b5080613d8d610da4610da489613c1b8c61182a565b10613d3c565b90939296918680600092613db2610e3f895463ffffffff9060981c1690565b915b613f28575b505050600014613e7f5750508154613c88939291859160981c63ffffffff1690613de285613b74565b602882901b63ffffffff60281b16179682613dfc8361182a565b0154935463ffffffff60481b198516604887901b63ffffffff60481b16908117959092909160b81c63ffffffff1690613e52610e3f613e44604a5463ffffffff9060d81c1690565b60025463ffffffff166125d7565b91161015613e66575b5050613c819061182a565b600163ffffffff60481b011916179250613c8138613e5b565b613c8894935081969250613e9a610e3f87613d51819561182a565b9263ffffffff60281b9783613ee68163ffffffff60481b958c8960281b1690878660481b161717179a63ffffffff60281b1983613ed68661182a565b015416908960281b16179261182a565b01558316613ef7575b50505061182a565b613f1e9063ffffffff60481b1983613f0e8661182a565b015416908560481b16179261182a565b0155388381613eef565b9091948a811680151580613f70575b15613f68578314613f5b57610e3f86613ca3613f529361182a565b94919082613db4565b9492505050863880613db9565b509491613db9565b5082613f85610da4610da48a613c1b8761182a565b1015613f37565b50805460981c63ffffffff1696613c08565b9050613fb5610e3f845463ffffffff9060b81c1690565b101538613c00565b505050509150611f35925080613fd5613fec92613b74565b613fdd611f28565b9260008452602084015261182a565b613b99565b604080546001600160a01b031960a086901b1695946001938488179363ffffffff936001600160601b039093169290919060981c84161561441d5783811680151590816143fe575b50156143ec57975b614054610da4610da488613c1b8d61182a565b83111561420a57505083906000915b61419d575b50156140f75750604885901b63ffffffff60481b161793816140ad63ffffffff60281b19826140968561182a565b01541663ffffffff60281b8660281b16179261182a565b01555b6001600160a01b038316156140ec5750613fec90611f35936140e26140d3611f28565b6001600160a01b039095168552565b602084015261182a565b9150613c889061182a565b90948061410b610e3f85613ca3819561182a565b9263ffffffff60281b918361415563ffffffff60481b9a858460281b16908c8960481b1617179a63ffffffff60481b19836141458661182a565b015416908a60481b16179261182a565b015583161561418c576141859063ffffffff60281b19836141758661182a565b015416908660281b16179261182a565b01556140b0565b50505061419882613b74565b6140b0565b90919293968381161515806141ef575b156141e5576141c2610e3f89613d518461182a565b90848216156141d75750969392919084614063565b979493925050508238614068565b9693929190614068565b5081614204610da4610da48b613c1b8661182a565b106141ad565b90939297918580600092614229610e3f895463ffffffff9060981c1690565b915b614388575b5050506000146142e3575050815483919060981c63ffffffff169061425486613b74565b602882901b63ffffffff60281b1617968261426e8361182a565b0154935463ffffffff60481b198516604888901b63ffffffff60481b16908117959092909160b81c63ffffffff16906142b6610e3f613e44604a5463ffffffff9060d81c1690565b911610156142ca575b50506141859061182a565b600163ffffffff60481b011916179250614185386142bf565b909692508391506142fa610e3f83613d518a61182a565b9263ffffffff60281b97836143468163ffffffff60481b958c8960281b1690878660481b161717179a63ffffffff60281b19836143368661182a565b015416908a60281b16179261182a565b01558316614357575b5050506140b0565b61437e9063ffffffff60481b198361436e8661182a565b015416908660481b16179261182a565b015538818161434f565b9091948b8116801515806143d0575b156143c85783146143bb57610e3f86613ca36143b29361182a565b9491908261422b565b9492505050853880614230565b509491614230565b50826143e5610da4610da48a613c1b8761182a565b1015614397565b50805460981c63ffffffff1697614041565b9050614415610e3f845463ffffffff9060b81c1690565b101538614039565b50505050611f359450829150614435613fec93613b74565b6140e26140d3611f28565b1561444757565b60405162461bcd60e51b815260206004820152600b60248201526a139bc8115512081cd95b9d60aa1b6044820152606490fd5b1561448157565b60405162461bcd60e51b815260206004820152600c60248201526b139bdd081e5bdd5c88189a5960a21b6044820152606490fd5b6001600160601b03918216908216019190821161346557565b611f359260016144dd8361182a565b015463ffffffff90818160281c16918160481c16918061453d575b5081614506575b5050613bb8565b6001906145349063ffffffff60281b19836145208661182a565b0154169063ffffffff60281b16179261182a565b015538806144ff565b600161456963ffffffff60481b19826145558561182a565b01541663ffffffff60481b8516179261182a565b0155386144f8565b63ffffffff8060405460981c169081156145c75781611f3592600052603960205260016145a881198260406000200154169261182a565b015560016145bc8260405460981c1661182a565b015460281c16613b74565b5050565b906145df60405463ffffffff9060981c1690565b63ffffffff928382161561469057600190614603610da4610da484613c1b8761182a565b6001600160601b03909116908111156146895781949293945b614627575b50505090565b9091939284811615158061466e575b156146675761464b610e3f84613d518461182a565b908582161561465f5750929391908161461c565b939450614621565b9293614621565b5081614683610da4610da486613c1b8661182a565b10614636565b5090925050565b506000925050565b63ffffffff6146b781604a5460d81c166125d760025463ffffffff1690565b816040549116828260b81c161015806146f1575b156146e6576001613c1b6105b393610da49360981c1661182a565b505060485460a01c90565b50818160981c1615156146cb565b66ffffffffffffff918216908216039190821161346557565b60405460601c66ffffffffffffff1666ffffffffffffff6000828216428111156148375761474891504290613b2f565b905b604c549263ffffffff92838560201c1611614766575b50505050565b61478861478261101f604a5466ffffffffffffff9060a01c1690565b826146ff565b838560401c16808483161061479f575b5050614760565b8061103a956147c29716946147b4868561344a565b1611614824575b505061344a565b7fc2b459809119087ca9d2bc10dea53a51b7d848b1a11075db037bdca58292c3e86148166147fc60405466ffffffffffffff9060601c1690565b60405166ffffffffffffff90911681529081906020820190565b0390a1388080808080614798565b61482f9293506146ff565b9038806147bb565b509061474a565b1561484557565b60405162461bcd60e51b8152602060048201526011602482015270105d58dd1a5bdb881b9bdd08195b991959607a1b6044820152606490fd5b1561488557565b60405162461bcd60e51b81526020600482015260076024820152664e6f206269647360c81b6044820152606490fd5b919081101561391e5760051b0190565b156148cb57565b60405162461bcd60e51b815260206004820152600f60248201526e105b1c9958591e4818db185a5b5959608a1b6044820152606490fd5b9081602091031261039757516105b3816104be565b9081602091031261039757516105b381610a01565b1561493357565b60405162461bcd60e51b815260206004820152600d60248201526c111a5cd8dbdd5b9d081d5cd959609a1b6044820152606490fd5b90600163ffffffff8093160191821161346557565b91909163ffffffff8080941691160191821161346557565b8181029291811591840414171561346557565b6001600160601b03908116612710039190821161346557565b6149f46149d360025463ffffffff1690565b63ffffffff60201b6041549160201b169063ffffffff60201b191617604155565b611f356126e0612906610c01614aa9614a2a614a19604a5463ffffffff9060d81c1690565b60415460201c63ffffffff166125d7565b60405463ffffffff919060b81c82168183168110614ac65750614a4c9061313e565b614a8f614a6d610da46001613c1b61151760405463ffffffff9060981c1690565b604080546001600160601b0319166001600160601b0392909216919091179055565b6040546001600160601b0381169160d89190911c16614995565b614ac0610da4614abb60475460a01c90565b6149a8565b90614995565b614ad0915061313e565b614adf614a6d60485460a01c90565b614a8f565b8060081c90600482101561391e5760ff600191161b90603b015416151590565b8060081c600481101561391e5760ff600191603b0192161b8154179055565b90604051614b3081611eb9565b82546001600160a01b031681526001909201546020830152565b3d15614b75573d90614b5b82611f37565b91614b696040519384611f07565b82523d6000602084013e565b606090565b6000918291829182916001600160a01b03165af1614b96614b4a565b5015614b9e57565b60405162461bcd60e51b8152602060048201526015602482015274115d1a195c881d1c985b9cd9995c8819985a5b1959605a1b6044820152606490fd5b90614be5826152bb565b8015614c4c57614bf4816136eb565b90614c026040519283611f07565b808252601f19614c11826136eb565b0136602084013760005b818110614c29575090925050565b80614c37614c4792876150ef565b614c41828661390a565b526138e5565b614c1b565b509050604051614c5b81611eec565b60008152600036813790565b90614c7a6020928281519485920161055a565b0190565b9060405191826000604454614c9281612be2565b600191808316908115614d0e5750600114614cc5575b5050614cb790611f3593614c67565b03601f198101845283611f07565b60446000908152602093509091600080516020615cef8339815191525b838310614cf85750505082010182614cb7614ca8565b8054898401860152889550918401918101614ce2565b614cb79450611f35969350602092915060ff1916828601528015150284010191819450614ca8565b90614d4082611f37565b614d4d6040519182611f07565b8281528092614d5e601f1991611f37565b0190602036910137565b15614d6f57565b60405162461bcd60e51b815260206004820152602860248201527f43616e6e6f742073657420646973636f756e742061667465722061756374696f6044820152676e2073746172747360c01b6064820152608490fd5b15614dcc57565b60405162461bcd60e51b8152602060048201526017602482015276105d58dd1a5bdb88185b1c9958591e481cdd185c9d1959604a1b6044820152606490fd5b15614e1257565b60405162461bcd60e51b815260206004820152601060248201526f20a61030b33a32b91030bab1ba34b7b760811b6044820152606490fd5b15614e5157565b60405162461bcd60e51b815260206004820152600d60248201526c4f6e6c7920646563726561736560981b6044820152606490fd5b15614e8d57565b60405162461bcd60e51b81526020600482015260116024820152706d6178537570706c7920746f6f206c6f7760781b6044820152606490fd5b15614ecd57565b60405162461bcd60e51b81526020600482015260086024820152674e6f2066756e647360c01b6044820152606490fd5b6006546001600160a01b03163303614f1157565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2043616c6c6572206973206e6f7420746865206f776e65726044820152fd5b6001600160a01b039081166000908152600460209081526040808320858516845290915290205460ff169291908315614f8c575050565b60ff60055460a81c16614f9d575050565b8091929350614faa612b02565b1691161490565b60809060208152602c60208201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60408201526b7574206f6620626f756e647360a01b60608201520190565b90600254908183101561506f57600092835b8381106150305760405162461bcd60e51b8152806113db60048201614fb1565b61503981615575565b61504c575b615047906138e5565b615010565b9381811461506857615060615047916138e5565b94905061503e565b5090915050565b60405162461bcd60e51b8152806113db60048201614fb1565b60809060208152602b60208201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560408201526a74206f6620626f756e647360a81b60608201520190565b60025481101561391e57600260005260206000200190600090565b906150f9826152bb565b811015615190576000908192600254935b84811061512a5760405162461bcd60e51b8152806113db60048201615088565b61514e611d5a615139836150d4565b905460039190911b1c6001600160a01b031690565b6001600160a01b0383161461516c575b615167906138e5565b61510a565b9282810361517c57505050905090565b615188615167916138e5565b93905061515e565b60405162461bcd60e51b8152806113db60048201615088565b60ff600080516020615d0f8339815191525460401c16156151c657565b604051631afcd79f60e31b8152600490fd5b9081516001600160401b038111611ed4576001906151ff816151fa8454612be2565b612cc3565b602080601f831160011461523a57508192939460009261522f575b5050600019600383901b1c191690821b179055565b01519050388061521a565b6001600052601f198316959091907fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6926000905b8882106152a4575050838596971061528b575b505050811b019055565b015160001960f88460031b161c19169055388080615281565b80878596829496860151815501950193019061526e565b6001600160a01b0316801561531857600254600091825b8281106152df5750505090565b6152ee611d5a615139836150d4565b8214615303575b6152fe906138e5565b6152d2565b926153106152fe916138e5565b9390506152f5565b60405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608490fd5b61537981615575565b156153aa5760025481101561391e576002600052600080516020615ccf83398151915201546001600160a01b031690565b60405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608490fd5b61540a81615575565b1561542a576000908152600360205260409020546001600160a01b031690565b60405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608490fd5b1561548b57565b60405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6044820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b6064820152608490fd5b9061550e9392916154fe61089b84336155ae565b615509838383615937565b615b67565b1561551557565b60405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b6064820152608490fd5b60025481109081615584575090565b901561391e576002600052600080516020615ccf83398151915201546001600160a01b0316151590565b6155b782615575565b15615610576155c582615370565b6001600160a01b0382811682821681149490919085156155f8575b50505082156155ee57505090565b6105b39250614f55565b6156059192939550615401565b1614913880806155e0565b60405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608490fd5b60025490600160401b821015611ed457600182018060025582101561391e576002600052611f3591600080516020615ccf83398151915201613042565b6001600160a01b0381169190821561574e576156c282615575565b6157095781611f35936156d58284615792565b6156de8361566a565b60007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8180a4615792565b60405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606490fd5b606460405162461bcd60e51b815260206004820152602060248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152fd5b60005b60019081811015614760578084018411613465576001600160a01b0383166157c957604051635cbd944160e01b8152600490fd5b01615795565b909160005b6001908181101561584a57808301808411613465576001600160a01b0386811615908616158080615843575b1561581757604051635cbd944160e01b8152600490fd5b15615825575b5050016157d4565b15615831575b8061581d565b61583d90868633615851565b3861582b565b5081615800565b5050505050565b9092916001600160a01b039182615866612b02565b1680615875575b505050505050565b80331461586d57803b15610397576000948460849481604051998a98899763657711f560e11b895216600488015216602486015216604484015260648301525afa8015612aa7576158cb575b808080808061586d565b806158d86158de92611ed9565b8061038c565b386158c1565b60005b6001908181101561584a578085018511613465576001600160a01b0383811615908161592c575b501561592657604051635cbd944160e01b8152600490fd5b016158e7565b90508416153861590e565b919061594282615370565b6001600160a01b0380851694918116859003615a225782169384156159d157611f359484916159728386866157cf565b61597b83615a79565b6159a785615988856150d4565b90919082549060031b9160018060a01b03809116831b921b1916179055565b7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef600080a46158e4565b60405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b60405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608490fd5b600081815260036020526040812080546001600160a01b03191690556001600160a01b03615aa683615370565b167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258280a4565b816000526003602052615ae4816040600020613042565b6001600160a01b0380615af684615370565b169116907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600080a4565b9081602091031261039757516105b3816103cb565b6001600160a01b0391821681529116602082015260408101919091526080606082018190526105b39291019061057d565b92909190823b15615c6857615b9a926020926000604051809681958294630a85bd0160e11b9a8b85523360048601615b36565b03926001600160a01b03165af160009181615c38575b50615c2a57615bbd614b4a565b80519081615c255760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b6064820152608490fd5b602001fd5b6001600160e01b0319161490565b615c5a91925060203d8111615c61575b615c528183611f07565b810190615b21565b9038615bb0565b503d615c48565b50505050600190565b611f3590615c7d6151a9565b615c856151a9565b600680546001600160a01b039283166001600160a01b0319821681179092559091167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a356fe405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace9b22d3d61959b4d3528b1d8ba932c96fbe302b36a1aad1d95cab54f9e0a135eaf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a2646970667358221220a7490472e6e63dfa7959a8faa7442df8cce2fdefdac519ad5e2f93fc085f386664736f6c63430008140033

Deployed Bytecode

0x6080604052600436101561001257600080fd5b60003560e01c8063014635461461038757806301ffc9a71461038257806306d254da1461037d57806306fdde0314610378578063081812fc14610373578063095ea7b31461036e578063098144d4146103695780630d705df6146103645780630e910d391461035f57806318160ddd1461035a57806323b872dd146103555780632a55205a146103505780632ed56f361461034b5780632f745c591461034657806335a83013146103415780633a7cb0861461033c5780633ccfd60b1461033757806342842e0e14610332578063438b63001461032d578063455d9ac4146103285780634f6ccce7146103235780634f808dc21461031e5780635077ee24146103195780636221d13c146103145780636352211e1461030f578063665155c01461030a57806370a0823114610305578063715018a614610300578063738cba9a146102fb57806378491b1b146102f65780637cb64759146102f15780637fd67d49146102ec578063816403a1146102e7578063881c632c146102e25780638da5cb5b146102dd578063916358a3146102d857806393803fdf146102d357806395d89b41146102ce5780639df742d7146102c95780639e05d240146102c4578063a22cb465146102bf578063a9fc664e146102ba578063b0153d5e146102b5578063b40a5627146102b0578063b88d4fde146102ab578063c87b56dd146102a6578063cac92669146102a1578063ccb1038a1461029c578063d5abeb0114610297578063d8d472d814610292578063e985e9c51461028d578063f2fde38b14610288578063f9da322414610283578063fafe3a201461027e5763fdca172e1461027957600080fd5b612707565b6125f8565b612493565b6123f9565b6123bb565b612386565b61235f565b61221e565b61218e565b611ff0565b611f89565b611e7c565b611caa565b611be9565b611afd565b611a91565b61191a565b611895565b611840565b611703565b6116da565b611604565b61156e565b6114a6565b611400565b611276565b61119c565b61113b565b611114565b6110ea565b6110cc565b6110a6565b610f9e565b610ee6565b610ec8565b610d1e565b610ca7565b610c7f565b610b70565b610ac9565b610a0b565b6109ce565b610903565b6108a5565b61087c565b610832565b610805565b6107dd565b6107c2565b6106a3565b610673565b6105b6565b6104cf565b6103dd565b61039c565b600091031261039757565b600080fd5b3461039757600036600319011261039757602060405173721c002b0059009a671d00ad1700c9748146cd1b8152f35b6001600160e01b031981160361039757565b346103975760203660031901126103975761042b6004356103fd816103cb565b63ffffffff60e01b1663152a902d60e11b811490811561042f575b5060405190151581529081906020820190565b0390f35b63780e9d6360e01b811491508115610449575b5038610418565b632b435fdb60e21b8114915081156104ad575b811561046a575b5038610442565b6380ac58cd60e01b81149150811561049c575b811561048b575b5038610463565b6301ffc9a760e01b14905038610484565b635b5e139f60e01b8114915061047d565b63503e914d60e11b8114915061045c565b6001600160a01b0381160361039757565b34610397576020366003190112610397576004356104ec816104be565b6006546001600160a01b03919061050690831633146135df565b16801561052357604880546001600160a01b031916919091179055005b60405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206164647265737360881b6044820152606490fd5b60005b83811061056d5750506000910152565b818101518382015260200161055d565b906020916105968151809281855285808601910161055a565b601f01601f1916010190565b9060206105b392818152019061057d565b90565b3461039757600080600319360112610670576040518180546105d781612be2565b80845290600190818116908115610648575060011461060d575b61042b8461060181880382611f07565b604051918291826105a2565b93508180526020938483205b828410610635575050508161042b9361060192820101936105f1565b8054858501870152928501928101610619565b61042b96506106019450602092508593915060ff191682840152151560051b820101936105f1565b80fd5b34610397576020366003190112610397576020610691600435615401565b6040516001600160a01b039091168152f35b34610397576040366003190112610397576004356106c0816104be565b6024356106cc81615370565b6001600160a01b038181169084168114610773573314908115610761575b50156106fb576106f991615acd565b005b60405162461bcd60e51b815260206004820152603860248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f74206f776044820152771b995c881b9bdc88185c1c1c9bdd995908199bdc88185b1b60421b6064820152608490fd5b61076d91503390614f55565b386106ea565b60405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608490fd5b34610397576000366003190112610397576020610691612b02565b34610397576000366003190112610397576040805163657711f560e11b815260016020820152f35b34610397576000366003190112610397576020610820614698565b6040516001600160601b039091168152f35b34610397576000366003190112610397576020600254604051908152f35b606090600319011261039757600435610868816104be565b90602435610875816104be565b9060443590565b34610397576106f961088d36610850565b916108a061089b84336155ae565b615484565b615937565b346103975760403660031901126103975760018060a01b03604854166127106108d560465460a01c602435614995565b604080516001600160a01b03949094168452919004602083015290f35b6001600160601b0381160361039757565b3461039757602036600319011261039757600435610920816108f2565b61093560018060a01b036006541633146135df565b6127106001600160601b03821611610989576106f99061096466ffffffffffffff604a5460a01c164210614d68565b604780546001600160a01b031660a09290921b6001600160a01b031916919091179055565b60405162461bcd60e51b815260206004820152601c60248201527f446973636f756e742070657263656e7461676520746f6f2068696768000000006044820152606490fd5b346103975760403660031901126103975760206109f96004356109f0816104be565b602435906150ef565b604051908152f35b8015150361039757565b3461039757602036600319011261039757600435610a2881610a01565b610a3d60018060a01b036006541633146135df565b6041805460ff60401b191691151560401b60ff60401b16919091179055005b9181601f84011215610397578235916001600160401b038311610397576020808501948460051b01011161039757565b6020908160408183019282815285518094520193019160005b828110610ab3575050505090565b8351151585529381019392810192600101610aa5565b34610397576020366003190112610397576004356001600160401b03811161039757610af9903690600401610a5c565b90610b03826136eb565b91610b116040519384611f07565b808352601f19610b20826136eb565b0136602085013760005b818110610b3f576040518061042b8682610a8c565b80610b57610b51610b6b9385876148b4565b35614ae4565b610b61828761390a565b90151590526138e5565b610b2a565b3461039757600036600319011261039757610b9660018060a01b036006541633146135df565b610b9e613b51565b60405466ffffffffffffff8160601c1642119081610c6d575b50610c60575b603f54610bcb811515614ec6565b610bd56000603f55565b610c10610c09610c01610bfb610bf3604c5462ffffff9060601c1690565b62ffffff1690565b84614995565b612710900490565b8092613b2f565b9080610c44575b5080610c28575b6106f96001603855565b604954610c3e91906001600160a01b0316614b7a565b38610c1e565b604a54610c5a91906001600160a01b0316614b7a565b38610c17565b610c686149c1565b610bbd565b6001600160601b031615905038610bb7565b34610397576106f9610c9036610850565b9060405192610c9e84611eec565b600084526154ea565b346103975760208060031936011261039757610ccd600435610cc8816104be565b614bdb565b906040519181839283018184528251809152816040850193019160005b828110610cf957505050500390f35b835185528695509381019392810192600101610cea565b63ffffffff81160361039757565b602036600319011261039757600435610d3681610d10565b610d3e613b51565b604a54610e2e610dfa66ffffffffffffff92610d61848260a01c16421015613a44565b610dd960405491610d9263ffffffff96878560b81c1694610d86868a8c161115613a7e565b60601c16421115613ab9565b610db8610db0610da460485460a01c90565b6001600160601b031690565b341015613af5565b610dc332331461384e565b610dcb614698565b956002549160d81c16613b2f565b93848210610eb357610df5906001600160601b03163411613af5565b613b3c565b6040805463ffffffff60b81b191660b883901b63ffffffff60b81b16179055923390346001600160601b0316908590613ff1565b604054610e489060b81c63ffffffff165b63ffffffff1690565b11610ea6575b610e56614718565b6040805163ffffffff9092168252346020830152429082015233907f025ecfc771110b33a5a72dd787c154336f05caa0447910a403028333139b75ec9080606081015b0390a26106f96001603855565b610eae614571565b610e4e565b610df5906001600160601b0316341015613af5565b346103975760203660031901126103975760206109f9600435614ffe565b3461039757602036600319011261039757600435610f03816108f2565b610f1860018060a01b036006541633146135df565b63ffffffff610f3381604a5460d81c1682600254169061362a565b60405460b81c821691161115610f4c576106f99061306b565b60405162461bcd60e51b8152602060048201526019602482015278115b9bdd59da081dda5b9b9a5b99c8189a591cc8195e1a5cdd603a1b6044820152606490fd5b66ffffffffffffff81160361039757565b3461039757602036600319011261039757600435610fbb81610f8d565b610fd060018060a01b036006541633146135df565b66ffffffffffffff610fea81604a5460a01c164210614dc5565b80604b5460a01c169082161061106557611003906130e4565b6106f961103a61101f604a5466ffffffffffffff9060a01c1690565b604b546110349060d81c63ffffffff16610e3f565b9061344a565b6040805466ffffffffffffff60601b191660609290921b66ffffffffffffff60601b16919091179055565b60405162461bcd60e51b815260206004820152601960248201527814dd185c9d0818d85b9b9bdd081899481899599bdc99481053603a1b6044820152606490fd5b3461039757600036600319011261039757602060ff60055460a81c166040519015158152f35b34610397576020366003190112610397576020610691600435615370565b3461039757600036600319011261039757602066ffffffffffffff60405460601c16604051908152f35b346103975760203660031901126103975760206109f9600435611136816104be565b6152bb565b34610397576000806003193601126106705760065481906001600160a01b038116906111683383146135df565b6001600160a01b0319166006557f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b34610397576020366003190112610397576004356111b981610d10565b6111ce60018060a01b036006541633146135df565b6111e766ffffffffffffff604a5460a01c164210614dc5565b63ffffffff80604b5460d81c1690821611156112065761100390613119565b60405162461bcd60e51b815260206004820152601660248201527526bab9ba1034b731b932b0b9b290323ab930ba34b7b760511b6044820152606490fd5b62ffffff81160361039757565b60409060031901126103975760043561126981611244565b906024356105b3816104be565b346103975761128436611251565b9061129a60018060a01b036006541633146135df565b604a546112ba9060a01c66ffffffffffffff165b66ffffffffffffff1690565b421015806113df575b6113a05760405466ffffffffffffff8160601c164211908161138e575b50611381575b60025461133762ffffff61132c610e3f600060405460018060601b038116611358575b50604a546113279060d81c63ffffffff1663ffffffff88169061362a565b61362a565b931692831115613640565b60005b82811061134357005b806113526001928401866156a7565b0161133a565b61137b915063ffffffff61137160415463ffffffff1690565b9160d81c1661362a565b38611309565b6113896149c1565b6112e6565b6001600160601b0316159050386112e0565b60405162461bcd60e51b815260206004820152601360248201527241756374696f6e20696e2070726f677265737360681b6044820152606490fd5b0390fd5b506040546113f89060601c66ffffffffffffff166112ae565b4211156112c3565b346103975760203660031901126103975761142660018060a01b036006541633146135df565b600435604555005b60409060031901126103975760043561144681610d10565b906024356105b381610d10565b60208082019080835283518092528060408094019401926000905b83821061147d57505050505090565b845180516001600160a01b0316875283015186840152948501949382019360019091019061146e565b34610397576114b43661142e565b63ffffffff809116916114c6836136eb565b9060406114d581519384611f07565b848352601f196114e4866136eb565b0160005b81811061154a57505060005b8481168681101561153d57906115326115389261152161151c611517858961497d565b61182a565b614b23565b61152b828961390a565b528661390a565b50613b3c565b6114f4565b82518061042b8782611453565b602090835161155881611eb9565b60008152826000818301528288010152016114e8565b346103975760203660031901126103975760043561158b816108f2565b6115a060018060a01b036006541633146135df565b66ffffffffffffff604b5460a01c164210156115bf576106f990613090565b60405162461bcd60e51b815260206004820152601e60248201527f416c6c6f776c697374206d696e7420616c7265616479207374617274656400006044820152606490fd5b346103975760203660031901126103975760043561162181610f8d565b61163660018060a01b036006541633146135df565b66ffffffffffffff9081604b5460a01c164210156116a3576116786106f99261166e6112ae604a5466ffffffffffffff9060a01c1690565b9083161115614e0b565b604b805466ffffffffffffff60a01b191660a09290921b66ffffffffffffff60a01b16919091179055565b60405162461bcd60e51b815260206004820152600f60248201526e1053081b5a5b9d081cdd185c9d1959608a1b6044820152606490fd5b34610397576000366003190112610397576006546040516001600160a01b039091168152602090f35b3461039757602080600319360112610397576001600160401b03600435818111610397573660238201121561039757806004013591821161039757602490368284830101116103975761176160018060a01b036006541633146135df565b61177583611770604454612be2565b612c6f565b600093601f84116001146117b657509282936000936117a9575b505050600019600383901b1c191660019190911b17604455005b010135905038808061178f565b6044600052601f19841694600080516020615cef833981519152939181905b87821061181057505084600196106117f4575b50505050811b01604455005b60001960f88660031b161c1992010135169055388080806117e8565b8060018497868395968901013581550196019201906117d5565b63ffffffff166000526039602052604060002090565b346103975760203660031901126103975763ffffffff60043561186281610d10565b16600090815260396020908152604091829020805460019091015483516001600160a01b03909216825291810191909152f35b3461039757600080600319360112610670576040518160018054906118b982612be2565b8085529181811690811561064857506001146118df5761042b8461060181880382611f07565b80945082526020938483205b828410611907575050508161042b9361060192820101936105f1565b80548585018701529285019281016118eb565b6040366003190112610397576004356001600160401b038111610397576119486106f9913690600401610a5c565b6119e26119dd6024359261195b846104be565b61197f6119776112ae604b5466ffffffffffffff9060a01c1690565b421015613677565b604a549461199a66ffffffffffffff8760a01c1642106136b4565b6045546040516001600160601b0319606088901b16602082019081526014825291926119d89290916119cd603482611f07565b519020933691613702565b613889565b613750565b6001600160a01b0381166000908152603a6020526040902054611a089060ff1615613788565b611a296002549263ffffffff611a1d856137be565b9160d81c1610156137d9565b611a4b611a3860495460a01c90565b346001600160601b039091161115613812565b611a5632331461384e565b6001600160a01b0381166000908152603a60205260409020611a7f90805460ff19166001179055565b611a8c34603f5401603f55565b6156a7565b34610397576020366003190112610397577f6787c7f9a80aa0f5ceddab2c54f1f5169c0b88e75dd5e19d5e858a64144c7dbc6020600435611ad181610a01565b611ad9614efd565b151560055460ff60a81b8260a81b169060ff60a81b191617600555604051908152a1005b3461039757604036600319011261039757600435611b1a816104be565b602435611b2681610a01565b6001600160a01b03821691338314611ba85781611b65611b769233600052600460205260406000209060018060a01b0316600052602052604060002090565b9060ff801983541691151516179055565b604051901515815233907f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3190602090a3005b60405162461bcd60e51b815260206004820152601960248201527822a9219b99189d1030b8383937bb32903a379031b0b63632b960391b6044820152606490fd5b3461039757602036600319011261039757600435611c06816104be565b611c0e614efd565b6001600160a01b038082169190821515823b1581611ca2575b50611c905760407fcc5dc080ff977b3c3a211fa63ab74f90f658f5ba9d3236e92c8f59570f442aac916106f994611c5c612b02565b8351921682526020820152a1600580546001600160a81b031916600883901b610100600160a81b0316176001179055612b4d565b6040516332483afb60e01b8152600490fd5b905038611c27565b610e997f3ab706acce053a4246886a2268a3fe0f7bac19ed2df0f36286da4936a0654c7a611cd73661142e565b9290611ce1613b51565b611e06604a549466ffffffffffffff611d01818860a01c16421015613a44565b60405490611d2363ffffffff91828460b81c1693610d86858588161115613a7e565b611d2e341515614440565b611d3932331461384e565b6001611d448661182a565b8054611d6c903390611d66906001600160a01b03165b6001600160a01b031690565b1461447a565b018054926001600160601b03611d9c611d8b34831660a088901c6144b5565b9b8561137160025463ffffffff1690565b9184611da6614698565b931611611e595780611dbc9216908b1611613af5565b6001600160f01b03831660a08a901b6001600160a01b031916179055604054611ded9060981c63ffffffff16610e3f565b90851614908115611e4d575b50611e40575b85836144ce565b611e0e614718565b6040805163ffffffff90921682526001600160601b039094166020820152429381019390935233929081906060820190565b611e48614571565b611dff565b60019150161538611df9565b611e779150611e6d610da460485460a01c90565b908b161015613af5565b611dbc565b3461039757600036600319011261039757602063ffffffff60405460b81c16604051908152f35b634e487b7160e01b600052604160045260246000fd5b604081019081106001600160401b03821117611ed457604052565b611ea3565b6001600160401b038111611ed457604052565b602081019081106001600160401b03821117611ed457604052565b90601f801991011681019081106001600160401b03821117611ed457604052565b60405190611f3582611eb9565b565b6001600160401b038111611ed457601f01601f191660200190565b929192611f5e82611f37565b91611f6c6040519384611f07565b829481845281830111610397578281602093846000960137010152565b3461039757608036600319011261039757600435611fa6816104be565b602435611fb2816104be565b606435916001600160401b038311610397573660238401121561039757611fe66106f9933690602481600401359101611f52565b91604435916154ea565b346103975760203660031901126103975760043561200d81615575565b15612157576000908072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8181811015612149575b50506d04ee2d6d415b85acef81000000008083101561213a575b50662386f26fc100008083101561212b575b506305f5e1008083101561211c575b506127108083101561210d575b5060648210156120fd575b600a809210156120f3575b6001908160216120a6828701614d36565b95860101905b6120bd575b61042b61060186614c7e565b600019019083906f181899199a1a9b1b9c1cb0b131b232b360811b8282061a8353049182156120ee579190826120ac565b6120b1565b9160010191612095565b919060646002910491019161208a565b6004919392049101913861207f565b60089193920491019138612072565b60109193920491019138612063565b60209193920491019138612051565b604094500491503880612037565b60405162461bcd60e51b815260206004820152600f60248201526e151bdad95b881b9bdd08199bdd5b99608a1b6044820152606490fd5b34610397576020366003190112610397576004356121ab816108f2565b6121c060018060a01b036006541633146135df565b6127106001600160601b038216116121db576106f9906130b5565b60405162461bcd60e51b815260206004820152601b60248201527a0a4def2c2d8e8f240e0cae4c6cadce8c2ceca40e8dede40d0d2ced602b1b6044820152606490fd5b3461039757600319602036820112610397576004356001600160401b0391828211610397576102c090823603011261039757600080516020615d0f833981519152549160ff8360401c1615921680159081612357575b600114908161234d575b159081612344575b5061233257600080516020615d0f833981519152805467ffffffffffffffff191660011790556122be908261230d575b60040161346a565b6122c457005b600080516020615d0f833981519152805460ff60401b19169055604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a1005b600080516020615d0f833981519152805460ff60401b1916600160401b1790556122b6565b60405163f92ee8a960e01b8152600490fd5b90501538612286565b303b15915061227e565b839150612274565b3461039757600036600319011261039757602063ffffffff604a5460d81c16604051908152f35b346103975760203660031901126103975760206123ad6004356123a8816108f2565b6145cb565b63ffffffff60405191168152f35b346103975760403660031901126103975760206123ef6004356123dd816104be565b602435906123ea826104be565b614f55565b6040519015158152f35b3461039757602036600319011261039757600435612416816104be565b6006546001600160a01b039061242f90821633146135df565b81161561243f576106f990615c85565b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608490fd5b34610397576020366003190112610397576004356124b081610d10565b6124c560018060a01b036006541633146135df565b604a549063ffffffff808216926124e2828260d81c168510614e4a565b6002549066ffffffffffffff9060a01c811642101561253257509261250d916106f994161115614e86565b604a805463ffffffff60d81b191660d89290921b63ffffffff60d81b16919091179055565b60405494919290606086901c16421161259d5760405162461bcd60e51b815260206004820152602a60248201527f43616e6e6f74206368616e6765206d6178537570706c7920647572696e67207460448201526934329030bab1ba34b7b760b11b6064820152608490fd5b6106f99461250d936125e492610e3f926001600160601b0316156125eb575b6040546125dd9060d81c63ffffffff165b60415463ffffffff165b9061362a565b911661497d565b1115614e86565b6125f36149c1565b6125bc565b61260136611251565b9062ffffff6040549161262166ffffffffffffff8460601c164211613923565b6041546126339060401c60ff16613961565b16906126408215156139a2565b61264b32331461384e565b6001600160601b0316156126fa575b600254916126a261269a610e3f61267d6125cd60405463ffffffff9060d81c1690565b604a546113279060d81c63ffffffff1663ffffffff89169061362a565b831115613640565b6126ba610da46126b460485460a01c90565b846139e7565b926126c784341015613a03565b60005b8381106126e5576106f96126e086603f546137cc565b603f55565b806126f46001928401856156a7565b016126ca565b6127026149c1565b61265a565b34610397576060366003190112610397576001600160401b0360043581811161039757612738903690600401610a5c565b909160243590811161039757612752903690600401610a5c565b929061275f6044356104be565b612767613b51565b60405461278166ffffffffffffff8260601c16421161483e565b61278c84151561487e565b6001600160601b031615612af5575b6000938493855b8181106127d45786806127b9576106f96001603855565b6127ce906044356001600160a01b0316614b7a565b80610c1e565b6127ea6115176127e58385896148b4565b61310f565b8054612804903390611d66906001600160a01b0316611d5a565b600181015497600290612819828b16156148c4565b60009060a08b901c60018c1615612adb57878b1061291c575b6001926128cd969594926128939261285160405460018060601b031690565b9061286384888060601b038416613b2f565b60009181811115612914576128789250613b2f565b925b156128d2575b5061288e84546044356156a7565b6137cc565b9a6128c46128ae6128a960415463ffffffff1690565b614968565b63ffffffff1663ffffffff196041541617604155565b179101556138e5565b6127a2565b6126e0612906610da46128f461290e946128ee60475460a01c90565b906139e7565b6127106001600160601b039091160490565b603f546137cc565b38612880565b50509261287a565b6129278b898b6148b4565b6046546040516331a9108f60e11b8152913560048301819052916001600160a01b0391821691906020908181602481875afa928315612aa75785918994612aac575b50831633149283156129f3575b5050509050612986575b50612832565b600193509a6128cd969594926129b88d6129b3612893959f6129aa6129ae91614ae4565b1590565b61492c565b614b04565b6040546129e5906129df90610da4906128f4906001600160601b031660475460a01c6128ee565b926138e5565b9c9250929495965092612980565b604b549294612a5d94508593612a1390611d5a906001600160a01b031681565b604051632e7cda1d60e21b81523360048201526001600160a01b039384166024820152929091166044830152606482019290925260006084820152928391908290819060a4820190565b03915afa918215612aa7578692612a7a575b505080388381612976565b612a999250803d10612aa0575b612a918183611f07565b810190614917565b3880612a6f565b503d612a87565b612b41565b612acd919450833d8511612ad4575b612ac58183611f07565b810190614902565b9238612969565b503d612abb565b60019250612aef906128cd969594926137cc565b9a6128c4565b612afd6149c1565b61279b565b600554600881901c6001600160a01b031691908215612b1e5750565b60ff1615612b2857565b73721c002b0059009a671d00ad1700c9748146cd1b9150565b6040513d6000823e3d90fd5b6001600160a01b0381169081612b61575050565b3b612b6a575b50565b803b15610397576000809160446040518094819363fb2de5d760e01b83523060048401526102d160248401525af115612b6757611f3590611ed9565b903590601e198136030182121561039757018035906001600160401b0382116103975760200191813603831361039757565b356105b3816104be565b90600182811c92168015612c12575b6020831014612bfc57565b634e487b7160e01b600052602260045260246000fd5b91607f1691612bf1565b601f8111612c28575050565b60009081805260208220906020601f850160051c83019410612c65575b601f0160051c01915b828110612c5a57505050565b818155600101612c4e565b9092508290612c45565b601f8111612c7b575050565b6000906044825260208220906020601f850160051c83019410612cb9575b601f0160051c01915b828110612cae57505050565b818155600101612ca2565b9092508290612c99565b90601f8211612cd0575050565b60019160009083825260208220906020601f850160051c83019410612d10575b601f0160051c01915b828110612d065750505050565b8181558301612cf9565b9092508290612cf0565b601f8111612d26575050565b6000906042825260208220906020601f850160051c83019410612d64575b601f0160051c01915b828110612d5957505050565b818155600101612d4d565b9092508290612d44565b601f8111612d7a575050565b6000906043825260208220906020601f850160051c83019410612db8575b601f0160051c01915b828110612dad57505050565b818155600101612da1565b9092508290612d98565b91906001600160401b038111611ed457612de681612de1604254612be2565b612d1a565b6000601f8211600114612e2057819293600092612e15575b50508160011b916000199060031b1c191617604255565b013590503880612dfe565b6042600052601f198216937f38dfe4635b27babeca8be38d3b448cb5161a639b899a14825ba9c8d7892eb8c391805b868110612e875750836001959610612e6d575b505050811b01604255565b0135600019600384901b60f8161c19169055388080612e62565b90926020600181928686013581550194019101612e4f565b91906001600160401b038111611ed457612ec381612ebe604354612be2565b612d6e565b6000601f8211600114612efd57819293600092612ef2575b50508160011b916000199060031b1c191617604355565b013590503880612edb565b6043600052601f198216937f9690ad99d6ce244efa8a0f6c2d04036d3b33a9474db32a71b71135c69510279391805b868110612f645750836001959610612f4a575b505050811b01604355565b0135600019600384901b60f8161c19169055388080612f3f565b90926020600181928686013581550194019101612f2c565b91906001600160401b038111611ed457612f9b81611770604454612be2565b6000601f8211600114612fd557819293600092612fca575b50508160011b916000199060031b1c191617604455565b013590503880612fb3565b6044600052601f19821693600080516020615cef83398151915291805b86811061302a5750836001959610613010575b505050811b01604455565b0135600019600384901b60f8161c19169055388080613005565b90926020600181928686013581550194019101612ff2565b80546001600160a01b0319166001600160a01b03909216919091179055565b356105b3816108f2565b604880546001600160a01b031660a09290921b6001600160a01b031916919091179055565b604980546001600160a01b031660a09290921b6001600160a01b031916919091179055565b604680546001600160a01b031660a09290921b6001600160a01b031916919091179055565b356105b381610f8d565b604a805466ffffffffffffff60a01b191660a09290921b66ffffffffffffff60a01b16919091179055565b356105b381610d10565b604b805463ffffffff60d81b191660d89290921b63ffffffff60d81b16919091179055565b6040805463ffffffff60d81b191660d89290921b63ffffffff60d81b16919091179055565b356105b381611244565b6134116102a0611f359261318a6131848280612ba6565b90612dc2565b6131a061319a6020830183612ba6565b90612e9f565b6131b66131b06040830183612ba6565b90612f7c565b60608101356045556131ef6131cd60808301612bd8565b604680546001600160a01b0319166001600160a01b0392909216919091179055565b6132036131fe60a08301613061565b6130b5565b61323461321260c08301612bd8565b604780546001600160a01b0319166001600160a01b0392909216919091179055565b61324361096460e08301613061565b6132756132536101008301612bd8565b604880546001600160a01b0319166001600160a01b0392909216919091179055565b61328a6132856101208301613061565b61306b565b6132bc61329a6101408301612bd8565b604980546001600160a01b0319166001600160a01b0392909216919091179055565b6132d16132cc6101608301613061565b613090565b6133036132e16101808301612bd8565b604a80546001600160a01b0319166001600160a01b0392909216919091179055565b6133186133136101a083016130da565b6130e4565b61332861250d6101c0830161310f565b61335a6133386101e08301612bd8565b604b80546001600160a01b0319166001600160a01b0392909216919091179055565b61336a61167861020083016130da565b61337f61337a610220830161310f565b613119565b6133a561338f610240830161310f565b63ffffffff1663ffffffff19604c541617604c55565b6133d66133b5610260830161310f565b63ffffffff60201b604c549160201b169063ffffffff60201b191617604c55565b61340b6133e6610280830161310f565b604c805463ffffffff60401b191660409290921b63ffffffff60401b16919091179055565b01613163565b604c805462ffffff60601b191660609290921b62ffffff60601b16919091179055565b634e487b7160e01b600052601160045260246000fd5b91909166ffffffffffffff8080941691160191821161346557565b613434565b6134748180612ba6565b9061349c60209261349461348a85870187612ba6565b9490923691611f52565b923691611f52565b916134a56151a9565b6134ad6151a9565b8151906001600160401b038211611ed4576000926134d4836134cf8654612be2565b612c1c565b81601f841160011461355157509180849261352a97969461350e9692613546575b50508160011b916000199060031b1c19161790556151d8565b613525613520611d5a60c08401612bd8565b615c71565b61316d565b611f3561103a61101f604a5466ffffffffffffff9060a01c1690565b0151905038806134f5565b600080529190601f1984167f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5639386905b8282106135c757505092600192859261352a99989661350e9896106135ae575b505050811b0190556151d8565b015160001960f88460031b161c191690553880806135a1565b80600186978294978701518155019601940190613581565b156135e657565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b63ffffffff918216908216039190821161346557565b1561364757565b60405162461bcd60e51b8152602060048201526008602482015267546f6f206d616e7960c01b6044820152606490fd5b1561367e57565b60405162461bcd60e51b815260206004820152600e60248201526d1053081b9bdd081cdd185c9d195960921b6044820152606490fd5b156136bb57565b60405162461bcd60e51b8152602060048201526008602482015267105308195b99195960c21b6044820152606490fd5b6001600160401b038111611ed45760051b60200190565b929161370d826136eb565b9161371b6040519384611f07565b829481845260208094019160051b810192831161039757905b8282106137415750505050565b81358152908301908301613734565b1561375757565b60405162461bcd60e51b8152602060048201526009602482015268139bdd081bdb88105360ba1b6044820152606490fd5b1561378f57565b60405162461bcd60e51b815260206004820152600760248201526610db185a5b595960ca1b6044820152606490fd5b906001820180921161346557565b9190820180921161346557565b156137e057565b60405162461bcd60e51b815260206004820152600a602482015269135a5b9d1959081bdd5d60b21b6044820152606490fd5b1561381957565b60405162461bcd60e51b815260206004820152600d60248201526c496e76616c69642066756e647360981b6044820152606490fd5b1561385557565b60405162461bcd60e51b815260206004820152600c60248201526b4e6f20636f6e74726163747360a01b6044820152606490fd5b929091906000915b84518310156138dd576138a4838661390a565b51906000828210156138cb57506000526020526138c56040600020926138e5565b91613891565b6040916138c5938252602052206129df565b915092501490565b60001981146134655760010190565b634e487b7160e01b600052603260045260246000fd5b805182101561391e5760209160051b010190565b6138f4565b1561392a57565b60405162461bcd60e51b815260206004820152600f60248201526e41756374696f6e206f6e676f696e6760881b6044820152606490fd5b1561396857565b60405162461bcd60e51b8152602060048201526012602482015271141d589b1a58c81b9bdd08185b1b1bddd95960721b6044820152606490fd5b156139a957565b60405162461bcd60e51b81526020600482015260166024820152754d757374206d696e74206174206c65617374206f6e6560501b6044820152606490fd5b6001600160601b03918216908216029081169190820361346557565b15613a0a57565b60405162461bcd60e51b8152602060048201526012602482015271496e73756666696369656e742066756e647360701b6044820152606490fd5b15613a4b57565b60405162461bcd60e51b815260206004820152600b60248201526a139bdd081cdd185c9d195960aa1b6044820152606490fd5b15613a8557565b60405162461bcd60e51b815260206004820152600c60248201526b42616420657374696d61746560a01b6044820152606490fd5b15613ac057565b60405162461bcd60e51b815260206004820152600d60248201526c105d58dd1a5bdb88195b991959609a1b6044820152606490fd5b15613afc57565b60405162461bcd60e51b815260206004820152600b60248201526a42696420746f6f206c6f7760a81b6044820152606490fd5b9190820391821161346557565b63ffffffff8091169081146134655760010190565b600260385414613b62576002603855565b604051633ee5aeb560e01b8152600490fd5b6040805463ffffffff60981b191660989290921b63ffffffff60981b16919091179055565b906020600191613bb1838060a01b0382511685613042565b0151910155565b6040805460a085901b6001600160a01b03191694600194938587179363ffffffff936001600160601b039093169290919060981c841615613fbd578381168015159081613f9e575b5015613f8c57965b613c23610da4610da489613c1b8c61182a565b015460a01c90565b831115613d9357505084906000915b613d31575b5015613c8c5750604884901b63ffffffff60481b161792613c88919083613c8163ffffffff60281b1982613c6a8561182a565b01541663ffffffff60281b8560281b16179261182a565b015561182a565b0155565b8385613cab610e3f83613ca3613c8898979a61182a565b015460481c90565b9263ffffffff60281b9183613cf563ffffffff60481b9a858460281b16908c8960481b1617179a63ffffffff60481b1983613ce58661182a565b015416908960481b16179261182a565b0155831615613d2557613c819063ffffffff60281b1983613d158661182a565b015416908560281b16179261182a565b50505061151781613b74565b828716151580613d78575b15613d7357613d59610e3f87613d518a61182a565b015460281c90565b83811615613d6957965085613c32565b5050508338613c37565b613c37565b5080613d8d610da4610da489613c1b8c61182a565b10613d3c565b90939296918680600092613db2610e3f895463ffffffff9060981c1690565b915b613f28575b505050600014613e7f5750508154613c88939291859160981c63ffffffff1690613de285613b74565b602882901b63ffffffff60281b16179682613dfc8361182a565b0154935463ffffffff60481b198516604887901b63ffffffff60481b16908117959092909160b81c63ffffffff1690613e52610e3f613e44604a5463ffffffff9060d81c1690565b60025463ffffffff166125d7565b91161015613e66575b5050613c819061182a565b600163ffffffff60481b011916179250613c8138613e5b565b613c8894935081969250613e9a610e3f87613d51819561182a565b9263ffffffff60281b9783613ee68163ffffffff60481b958c8960281b1690878660481b161717179a63ffffffff60281b1983613ed68661182a565b015416908960281b16179261182a565b01558316613ef7575b50505061182a565b613f1e9063ffffffff60481b1983613f0e8661182a565b015416908560481b16179261182a565b0155388381613eef565b9091948a811680151580613f70575b15613f68578314613f5b57610e3f86613ca3613f529361182a565b94919082613db4565b9492505050863880613db9565b509491613db9565b5082613f85610da4610da48a613c1b8761182a565b1015613f37565b50805460981c63ffffffff1696613c08565b9050613fb5610e3f845463ffffffff9060b81c1690565b101538613c00565b505050509150611f35925080613fd5613fec92613b74565b613fdd611f28565b9260008452602084015261182a565b613b99565b604080546001600160a01b031960a086901b1695946001938488179363ffffffff936001600160601b039093169290919060981c84161561441d5783811680151590816143fe575b50156143ec57975b614054610da4610da488613c1b8d61182a565b83111561420a57505083906000915b61419d575b50156140f75750604885901b63ffffffff60481b161793816140ad63ffffffff60281b19826140968561182a565b01541663ffffffff60281b8660281b16179261182a565b01555b6001600160a01b038316156140ec5750613fec90611f35936140e26140d3611f28565b6001600160a01b039095168552565b602084015261182a565b9150613c889061182a565b90948061410b610e3f85613ca3819561182a565b9263ffffffff60281b918361415563ffffffff60481b9a858460281b16908c8960481b1617179a63ffffffff60481b19836141458661182a565b015416908a60481b16179261182a565b015583161561418c576141859063ffffffff60281b19836141758661182a565b015416908660281b16179261182a565b01556140b0565b50505061419882613b74565b6140b0565b90919293968381161515806141ef575b156141e5576141c2610e3f89613d518461182a565b90848216156141d75750969392919084614063565b979493925050508238614068565b9693929190614068565b5081614204610da4610da48b613c1b8661182a565b106141ad565b90939297918580600092614229610e3f895463ffffffff9060981c1690565b915b614388575b5050506000146142e3575050815483919060981c63ffffffff169061425486613b74565b602882901b63ffffffff60281b1617968261426e8361182a565b0154935463ffffffff60481b198516604888901b63ffffffff60481b16908117959092909160b81c63ffffffff16906142b6610e3f613e44604a5463ffffffff9060d81c1690565b911610156142ca575b50506141859061182a565b600163ffffffff60481b011916179250614185386142bf565b909692508391506142fa610e3f83613d518a61182a565b9263ffffffff60281b97836143468163ffffffff60481b958c8960281b1690878660481b161717179a63ffffffff60281b19836143368661182a565b015416908a60281b16179261182a565b01558316614357575b5050506140b0565b61437e9063ffffffff60481b198361436e8661182a565b015416908660481b16179261182a565b015538818161434f565b9091948b8116801515806143d0575b156143c85783146143bb57610e3f86613ca36143b29361182a565b9491908261422b565b9492505050853880614230565b509491614230565b50826143e5610da4610da48a613c1b8761182a565b1015614397565b50805460981c63ffffffff1697614041565b9050614415610e3f845463ffffffff9060b81c1690565b101538614039565b50505050611f359450829150614435613fec93613b74565b6140e26140d3611f28565b1561444757565b60405162461bcd60e51b815260206004820152600b60248201526a139bc8115512081cd95b9d60aa1b6044820152606490fd5b1561448157565b60405162461bcd60e51b815260206004820152600c60248201526b139bdd081e5bdd5c88189a5960a21b6044820152606490fd5b6001600160601b03918216908216019190821161346557565b611f359260016144dd8361182a565b015463ffffffff90818160281c16918160481c16918061453d575b5081614506575b5050613bb8565b6001906145349063ffffffff60281b19836145208661182a565b0154169063ffffffff60281b16179261182a565b015538806144ff565b600161456963ffffffff60481b19826145558561182a565b01541663ffffffff60481b8516179261182a565b0155386144f8565b63ffffffff8060405460981c169081156145c75781611f3592600052603960205260016145a881198260406000200154169261182a565b015560016145bc8260405460981c1661182a565b015460281c16613b74565b5050565b906145df60405463ffffffff9060981c1690565b63ffffffff928382161561469057600190614603610da4610da484613c1b8761182a565b6001600160601b03909116908111156146895781949293945b614627575b50505090565b9091939284811615158061466e575b156146675761464b610e3f84613d518461182a565b908582161561465f5750929391908161461c565b939450614621565b9293614621565b5081614683610da4610da486613c1b8661182a565b10614636565b5090925050565b506000925050565b63ffffffff6146b781604a5460d81c166125d760025463ffffffff1690565b816040549116828260b81c161015806146f1575b156146e6576001613c1b6105b393610da49360981c1661182a565b505060485460a01c90565b50818160981c1615156146cb565b66ffffffffffffff918216908216039190821161346557565b60405460601c66ffffffffffffff1666ffffffffffffff6000828216428111156148375761474891504290613b2f565b905b604c549263ffffffff92838560201c1611614766575b50505050565b61478861478261101f604a5466ffffffffffffff9060a01c1690565b826146ff565b838560401c16808483161061479f575b5050614760565b8061103a956147c29716946147b4868561344a565b1611614824575b505061344a565b7fc2b459809119087ca9d2bc10dea53a51b7d848b1a11075db037bdca58292c3e86148166147fc60405466ffffffffffffff9060601c1690565b60405166ffffffffffffff90911681529081906020820190565b0390a1388080808080614798565b61482f9293506146ff565b9038806147bb565b509061474a565b1561484557565b60405162461bcd60e51b8152602060048201526011602482015270105d58dd1a5bdb881b9bdd08195b991959607a1b6044820152606490fd5b1561488557565b60405162461bcd60e51b81526020600482015260076024820152664e6f206269647360c81b6044820152606490fd5b919081101561391e5760051b0190565b156148cb57565b60405162461bcd60e51b815260206004820152600f60248201526e105b1c9958591e4818db185a5b5959608a1b6044820152606490fd5b9081602091031261039757516105b3816104be565b9081602091031261039757516105b381610a01565b1561493357565b60405162461bcd60e51b815260206004820152600d60248201526c111a5cd8dbdd5b9d081d5cd959609a1b6044820152606490fd5b90600163ffffffff8093160191821161346557565b91909163ffffffff8080941691160191821161346557565b8181029291811591840414171561346557565b6001600160601b03908116612710039190821161346557565b6149f46149d360025463ffffffff1690565b63ffffffff60201b6041549160201b169063ffffffff60201b191617604155565b611f356126e0612906610c01614aa9614a2a614a19604a5463ffffffff9060d81c1690565b60415460201c63ffffffff166125d7565b60405463ffffffff919060b81c82168183168110614ac65750614a4c9061313e565b614a8f614a6d610da46001613c1b61151760405463ffffffff9060981c1690565b604080546001600160601b0319166001600160601b0392909216919091179055565b6040546001600160601b0381169160d89190911c16614995565b614ac0610da4614abb60475460a01c90565b6149a8565b90614995565b614ad0915061313e565b614adf614a6d60485460a01c90565b614a8f565b8060081c90600482101561391e5760ff600191161b90603b015416151590565b8060081c600481101561391e5760ff600191603b0192161b8154179055565b90604051614b3081611eb9565b82546001600160a01b031681526001909201546020830152565b3d15614b75573d90614b5b82611f37565b91614b696040519384611f07565b82523d6000602084013e565b606090565b6000918291829182916001600160a01b03165af1614b96614b4a565b5015614b9e57565b60405162461bcd60e51b8152602060048201526015602482015274115d1a195c881d1c985b9cd9995c8819985a5b1959605a1b6044820152606490fd5b90614be5826152bb565b8015614c4c57614bf4816136eb565b90614c026040519283611f07565b808252601f19614c11826136eb565b0136602084013760005b818110614c29575090925050565b80614c37614c4792876150ef565b614c41828661390a565b526138e5565b614c1b565b509050604051614c5b81611eec565b60008152600036813790565b90614c7a6020928281519485920161055a565b0190565b9060405191826000604454614c9281612be2565b600191808316908115614d0e5750600114614cc5575b5050614cb790611f3593614c67565b03601f198101845283611f07565b60446000908152602093509091600080516020615cef8339815191525b838310614cf85750505082010182614cb7614ca8565b8054898401860152889550918401918101614ce2565b614cb79450611f35969350602092915060ff1916828601528015150284010191819450614ca8565b90614d4082611f37565b614d4d6040519182611f07565b8281528092614d5e601f1991611f37565b0190602036910137565b15614d6f57565b60405162461bcd60e51b815260206004820152602860248201527f43616e6e6f742073657420646973636f756e742061667465722061756374696f6044820152676e2073746172747360c01b6064820152608490fd5b15614dcc57565b60405162461bcd60e51b8152602060048201526017602482015276105d58dd1a5bdb88185b1c9958591e481cdd185c9d1959604a1b6044820152606490fd5b15614e1257565b60405162461bcd60e51b815260206004820152601060248201526f20a61030b33a32b91030bab1ba34b7b760811b6044820152606490fd5b15614e5157565b60405162461bcd60e51b815260206004820152600d60248201526c4f6e6c7920646563726561736560981b6044820152606490fd5b15614e8d57565b60405162461bcd60e51b81526020600482015260116024820152706d6178537570706c7920746f6f206c6f7760781b6044820152606490fd5b15614ecd57565b60405162461bcd60e51b81526020600482015260086024820152674e6f2066756e647360c01b6044820152606490fd5b6006546001600160a01b03163303614f1157565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2043616c6c6572206973206e6f7420746865206f776e65726044820152fd5b6001600160a01b039081166000908152600460209081526040808320858516845290915290205460ff169291908315614f8c575050565b60ff60055460a81c16614f9d575050565b8091929350614faa612b02565b1691161490565b60809060208152602c60208201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60408201526b7574206f6620626f756e647360a01b60608201520190565b90600254908183101561506f57600092835b8381106150305760405162461bcd60e51b8152806113db60048201614fb1565b61503981615575565b61504c575b615047906138e5565b615010565b9381811461506857615060615047916138e5565b94905061503e565b5090915050565b60405162461bcd60e51b8152806113db60048201614fb1565b60809060208152602b60208201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560408201526a74206f6620626f756e647360a81b60608201520190565b60025481101561391e57600260005260206000200190600090565b906150f9826152bb565b811015615190576000908192600254935b84811061512a5760405162461bcd60e51b8152806113db60048201615088565b61514e611d5a615139836150d4565b905460039190911b1c6001600160a01b031690565b6001600160a01b0383161461516c575b615167906138e5565b61510a565b9282810361517c57505050905090565b615188615167916138e5565b93905061515e565b60405162461bcd60e51b8152806113db60048201615088565b60ff600080516020615d0f8339815191525460401c16156151c657565b604051631afcd79f60e31b8152600490fd5b9081516001600160401b038111611ed4576001906151ff816151fa8454612be2565b612cc3565b602080601f831160011461523a57508192939460009261522f575b5050600019600383901b1c191690821b179055565b01519050388061521a565b6001600052601f198316959091907fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6926000905b8882106152a4575050838596971061528b575b505050811b019055565b015160001960f88460031b161c19169055388080615281565b80878596829496860151815501950193019061526e565b6001600160a01b0316801561531857600254600091825b8281106152df5750505090565b6152ee611d5a615139836150d4565b8214615303575b6152fe906138e5565b6152d2565b926153106152fe916138e5565b9390506152f5565b60405162461bcd60e51b815260206004820152602a60248201527f4552433732313a2062616c616e636520717565727920666f7220746865207a65604482015269726f206164647265737360b01b6064820152608490fd5b61537981615575565b156153aa5760025481101561391e576002600052600080516020615ccf83398151915201546001600160a01b031690565b60405162461bcd60e51b815260206004820152602960248201527f4552433732313a206f776e657220717565727920666f72206e6f6e657869737460448201526832b73a103a37b5b2b760b91b6064820152608490fd5b61540a81615575565b1561542a576000908152600360205260409020546001600160a01b031690565b60405162461bcd60e51b815260206004820152602c60248201527f4552433732313a20617070726f76656420717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608490fd5b1561548b57565b60405162461bcd60e51b815260206004820152603160248201527f4552433732313a207472616e736665722063616c6c6572206973206e6f74206f6044820152701ddb995c881b9bdc88185c1c1c9bdd9959607a1b6064820152608490fd5b9061550e9392916154fe61089b84336155ae565b615509838383615937565b615b67565b1561551557565b60405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b6064820152608490fd5b60025481109081615584575090565b901561391e576002600052600080516020615ccf83398151915201546001600160a01b0316151590565b6155b782615575565b15615610576155c582615370565b6001600160a01b0382811682821681149490919085156155f8575b50505082156155ee57505090565b6105b39250614f55565b6156059192939550615401565b1614913880806155e0565b60405162461bcd60e51b815260206004820152602c60248201527f4552433732313a206f70657261746f7220717565727920666f72206e6f6e657860448201526b34b9ba32b73a103a37b5b2b760a11b6064820152608490fd5b60025490600160401b821015611ed457600182018060025582101561391e576002600052611f3591600080516020615ccf83398151915201613042565b6001600160a01b0381169190821561574e576156c282615575565b6157095781611f35936156d58284615792565b6156de8361566a565b60007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8180a4615792565b60405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e746564000000006044820152606490fd5b606460405162461bcd60e51b815260206004820152602060248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152fd5b60005b60019081811015614760578084018411613465576001600160a01b0383166157c957604051635cbd944160e01b8152600490fd5b01615795565b909160005b6001908181101561584a57808301808411613465576001600160a01b0386811615908616158080615843575b1561581757604051635cbd944160e01b8152600490fd5b15615825575b5050016157d4565b15615831575b8061581d565b61583d90868633615851565b3861582b565b5081615800565b5050505050565b9092916001600160a01b039182615866612b02565b1680615875575b505050505050565b80331461586d57803b15610397576000948460849481604051998a98899763657711f560e11b895216600488015216602486015216604484015260648301525afa8015612aa7576158cb575b808080808061586d565b806158d86158de92611ed9565b8061038c565b386158c1565b60005b6001908181101561584a578085018511613465576001600160a01b0383811615908161592c575b501561592657604051635cbd944160e01b8152600490fd5b016158e7565b90508416153861590e565b919061594282615370565b6001600160a01b0380851694918116859003615a225782169384156159d157611f359484916159728386866157cf565b61597b83615a79565b6159a785615988856150d4565b90919082549060031b9160018060a01b03809116831b921b1916179055565b7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef600080a46158e4565b60405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b60405162461bcd60e51b815260206004820152602960248201527f4552433732313a207472616e73666572206f6620746f6b656e2074686174206960448201526839903737ba1037bbb760b91b6064820152608490fd5b600081815260036020526040812080546001600160a01b03191690556001600160a01b03615aa683615370565b167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258280a4565b816000526003602052615ae4816040600020613042565b6001600160a01b0380615af684615370565b169116907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925600080a4565b9081602091031261039757516105b3816103cb565b6001600160a01b0391821681529116602082015260408101919091526080606082018190526105b39291019061057d565b92909190823b15615c6857615b9a926020926000604051809681958294630a85bd0160e11b9a8b85523360048601615b36565b03926001600160a01b03165af160009181615c38575b50615c2a57615bbd614b4a565b80519081615c255760405162461bcd60e51b815260206004820152603260248201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560448201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b6064820152608490fd5b602001fd5b6001600160e01b0319161490565b615c5a91925060203d8111615c61575b615c528183611f07565b810190615b21565b9038615bb0565b503d615c48565b50505050600190565b611f3590615c7d6151a9565b615c856151a9565b600680546001600160a01b039283166001600160a01b0319821681179092559091167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a356fe405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace9b22d3d61959b4d3528b1d8ba932c96fbe302b36a1aad1d95cab54f9e0a135eaf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a2646970667358221220a7490472e6e63dfa7959a8faa7442df8cce2fdefdac519ad5e2f93fc085f386664736f6c63430008140033

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

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