ETH Price: $2,821.46 (+8.73%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
0x60806040186272492023-11-22 12:22:59350 days ago1700655779IN
 Create: CHARACTER_SHOP_UPGRADEABLE
0 ETH0.0988409430

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CHARACTER_SHOP_UPGRADEABLE

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 10 runs

Other Settings:
default evmVersion
File 1 of 37 : CHARACTER_SHOP_UPGRADABLE.sol
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/utils/cryptography/MerkleProofUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol";
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol';
import "./CHARACTER_V1_UPGRADABLE.sol";

// @title: Wally Shop Smart contract
// @author: SQuare Enix
// @notice: NFT marketplace for the sale of Symbiogenesis project's NFTs(ERC-721).
// @custom: Users can bid on their favorite NFT tokens and win the auction by making highest bid or buy NFT token direcly

contract CHARACTER_SHOP_UPGRADEABLE is Initializable, ReentrancyGuardUpgradeable, PausableUpgradeable, OwnableUpgradeable {
    using StringsUpgradeable for uint256;
    //private mapping variable that stores auction data as keys reference to address and id of token 
    //returns structure type auction data
    mapping(address => mapping(uint256 => Auction)) private nftContractAuctions;
    //private mapping variable that stores counts of NFT token which user bought
    mapping(address => mapping(uint256 => uint128)) public userBuyCountInSmallSale;
    //private array variable that stores that stores sale data
    //returns structure type sale data.
    SmallSale[] public smallSales;
    //address that payment for NFT token from users is transferred.
    address public feeReceiver;
    //Amount of ethers which sending transactions are failed in the process of NFT sale.
    uint256 public failedTransferCredits;
    //public mapping variable that stores base Uri for chapter as keys reference to address and id of token.
    //returns structure type  BaseUriForChapter data.
    mapping(address => mapping(uint8 => BaseUrlForChapter)) public baseUrlForChapter;
    //enum type data that stores Sale type.
    enum SaleType {
        BuyNow, // immediate sell and buy sale type that has price larger than zero.
        EnglishAuction, // Auction sale type.
        ZeroPriceSale // imediate sell and buy sale type which price is equal with zero.
    }
    
    struct SmallSale {
        bytes32 allowListRoot; // root value of merkletree for allowlists
        uint128 price; //  price of token being sold or start price of token in auction.
        uint128 buyLimit; // limit count of token that user can purchase.
        address nftContractAddress; // NFT contract address
        uint8 chapterId; // chapter id 
        SaleType saleType; // Sale type
        uint128 bidIncreaseAmount; // amount that user should pay more than prevous highest bidder in Auction
        uint256 startAt; // start time of auction
        uint256 auctionEnd; // end tine of auction
    }

    struct BaseUrlForChapter {
        uint8 isSet; // status variable that represent whether baseUri is set or not
        string baseUrl; // base uri
    }

    struct Auction {
        uint256 auctionEnd; // auction end time
        uint128 nftHighestBid; // amount that highest bidder pay(ether or other native token)
        address nftHighestBidder; // address of highest bidder
        uint8 sold; // status variable represent whether NFT token is sold or not.
        bool isOnAuction; // status variable represent whether auction is going or not.
        uint256 bidsCount; // count of bidders.
        uint256 smallSaleId; // Sale id
    }
    //Comprehensive Auction data structure.
    //it supports to getting the comprehensive auction data and providing it to the out of blockchain 
    struct CombinedAuctionData {
        uint128 bidIncreaseAmount;
        uint32 reserved_1;
        uint256 auctionEnd;
        uint128 minPrice;
        uint128 buyNowPrice;
        uint128 nftHighestBid;
        bytes32 allowListRoot;
        address nftHighestBidder;
        string tokenURI;
        uint8 sold;
        bool isOnAuction;
        uint256 bidsCount;
        uint256 startAt;
        uint256 smallSaleId;
    }

    /*╔═════════════════════════════╗
      ║           EVENTS            ║
      ╚═════════════════════════════╝*/
    //event that is trigered when auction is created
    //NFT contract address, token id and sale id
    event AuctionCreated(
        address indexed nftContractAddress,
        uint256 indexed tokenId,
        uint256 indexed smallSaleId
    );
    //event that is trigered when sale is created
    //NFT contract address, token id, token price and buyer address
    event SaleCreated(
        address indexed nftContractAddress,
        uint256 indexed tokenId,
        uint128 buyNowPrice,
        address buyer
    );
    //event that is trigered when bid is made
    //NFT contract address, token id, bidder address, eth amount bidder pay, time bid is made.
    event BidMade(
        address indexed nftContractAddress,
        uint256 indexed tokenId,
        address bidder,
        uint128 ethAmount,
        uint256 createdAt
    );
    //event that is trigered when payout is failed
    //NFT contract address, token id, sale id, eth amount that payout, recipient address.
    event FailedPayout(
        address indexed nftContractAddress,
        uint256 indexed tokenId,
        address toAddress,
        uint128 ethAmount
    );
    //event that is trigered when auction end time is updated
    //param: NFT contract address, token id and time added to auction end time
    event AuctionPeriodUpdated(
        address indexed nftContractAddress,
        uint256 indexed tokenId,
        uint256 auctionEndPeriod
    );
    //event that is trigered when NFT(id)is minted and nfthighestBid is transferred to feeReceiver address.
    //param: NFT contract address, token id, eth amount of highest bidder pay and address of highest bidder
    event CharaterMintedAndPaymentPaid(
        address indexed nftContractAddress,
        uint256 indexed tokenId,
        uint128 nftHighestBid,
        address nftHighestBidder
    );
    //event that is trigered when auction is settled
    //param: NFT contract address, token id and address of user call settleAuction function.
    event AuctionSettled(
        address indexed nftContractAddress,
        uint256 indexed tokenId,
        address auctionSettler
    );
    //event that is trigered when auction is widrawn
    //param: NFT contract address, token id and address of nft owner.
    event AuctionWithdrawn(
        address indexed nftContractAddress,
        uint256 indexed tokenId,
        address nftOwner
    );
    //event that is trigered when takeHighestBidder is triggered.
    //param: NFT contract address and token id 
    event HighestBidTaken(
        address indexed nftContractAddress,
        uint256 indexed tokenId
    );
    //event that is trigered when sale is created
    //param: NFT contract address, token id, sale id and time that sale created at.
    event SmallSaleCreated(uint256 indexed smallSaleId, uint256 createdAt);
    //event that is trigered when BaseUri is set for chapter.
    //param: NFT contract address, token id, sale id, baseUrl and time that baseUrl is set.
    event BaseUrlForChapterSet(
        address indexed nftContractAddress,
        uint8 indexed chapterId,
        string baseUrl,
        uint256 createdAt
    );

    /**********************************/
    /*╔═════════════════════════════╗
      ║             END             ║
      ║            EVENTS           ║
      ╚═════════════════════════════╝*/
    /**********************************/
    //modifier that check if auction is ongoing
    //param: NFT contract address, token id and sale id
    //check if token is sold, saleId is valid and current time is in the range of auction time
    modifier auctionOngoing(address _nftContractAddress, uint256 _tokenId) {
        require(
            nftContractAuctions[_nftContractAddress][_tokenId].sold == 0,
            "Token is already sold!"
        );
        require(
            nftContractAuctions[_nftContractAddress][_tokenId].smallSaleId < smallSales.length,
            "Small sale does not exist on this token."
        );
        require(
            _isAuctionOngoing(_nftContractAddress, _tokenId) == 1,
            "Auction has ended or not started yet"
        );
        _;
    }
    //modifier that check if smallSale exists.
    //param: sale id
    //check if the sale id is in the valid range.
    modifier smallSaleExist(uint256 _smallSaleId) {
        require(_smallSaleId < smallSales.length, "SmallSaleID is invalid!");
        _;
    }
    //modifier that check if counts of NFT that user bought exceed the limit.
    //param: NFT contract address, token id 
    //first check if the sale id is in the valid range and check if userBuyCount exceed the limit.
    modifier notExceedBuyLimit(address _nftContractAddress, uint256 _tokenId) {
        uint256 smallSaleId = nftContractAuctions[_nftContractAddress][_tokenId]
            .smallSaleId;
        require(
            smallSaleId < smallSales.length,
            "Not existing small sale for current token"
        );
        require(
            userBuyCountInSmallSale[msg.sender][smallSaleId] <
                smallSales[smallSaleId].buyLimit,
            "User exceeds buy limit for current small sale"
        );
        _;
    }

    //modifier that check if bid amount user pay meets certain requirement 
    //param: NFT contract address, token id 
    //call other modifier _doesBidMeetBidRequirements.
    modifier bidAmountMeetsBidRequirements(
        address _nftContractAddress,
        uint256 _tokenId
    ) {
        require(
            _doesBidMeetBidRequirements(_nftContractAddress, _tokenId) == 1,
            "Not enough funds to bid on NFT"
        );
        _;
    }
    //modifier that check if chapter is valid 
    //param: NFT contract address, token id 
    //check isSet of baseUriForChapter is equal with 1
    modifier isValidChapter(address _nftContractAddress, uint8 _chapterId) {
        require(
            baseUrlForChapter[_nftContractAddress][_chapterId].isSet == 1,
            "Base URL for chapter is not set"
        );
        _;
    }

    /**********************************/
    /*╔═════════════════════════════╗
      ║             END             ║
      ║          MODIFIERS          ║
      ╚═════════════════════════════╝*/

      
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++///@notice: modifier that check if bid amount user pay meets certain requirement 
    //This is a constructor that is executed when contract deployed, 
    //param: wallet address that all ethers that users pay for NFT are transferred
    //check if parameter is valid address.
     function initialize(address _feeReceiver) external initializer {
        require(_feeReceiver != address(0), "Cannot specify 0 address");
        feeReceiver = _feeReceiver;
        __Pausable_init();
        __ReentrancyGuard_init();
        __Ownable_init();
     }


    //@nitice: This is a externalfunction that create one of three kinds of Sales according to Sale type.
    //@param: all variables to create Sale and describe the Sale.
    //@dev: Only Contract Owner can call this function and can execute this function when contract is not paused, there is no reentrance attack and baseUrl for chapter is set correctly. 
    //@return: return Sale id.
    function createSmallSale(
        bytes32 _allowRoot,
        SaleType _saleType,
        uint128 _price,
        uint128 _buyLimit,
        address _nftContractAddress,
        uint8 _chapterId,
        uint128 _bidIncreaseAmount,
        uint256 _startAt,
        uint256 _endAt
    )
        external
        onlyOwner
        whenNotPaused
        nonReentrant
        isValidChapter(_nftContractAddress, _chapterId)
        returns (uint256)
    {
        ///check if cureent time is in the range of auction time
        require(
            block.timestamp < _endAt,
            "Auction end is less than current timestamp"
        );
        require(_startAt < _endAt, "Auction end is less than auction start");
        ///check if buylimits is valid value(must be bigger than zero).
        require(_buyLimit > 0, "Buy limit must larger than 0");
        /// check if corresponding conditions fit depending on the sale type
        if (_saleType == SaleType.ZeroPriceSale && _price > 0)
            revert("Price should be zero on Zero price sale.");
        if (_saleType == SaleType.BuyNow && _price == 0)
            revert("Price should be larger than zero on Buy now sale.");
        if (_saleType == SaleType.EnglishAuction && _bidIncreaseAmount == 0)
            revert(
                "Bid increase amount should be larger than zero on English auction."
            );
        if (_saleType != SaleType.EnglishAuction && _bidIncreaseAmount != 0)
            revert("Bid increae amount should be zero on buy now sale.");
        
        smallSales.push(
            SmallSale(
                _allowRoot,
                _price,
                _buyLimit,
                _nftContractAddress,
                _chapterId,
                _saleType,
                _bidIncreaseAmount,
                _startAt,
                _endAt
            )
        );
        uint256 saleCount = smallSales.length - 1;
        emit SmallSaleCreated(saleCount, block.timestamp);
        return saleCount;
    }

    //@notice: This is a external function that can set the baseUrl for Chapter of NFT.
    //@param: NFT contract address, Chapter id, baseUrl
    //@dev: Only contract owner can call this function and can execute when contract is not paused.
    function setBaseUrlForChapter(
        address _nftContractAddress,
        uint8 _chapterId,
        string calldata _baseUrl
    ) external onlyOwner whenNotPaused {
        require(_nftContractAddress != address(0), "Invalid address");
        baseUrlForChapter[_nftContractAddress][_chapterId] = BaseUrlForChapter(
            1,
            _baseUrl
        );
        emit BaseUrlForChapterSet(
            _nftContractAddress,
            _chapterId,
            _baseUrl,
            block.timestamp
        );
    }

    /*╔══════════════════════════════╗
      ║    AUCTION CHECK FUNCTIONS   ║
      ╚══════════════════════════════╝*/

    //This is a internal view function that can check msg.sender is in the allow list.
    //param: merkle root and merkle proof of allowlist merkle tree.
    //return bool value that verify if byte value of msg.sender is a part of allowlist merkle tree
    function _isInAllowList(
        bytes32 merkleRoot,
        bytes32[] memory merkleProof
    ) internal view returns (bool) {
        return
            MerkleProofUpgradeable.verify(merkleProof, merkleRoot, toBytes32(msg.sender));
    }

    //This is an internal view function that can get a URI of a certain token 
    //param: NFT contract address, token id 
    //token URI is obtained from baseUriForChapter mapping variable.
    //return: return  token URI as string
    function _tokenURI(
        address _nftContractAddress,
        uint256 _tokenId
    ) internal view returns (string memory) {
        uint256 smallSaleId = nftContractAuctions[_nftContractAddress][_tokenId]
            .smallSaleId;
        string memory baseURI = baseUrlForChapter[_nftContractAddress][
            smallSales[smallSaleId].chapterId
        ].baseUrl;
        return
            bytes(baseURI).length > 0
                ? string(abi.encodePacked(baseURI, _tokenId.toString()))
                : "";
    }

    //This is an internal view function that check if auction is ongoing 
    //param: NFT contract address, token id 
    //token URI is obtained from baseUriForChapter mapping variable.
    //return  uint value that represent the staus whether the auction is going or not.
    function _isAuctionOngoing(
        address _nftContractAddress,
        uint256 _tokenId
    ) internal view returns (uint8) {
        uint256 auctionEndTimestamp = nftContractAuctions[_nftContractAddress][
            _tokenId
        ].auctionEnd;
        uint256 smallSaleId = nftContractAuctions[_nftContractAddress][_tokenId]
            .smallSaleId;
        uint256 auctionStart = smallSales[smallSaleId].startAt;

        if (auctionEndTimestamp != 0 &&
            block.timestamp < auctionEndTimestamp &&
            block.timestamp >= auctionStart) {
            return 1;
        }

        return 0;
    }

    //This is an internal view function that check if there is a bid on a certain auction.
    //param: NFT contract address, token id 
    //return  uint value that represent the staus if there is a bid on a certain auction
    function _isABidMade(
        address _nftContractAddress,
        uint256 _tokenId
    ) internal view returns (uint8) {
        if (nftContractAuctions[_nftContractAddress][_tokenId]
            .nftHighestBidder != address(0)) {
            return 1;
        }
        return 0;
    }

    //This is an internal view function that check whether current auction is one of buyNowSale and zeroSale or not and check if corresponding conditions fit.
    //param: NFT contract address, token id.
    //return uint value that represent the staus if current auction is one of buyNowSale and zeroSale or not and check if corresponding conditions fit.
    function _isBuyNowPriceMetOrZeroSale(
        address _nftContractAddress,
        uint256 _tokenId
    ) internal view returns (uint8) {
        uint256 smallSaleId = nftContractAuctions[_nftContractAddress][_tokenId]
            .smallSaleId;
        if (smallSales[smallSaleId].saleType != SaleType.EnglishAuction &&
            nftContractAuctions[_nftContractAddress][_tokenId].nftHighestBid >= smallSales[smallSaleId].price)
        {
            return 1;
        }

        return 0;
    }

    //This is an internal view function that checks if the current bid meets the requirement of the corresponding auction.
    //param: NFT contract address, token id.
    //return uint value that represent the staus if the current bid meets the requirement of the corresponding auction.
    function _doesBidMeetBidRequirements(
        address _nftContractAddress,
        uint256 _tokenId
    ) internal view returns (uint8) {

        uint256 smallSaleId = nftContractAuctions[_nftContractAddress][_tokenId]
            .smallSaleId;
        SmallSale memory currentSmallSale = smallSales[smallSaleId];
        //if buyNowPrice is met, ether amount of bid is bigger than token price of current auction.
        if (currentSmallSale.saleType == SaleType.BuyNow) {
            if (msg.value >= currentSmallSale.price) {
                return 1;
            }
            return 0;
        } else if (
            smallSales[smallSaleId].saleType == SaleType.EnglishAuction
        ) {
            //if the NFT is up for auction, if highestBid exists, ether amount of bid should be bigger than highestbid + bidIncreaseAmount and if highest bidder nonexists, ether amount of bid should be bigger than minprice of current auction.
            uint256 highestBid = nftContractAuctions[_nftContractAddress][
                _tokenId
            ].nftHighestBid;
            address nftHighestBidder = nftContractAuctions[_nftContractAddress][
                _tokenId
            ].nftHighestBidder;
            uint256 validBidAmount = nftHighestBidder == address(0)
                ? currentSmallSale.price
                : highestBid + currentSmallSale.bidIncreaseAmount;

            if (msg.value >= validBidAmount) {
                return 1;
            }
            return 0;
        } else {
            // ZeroPriceSale
            return 1;
        }
    }

    /**********************************/
    /*╔══════════════════════════════╗
      ║             END              ║
      ║    AUCTION CHECK FUNCTIONS   ║
      ╚══════════════════════════════╝*/
    /**********************************/

    /*╔══════════════════════════════╗
      ║       AUCTION CREATION       ║
      ╚══════════════════════════════╝*/
    //This is an internal function that setup Auction with given auction info.
    //param: Sale id, NFT contract address, token id and auction end time
    //store auction info to the nftContractAuctions mapping variable as keys reference to NFT address and token id.
    function _setupAuction(    
        uint256 _smallSaleId,
        address _nftContractAddress,
        uint256 _tokenId,
        uint256 _auctionEnd
    ) internal {

        nftContractAuctions[_nftContractAddress][_tokenId]
            .auctionEnd = _auctionEnd;

        nftContractAuctions[_nftContractAddress][_tokenId]
            .smallSaleId = _smallSaleId;

        nftContractAuctions[_nftContractAddress][_tokenId]
            .isOnAuction = true;

        // emit AuctionCreated(_nftContractAddress, _tokenId, _smallSaleId);
    }
    //This is an internal function that create Auction with given auction info.
    //param: Sale id, NFT contract address, token id and auction end time
    //first check if current auction is already created and check if there is higest bidder ,and call _sepupAuction function. 
    function _createNewNftAuction(
        uint256 _smallSaleId,
        address _nftContractAddress,
        uint256 _tokenId,
        uint256 _auctionEnd
    ) internal {
        if (nftContractAuctions[_nftContractAddress][_tokenId].isOnAuction) {
            require(
                block.timestamp > nftContractAuctions[_nftContractAddress][_tokenId].auctionEnd &&
                nftContractAuctions[_nftContractAddress][_tokenId].nftHighestBidder == address(0), 
                "Auction still ongoing or there is highestBidder"
            );
        }
        _setupAuction(
            _smallSaleId,
            _nftContractAddress,
            _tokenId,
            _auctionEnd
        );
    }
    //@notice: This is an external function that create Auction on batch token ids.
    //@param: Sale id and token ids
    //@dev: Only contract owner can execute this function, this function can execute when contract is not paused and Sale id is valid. check if current token is minted or burned on every token id while circulate token ids. if not minted and not burned, call _createNewNftAuction function.
    function createNewNftAuction(
        uint256 _smallSaleId,
        uint256[] calldata _tokenIds
        ) external onlyOwner whenNotPaused smallSaleExist(_smallSaleId) {
        SmallSale memory smallSale = smallSales[_smallSaleId];
        address _nftContractAddress = smallSale.nftContractAddress;
        uint256 auctionEndTime = smallSale.auctionEnd;
        CHARACTER_V1_UPGRADEABLE character = CHARACTER_V1_UPGRADEABLE(_nftContractAddress);
        uint256 length = _tokenIds.length;

        for (uint16 i; i < length;) {
            // require(!character.isBurnedToken(_tokenIds[i]), "Token is burned");
            require(!character.exists(_tokenIds[i]), "Token is minted");
            _createNewNftAuction(
                _smallSaleId,
                _nftContractAddress,
                _tokenIds[i],
                auctionEndTime
            );
            unchecked {++i;}
        }
    }
    //@notice: This is an external view function that get comprehensive Auction data depending on Nft address and token id.
    //@param: NFT contract address and token id
    //@return: if auction exists, return CombinedAuctionData according Nft address and token id and if auction is nonexist, return CombinedAuctionData with empty values.
    function getAunctionData(
        address _nftContractAddress,
        uint256 _tokenId
    ) external view returns (CombinedAuctionData memory auctionData) {
        Auction memory res_1 = nftContractAuctions[_nftContractAddress][
            _tokenId
        ];
        if (res_1.auctionEnd == 0) {
            auctionData = CombinedAuctionData(
                0,
                0,
                0,
                0,
                0,
                0,
                bytes32(0),
                address(0),
                "",
                0,
                false,
                0,
                0,
                0
            );
        } else {
            SmallSale memory res_2 = smallSales[res_1.smallSaleId];
            string memory tokenURI = _tokenURI(_nftContractAddress, _tokenId);
            auctionData = CombinedAuctionData(
                res_2.bidIncreaseAmount,
                0,
                res_1.auctionEnd,
                res_2.price,
                res_2.price,
                res_1.nftHighestBid,
                res_2.allowListRoot,
                res_1.nftHighestBidder,
                tokenURI,
                res_1.sold,
                res_1.isOnAuction,
                res_1.bidsCount,
                res_2.startAt,
                res_1.smallSaleId
            );
        }
        return auctionData;
    }

    /**********************************/
    /*╔══════════════════════════════╗
      ║             END              ║
      ║       AUCTION CREATION       ║
      ╚══════════════════════════════╝*/
    /**********************************/

    /*╔══════════════════════════════╗
      ║            SALES             ║
      ╚══════════════════════════════╝*/

    /********************************************************************
     * Allows for a standard sale mechanism where the NFT seller can    *
     * can select an allow list. This list is then    *
     * allowed to make a bid on the NFT. No other address can bid on    *
     * the NFT.                                                         *
     ********************************************************************/

    //This is an internal function that deal with the sale in case of BuyNow sale and ZeroPrice sale.
    //param: NFT contract address and token id
    //call _mintNftAndTransferPayment with zero status value(EnglishAuction:1, BuyNow and ZeroPrice:0)
    function _createSale(
        address _nftContractAddress,
        uint256 _tokenId
    ) internal {
        _mintNftAndTransferPayment(_nftContractAddress, _tokenId, 0);
        address _buyer = nftContractAuctions[_nftContractAddress][_tokenId]
            .nftHighestBidder;
        uint128 _amount = nftContractAuctions[_nftContractAddress][_tokenId]
            .nftHighestBid;

        emit SaleCreated(_nftContractAddress, _tokenId, _amount, _buyer);
    }

    /**********************************/
    /*╔══════════════════════════════╗
      ║             END              ║
      ║            SALES             ║
      ╚══════════════════════════════╝*/
    /**********************************/

    /*╔═════════════════════════════╗
      ║        BID FUNCTIONS        ║
      ╚═════════════════════════════╝*/

    
    //This is an internal function that deal with making a bid
    //param: NFT contract address and token id
    //this function execute when amount of bid meets requirement of current auction. Call _reversePreviousBidAndUpdateHighestBid function, update auction time(extend the auction duration) and increase bidsCount.
    function _makeBid(
        address _nftContractAddress,
        uint256 _tokenId
    ) internal bidAmountMeetsBidRequirements(_nftContractAddress, _tokenId) {
        _reversePreviousBidAndUpdateHighestBid(_nftContractAddress, _tokenId);

        _updateOngoingAuction(_nftContractAddress, _tokenId);
        nftContractAuctions[_nftContractAddress][_tokenId].bidsCount++;

        emit BidMade(
            _nftContractAddress,
            _tokenId,
            msg.sender,
            uint128(msg.value),
            block.timestamp
        );
    }
    //@notice: This is an external payable function that deal with making a bid
    //@param: NFT contract address, token id and merkleproof.
    //@dev: this function execute when contract is not paused, there is no reentrance call, auction is on the status of ongoing, do not exceed the buylimits and there is valid sale id and merkleproof. Call _makeBid and in case of BuyNow and Zeroprice, call _createSale.
    function makeBid(
        address _nftContractAddress,
        uint256 _tokenId,
        bytes32[] calldata merkleProof
    )
        external
        payable
        whenNotPaused
        nonReentrant
        auctionOngoing(_nftContractAddress, _tokenId)
        notExceedBuyLimit(_nftContractAddress, _tokenId)
    {
        bytes32 root = smallSales[
            nftContractAuctions[_nftContractAddress][_tokenId].smallSaleId
        ].allowListRoot;
        require(
            root == bytes32(0) || _isInAllowList(root, merkleProof),
            "invalid merkle proof"
        );
        _makeBid(_nftContractAddress, _tokenId);
        if (_isBuyNowPriceMetOrZeroSale(_nftContractAddress, _tokenId) == 1) {
            _createSale(_nftContractAddress, _tokenId);
        }
    }

    /**********************************/
    /*╔══════════════════════════════╗
      ║             END              ║
      ║        BID FUNCTIONS         ║
      ╚══════════════════════════════╝*/
    /**********************************/

    /*╔══════════════════════════════╗
      ║       UPDATE AUCTION         ║
      ╚══════════════════════════════╝*/

    /***************************************************************
     * Settle an auction or sale if the buyNowPrice is met or set  *
     *  auction period to begin if the minimum price has been met. *
     ***************************************************************/

    //This is an internal function that update Auction time
    //param: NFT contract address and token id
    //When sale type is EmglishAuction, Call _updateAuctionEnd.
    function _updateOngoingAuction(
        address _nftContractAddress,
        uint256 _tokenId
    ) internal {
        if (_isBuyNowPriceMetOrZeroSale(_nftContractAddress, _tokenId) == 1) {
            return;
        }
        //min price not set, nft not up for auction yet
        _updateAuctionEnd(_nftContractAddress, _tokenId);
    }
    //his is an internal function that update Auction End time
    //param: NFT contract address and token id
    //When it is 5 mins before auction end, increase auction end by 5 mins.
    function _updateAuctionEnd(
        address _nftContractAddress,
        uint256 _tokenId
    ) internal {
        //the auction end is always set to now + the bid period
        if (
            nftContractAuctions[_nftContractAddress][_tokenId].auctionEnd -
                block.timestamp <
            300
        ) {
            nftContractAuctions[_nftContractAddress][_tokenId]
                .auctionEnd += 300;
            emit AuctionPeriodUpdated(
                _nftContractAddress,
                _tokenId,
                nftContractAuctions[_nftContractAddress][_tokenId].auctionEnd
            );
        }
    }

    /**********************************/
    /*╔══════════════════════════════╗
      ║             END              ║
      ║       UPDATE AUCTION         ║
      ╚══════════════════════════════╝*/
    /**********************************/


    /*╔══════════════════════════════╗
      ║         UPDATE BIDS          ║
      ╚══════════════════════════════╝*/
    /******************************************************************
     * Internal functions that update bid parameters and reverse bids *
     * to ensure contract only holds the highest bid.                 *
     ******************************************************************/

    //This is an internal function that update highestBid
    //param: NFT contract address and token id
    //Set current bidder as highest bidder and increase corresponding userBuyCountInSmallSale.
    function _updateHighestBid(
        address _nftContractAddress,
        uint256 _tokenId
    ) internal {
        nftContractAuctions[_nftContractAddress][_tokenId]
            .nftHighestBid = uint128(msg.value);
        nftContractAuctions[_nftContractAddress][_tokenId]
            .nftHighestBidder = msg.sender;
        // update user's buyCount in smallSale
        userBuyCountInSmallSale[msg.sender][
            nftContractAuctions[_nftContractAddress][_tokenId].smallSaleId
        ]++;
    }
    //This is an internal function that refund previousBid and update highest bid when there is new highest bidder.
    //param: NFT contract address and token id
    //Call _updateHighestBid and when there is prevNftHighestBidder, refund. 
    function _reversePreviousBidAndUpdateHighestBid(
        address _nftContractAddress,
        uint256 _tokenId
    ) internal {
        address prevNftHighestBidder = nftContractAuctions[_nftContractAddress][
            _tokenId
        ].nftHighestBidder;

        uint128 prevNftHighestBid = nftContractAuctions[_nftContractAddress][
            _tokenId
        ].nftHighestBid;
        uint256 smallSaleId = nftContractAuctions[_nftContractAddress][_tokenId]
            .smallSaleId;
        _updateHighestBid(_nftContractAddress, _tokenId);

        if (prevNftHighestBidder != address(0)) {
            if (prevNftHighestBid > 0) {
                _payout(
                    _nftContractAddress,
                    _tokenId,
                    prevNftHighestBidder,
                    prevNftHighestBid
                );
            }
            userBuyCountInSmallSale[prevNftHighestBidder][smallSaleId]--;
        }
    }

    /**********************************/
    /*╔══════════════════════════════╗
      ║             END              ║
      ║         UPDATE BIDS          ║
      ╚══════════════════════════════╝*/
    /**********************************/

    /*╔══════════════════════════════╗
      ║  TRANSFER NFT & PAY SELLER   ║
      ╚══════════════════════════════╝*/
    //This is an internal function that mint NFT and transfer payments when auction winner is determined or auction end.
    //param: NFT contract address, token id and _refundWhenMinted the status value that represent whether refund or not when token is minted.
    //Check if NFT token id is minted. if not minted mint NFT token to the address of winner, transfer payment to the feeReceiver address, set sold status of auction data as true and update the auctionEnd of auction data as current time. if minted, in case of EnglishAuctoin(depending on _refundWhenMinted), refund payment to winner and in case of rest cases, just revert with error message.
    function _mintNftAndTransferPayment(
        address _nftContractAddress,
        uint256 _tokenId,
        uint8 _refundWhenMinted
    ) internal {
        address _nftHighestBidder = nftContractAuctions[_nftContractAddress][
            _tokenId
        ].nftHighestBidder;
        uint128 _nftHighestBid = nftContractAuctions[_nftContractAddress][
            _tokenId
        ].nftHighestBid;
        string memory _tokenUri = _tokenURI(_nftContractAddress, _tokenId);

        if (CHARACTER_V1_UPGRADEABLE(_nftContractAddress).exists(_tokenId)) {
            if (_refundWhenMinted == 1) {
                if (_nftHighestBid > 0) {
                    _payout(
                        _nftContractAddress,
                        _tokenId,
                        _nftHighestBidder,
                        _nftHighestBid
                    );
                }
            }
            else {
                revert("Token is already minted");
            }
        } else {
            if (_nftHighestBid > 0) {
                _payout(_nftContractAddress, _tokenId, feeReceiver, _nftHighestBid);
            }

            CHARACTER_V1_UPGRADEABLE(_nftContractAddress).mint(
                _tokenId,
                _nftHighestBidder,
                _tokenUri
            );

            emit CharaterMintedAndPaymentPaid(
                _nftContractAddress,
                _tokenId,
                _nftHighestBid,
                _nftHighestBidder
            );
        }

        nftContractAuctions[_nftContractAddress][_tokenId].auctionEnd = block.timestamp;
        nftContractAuctions[_nftContractAddress][_tokenId].sold = 1;
    }
    //This is an internal function that transfer fund(ethers or other native token)
    //param: NFT contract address, token id, recipient address and amount to be transferred.
    //Check if transferring succeed. if not success, increase failedTransferCredits.
    function _payout(
        address _nftContractAddress,
        uint256 _tokenId,
        address _toAddress,
        uint128 _amount
    ) internal {
        // attempt to send the funds to the recipient
        (bool success, ) = payable(_toAddress).call{value: _amount, gas: 5000}("");

        // if someone tried to pull the trick of Dos, keep the fund
        if (!success) {
            failedTransferCredits += _amount;

            emit FailedPayout(
                _nftContractAddress,
                _tokenId,
                _toAddress,
                _amount
            );
        }
    }

    /**********************************/
    /*╔══════════════════════════════╗
      ║             END              ║
      ║  TRANSFER NFT & PAY SELLER   ║
      ╚══════════════════════════════╝*/
    /**********************************/

    /*╔══════════════════════════════╗
      ║      SETTLE & WITHDRAW       ║
      ╚══════════════════════════════╝*/

    //@notice: This is an external function that settle auction
    //@param: NFT contract address and token id.
    //@dev: This function can be executed when contract is not paused and there is not reentrance call. it requires that auction is ongoing, there is a bid made and token is not sold. Finally all conditions meet, call _mintNftAndTransferPayment
    function settleAuction(
        address _nftContractAddress,
        uint256 _tokenId
    ) external whenNotPaused nonReentrant {
        require(
            _isAuctionOngoing(_nftContractAddress, _tokenId) == 0,
            "Auction is not yet over"
        );
        require(
            _isABidMade(_nftContractAddress, _tokenId) == 1,
            "No highest bidder yet"
        );
        require(
            nftContractAuctions[_nftContractAddress][_tokenId].sold == 0,
            "Token already sold"
        );

        _mintNftAndTransferPayment(_nftContractAddress, _tokenId, 1);
        emit AuctionSettled(_nftContractAddress, _tokenId, msg.sender);
    }

    //@notice: This is an external function that withdraw auction.
    //@param: NFT contract address and token id.
    //@dev: Only contract ownner can call this function. This function can be executed when there is no reentrance call. it requires that token is not sold and there is no bid made.Finally reset main variables of auction data determinative to auction as zeros and false.
    function withdrawAuction(
        address _nftContractAddress,
        uint256 _tokenId
    ) external onlyOwner nonReentrant {
        require(
            nftContractAuctions[_nftContractAddress][_tokenId].sold == 0,
            "token has already sold"
        );
        require(
            nftContractAuctions[_nftContractAddress][_tokenId].nftHighestBid ==
                0,
            "Can not withdraw when a bid is made"
        );

        nftContractAuctions[_nftContractAddress][_tokenId].auctionEnd = 0;
        nftContractAuctions[_nftContractAddress][_tokenId].nftHighestBid = 0;
        nftContractAuctions[_nftContractAddress][_tokenId].nftHighestBidder = address(0);
        nftContractAuctions[_nftContractAddress][_tokenId].isOnAuction = false;
        nftContractAuctions[_nftContractAddress][_tokenId].bidsCount = 0;

        emit AuctionWithdrawn(_nftContractAddress, _tokenId, msg.sender);
    }

    /**********************************/
    /*╔══════════════════════════════╗
      ║             END              ║
      ║      SETTLE & WITHDRAW       ║
      ╚══════════════════════════════╝*/
    /**********************************/

    /*╔══════════════════════════════╗
      ║       UPDATE AUCTION         ║
      ╚══════════════════════════════╝*/
    /*
     * The NFT seller can opt to end an auction by taking the current highest bid.
     */
    //@notice: This is an external function that take highest bidder regardless of auction end time.
    //@param: NFT contract address and token id.
    //@dev: Only contract ownner can call this function. This function can be executed when contract is not paused and there is no reentrance call. it requires that token is not sold and there is a bid made.Finally call _mintNftAndTransferPaymen
    function takeHighestBid(
        address _nftContractAddress,
        uint256 _tokenId
    ) external onlyOwner whenNotPaused nonReentrant {
        require(
            _isABidMade(_nftContractAddress, _tokenId) == 1,
            "No highest bidder yet"
        );
        require(
            nftContractAuctions[_nftContractAddress][_tokenId].sold == 0,
            "Token already sold"
        );
        _mintNftAndTransferPayment(_nftContractAddress, _tokenId, 1);
        emit HighestBidTaken(_nftContractAddress, _tokenId);
    }

    /**********************************/
    /*╔══════════════════════════════╗
      ║             END              ║
      ║       UPDATE AUCTION         ║
      ╚══════════════════════════════╝*/
    /**********************************/

    function toBytes32(address addr) internal pure returns (bytes32) {
        return bytes32(uint256(uint160(addr)));
    }

    /*
     * Claim all the leftover fund to recepient and settle payment later
     */
    //@notice: This is an external function that Claim all fund which tansferring is failed to recepient
    //@param: address of fund receiver.
    //@dev: Only contract ownner can call this function. This function can be executed when there is no reentrance call. it requires that amount of failed fund is not equal with zero.
    function withdrawAllFailedCredits(address receiver) external onlyOwner nonReentrant {
        uint256 amount = failedTransferCredits;
        require(amount != 0, "no credits to withdraw");
        (bool success, ) = payable(receiver).call{value: amount, gas: 5000}("");
        if(success){
            failedTransferCredits = 0;
        }
    }

    //@notice: This is an external function that triger pause state of contract.
    //@dev: Only contract ownner can call this function. Call _pause() in the Pausable Cootract.
    function pause() external onlyOwner
    {
        _pause();
    }

    //@notice: This is an external function that triger uppause state of contract from pause state.
    //@dev: Only contract ownner can call this function. Call _unpause() in the Pausable Cootract.
    function unpause() external onlyOwner
    {
        _unpause();
    }
    //@notice: This is an external function that update the address of feeReceiver.
    //@param: address of feeReceiver to be updated
    //@dev: Only contract ownner can call this function. This function is executed when there is no reentrance calling. It requires feeReceiver address is valid.
    function updateFeeReceiver(address updatedFeeReceiver) external onlyOwner nonReentrant {
        require(updatedFeeReceiver != address(0), "Invalid address");
        feeReceiver = updatedFeeReceiver;

    }
    //@notice: This is an external function that renounce ownership.
    //@dev: Only contract ownner can call this function. 
    //@inheritdoc: Ownerable
    function renounceOwnership() public virtual override onlyOwner {
        revert("Can not renounce onwership");
    }
    // if there is emergency or when migrating to other shop contract, close current ongoing Auction.
    function _closeAuction(address _nftContractAddress,uint256 _tokenId) internal {

        address nftHighestBidder = nftContractAuctions[_nftContractAddress][_tokenId].nftHighestBidder;
        uint128 nftHighestBid = nftContractAuctions[_nftContractAddress][_tokenId].nftHighestBid;
        uint8 sold = nftContractAuctions[_nftContractAddress][_tokenId].sold;
        // refund to highest bidder when  
        if(nftHighestBidder != address(0) && sold == 0){
            if(nftHighestBid >0){
                _payout(
                    _nftContractAddress,
                    _tokenId,
                    nftHighestBidder,
                    nftHighestBid
                );
            }
        nftContractAuctions[_nftContractAddress][_tokenId].auctionEnd = 0;
        nftContractAuctions[_nftContractAddress][_tokenId].nftHighestBid = 0;
        nftContractAuctions[_nftContractAddress][_tokenId].nftHighestBidder = address(0);
        nftContractAuctions[_nftContractAddress][_tokenId].isOnAuction = false;
        nftContractAuctions[_nftContractAddress][_tokenId].bidsCount = 0;
        }
    }

    function closeAuction(address _nftContractAddress, uint256 tokenId) external onlyOwner nonReentrant whenPaused{
    _closeAuction(_nftContractAddress, tokenId);
    }

    function closeBatchAuctions(address _nftContractAddress, uint256 count) external onlyOwner nonReentrant whenPaused{
        for(uint256 i=1; i<= count; i++){
            _closeAuction(_nftContractAddress, i);
        }
    }
}

File 2 of 37 : AccessControlEnumerableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControlEnumerableUpgradeable.sol";
import "./AccessControlUpgradeable.sol";
import "../utils/structs/EnumerableSetUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Extension of {AccessControl} that allows enumerating the members of each role.
 */
abstract contract AccessControlEnumerableUpgradeable is Initializable, IAccessControlEnumerableUpgradeable, AccessControlUpgradeable {
    function __AccessControlEnumerable_init() internal onlyInitializing {
    }

    function __AccessControlEnumerable_init_unchained() internal onlyInitializing {
    }
    using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;

    mapping(bytes32 => EnumerableSetUpgradeable.AddressSet) private _roleMembers;

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

    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {
        return _roleMembers[role].at(index);
    }

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {
        return _roleMembers[role].length();
    }

    /**
     * @dev Overload {_grantRole} to track enumerable memberships
     */
    function _grantRole(bytes32 role, address account) internal virtual override {
        super._grantRole(role, account);
        _roleMembers[role].add(account);
    }

    /**
     * @dev Overload {_revokeRole} to track enumerable memberships
     */
    function _revokeRole(bytes32 role, address account) internal virtual override {
        super._revokeRole(role, account);
        _roleMembers[role].remove(account);
    }

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

File 3 of 37 : AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/utils/Initializable.sol";

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

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

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

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

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        StringsUpgradeable.toHexString(account),
                        " is missing role ",
                        StringsUpgradeable.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

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

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

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

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

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

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

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }

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

File 4 of 37 : IAccessControlEnumerableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControlUpgradeable.sol";

/**
 * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
 */
interface IAccessControlEnumerableUpgradeable is IAccessControlUpgradeable {
    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) external view returns (uint256);
}

File 5 of 37 : IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControlUpgradeable {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

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

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

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

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

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

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

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

File 6 of 37 : OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling 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;
}

File 7 of 37 : IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC165.sol)

pragma solidity ^0.8.0;

import "../utils/introspection/IERC165Upgradeable.sol";

File 8 of 37 : IERC2981Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC2981.sol)

pragma solidity ^0.8.0;

import "../utils/introspection/IERC165Upgradeable.sol";

/**
 * @dev Interface for the NFT Royalty Standard.
 *
 * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal
 * support for royalty payments across all NFT marketplaces and ecosystem participants.
 *
 * _Available since v4.5._
 */
interface IERC2981Upgradeable is IERC165Upgradeable {
    /**
     * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
     * exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
     */
    function royaltyInfo(
        uint256 tokenId,
        uint256 salePrice
    ) external view returns (address receiver, uint256 royaltyAmount);
}

File 9 of 37 : IERC4906Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC4906.sol)

pragma solidity ^0.8.0;

import "./IERC165Upgradeable.sol";
import "./IERC721Upgradeable.sol";

/// @title EIP-721 Metadata Update Extension
interface IERC4906Upgradeable is IERC165Upgradeable, IERC721Upgradeable {
    /// @dev This event emits when the metadata of a token is changed.
    /// So that the third-party platforms such as NFT market could
    /// timely update the images and related attributes of the NFT.
    event MetadataUpdate(uint256 _tokenId);

    /// @dev This event emits when the metadata of a range of tokens is changed.
    /// So that the third-party platforms such as NFT market could
    /// timely update the images and related attributes of the NFTs.
    event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);
}

File 10 of 37 : IERC721Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC721.sol)

pragma solidity ^0.8.0;

import "../token/ERC721/IERC721Upgradeable.sol";

File 11 of 37 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

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

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```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 Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

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

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

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized != type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

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

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

File 12 of 37 : PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

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

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

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

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

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

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

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

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }

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

File 13 of 37 : ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // 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;

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _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
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // 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;
    }

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

File 14 of 37 : ERC2981Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/common/ERC2981.sol)

pragma solidity ^0.8.0;

import "../../interfaces/IERC2981Upgradeable.sol";
import "../../utils/introspection/ERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the NFT Royalty Standard, a standardized way to retrieve royalty payment information.
 *
 * Royalty information can be specified globally for all token ids via {_setDefaultRoyalty}, and/or individually for
 * specific token ids via {_setTokenRoyalty}. The latter takes precedence over the first.
 *
 * Royalty is specified as a fraction of sale price. {_feeDenominator} is overridable but defaults to 10000, meaning the
 * fee is specified in basis points by default.
 *
 * IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See
 * https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the EIP. Marketplaces are expected to
 * voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.
 *
 * _Available since v4.5._
 */
abstract contract ERC2981Upgradeable is Initializable, IERC2981Upgradeable, ERC165Upgradeable {
    function __ERC2981_init() internal onlyInitializing {
    }

    function __ERC2981_init_unchained() internal onlyInitializing {
    }
    struct RoyaltyInfo {
        address receiver;
        uint96 royaltyFraction;
    }

    RoyaltyInfo private _defaultRoyaltyInfo;
    mapping(uint256 => RoyaltyInfo) private _tokenRoyaltyInfo;

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

    /**
     * @inheritdoc IERC2981Upgradeable
     */
    function royaltyInfo(uint256 tokenId, uint256 salePrice) public view virtual override returns (address, uint256) {
        RoyaltyInfo memory royalty = _tokenRoyaltyInfo[tokenId];

        if (royalty.receiver == address(0)) {
            royalty = _defaultRoyaltyInfo;
        }

        uint256 royaltyAmount = (salePrice * royalty.royaltyFraction) / _feeDenominator();

        return (royalty.receiver, royaltyAmount);
    }

    /**
     * @dev The denominator with which to interpret the fee set in {_setTokenRoyalty} and {_setDefaultRoyalty} as a
     * fraction of the sale price. Defaults to 10000 so fees are expressed in basis points, but may be customized by an
     * override.
     */
    function _feeDenominator() internal pure virtual returns (uint96) {
        return 10000;
    }

    /**
     * @dev Sets the royalty information that all ids in this contract will default to.
     *
     * Requirements:
     *
     * - `receiver` cannot be the zero address.
     * - `feeNumerator` cannot be greater than the fee denominator.
     */
    function _setDefaultRoyalty(address receiver, uint96 feeNumerator) internal virtual {
        require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
        require(receiver != address(0), "ERC2981: invalid receiver");

        _defaultRoyaltyInfo = RoyaltyInfo(receiver, feeNumerator);
    }

    /**
     * @dev Removes default royalty information.
     */
    function _deleteDefaultRoyalty() internal virtual {
        delete _defaultRoyaltyInfo;
    }

    /**
     * @dev Sets the royalty information for a specific token id, overriding the global default.
     *
     * Requirements:
     *
     * - `receiver` cannot be the zero address.
     * - `feeNumerator` cannot be greater than the fee denominator.
     */
    function _setTokenRoyalty(uint256 tokenId, address receiver, uint96 feeNumerator) internal virtual {
        require(feeNumerator <= _feeDenominator(), "ERC2981: royalty fee will exceed salePrice");
        require(receiver != address(0), "ERC2981: Invalid parameters");

        _tokenRoyaltyInfo[tokenId] = RoyaltyInfo(receiver, feeNumerator);
    }

    /**
     * @dev Resets royalty information for the token id back to the global default.
     */
    function _resetTokenRoyalty(uint256 tokenId) internal virtual {
        delete _tokenRoyaltyInfo[tokenId];
    }

    /**
     * @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[48] private __gap;
}

File 15 of 37 : ERC721Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/ERC721.sol)

pragma solidity ^0.8.0;

import "./IERC721Upgradeable.sol";
import "./IERC721ReceiverUpgradeable.sol";
import "./extensions/IERC721MetadataUpgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/ContextUpgradeable.sol";
import "../../utils/StringsUpgradeable.sol";
import "../../utils/introspection/ERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
contract ERC721Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC721Upgradeable, IERC721MetadataUpgradeable {
    using AddressUpgradeable for address;
    using StringsUpgradeable for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Mapping from token ID to owner address
    mapping(uint256 => address) private _owners;

    // Mapping owner address to token count
    mapping(address => uint256) private _balances;

    // Mapping from token ID to approved address
    mapping(uint256 => address) private _tokenApprovals;

    // Mapping from owner to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    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, IERC165Upgradeable) returns (bool) {
        return
            interfaceId == type(IERC721Upgradeable).interfaceId ||
            interfaceId == type(IERC721MetadataUpgradeable).interfaceId ||
            super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: address zero is not a valid owner");
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _ownerOf(tokenId);
        require(owner != address(0), "ERC721: invalid token ID");
        return owner;
    }

    /**
     * @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 {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        _requireMinted(tokenId);

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
    }

    /**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, can be overridden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return "";
    }

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

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

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        _requireMinted(tokenId);

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        _setApprovalForAll(_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: caller is not token owner or 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: caller is not token owner or 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 the owner of the `tokenId`. Does NOT revert if token doesn't exist
     */
    function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
        return _owners[tokenId];
    }

    /**
     * @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 _ownerOf(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) {
        address owner = ERC721Upgradeable.ownerOf(tokenId);
        return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == 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);

        // Check that tokenId was not minted by `_beforeTokenTransfer` hook
        require(!_exists(tokenId), "ERC721: token already minted");

        unchecked {
            // Will not overflow unless all 2**256 token ids are minted to the same owner.
            // Given that tokens are minted one by one, it is impossible in practice that
            // this ever happens. Might change if we allow batch minting.
            // The ERC fails to describe this case.
            _balances[to] += 1;
        }

        _owners[tokenId] = to;

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

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

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     * This is an internal function that does not check if the sender is authorized to operate on the token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721Upgradeable.ownerOf(tokenId);

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

        // Update ownership in case tokenId was transferred by `_beforeTokenTransfer` hook
        owner = ERC721Upgradeable.ownerOf(tokenId);

        // Clear approvals
        delete _tokenApprovals[tokenId];

        unchecked {
            // Cannot overflow, as that would require more tokens to be burned/transferred
            // out than the owner initially received through minting and transferring in.
            _balances[owner] -= 1;
        }
        delete _owners[tokenId];

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

        _afterTokenTransfer(owner, address(0), 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 from incorrect owner");
        require(to != address(0), "ERC721: transfer to the zero address");

        _beforeTokenTransfer(from, to, tokenId, 1);

        // Check that tokenId was not transferred by `_beforeTokenTransfer` hook
        require(ERC721Upgradeable.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");

        // Clear approvals from the previous owner
        delete _tokenApprovals[tokenId];

        unchecked {
            // `_balances[from]` cannot overflow for the same reason as described in `_burn`:
            // `from`'s balance is the number of token held, which is at least one before the current
            // transfer.
            // `_balances[to]` could overflow in the conditions described in `_mint`. That would require
            // all 2**256 token ids to be minted, which in practice is impossible.
            _balances[from] -= 1;
            _balances[to] += 1;
        }
        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);

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

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

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Emits an {ApprovalForAll} event.
     */
    function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
        require(owner != operator, "ERC721: approve to caller");
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Reverts if the `tokenId` has not been minted yet.
     */
    function _requireMinted(uint256 tokenId) internal view virtual {
        require(_exists(tokenId), "ERC721: invalid token ID");
    }

    /**
     * @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 IERC721ReceiverUpgradeable(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
                return retval == IERC721ReceiverUpgradeable.onERC721Received.selector;
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert("ERC721: transfer to non ERC721Receiver implementer");
                } else {
                    /// @solidity memory-safe-assembly
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        } else {
            return true;
        }
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting and burning. If {ERC721Consecutive} is
     * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`.
     * - When `from` is zero, the tokens will be minted for `to`.
     * - When `to` is zero, ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     * - `batchSize` is non-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 {}

    /**
     * @dev Hook that is called after any token transfer. This includes minting and burning. If {ERC721Consecutive} is
     * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s tokens were transferred to `to`.
     * - When `from` is zero, the tokens were minted for `to`.
     * - When `to` is zero, ``from``'s tokens were burned.
     * - `from` and `to` are never both zero.
     * - `batchSize` is non-zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {}

    /**
     * @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
     *
     * WARNING: Anyone calling this MUST ensure that the balances remain consistent with the ownership. The invariant
     * being that for any address `a` the value returned by `balanceOf(a)` must be equal to the number of tokens such
     * that `ownerOf(tokenId)` is `a`.
     */
    // solhint-disable-next-line func-name-mixedcase
    function __unsafe_increaseBalance(address account, uint256 amount) internal {
        _balances[account] += amount;
    }

    /**
     * @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[44] private __gap;
}

File 16 of 37 : ERC721BurnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/extensions/ERC721Burnable.sol)

pragma solidity ^0.8.0;

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

/**
 * @title ERC721 Burnable Token
 * @dev ERC721 Token that can be burned (destroyed).
 */
abstract contract ERC721BurnableUpgradeable is Initializable, ContextUpgradeable, ERC721Upgradeable {
    function __ERC721Burnable_init() internal onlyInitializing {
    }

    function __ERC721Burnable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Burns `tokenId`. See {ERC721-_burn}.
     *
     * Requirements:
     *
     * - The caller must own `tokenId` or be an approved operator.
     */
    function burn(uint256 tokenId) public virtual {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
        _burn(tokenId);
    }

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

File 17 of 37 : ERC721EnumerableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/extensions/ERC721Enumerable.sol)

pragma solidity ^0.8.0;

import "../ERC721Upgradeable.sol";
import "./IERC721EnumerableUpgradeable.sol";
import "../../../proxy/utils/Initializable.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.
 */
abstract contract ERC721EnumerableUpgradeable is Initializable, ERC721Upgradeable, IERC721EnumerableUpgradeable {
    function __ERC721Enumerable_init() internal onlyInitializing {
    }

    function __ERC721Enumerable_init_unchained() internal onlyInitializing {
    }
    // Mapping from owner to list of owned token IDs
    mapping(address => mapping(uint256 => uint256)) private _ownedTokens;

    // Mapping from token ID to index of the owner tokens list
    mapping(uint256 => uint256) private _ownedTokensIndex;

    // Array with all token ids, used for enumeration
    uint256[] private _allTokens;

    // Mapping from token id to position in the allTokens array
    mapping(uint256 => uint256) private _allTokensIndex;

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

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

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

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

    /**
     * @dev See {ERC721-_beforeTokenTransfer}.
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 firstTokenId,
        uint256 batchSize
    ) internal virtual override {
        super._beforeTokenTransfer(from, to, firstTokenId, batchSize);

        if (batchSize > 1) {
            // Will only trigger during construction. Batch transferring (minting) is not available afterwards.
            revert("ERC721Enumerable: consecutive transfers not supported");
        }

        uint256 tokenId = firstTokenId;

        if (from == address(0)) {
            _addTokenToAllTokensEnumeration(tokenId);
        } else if (from != to) {
            _removeTokenFromOwnerEnumeration(from, tokenId);
        }
        if (to == address(0)) {
            _removeTokenFromAllTokensEnumeration(tokenId);
        } else if (to != from) {
            _addTokenToOwnerEnumeration(to, tokenId);
        }
    }

    /**
     * @dev Private function to add a token to this extension's ownership-tracking data structures.
     * @param to address representing the new owner of the given token ID
     * @param tokenId uint256 ID of the token to be added to the tokens list of the given address
     */
    function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
        uint256 length = ERC721Upgradeable.balanceOf(to);
        _ownedTokens[to][length] = tokenId;
        _ownedTokensIndex[tokenId] = length;
    }

    /**
     * @dev Private function to add a token to this extension's token tracking data structures.
     * @param tokenId uint256 ID of the token to be added to the tokens list
     */
    function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
        _allTokensIndex[tokenId] = _allTokens.length;
        _allTokens.push(tokenId);
    }

    /**
     * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
     * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
     * gas optimizations e.g. when performing a transfer operation (avoiding double writes).
     * This has O(1) time complexity, but alters the order of the _ownedTokens array.
     * @param from address representing the previous owner of the given token ID
     * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
     */
    function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
        // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
        // then delete the last slot (swap and pop).

        uint256 lastTokenIndex = ERC721Upgradeable.balanceOf(from) - 1;
        uint256 tokenIndex = _ownedTokensIndex[tokenId];

        // When the token to delete is the last token, the swap operation is unnecessary
        if (tokenIndex != lastTokenIndex) {
            uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];

            _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
            _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
        }

        // This also deletes the contents at the last position of the array
        delete _ownedTokensIndex[tokenId];
        delete _ownedTokens[from][lastTokenIndex];
    }

    /**
     * @dev Private function to remove a token from this extension's token tracking data structures.
     * This has O(1) time complexity, but alters the order of the _allTokens array.
     * @param tokenId uint256 ID of the token to be removed from the tokens list
     */
    function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
        // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
        // then delete the last slot (swap and pop).

        uint256 lastTokenIndex = _allTokens.length - 1;
        uint256 tokenIndex = _allTokensIndex[tokenId];

        // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
        // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
        // an 'if' statement (like in _removeTokenFromOwnerEnumeration)
        uint256 lastTokenId = _allTokens[lastTokenIndex];

        _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
        _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index

        // This also deletes the contents at the last position of the array
        delete _allTokensIndex[tokenId];
        _allTokens.pop();
    }

    /**
     * @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[46] private __gap;
}

File 18 of 37 : ERC721RoyaltyUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/extensions/ERC721Royalty.sol)

pragma solidity ^0.8.0;

import "../ERC721Upgradeable.sol";
import "../../common/ERC2981Upgradeable.sol";
import "../../../utils/introspection/ERC165Upgradeable.sol";
import "../../../proxy/utils/Initializable.sol";

/**
 * @dev Extension of ERC721 with the ERC2981 NFT Royalty Standard, a standardized way to retrieve royalty payment
 * information.
 *
 * Royalty information can be specified globally for all token ids via {ERC2981-_setDefaultRoyalty}, and/or individually for
 * specific token ids via {ERC2981-_setTokenRoyalty}. The latter takes precedence over the first.
 *
 * IMPORTANT: ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See
 * https://eips.ethereum.org/EIPS/eip-2981#optional-royalty-payments[Rationale] in the EIP. Marketplaces are expected to
 * voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.
 *
 * _Available since v4.5._
 */
abstract contract ERC721RoyaltyUpgradeable is Initializable, ERC2981Upgradeable, ERC721Upgradeable {
    function __ERC721Royalty_init() internal onlyInitializing {
    }

    function __ERC721Royalty_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Upgradeable, ERC2981Upgradeable) returns (bool) {
        return super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {ERC721-_burn}. This override additionally clears the royalty information for the token.
     */
    function _burn(uint256 tokenId) internal virtual override {
        super._burn(tokenId);
        _resetTokenRoyalty(tokenId);
    }

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

File 19 of 37 : ERC721URIStorageUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/extensions/ERC721URIStorage.sol)

pragma solidity ^0.8.0;

import "../ERC721Upgradeable.sol";
import "../../../interfaces/IERC4906Upgradeable.sol";
import "../../../proxy/utils/Initializable.sol";

/**
 * @dev ERC721 token with storage based token URI management.
 */
abstract contract ERC721URIStorageUpgradeable is Initializable, IERC4906Upgradeable, ERC721Upgradeable {
    function __ERC721URIStorage_init() internal onlyInitializing {
    }

    function __ERC721URIStorage_init_unchained() internal onlyInitializing {
    }
    using StringsUpgradeable for uint256;

    // Optional mapping for token URIs
    mapping(uint256 => string) private _tokenURIs;

    /**
     * @dev See {IERC165-supportsInterface}
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Upgradeable, IERC165Upgradeable) returns (bool) {
        return interfaceId == bytes4(0x49064906) || super.supportsInterface(interfaceId);
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        _requireMinted(tokenId);

        string memory _tokenURI = _tokenURIs[tokenId];
        string memory base = _baseURI();

        // If there is no base URI, return the token URI.
        if (bytes(base).length == 0) {
            return _tokenURI;
        }
        // If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
        if (bytes(_tokenURI).length > 0) {
            return string(abi.encodePacked(base, _tokenURI));
        }

        return super.tokenURI(tokenId);
    }

    /**
     * @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
     *
     * Emits {MetadataUpdate}.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
        require(_exists(tokenId), "ERC721URIStorage: URI set of nonexistent token");
        _tokenURIs[tokenId] = _tokenURI;

        emit MetadataUpdate(tokenId);
    }

    /**
     * @dev See {ERC721-_burn}. This override additionally checks to see if a
     * token-specific URI was set for the token, and if so, it deletes the token URI from
     * the storage mapping.
     */
    function _burn(uint256 tokenId) internal virtual override {
        super._burn(tokenId);

        if (bytes(_tokenURIs[tokenId]).length != 0) {
            delete _tokenURIs[tokenId];
        }
    }

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

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

pragma solidity ^0.8.0;

import "../IERC721Upgradeable.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721EnumerableUpgradeable is IERC721Upgradeable {
    /**
     * @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);
}

File 21 of 37 : IERC721MetadataUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC721Upgradeable.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721MetadataUpgradeable is IERC721Upgradeable {
    /**
     * @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);
}

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

pragma solidity ^0.8.0;

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

File 23 of 37 : IERC721Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165Upgradeable.sol";

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

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

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

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

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

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

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

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

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

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

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

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

File 24 of 37 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

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

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

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

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

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

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

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

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

File 25 of 37 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

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

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

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

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

File 26 of 37 : MerkleProofUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.2) (utils/cryptography/MerkleProof.sol)

pragma solidity ^0.8.0;

/**
 * @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.
 */
library MerkleProofUpgradeable {
    /**
     * @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.
     */
    function verify(bytes32[] memory proof, bytes32 root, bytes32 leaf) internal pure returns (bool) {
        return processProof(proof, leaf) == root;
    }

    /**
     * @dev Calldata version of {verify}
     *
     * _Available since v4.7._
     */
    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 leafs & pre-images are assumed to be sorted.
     *
     * _Available since v4.4._
     */
    function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Calldata version of {processProof}
     *
     * _Available since v4.7._
     */
    function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(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}.
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    function multiProofVerify(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProof(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Calldata version of {multiProofVerify}
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    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.
     *
     * 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).
     *
     * _Available since v4.7._
     */
    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 proofLen = proof.length;
        uint256 totalHashes = proofFlags.length;

        // Check proof validity.
        require(leavesLen + proofLen - 1 == totalHashes, "MerkleProof: invalid multiproof");

        // 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[](totalHashes);
        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 < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }

        if (totalHashes > 0) {
            require(proofPos == proofLen, "MerkleProof: invalid multiproof");
            unchecked {
                return hashes[totalHashes - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @dev Calldata version of {processMultiProof}.
     *
     * CAUTION: Not all merkle trees admit multiproofs. See {processMultiProof} for details.
     *
     * _Available since v4.7._
     */
    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 proofLen = proof.length;
        uint256 totalHashes = proofFlags.length;

        // Check proof validity.
        require(leavesLen + proofLen - 1 == totalHashes, "MerkleProof: invalid multiproof");

        // 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[](totalHashes);
        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 < totalHashes; i++) {
            bytes32 a = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++];
            bytes32 b = proofFlags[i]
                ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++])
                : proof[proofPos++];
            hashes[i] = _hashPair(a, b);
        }

        if (totalHashes > 0) {
            require(proofPos == proofLen, "MerkleProof: invalid multiproof");
            unchecked {
                return hashes[totalHashes - 1];
            }
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
        return a < b ? _efficientHash(a, b) : _efficientHash(b, a);
    }

    function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, a)
            mstore(0x20, b)
            value := keccak256(0x00, 0x40)
        }
    }
}

File 27 of 37 : ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

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

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

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

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

File 28 of 37 : IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

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

File 29 of 37 : MathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

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

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

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

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

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

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

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

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv 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.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 30 of 37 : SignedMathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

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

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

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

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

File 31 of 37 : StringsUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/MathUpgradeable.sol";
import "./math/SignedMathUpgradeable.sol";

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

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

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMathUpgradeable.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, MathUpgradeable.log256(value) + 1);
        }
    }

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

            return true;
        } else {
            return false;
        }
    }

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

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

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

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }
}

File 33 of 37 : CHARACTER_V1_UPGRADABLE.sol
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.17;

import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721RoyaltyUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721BurnableUpgradeable.sol";
import "operator-filter-registry1.4.1/src/upgradeable/DefaultOperatorFiltererUpgradeable.sol";
import '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol';

// @title: Wally Character_V1 Smart contract
// @notice: ERC721 NFT Smart Contract for Symbiogenesis project's Character
// @dev: This contract inherited ERC721,ERC721Enumerable, ERC721URIStorage, Pausable, AccessControlEnumerable, ERC721Burnable, ERC721Royalty, Ownable and DefaultOperatorFilterer Smart contracts from openzepplin
contract CHARACTER_V1_UPGRADEABLE is Initializable, ERC721Upgradeable, ERC721EnumerableUpgradeable, ERC721URIStorageUpgradeable, PausableUpgradeable, AccessControlEnumerableUpgradeable, ERC721BurnableUpgradeable, ERC721RoyaltyUpgradeable, OwnableUpgradeable, DefaultOperatorFiltererUpgradeable {
    // As byte32 type public constants , stores hash for string value that display various kinds of roles
    bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
    bytes32 public constant ROYALTY_ROLE = keccak256("ROYALTY_ROLE");
    // Private mapping that stores status variable as bool type that display whether token is burned or not
    mapping(uint256 => bool) private burnedTokens;
    //@notice: This construcor function is executed when contract is deployed
    //@param: token name and token symbol
    //@dev:assign all kinds of roles to deployer's address
    function initialize(
        string memory _name,
        string memory _symbol
    ) external initializer {
        __ERC721_init(_name, _symbol);
        __ERC721Enumerable_init();
        __ERC721URIStorage_init();
        __ERC721Burnable_init();
        __ERC721Royalty_init();
        __Pausable_init();
        __Ownable_init();
        __AccessControlEnumerable_init();
        __DefaultOperatorFilterer_init();
        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _setupRole(MINTER_ROLE, msg.sender);
        _setupRole(PAUSER_ROLE, msg.sender);
        _setupRole(ROYALTY_ROLE, msg.sender);
    }

    ////////////////////
    //@notice: This is a function that mint token
    //@param: token id, address that token is minted to, token uri
    //@dev: Only address that has minter role can execute this function. It requires that token id to be minter is not burned. Call safeMint function. Set token uri
    function mint(uint256 tokenId, address to, string memory uri) public onlyRole(MINTER_ROLE)
    {
        require(isBurnedToken(tokenId) == false, "Token is burned");
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri);
    }

    //@notice: This function triggers stoped state of the contract
    //@dev: Only msg.sender that has PAUSER_ROLE can call this function. Call _pause() in the Pausable contract
    function pause() public onlyRole(PAUSER_ROLE)
    {
        _pause();
    }

    //@notice: This function triggers unstoped state of the contract
    //@dev: Only msg.sender that has PAUSER_ROLE can call this function. Call _unpause() in the Pausable contract
    function unpause() public onlyRole(PAUSER_ROLE)
    {
        _unpause();
    }

    ////////////////////

    //@notice: This is a public function that set defaukt royalty.
    //@param: receiver address that represents the address that royalty will be transferred, feeNumerator that represents the numerator of the fee percentage charged when a token is transferred.
    //@dev: Only msg.sender that has ROYALTY_ROLE can call this function. Call _setDefaultRoyalty in the ERC721Royalty contract
    function setDefaultRoyalty(address receiver, uint96 feeNumerator) public onlyRole(ROYALTY_ROLE)
    {
        _setDefaultRoyalty(receiver, feeNumerator);
    }

    //@notice: This is a function that delete default royalty
    //@dev: Only msg.sender that has ROYALTY_ROLE can call this function. Call _deleteDefaultRoyalty in the ERC721Royalty contract
    function deleteDefaultRoyalty() external onlyRole(ROYALTY_ROLE)
    {
        _deleteDefaultRoyalty();
    }

    //@notice: This is a function that sets the royalty information for a specific token id.
    //@param: token id, receiver address, feeNumerator
    //@dev: Only msg.sender that has ROYALTY_ROLE can call this function. Call  _setTokenRoyalty in the ERC721Royalty contract
    function setTokenRoyalty(uint256 tokenId ,address receiver, uint96 feeNumerator) public onlyRole(ROYALTY_ROLE)
    {
        _setTokenRoyalty(tokenId, receiver, feeNumerator);
    }

    //@notice: This is a function that resets the royalty information for a specific token id.
    //@param: token id
    //@dev: Only msg.sender that has ROYALTY_ROLE can call this function. Call  _resetTokenRoyalty in the ERC721Royalty contract
    function resetTokenRoyalty(uint256 tokenId) public onlyRole(ROYALTY_ROLE) {
        _resetTokenRoyalty(tokenId);
    }

    ////////////////////
    // The following functions are overrides from inherited contract
    function _burn(uint256 tokenId) internal override(ERC721Upgradeable, ERC721URIStorageUpgradeable, ERC721RoyaltyUpgradeable)
    {
        super._burn(tokenId);
        burnedTokens[tokenId] = true;
    }

    function tokenURI(uint256 tokenId)
        public
        view
        override(ERC721Upgradeable, ERC721URIStorageUpgradeable)
        returns (string memory)
    {
        return super.tokenURI(tokenId);
    }

    function supportsInterface(bytes4 interfaceId)
        public
        view
        override(AccessControlEnumerableUpgradeable, ERC721EnumerableUpgradeable, ERC721RoyaltyUpgradeable, ERC721URIStorageUpgradeable, ERC721Upgradeable)
        returns (bool)
    {
        return super.supportsInterface(interfaceId);
    }

    function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize)
        internal
        override(ERC721Upgradeable, ERC721EnumerableUpgradeable)
    {
        super._beforeTokenTransfer(from, to, tokenId, batchSize);
    }

    function setApprovalForAll(address operator, bool approved) public override(ERC721Upgradeable, IERC721Upgradeable) onlyAllowedOperatorApproval(operator) {
        super.setApprovalForAll(operator, approved);
    }

    function approve(address operator, uint256 tokenId) public override(ERC721Upgradeable, IERC721Upgradeable) onlyAllowedOperatorApproval(operator) {
        super.approve(operator, tokenId);
    }

    function transferFrom(address from, address to, uint256 tokenId) public virtual whenNotPaused onlyAllowedOperator(from) override(ERC721Upgradeable, IERC721Upgradeable) {
        super.transferFrom(from, to, tokenId);
        if (to == address(0)) {
            burnedTokens[tokenId] = true;
        }
    }

    function safeTransferFrom(address from, address to, uint256 tokenId) public virtual whenNotPaused onlyAllowedOperator(from) override(ERC721Upgradeable, IERC721Upgradeable) {
        super.safeTransferFrom(from, to, tokenId);
        if (to == address(0)) {
            burnedTokens[tokenId] = true;
        }
    }

    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data)
        public
        virtual whenNotPaused onlyAllowedOperator(from)
        override(ERC721Upgradeable, IERC721Upgradeable)
    {
        super.safeTransferFrom(from, to, tokenId, data);
    }

    //@notice: This is a function that represents if current token is burned or not.
    //@param: token id.
    //@return: return bool type state variable that is stored in the burnedTokens mapping.
    function isBurnedToken(uint256 tokenId) public view returns (bool) {
        return burnedTokens[tokenId];
    }
    //@notice: This is a function that represents if current token id exists.
    //@param: token id
    //@return: return _exists function that return state variable that indicate the existance of token id.
    function exists(uint _tokenId) external view returns (bool) {
        return _exists(_tokenId);
    }
}

File 34 of 37 : IOperatorFilterRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

interface IOperatorFilterRegistry {
    /**
     * @notice Returns true if operator is not filtered for a given token, either by address or codeHash. Also returns
     *         true if supplied registrant address is not registered.
     */
    function isOperatorAllowed(address registrant, address operator) external view returns (bool);

    /**
     * @notice Registers an address with the registry. May be called by address itself or by EIP-173 owner.
     */
    function register(address registrant) external;

    /**
     * @notice Registers an address with the registry and "subscribes" to another address's filtered operators and codeHashes.
     */
    function registerAndSubscribe(address registrant, address subscription) external;

    /**
     * @notice Registers an address with the registry and copies the filtered operators and codeHashes from another
     *         address without subscribing.
     */
    function registerAndCopyEntries(address registrant, address registrantToCopy) external;

    /**
     * @notice Unregisters an address with the registry and removes its subscription. May be called by address itself or by EIP-173 owner.
     *         Note that this does not remove any filtered addresses or codeHashes.
     *         Also note that any subscriptions to this registrant will still be active and follow the existing filtered addresses and codehashes.
     */
    function unregister(address addr) external;

    /**
     * @notice Update an operator address for a registered address - when filtered is true, the operator is filtered.
     */
    function updateOperator(address registrant, address operator, bool filtered) external;

    /**
     * @notice Update multiple operators for a registered address - when filtered is true, the operators will be filtered. Reverts on duplicates.
     */
    function updateOperators(address registrant, address[] calldata operators, bool filtered) external;

    /**
     * @notice Update a codeHash for a registered address - when filtered is true, the codeHash is filtered.
     */
    function updateCodeHash(address registrant, bytes32 codehash, bool filtered) external;

    /**
     * @notice Update multiple codeHashes for a registered address - when filtered is true, the codeHashes will be filtered. Reverts on duplicates.
     */
    function updateCodeHashes(address registrant, bytes32[] calldata codeHashes, bool filtered) external;

    /**
     * @notice Subscribe an address to another registrant's filtered operators and codeHashes. Will remove previous
     *         subscription if present.
     *         Note that accounts with subscriptions may go on to subscribe to other accounts - in this case,
     *         subscriptions will not be forwarded. Instead the former subscription's existing entries will still be
     *         used.
     */
    function subscribe(address registrant, address registrantToSubscribe) external;

    /**
     * @notice Unsubscribe an address from its current subscribed registrant, and optionally copy its filtered operators and codeHashes.
     */
    function unsubscribe(address registrant, bool copyExistingEntries) external;

    /**
     * @notice Get the subscription address of a given registrant, if any.
     */
    function subscriptionOf(address addr) external returns (address registrant);

    /**
     * @notice Get the set of addresses subscribed to a given registrant.
     *         Note that order is not guaranteed as updates are made.
     */
    function subscribers(address registrant) external returns (address[] memory);

    /**
     * @notice Get the subscriber at a given index in the set of addresses subscribed to a given registrant.
     *         Note that order is not guaranteed as updates are made.
     */
    function subscriberAt(address registrant, uint256 index) external returns (address);

    /**
     * @notice Copy filtered operators and codeHashes from a different registrantToCopy to addr.
     */
    function copyEntriesOf(address registrant, address registrantToCopy) external;

    /**
     * @notice Returns true if operator is filtered by a given address or its subscription.
     */
    function isOperatorFiltered(address registrant, address operator) external returns (bool);

    /**
     * @notice Returns true if the hash of an address's code is filtered by a given address or its subscription.
     */
    function isCodeHashOfFiltered(address registrant, address operatorWithCode) external returns (bool);

    /**
     * @notice Returns true if a codeHash is filtered by a given address or its subscription.
     */
    function isCodeHashFiltered(address registrant, bytes32 codeHash) external returns (bool);

    /**
     * @notice Returns a list of filtered operators for a given address or its subscription.
     */
    function filteredOperators(address addr) external returns (address[] memory);

    /**
     * @notice Returns the set of filtered codeHashes for a given address or its subscription.
     *         Note that order is not guaranteed as updates are made.
     */
    function filteredCodeHashes(address addr) external returns (bytes32[] memory);

    /**
     * @notice Returns the filtered operator at the given index of the set of filtered operators for a given address or
     *         its subscription.
     *         Note that order is not guaranteed as updates are made.
     */
    function filteredOperatorAt(address registrant, uint256 index) external returns (address);

    /**
     * @notice Returns the filtered codeHash at the given index of the list of filtered codeHashes for a given address or
     *         its subscription.
     *         Note that order is not guaranteed as updates are made.
     */
    function filteredCodeHashAt(address registrant, uint256 index) external returns (bytes32);

    /**
     * @notice Returns true if an address has registered
     */
    function isRegistered(address addr) external returns (bool);

    /**
     * @dev Convenience method to compute the code hash of an arbitrary contract
     */
    function codeHashOf(address addr) external returns (bytes32);
}

File 35 of 37 : Constants.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

address constant CANONICAL_OPERATOR_FILTER_REGISTRY_ADDRESS = 0x000000000000AAeB6D7670E522A718067333cd4E;
address constant CANONICAL_CORI_SUBSCRIPTION = 0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6;

File 36 of 37 : DefaultOperatorFiltererUpgradeable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {OperatorFiltererUpgradeable} from "./OperatorFiltererUpgradeable.sol";
import {CANONICAL_CORI_SUBSCRIPTION} from "../lib/Constants.sol";

/**
 * @title  DefaultOperatorFiltererUpgradeable
 * @notice Inherits from OperatorFiltererUpgradeable and automatically subscribes to the default OpenSea subscription
 *         when the init function is called.
 */
abstract contract DefaultOperatorFiltererUpgradeable is OperatorFiltererUpgradeable {
    /// @dev The upgradeable initialize function that should be called when the contract is being deployed.
    function __DefaultOperatorFilterer_init() internal onlyInitializing {
        OperatorFiltererUpgradeable.__OperatorFilterer_init(CANONICAL_CORI_SUBSCRIPTION, true);
    }
}

File 37 of 37 : OperatorFiltererUpgradeable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {IOperatorFilterRegistry} from "../IOperatorFilterRegistry.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

/**
 * @title  OperatorFiltererUpgradeable
 * @notice Abstract contract whose constructor automatically registers and optionally subscribes to or copies another
 *         registrant's entries in the OperatorFilterRegistry when the init function is called.
 * @dev    This smart contract is meant to be inherited by token contracts so they can use the following:
 *         - `onlyAllowedOperator` modifier for `transferFrom` and `safeTransferFrom` methods.
 *         - `onlyAllowedOperatorApproval` modifier for `approve` and `setApprovalForAll` methods.
 */
abstract contract OperatorFiltererUpgradeable is Initializable {
    /// @notice Emitted when an operator is not allowed.
    error OperatorNotAllowed(address operator);

    IOperatorFilterRegistry constant OPERATOR_FILTER_REGISTRY =
        IOperatorFilterRegistry(0x000000000000AAeB6D7670E522A718067333cd4E);

    /// @dev The upgradeable initialize function that should be called when the contract is being upgraded.
    function __OperatorFilterer_init(address subscriptionOrRegistrantToCopy, bool subscribe)
        internal
        onlyInitializing
    {
        // If an inheriting token contract is deployed to a network without the registry deployed, the modifier
        // will not revert, but the contract will need to be registered with the registry once it is deployed in
        // order for the modifier to filter addresses.
        if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
            if (!OPERATOR_FILTER_REGISTRY.isRegistered(address(this))) {
                if (subscribe) {
                    OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);
                } else {
                    if (subscriptionOrRegistrantToCopy != address(0)) {
                        OPERATOR_FILTER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);
                    } else {
                        OPERATOR_FILTER_REGISTRY.register(address(this));
                    }
                }
            }
        }
    }

    /**
     * @dev A helper modifier to check if the operator is allowed.
     */
    modifier onlyAllowedOperator(address from) virtual {
        // Allow spending tokens from addresses with balance
        // Note that this still allows listings and marketplaces with escrow to transfer tokens if transferred
        // from an EOA.
        if (from != msg.sender) {
            _checkFilterOperator(msg.sender);
        }
        _;
    }

    /**
     * @dev A helper modifier to check if the operator approval is allowed.
     */
    modifier onlyAllowedOperatorApproval(address operator) virtual {
        _checkFilterOperator(operator);
        _;
    }

    /**
     * @dev A helper function to check if the operator is allowed.
     */
    function _checkFilterOperator(address operator) internal view virtual {
        // Check registry code length to facilitate testing in environments without a deployed registry.
        if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {
            // under normal circumstances, this function will revert rather than return false, but inheriting or
            // upgraded contracts may specify their own OperatorFilterRegistry implementations, which may behave
            // differently
            if (!OPERATOR_FILTER_REGISTRY.isOperatorAllowed(address(this), operator)) {
                revert OperatorNotAllowed(operator);
            }
        }
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 10
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftContractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"smallSaleId","type":"uint256"}],"name":"AuctionCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftContractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"auctionEndPeriod","type":"uint256"}],"name":"AuctionPeriodUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftContractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"auctionSettler","type":"address"}],"name":"AuctionSettled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftContractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"nftOwner","type":"address"}],"name":"AuctionWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftContractAddress","type":"address"},{"indexed":true,"internalType":"uint8","name":"chapterId","type":"uint8"},{"indexed":false,"internalType":"string","name":"baseUrl","type":"string"},{"indexed":false,"internalType":"uint256","name":"createdAt","type":"uint256"}],"name":"BaseUrlForChapterSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftContractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"bidder","type":"address"},{"indexed":false,"internalType":"uint128","name":"ethAmount","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"createdAt","type":"uint256"}],"name":"BidMade","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftContractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"nftHighestBid","type":"uint128"},{"indexed":false,"internalType":"address","name":"nftHighestBidder","type":"address"}],"name":"CharaterMintedAndPaymentPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftContractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"toAddress","type":"address"},{"indexed":false,"internalType":"uint128","name":"ethAmount","type":"uint128"}],"name":"FailedPayout","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftContractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"HighestBidTaken","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"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":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftContractAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"buyNowPrice","type":"uint128"},{"indexed":false,"internalType":"address","name":"buyer","type":"address"}],"name":"SaleCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"smallSaleId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"createdAt","type":"uint256"}],"name":"SmallSaleCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint8","name":"","type":"uint8"}],"name":"baseUrlForChapter","outputs":[{"internalType":"uint8","name":"isSet","type":"uint8"},{"internalType":"string","name":"baseUrl","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_nftContractAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"closeAuction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_nftContractAddress","type":"address"},{"internalType":"uint256","name":"count","type":"uint256"}],"name":"closeBatchAuctions","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_smallSaleId","type":"uint256"},{"internalType":"uint256[]","name":"_tokenIds","type":"uint256[]"}],"name":"createNewNftAuction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_allowRoot","type":"bytes32"},{"internalType":"enum CHARACTER_SHOP_UPGRADEABLE.SaleType","name":"_saleType","type":"uint8"},{"internalType":"uint128","name":"_price","type":"uint128"},{"internalType":"uint128","name":"_buyLimit","type":"uint128"},{"internalType":"address","name":"_nftContractAddress","type":"address"},{"internalType":"uint8","name":"_chapterId","type":"uint8"},{"internalType":"uint128","name":"_bidIncreaseAmount","type":"uint128"},{"internalType":"uint256","name":"_startAt","type":"uint256"},{"internalType":"uint256","name":"_endAt","type":"uint256"}],"name":"createSmallSale","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"failedTransferCredits","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_nftContractAddress","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getAunctionData","outputs":[{"components":[{"internalType":"uint128","name":"bidIncreaseAmount","type":"uint128"},{"internalType":"uint32","name":"reserved_1","type":"uint32"},{"internalType":"uint256","name":"auctionEnd","type":"uint256"},{"internalType":"uint128","name":"minPrice","type":"uint128"},{"internalType":"uint128","name":"buyNowPrice","type":"uint128"},{"internalType":"uint128","name":"nftHighestBid","type":"uint128"},{"internalType":"bytes32","name":"allowListRoot","type":"bytes32"},{"internalType":"address","name":"nftHighestBidder","type":"address"},{"internalType":"string","name":"tokenURI","type":"string"},{"internalType":"uint8","name":"sold","type":"uint8"},{"internalType":"bool","name":"isOnAuction","type":"bool"},{"internalType":"uint256","name":"bidsCount","type":"uint256"},{"internalType":"uint256","name":"startAt","type":"uint256"},{"internalType":"uint256","name":"smallSaleId","type":"uint256"}],"internalType":"struct CHARACTER_SHOP_UPGRADEABLE.CombinedAuctionData","name":"auctionData","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_feeReceiver","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_nftContractAddress","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"}],"name":"makeBid","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_nftContractAddress","type":"address"},{"internalType":"uint8","name":"_chapterId","type":"uint8"},{"internalType":"string","name":"_baseUrl","type":"string"}],"name":"setBaseUrlForChapter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_nftContractAddress","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"settleAuction","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"smallSales","outputs":[{"internalType":"bytes32","name":"allowListRoot","type":"bytes32"},{"internalType":"uint128","name":"price","type":"uint128"},{"internalType":"uint128","name":"buyLimit","type":"uint128"},{"internalType":"address","name":"nftContractAddress","type":"address"},{"internalType":"uint8","name":"chapterId","type":"uint8"},{"internalType":"enum CHARACTER_SHOP_UPGRADEABLE.SaleType","name":"saleType","type":"uint8"},{"internalType":"uint128","name":"bidIncreaseAmount","type":"uint128"},{"internalType":"uint256","name":"startAt","type":"uint256"},{"internalType":"uint256","name":"auctionEnd","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_nftContractAddress","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"takeHighestBid","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"updatedFeeReceiver","type":"address"}],"name":"updateFeeReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"userBuyCountInSmallSale","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"withdrawAllFailedCredits","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_nftContractAddress","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"withdrawAuction","outputs":[],"stateMutability":"nonpayable","type":"function"}]

608060405234801561001057600080fd5b50613a99806100206000396000f3fe60806040526004361061011b5760003560e01c80630ac08b27146101205780632616bb7114610156578063285afc0d1461018b5780633f4ba83a146101ad578063438364a1146101c257806350a33c7b146101e25780635138b08c1461023b578063566b9c511461025b57806356d73145146102895780635c975abb146102b7578063715018a6146102da57806377f61b3b146102ef5780638456cb591461030f578063848e5c77146103245780638da5cb5b146103445780639148ff4a14610366578063a72d8f211461037c578063ad3014c41461039c578063b3f00674146103af578063c4d66de8146103cf578063c69bebe4146103ef578063c90941b11461040f578063ebea60251461042f578063f2fde38b1461044f575b600080fd5b34801561012c57600080fd5b5061014061013b36600461319f565b61046f565b60405161014d9190613226565b60405180910390f35b34801561016257600080fd5b50610176610171366004613332565b6107bc565b60405161014d99989796959493929190613361565b34801561019757600080fd5b506101ab6101a63660046133f2565b61083a565b005b3480156101b957600080fd5b506101ab610962565b3480156101ce57600080fd5b506101ab6101dd36600461319f565b610974565b3480156101ee57600080fd5b506102236101fd36600461319f565b60ca6020908152600092835260408084209091529082529020546001600160801b031681565b6040516001600160801b03909116815260200161014d565b34801561024757600080fd5b506101ab61025636600461319f565b6109a3565b34801561026757600080fd5b5061027b610276366004613496565b610ad8565b60405190815260200161014d565b34801561029557600080fd5b506102a96102a436600461352f565b6110a0565b60405161014d929190613562565b3480156102c357600080fd5b5060655460ff16604051901515815260200161014d565b3480156102e657600080fd5b506101ab611154565b3480156102fb57600080fd5b506101ab61030a3660046135d1565b6111a1565b34801561031b57600080fd5b506101ab611400565b34801561033057600080fd5b506101ab61033f36600461319f565b611410565b34801561035057600080fd5b506103596114ed565b60405161014d919061361c565b34801561037257600080fd5b5061027b60cd5481565b34801561038857600080fd5b506101ab61039736600461319f565b6114fc565b6101ab6103aa366004613630565b611544565b3480156103bb57600080fd5b5060cc54610359906001600160a01b031681565b3480156103db57600080fd5b506101ab6103ea366004613689565b611917565b3480156103fb57600080fd5b506101ab61040a366004613689565b611aa4565b34801561041b57600080fd5b506101ab61042a366004613689565b611aff565b34801561043b57600080fd5b506101ab61044a36600461319f565b611bce565b34801561045b57600080fd5b506101ab61046a366004613689565b611d62565b604080516101c08101825260008082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e0820183905261010082015261012081018290526101408101829052610160810182905261018081018290526101a08101919091526001600160a01b03808416600090815260c9602090815260408083208684528252808320815160e081018352815480825260018301546001600160801b03169482019490945260028201549586169281019290925260ff600160a01b860481166060840152600160a81b90950490941615156080820152600384015460a082015260049093015460c084015290036105f657604080516101c08101825260008082526020808301829052828401829052606083018290526080830182905260a0830182905260c0830182905260e08301829052835190810190935280835261010082019290925261012081018290526101408101829052610160810182905261018081018290526101a081019190915291506107b4565b600060cb8260c001518154811061060f5761060f6136a4565b6000918252602091829020604080516101208101825260069093029091018054835260018101546001600160801b0380821695850195909552600160801b9004909316908201526002808301546001600160a01b038116606084015260ff600160a01b82048116608085015292939260a0850192600160a81b909204169081111561069c5761069c61334b565b60028111156106ad576106ad61334b565b815260038201546001600160801b0316602082015260048201546040820152600590910154606090910152905060006106e68686611dd8565b9050604051806101c001604052808360c001516001600160801b03168152602001600063ffffffff1681526020018460000151815260200183602001516001600160801b0316815260200183602001516001600160801b0316815260200184602001516001600160801b031681526020018360000151815260200184604001516001600160a01b03168152602001828152602001846060015160ff1681526020018460800151151581526020018460a0015181526020018360e0015181526020018460c00151815250935050505b505b92915050565b60cb81815481106107cc57600080fd5b60009182526020909120600690910201805460018201546002830154600384015460048501546005909501549395506001600160801b0380841695600160801b9094048116946001600160a01b0384169460ff600160a01b8604811695600160a81b90041693909216919089565b610842611f38565b61084a611f97565b6001600160a01b0384166108795760405162461bcd60e51b8152600401610870906136ba565b60405180910390fd5b6040518060400160405280600160ff16815260200183838080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509390945250506001600160a01b038716815260ce6020908152604080832060ff898116855290835292208451815460ff19169316929092178255830151909150600182019061090f9082613782565b509050508260ff16846001600160a01b03167f9a7956ba73d918511b7fa9a38abad497e8a10ad0ab89e6aad8870f6628d012c184844260405161095493929190613841565b60405180910390a350505050565b61096a611f38565b610972611fdd565b565b61097c611f38565b610984612029565b61098c612082565b61099682826120cb565b61099f60018055565b5050565b6109ab611f97565b6109b3612029565b6109bd828261219f565b60ff1615610a075760405162461bcd60e51b815260206004820152601760248201527620bab1ba34b7b71034b9903737ba103cb2ba1037bb32b960491b6044820152606401610870565b610a11828261222e565b60ff16600114610a335760405162461bcd60e51b81526004016108709061387a565b6001600160a01b038216600090815260c960209081526040808320848452909152902060020154600160a01b900460ff1615610a815760405162461bcd60e51b8152600401610870906138a9565b610a8d8282600161226f565b80826001600160a01b03167fe6b94748c5d6e0d188a0fcb9b7f2973b01fc0095627f1ec5accdcd9d2e65ca3633604051610ac7919061361c565b60405180910390a361099f60018055565b6000610ae2611f38565b610aea611f97565b610af2612029565b6001600160a01b038616600090815260ce6020908152604080832060ff808a1685529252909120548791879116600114610b6e5760405162461bcd60e51b815260206004820152601f60248201527f426173652055524c20666f722063686170746572206973206e6f7420736574006044820152606401610870565b834210610bd05760405162461bcd60e51b815260206004820152602a60248201527f41756374696f6e20656e64206973206c657373207468616e2063757272656e7460448201526902074696d657374616d760b41b6064820152608401610870565b838510610c2e5760405162461bcd60e51b815260206004820152602660248201527f41756374696f6e20656e64206973206c657373207468616e2061756374696f6e604482015265081cdd185c9d60d21b6064820152608401610870565b6000896001600160801b031611610c865760405162461bcd60e51b815260206004820152601c60248201527b0427579206c696d6974206d757374206c6172676572207468616e20360241b6044820152606401610870565b60028b6002811115610c9a57610c9a61334b565b148015610cb0575060008a6001600160801b0316115b15610d0e5760405162461bcd60e51b815260206004820152602860248201527f50726963652073686f756c64206265207a65726f206f6e205a65726f2070726960448201526731b29039b0b6329760c11b6064820152608401610870565b60008b6002811115610d2257610d2261334b565b148015610d3657506001600160801b038a16155b15610d9d5760405162461bcd60e51b815260206004820152603160248201527f50726963652073686f756c64206265206c6172676572207468616e207a65726f6044820152701037b710213abc903737bb9039b0b6329760791b6064820152608401610870565b60018b6002811115610db157610db161334b565b148015610dc557506001600160801b038616155b15610e435760405162461bcd60e51b815260206004820152604260248201527f42696420696e63726561736520616d6f756e742073686f756c64206265206c6160448201527f72676572207468616e207a65726f206f6e20456e676c6973682061756374696f606482015261371760f11b608482015260a401610870565b60018b6002811115610e5757610e5761334b565b14158015610e6d57506001600160801b03861615155b15610ed55760405162461bcd60e51b815260206004820152603260248201527f42696420696e637265616520616d6f756e742073686f756c64206265207a6572604482015271379037b710313abc903737bb9039b0b6329760711b6064820152608401610870565b60cb6040518061012001604052808e81526020018c6001600160801b031681526020018b6001600160801b031681526020018a6001600160a01b031681526020018960ff1681526020018d6002811115610f3157610f3161334b565b81526001600160801b03808a1660208084019190915260408084018b905260609384018a9052855460018181018855600097885296839020865160069092020190815591850151908501518316600160801b029216919091179381019390935581015160028084018054608085015160ff16600160a01b026001600160a81b03199091166001600160a01b03909416939093179290921780835560a0840151939493929160ff60a81b1990911690600160a81b908490811115610ff657610ff661334b565b021790555060c08201516003820180546001600160801b0319166001600160801b0390921691909117905560e082015160048201556101009091015160059091015560cb5460009061104a906001906138eb565b9050807fedd3881684d03e8c0fecdc07db380143d03bbcf9aa9f386bbc98701efed23c814260405161107e91815260200190565b60405180910390a29250505061109360018055565b9998505050505050505050565b60ce6020908152600092835260408084209091529082529020805460018201805460ff90921692916110d1906136f9565b80601f01602080910402602001604051908101604052809291908181526020018280546110fd906136f9565b801561114a5780601f1061111f5761010080835404028352916020019161114a565b820191906000526020600020905b81548152906001019060200180831161112d57829003601f168201915b5050505050905082565b61115c611f38565b60405162461bcd60e51b815260206004820152601a602482015279043616e206e6f742072656e6f756e6365206f6e776572736869760341b6044820152606401610870565b6111a9611f38565b6111b1611f97565b60cb54839081106111fe5760405162461bcd60e51b8152602060048201526017602482015276536d616c6c53616c65494420697320696e76616c69642160481b6044820152606401610870565b600060cb8581548110611213576112136136a4565b6000918252602091829020604080516101208101825260069093029091018054835260018101546001600160801b0380821695850195909552600160801b9004909316908201526002808301546001600160a01b038116606084015260ff600160a01b82048116608085015292939260a0850192600160a81b90920416908111156112a0576112a061334b565b60028111156112b1576112b161334b565b815260038201546001600160801b031660208201526004820154604082015260059091015460609182015281015161010082015191925090818560005b818161ffff1610156113f457826001600160a01b0316634f558e798a8a8461ffff1681811061131f5761131f6136a4565b905060200201356040518263ffffffff1660e01b815260040161134491815260200190565b602060405180830381865afa158015611361573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061138591906138fe565b156113c45760405162461bcd60e51b815260206004820152600f60248201526e151bdad95b881a5cc81b5a5b9d1959608a1b6044820152606401610870565b6113ec8a868b8b8561ffff168181106113df576113df6136a4565b90506020020135876124a4565b6001016112ee565b50505050505050505050565b611408611f38565b6109726125dc565b611418611f38565b611420611f97565b611428612029565b611432828261222e565b60ff166001146114545760405162461bcd60e51b81526004016108709061387a565b6001600160a01b038216600090815260c960209081526040808320848452909152902060020154600160a01b900460ff16156114a25760405162461bcd60e51b8152600401610870906138a9565b6114ae8282600161226f565b60405181906001600160a01b038416907f711f4eae05533b90c24ff0ae762d6e9e1ef1b2c85d4c484a2913c5201bcbb7c990600090a361099f60018055565b6097546001600160a01b031690565b611504611f38565b61150c612029565b611514612082565b60015b81811161153a5761152883826120cb565b8061153281613920565b915050611517565b5061099f60018055565b61154c611f97565b611554612029565b6001600160a01b038416600090815260c96020908152604080832086845290915290206002015484908490600160a01b900460ff16156115cf5760405162461bcd60e51b8152602060048201526016602482015275546f6b656e20697320616c726561647920736f6c642160501b6044820152606401610870565b60cb546001600160a01b038316600090815260c960209081526040808320858452909152902060040154106116575760405162461bcd60e51b815260206004820152602860248201527f536d616c6c2073616c6520646f6573206e6f74206578697374206f6e2074686960448201526739903a37b5b2b71760c11b6064820152608401610870565b611661828261219f565b60ff166001146116bf5760405162461bcd60e51b8152602060048201526024808201527f41756374696f6e2068617320656e646564206f72206e6f742073746172746564604482015263081e595d60e21b6064820152608401610870565b6001600160a01b038616600090815260c96020908152604080832088845290915290206004015460cb5487918791811061174d5760405162461bcd60e51b815260206004820152602960248201527f4e6f74206578697374696e6720736d616c6c2073616c6520666f72206375727260448201526832b73a103a37b5b2b760b91b6064820152608401610870565b60cb8181548110611760576117606136a4565b600091825260208083206001600690930201919091015433835260ca825260408084208585529092529120546001600160801b03600160801b90920482169116106118035760405162461bcd60e51b815260206004820152602d60248201527f55736572206578636565647320627579206c696d697420666f7220637572726560448201526c6e7420736d616c6c2073616c6560981b6064820152608401610870565b6001600160a01b038916600090815260c9602090815260408083208b845290915281206004015460cb8054909190811061183f5761183f6136a4565b6000918252602090912060069091020154905080158061189757506118978189898080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061261992505050565b6118da5760405162461bcd60e51b815260206004820152601460248201527334b73b30b634b21036b2b935b63290383937b7b360611b6044820152606401610870565b6118e48a8a61262d565b6118ee8a8a61272b565b60ff16600103611902576119028a8a612810565b50505050505061191160018055565b50505050565b600054610100900460ff16158080156119375750600054600160ff909116105b806119515750303b158015611951575060005460ff166001145b6119b45760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610870565b6000805460ff1916600117905580156119d7576000805461ff0019166101001790555b6001600160a01b038216611a285760405162461bcd60e51b815260206004820152601860248201527743616e6e6f7420737065636966792030206164647265737360401b6044820152606401610870565b60cc80546001600160a01b0319166001600160a01b038416179055611a4b61288f565b611a536128be565b611a5b6128ed565b801561099f576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15050565b611aac611f38565b611ab4612029565b6001600160a01b038116611ada5760405162461bcd60e51b8152600401610870906136ba565b60cc80546001600160a01b0319166001600160a01b0383161790556001805550565b50565b611b07611f38565b611b0f612029565b60cd546000819003611b5c5760405162461bcd60e51b81526020600482015260166024820152756e6f206372656469747320746f20776974686472617760501b6044820152606401610870565b6000826001600160a01b03168261138890604051600060405180830381858888f193505050503d8060008114611bae576040519150601f19603f3d011682016040523d82523d6000602084013e611bb3565b606091505b505090508015611bc357600060cd555b5050611afc60018055565b611bd6611f38565b611bde612029565b6001600160a01b038216600090815260c960209081526040808320848452909152902060020154600160a01b900460ff1615611c555760405162461bcd60e51b81526020600482015260166024820152751d1bdad95b881a185cc8185b1c9958591e481cdbdb1960521b6044820152606401610870565b6001600160a01b038216600090815260c9602090815260408083208484529091529020600101546001600160801b031615611cde5760405162461bcd60e51b815260206004820152602360248201527f43616e206e6f74207769746864726177207768656e206120626964206973206d60448201526261646560e81b6064820152608401610870565b6001600160a01b038216600081815260c9602090815260408083208584529091528082208281556001810180546001600160801b0319169055600281018054600161ff0160a01b031916905560030191909155518291907fec19f84af4aad6523d37faa19e243c77717842cca9bf492dc5379830cac958d090610ac790339061361c565b611d6a611f38565b6001600160a01b038116611dcf5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610870565b611afc8161291c565b6001600160a01b038216600081815260c96020908152604080832085845282528083206004015493835260ce909152812060cb8054606094939291839185908110611e2557611e256136a4565b906000526020600020906006020160020160149054906101000a900460ff1660ff1660ff1681526020019081526020016000206001018054611e66906136f9565b80601f0160208091040260200160405190810160405280929190818152602001828054611e92906136f9565b8015611edf5780601f10611eb457610100808354040283529160200191611edf565b820191906000526020600020905b815481529060010190602001808311611ec257829003601f168201915b505050505090506000815111611f045760405180602001604052806000815250611f2f565b80611f0e8561296e565b604051602001611f1f929190613939565b6040516020818303038152906040525b95945050505050565b33611f416114ed565b6001600160a01b0316146109725760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610870565b60655460ff16156109725760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610870565b611fe5612082565b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b60405161201f919061361c565b60405180910390a1565b60026001540361207b5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610870565b6002600155565b60655460ff166109725760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610870565b6001600160a01b03828116600090815260c96020908152604080832085845290915290206002810154600190910154918116916001600160801b031690600160a01b900460ff168215801590612122575060ff8116155b15612192576001600160801b038216156121425761214285858585612a00565b6001600160a01b038516600090815260c96020908152604080832087845290915281208181556001810180546001600160801b0319169055600281018054600161ff0160a01b0319169055600301555b5050505050565b60018055565b6001600160a01b038216600090815260c9602090815260408083208484529091528120805460049091015460cb8054849190839081106121e1576121e16136a4565b90600052602060002090600602016004015490508260001415801561220557508242105b80156122115750804210155b1561222257600193505050506107b6565b50600095945050505050565b6001600160a01b03828116600090815260c96020908152604080832085845290915281206002015490911615612266575060016107b6565b50600092915050565b6001600160a01b03838116600090815260c960209081526040808320868452909152812060028101546001909101549216916001600160801b0316906122b58686611dd8565b604051634f558e7960e01b8152600481018790529091506001600160a01b03871690634f558e7990602401602060405180830381865afa1580156122fd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061232191906138fe565b15612393578360ff16600103612351576001600160801b0382161561234c5761234c86868585612a00565b612463565b60405162461bcd60e51b8152602060048201526017602482015276151bdad95b881a5cc8185b1c9958591e481b5a5b9d1959604a1b6044820152606401610870565b6001600160801b038216156123bc5760cc546123bc90879087906001600160a01b031685612a00565b60405163399f900b60e21b81526001600160a01b0387169063e67e402c906123ec90889087908690600401613968565b600060405180830381600087803b15801561240657600080fd5b505af115801561241a573d6000803e3d6000fd5b5050505084866001600160a01b03167fecdc1a9f2d5709924193921a7138c0414b5192b522ffdebbb664cfb5505ad5dc848660405161245a929190613992565b60405180910390a35b505050506001600160a01b0391909116600090815260c96020908152604080832093835292905220428155600201805460ff60a01b1916600160a01b179055565b6001600160a01b038316600090815260c960209081526040808320858452909152902060020154600160a81b900460ff1615612596576001600160a01b038316600090815260c9602090815260408083208584529091529020544211801561253257506001600160a01b03838116600090815260c96020908152604080832086845290915290206002015416155b6125965760405162461bcd60e51b815260206004820152602f60248201527f41756374696f6e207374696c6c206f6e676f696e67206f72207468657265206960448201526e39903434b3b432b9ba2134b23232b960891b6064820152608401610870565b6001600160a01b038316600090815260c960209081526040808320858452909152902081815560048101859055600201805460ff60a81b1916600160a81b179055611911565b6125e4611f97565b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586120123390565b6000612626828433612ae1565b9392505050565b81816126398282612af7565b60ff1660011461268b5760405162461bcd60e51b815260206004820152601e60248201527f4e6f7420656e6f7567682066756e647320746f20626964206f6e204e465400006044820152606401610870565b6126958484612d30565b61269f8484612e0b565b6001600160a01b038416600090815260c96020908152604080832086845290915281206003018054916126d183613920565b9091555050604080513381526001600160801b0334166020820152429181019190915283906001600160a01b038616907f86eb12135b4767e80be549166e1b023eda3f1d5fe08c02964516bf6acf72ea3c90606001610954565b6001600160a01b038216600090815260c960209081526040808320848452909152812060040154600160cb8281548110612767576127676136a4565b906000526020600020906006020160020160159054906101000a900460ff1660028111156127975761279761334b565b141580156127f7575060cb81815481106127b3576127b36136a4565b6000918252602080832060016006909302018201546001600160a01b038816845260c982526040808520888652909252922001546001600160801b03918216911610155b156128065760019150506107b6565b5060009392505050565b61281c8282600061226f565b6001600160a01b03828116600081815260c96020908152604080832086845290915290819020600281015460019091015491519316926001600160801b039091169184917fa2797d9d0c0b85157b324b5092bbbac2874ad695dc2fe8eae9e882e87f6f5c49906109549085908790613992565b600054610100900460ff166128b65760405162461bcd60e51b8152600401610870906139b4565b610972612e2d565b600054610100900460ff166128e55760405162461bcd60e51b8152600401610870906139b4565b610972612e60565b600054610100900460ff166129145760405162461bcd60e51b8152600401610870906139b4565b610972612e87565b609780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6060600061297b83612eb7565b60010190506000816001600160401b0381111561299a5761299a6136e3565b6040519080825280601f01601f1916602001820160405280156129c4576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846129ce57509392505050565b6000826001600160a01b0316826001600160801b031661138890604051600060405180830381858888f193505050503d8060008114612a5b576040519150601f19603f3d011682016040523d82523d6000602084013e612a60565b606091505b505090508061219257816001600160801b031660cd6000828254612a8491906139ff565b9091555050604080516001600160a01b0385811682526001600160801b03851660208301528692908816917f828d6ed82f77bf7a60b33772a701df6a76530de0b00ec20d1a1eb7ef02073de9910160405180910390a35050505050565b600082612aee8584612f8d565b14949350505050565b6001600160a01b038216600090815260c96020908152604080832084845290915281206004015460cb805483919083908110612b3557612b356136a4565b6000918252602091829020604080516101208101825260069093029091018054835260018101546001600160801b0380821695850195909552600160801b9004909316908201526002808301546001600160a01b038116606084015260ff600160a01b82048116608085015292939260a0850192600160a81b9092041690811115612bc257612bc261334b565b6002811115612bd357612bd361334b565b815260038201546001600160801b0316602082015260048201546040820152600590910154606090910152905060008160a001516002811115612c1857612c1861334b565b03612c475780602001516001600160801b03163410612c3c576001925050506107b6565b6000925050506107b6565b600160cb8381548110612c5c57612c5c6136a4565b906000526020600020906006020160020160159054906101000a900460ff166002811115612c8c57612c8c61334b565b03612d25576001600160a01b03858116600090815260c960209081526040808320888452909152812060018101546002909101546001600160801b039091169216908115612cf15760c0840151612cec906001600160801b0316846139ff565b612d00565b83602001516001600160801b03165b9050803410612d17576001955050505050506107b6565b6000955050505050506107b6565b6001925050506107b6565b6001600160a01b03828116600090815260c9602090815260408083208584529091529020600281015460018201546004909201549216916001600160801b0390911690612d7d8585612fda565b6001600160a01b03831615612192576001600160801b03821615612da757612da785858585612a00565b6001600160a01b038316600090815260ca60209081526040808320848452909152812080546001600160801b031691612ddf83613a12565b91906101000a8154816001600160801b0302191690836001600160801b03160217905550505050505050565b612e15828261272b565b60ff16600103612e23575050565b61099f8282613085565b600054610100900460ff16612e545760405162461bcd60e51b8152600401610870906139b4565b6065805460ff19169055565b600054610100900460ff166121995760405162461bcd60e51b8152600401610870906139b4565b600054610100900460ff16612eae5760405162461bcd60e51b8152600401610870906139b4565b6109723361291c565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8310612ef65772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6904ee2d6d415b85acef8160201b8310612f20576904ee2d6d415b85acef8160201b830492506020015b662386f26fc100008310612f3e57662386f26fc10000830492506010015b6305f5e1008310612f56576305f5e100830492506008015b6127108310612f6a57612710830492506004015b60648310612f7c576064830492506002015b600a83106107b65760010192915050565b600081815b8451811015612fd257612fbe82868381518110612fb157612fb16136a4565b6020026020010151613154565b915080612fca81613920565b915050612f92565b509392505050565b6001600160a01b038216600090815260c96020908152604080832084845282528083206001810180546001600160801b033481166001600160801b0319909216919091179091556002820180546001600160a01b03191633908117909155855260ca845282852060049092015485529252822080549091169161305c83613a35565b91906101000a8154816001600160801b0302191690836001600160801b03160217905550505050565b6001600160a01b038216600090815260c96020908152604080832084845290915290205461012c906130b89042906138eb565b101561099f576001600160a01b038216600090815260c9602090815260408083208484529091528120805461012c92906130f39084906139ff565b90915550506001600160a01b038216600081815260c9602090815260408083208584528252918290205491519182528392917f86dfe42cdd55a98787dad0c1abd84accf1ff905d6d6aa754eb8f9033c3cd9e42910160405180910390a35050565b6000818310613170576000828152602084905260409020612626565b6000838152602083905260409020612626565b80356001600160a01b038116811461319a57600080fd5b919050565b600080604083850312156131b257600080fd5b6131bb83613183565b946020939093013593505050565b6001600160801b03169052565b60005b838110156131f15781810151838201526020016131d9565b50506000910152565b600081518084526132128160208601602086016131d6565b601f01601f19169290920160200192915050565b602081526132386020820183516131c9565b60006020830151613251604084018263ffffffff169052565b5060408301516060830152606083015161326e60808401826131c9565b50608083015161328160a08401826131c9565b5060a083015161329460c08401826131c9565b5060c083015160e083015260e08301516101006132bb818501836001600160a01b03169052565b808501519150506101c061012081818601526132db6101e08601846131fa565b908601519092506101406132f38682018360ff169052565b86015190506101606133088682018315159052565b860151610180868101919091528601516101a0808701919091529095015193019290925250919050565b60006020828403121561334457600080fd5b5035919050565b634e487b7160e01b600052602160045260246000fd5b8981526001600160801b038981166020830152881660408201526001600160a01b038716606082015260ff861660808201526101208101600386106133b657634e487b7160e01b600052602160045260246000fd5b8560a08301526133c960c08301866131c9565b60e08201939093526101000152979650505050505050565b803560ff8116811461319a57600080fd5b6000806000806060858703121561340857600080fd5b61341185613183565b935061341f602086016133e1565b925060408501356001600160401b038082111561343b57600080fd5b818701915087601f83011261344f57600080fd5b81358181111561345e57600080fd5b88602082850101111561347057600080fd5b95989497505060200194505050565b80356001600160801b038116811461319a57600080fd5b60008060008060008060008060006101208a8c0312156134b557600080fd5b8935985060208a0135600381106134cb57600080fd5b97506134d960408b0161347f565b96506134e760608b0161347f565b95506134f560808b01613183565b945061350360a08b016133e1565b935061351160c08b0161347f565b925060e08a013591506101008a013590509295985092959850929598565b6000806040838503121561354257600080fd5b61354b83613183565b9150613559602084016133e1565b90509250929050565b60ff8316815260406020820152600061357e60408301846131fa565b949350505050565b60008083601f84011261359857600080fd5b5081356001600160401b038111156135af57600080fd5b6020830191508360208260051b85010111156135ca57600080fd5b9250929050565b6000806000604084860312156135e657600080fd5b8335925060208401356001600160401b0381111561360357600080fd5b61360f86828701613586565b9497909650939450505050565b6001600160a01b0391909116815260200190565b6000806000806060858703121561364657600080fd5b61364f85613183565b93506020850135925060408501356001600160401b0381111561367157600080fd5b61367d87828801613586565b95989497509550505050565b60006020828403121561369b57600080fd5b61262682613183565b634e487b7160e01b600052603260045260246000fd5b6020808252600f908201526e496e76616c6964206164647265737360881b604082015260600190565b634e487b7160e01b600052604160045260246000fd5b600181811c9082168061370d57607f821691505b60208210810361372d57634e487b7160e01b600052602260045260246000fd5b50919050565b601f82111561377d57600081815260208120601f850160051c8101602086101561375a5750805b601f850160051c820191505b8181101561377957828155600101613766565b5050505b505050565b81516001600160401b0381111561379b5761379b6136e3565b6137af816137a984546136f9565b84613733565b602080601f8311600181146137e457600084156137cc5750858301515b600019600386901b1c1916600185901b178555613779565b600085815260208120601f198616915b82811015613813578886015182559484019460019091019084016137f4565b50858210156138315787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b604081528260408201528284606083013760006060848301015260006060601f19601f8601168301019050826020830152949350505050565b602080825260159082015274139bc81a1a59da195cdd08189a5919195c881e595d605a1b604082015260600190565b602080825260129082015271151bdad95b88185b1c9958591e481cdbdb1960721b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b818103818111156107b6576107b66138d5565b60006020828403121561391057600080fd5b8151801515811461262657600080fd5b600060018201613932576139326138d5565b5060010190565b6000835161394b8184602088016131d6565b83519083019061395f8183602088016131d6565b01949350505050565b8381526001600160a01b0383166020820152606060408201819052600090611f2f908301846131fa565b6001600160801b039290921682526001600160a01b0316602082015260400190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b808201808211156107b6576107b66138d5565b60006001600160801b03821680613a2b57613a2b6138d5565b6000190192915050565b60006001600160801b038281166002600160801b03198101613a5957613a596138d5565b600101939250505056fea264697066735822122042ad708a389ca161653fdbeef5b1dc096fe1bdedbac9bedacb71d3f9794e7d7164736f6c63430008110033

Deployed Bytecode

0x60806040526004361061011b5760003560e01c80630ac08b27146101205780632616bb7114610156578063285afc0d1461018b5780633f4ba83a146101ad578063438364a1146101c257806350a33c7b146101e25780635138b08c1461023b578063566b9c511461025b57806356d73145146102895780635c975abb146102b7578063715018a6146102da57806377f61b3b146102ef5780638456cb591461030f578063848e5c77146103245780638da5cb5b146103445780639148ff4a14610366578063a72d8f211461037c578063ad3014c41461039c578063b3f00674146103af578063c4d66de8146103cf578063c69bebe4146103ef578063c90941b11461040f578063ebea60251461042f578063f2fde38b1461044f575b600080fd5b34801561012c57600080fd5b5061014061013b36600461319f565b61046f565b60405161014d9190613226565b60405180910390f35b34801561016257600080fd5b50610176610171366004613332565b6107bc565b60405161014d99989796959493929190613361565b34801561019757600080fd5b506101ab6101a63660046133f2565b61083a565b005b3480156101b957600080fd5b506101ab610962565b3480156101ce57600080fd5b506101ab6101dd36600461319f565b610974565b3480156101ee57600080fd5b506102236101fd36600461319f565b60ca6020908152600092835260408084209091529082529020546001600160801b031681565b6040516001600160801b03909116815260200161014d565b34801561024757600080fd5b506101ab61025636600461319f565b6109a3565b34801561026757600080fd5b5061027b610276366004613496565b610ad8565b60405190815260200161014d565b34801561029557600080fd5b506102a96102a436600461352f565b6110a0565b60405161014d929190613562565b3480156102c357600080fd5b5060655460ff16604051901515815260200161014d565b3480156102e657600080fd5b506101ab611154565b3480156102fb57600080fd5b506101ab61030a3660046135d1565b6111a1565b34801561031b57600080fd5b506101ab611400565b34801561033057600080fd5b506101ab61033f36600461319f565b611410565b34801561035057600080fd5b506103596114ed565b60405161014d919061361c565b34801561037257600080fd5b5061027b60cd5481565b34801561038857600080fd5b506101ab61039736600461319f565b6114fc565b6101ab6103aa366004613630565b611544565b3480156103bb57600080fd5b5060cc54610359906001600160a01b031681565b3480156103db57600080fd5b506101ab6103ea366004613689565b611917565b3480156103fb57600080fd5b506101ab61040a366004613689565b611aa4565b34801561041b57600080fd5b506101ab61042a366004613689565b611aff565b34801561043b57600080fd5b506101ab61044a36600461319f565b611bce565b34801561045b57600080fd5b506101ab61046a366004613689565b611d62565b604080516101c08101825260008082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e0820183905261010082015261012081018290526101408101829052610160810182905261018081018290526101a08101919091526001600160a01b03808416600090815260c9602090815260408083208684528252808320815160e081018352815480825260018301546001600160801b03169482019490945260028201549586169281019290925260ff600160a01b860481166060840152600160a81b90950490941615156080820152600384015460a082015260049093015460c084015290036105f657604080516101c08101825260008082526020808301829052828401829052606083018290526080830182905260a0830182905260c0830182905260e08301829052835190810190935280835261010082019290925261012081018290526101408101829052610160810182905261018081018290526101a081019190915291506107b4565b600060cb8260c001518154811061060f5761060f6136a4565b6000918252602091829020604080516101208101825260069093029091018054835260018101546001600160801b0380821695850195909552600160801b9004909316908201526002808301546001600160a01b038116606084015260ff600160a01b82048116608085015292939260a0850192600160a81b909204169081111561069c5761069c61334b565b60028111156106ad576106ad61334b565b815260038201546001600160801b0316602082015260048201546040820152600590910154606090910152905060006106e68686611dd8565b9050604051806101c001604052808360c001516001600160801b03168152602001600063ffffffff1681526020018460000151815260200183602001516001600160801b0316815260200183602001516001600160801b0316815260200184602001516001600160801b031681526020018360000151815260200184604001516001600160a01b03168152602001828152602001846060015160ff1681526020018460800151151581526020018460a0015181526020018360e0015181526020018460c00151815250935050505b505b92915050565b60cb81815481106107cc57600080fd5b60009182526020909120600690910201805460018201546002830154600384015460048501546005909501549395506001600160801b0380841695600160801b9094048116946001600160a01b0384169460ff600160a01b8604811695600160a81b90041693909216919089565b610842611f38565b61084a611f97565b6001600160a01b0384166108795760405162461bcd60e51b8152600401610870906136ba565b60405180910390fd5b6040518060400160405280600160ff16815260200183838080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509390945250506001600160a01b038716815260ce6020908152604080832060ff898116855290835292208451815460ff19169316929092178255830151909150600182019061090f9082613782565b509050508260ff16846001600160a01b03167f9a7956ba73d918511b7fa9a38abad497e8a10ad0ab89e6aad8870f6628d012c184844260405161095493929190613841565b60405180910390a350505050565b61096a611f38565b610972611fdd565b565b61097c611f38565b610984612029565b61098c612082565b61099682826120cb565b61099f60018055565b5050565b6109ab611f97565b6109b3612029565b6109bd828261219f565b60ff1615610a075760405162461bcd60e51b815260206004820152601760248201527620bab1ba34b7b71034b9903737ba103cb2ba1037bb32b960491b6044820152606401610870565b610a11828261222e565b60ff16600114610a335760405162461bcd60e51b81526004016108709061387a565b6001600160a01b038216600090815260c960209081526040808320848452909152902060020154600160a01b900460ff1615610a815760405162461bcd60e51b8152600401610870906138a9565b610a8d8282600161226f565b80826001600160a01b03167fe6b94748c5d6e0d188a0fcb9b7f2973b01fc0095627f1ec5accdcd9d2e65ca3633604051610ac7919061361c565b60405180910390a361099f60018055565b6000610ae2611f38565b610aea611f97565b610af2612029565b6001600160a01b038616600090815260ce6020908152604080832060ff808a1685529252909120548791879116600114610b6e5760405162461bcd60e51b815260206004820152601f60248201527f426173652055524c20666f722063686170746572206973206e6f7420736574006044820152606401610870565b834210610bd05760405162461bcd60e51b815260206004820152602a60248201527f41756374696f6e20656e64206973206c657373207468616e2063757272656e7460448201526902074696d657374616d760b41b6064820152608401610870565b838510610c2e5760405162461bcd60e51b815260206004820152602660248201527f41756374696f6e20656e64206973206c657373207468616e2061756374696f6e604482015265081cdd185c9d60d21b6064820152608401610870565b6000896001600160801b031611610c865760405162461bcd60e51b815260206004820152601c60248201527b0427579206c696d6974206d757374206c6172676572207468616e20360241b6044820152606401610870565b60028b6002811115610c9a57610c9a61334b565b148015610cb0575060008a6001600160801b0316115b15610d0e5760405162461bcd60e51b815260206004820152602860248201527f50726963652073686f756c64206265207a65726f206f6e205a65726f2070726960448201526731b29039b0b6329760c11b6064820152608401610870565b60008b6002811115610d2257610d2261334b565b148015610d3657506001600160801b038a16155b15610d9d5760405162461bcd60e51b815260206004820152603160248201527f50726963652073686f756c64206265206c6172676572207468616e207a65726f6044820152701037b710213abc903737bb9039b0b6329760791b6064820152608401610870565b60018b6002811115610db157610db161334b565b148015610dc557506001600160801b038616155b15610e435760405162461bcd60e51b815260206004820152604260248201527f42696420696e63726561736520616d6f756e742073686f756c64206265206c6160448201527f72676572207468616e207a65726f206f6e20456e676c6973682061756374696f606482015261371760f11b608482015260a401610870565b60018b6002811115610e5757610e5761334b565b14158015610e6d57506001600160801b03861615155b15610ed55760405162461bcd60e51b815260206004820152603260248201527f42696420696e637265616520616d6f756e742073686f756c64206265207a6572604482015271379037b710313abc903737bb9039b0b6329760711b6064820152608401610870565b60cb6040518061012001604052808e81526020018c6001600160801b031681526020018b6001600160801b031681526020018a6001600160a01b031681526020018960ff1681526020018d6002811115610f3157610f3161334b565b81526001600160801b03808a1660208084019190915260408084018b905260609384018a9052855460018181018855600097885296839020865160069092020190815591850151908501518316600160801b029216919091179381019390935581015160028084018054608085015160ff16600160a01b026001600160a81b03199091166001600160a01b03909416939093179290921780835560a0840151939493929160ff60a81b1990911690600160a81b908490811115610ff657610ff661334b565b021790555060c08201516003820180546001600160801b0319166001600160801b0390921691909117905560e082015160048201556101009091015160059091015560cb5460009061104a906001906138eb565b9050807fedd3881684d03e8c0fecdc07db380143d03bbcf9aa9f386bbc98701efed23c814260405161107e91815260200190565b60405180910390a29250505061109360018055565b9998505050505050505050565b60ce6020908152600092835260408084209091529082529020805460018201805460ff90921692916110d1906136f9565b80601f01602080910402602001604051908101604052809291908181526020018280546110fd906136f9565b801561114a5780601f1061111f5761010080835404028352916020019161114a565b820191906000526020600020905b81548152906001019060200180831161112d57829003601f168201915b5050505050905082565b61115c611f38565b60405162461bcd60e51b815260206004820152601a602482015279043616e206e6f742072656e6f756e6365206f6e776572736869760341b6044820152606401610870565b6111a9611f38565b6111b1611f97565b60cb54839081106111fe5760405162461bcd60e51b8152602060048201526017602482015276536d616c6c53616c65494420697320696e76616c69642160481b6044820152606401610870565b600060cb8581548110611213576112136136a4565b6000918252602091829020604080516101208101825260069093029091018054835260018101546001600160801b0380821695850195909552600160801b9004909316908201526002808301546001600160a01b038116606084015260ff600160a01b82048116608085015292939260a0850192600160a81b90920416908111156112a0576112a061334b565b60028111156112b1576112b161334b565b815260038201546001600160801b031660208201526004820154604082015260059091015460609182015281015161010082015191925090818560005b818161ffff1610156113f457826001600160a01b0316634f558e798a8a8461ffff1681811061131f5761131f6136a4565b905060200201356040518263ffffffff1660e01b815260040161134491815260200190565b602060405180830381865afa158015611361573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061138591906138fe565b156113c45760405162461bcd60e51b815260206004820152600f60248201526e151bdad95b881a5cc81b5a5b9d1959608a1b6044820152606401610870565b6113ec8a868b8b8561ffff168181106113df576113df6136a4565b90506020020135876124a4565b6001016112ee565b50505050505050505050565b611408611f38565b6109726125dc565b611418611f38565b611420611f97565b611428612029565b611432828261222e565b60ff166001146114545760405162461bcd60e51b81526004016108709061387a565b6001600160a01b038216600090815260c960209081526040808320848452909152902060020154600160a01b900460ff16156114a25760405162461bcd60e51b8152600401610870906138a9565b6114ae8282600161226f565b60405181906001600160a01b038416907f711f4eae05533b90c24ff0ae762d6e9e1ef1b2c85d4c484a2913c5201bcbb7c990600090a361099f60018055565b6097546001600160a01b031690565b611504611f38565b61150c612029565b611514612082565b60015b81811161153a5761152883826120cb565b8061153281613920565b915050611517565b5061099f60018055565b61154c611f97565b611554612029565b6001600160a01b038416600090815260c96020908152604080832086845290915290206002015484908490600160a01b900460ff16156115cf5760405162461bcd60e51b8152602060048201526016602482015275546f6b656e20697320616c726561647920736f6c642160501b6044820152606401610870565b60cb546001600160a01b038316600090815260c960209081526040808320858452909152902060040154106116575760405162461bcd60e51b815260206004820152602860248201527f536d616c6c2073616c6520646f6573206e6f74206578697374206f6e2074686960448201526739903a37b5b2b71760c11b6064820152608401610870565b611661828261219f565b60ff166001146116bf5760405162461bcd60e51b8152602060048201526024808201527f41756374696f6e2068617320656e646564206f72206e6f742073746172746564604482015263081e595d60e21b6064820152608401610870565b6001600160a01b038616600090815260c96020908152604080832088845290915290206004015460cb5487918791811061174d5760405162461bcd60e51b815260206004820152602960248201527f4e6f74206578697374696e6720736d616c6c2073616c6520666f72206375727260448201526832b73a103a37b5b2b760b91b6064820152608401610870565b60cb8181548110611760576117606136a4565b600091825260208083206001600690930201919091015433835260ca825260408084208585529092529120546001600160801b03600160801b90920482169116106118035760405162461bcd60e51b815260206004820152602d60248201527f55736572206578636565647320627579206c696d697420666f7220637572726560448201526c6e7420736d616c6c2073616c6560981b6064820152608401610870565b6001600160a01b038916600090815260c9602090815260408083208b845290915281206004015460cb8054909190811061183f5761183f6136a4565b6000918252602090912060069091020154905080158061189757506118978189898080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061261992505050565b6118da5760405162461bcd60e51b815260206004820152601460248201527334b73b30b634b21036b2b935b63290383937b7b360611b6044820152606401610870565b6118e48a8a61262d565b6118ee8a8a61272b565b60ff16600103611902576119028a8a612810565b50505050505061191160018055565b50505050565b600054610100900460ff16158080156119375750600054600160ff909116105b806119515750303b158015611951575060005460ff166001145b6119b45760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610870565b6000805460ff1916600117905580156119d7576000805461ff0019166101001790555b6001600160a01b038216611a285760405162461bcd60e51b815260206004820152601860248201527743616e6e6f7420737065636966792030206164647265737360401b6044820152606401610870565b60cc80546001600160a01b0319166001600160a01b038416179055611a4b61288f565b611a536128be565b611a5b6128ed565b801561099f576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15050565b611aac611f38565b611ab4612029565b6001600160a01b038116611ada5760405162461bcd60e51b8152600401610870906136ba565b60cc80546001600160a01b0319166001600160a01b0383161790556001805550565b50565b611b07611f38565b611b0f612029565b60cd546000819003611b5c5760405162461bcd60e51b81526020600482015260166024820152756e6f206372656469747320746f20776974686472617760501b6044820152606401610870565b6000826001600160a01b03168261138890604051600060405180830381858888f193505050503d8060008114611bae576040519150601f19603f3d011682016040523d82523d6000602084013e611bb3565b606091505b505090508015611bc357600060cd555b5050611afc60018055565b611bd6611f38565b611bde612029565b6001600160a01b038216600090815260c960209081526040808320848452909152902060020154600160a01b900460ff1615611c555760405162461bcd60e51b81526020600482015260166024820152751d1bdad95b881a185cc8185b1c9958591e481cdbdb1960521b6044820152606401610870565b6001600160a01b038216600090815260c9602090815260408083208484529091529020600101546001600160801b031615611cde5760405162461bcd60e51b815260206004820152602360248201527f43616e206e6f74207769746864726177207768656e206120626964206973206d60448201526261646560e81b6064820152608401610870565b6001600160a01b038216600081815260c9602090815260408083208584529091528082208281556001810180546001600160801b0319169055600281018054600161ff0160a01b031916905560030191909155518291907fec19f84af4aad6523d37faa19e243c77717842cca9bf492dc5379830cac958d090610ac790339061361c565b611d6a611f38565b6001600160a01b038116611dcf5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610870565b611afc8161291c565b6001600160a01b038216600081815260c96020908152604080832085845282528083206004015493835260ce909152812060cb8054606094939291839185908110611e2557611e256136a4565b906000526020600020906006020160020160149054906101000a900460ff1660ff1660ff1681526020019081526020016000206001018054611e66906136f9565b80601f0160208091040260200160405190810160405280929190818152602001828054611e92906136f9565b8015611edf5780601f10611eb457610100808354040283529160200191611edf565b820191906000526020600020905b815481529060010190602001808311611ec257829003601f168201915b505050505090506000815111611f045760405180602001604052806000815250611f2f565b80611f0e8561296e565b604051602001611f1f929190613939565b6040516020818303038152906040525b95945050505050565b33611f416114ed565b6001600160a01b0316146109725760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610870565b60655460ff16156109725760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610870565b611fe5612082565b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b60405161201f919061361c565b60405180910390a1565b60026001540361207b5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610870565b6002600155565b60655460ff166109725760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610870565b6001600160a01b03828116600090815260c96020908152604080832085845290915290206002810154600190910154918116916001600160801b031690600160a01b900460ff168215801590612122575060ff8116155b15612192576001600160801b038216156121425761214285858585612a00565b6001600160a01b038516600090815260c96020908152604080832087845290915281208181556001810180546001600160801b0319169055600281018054600161ff0160a01b0319169055600301555b5050505050565b60018055565b6001600160a01b038216600090815260c9602090815260408083208484529091528120805460049091015460cb8054849190839081106121e1576121e16136a4565b90600052602060002090600602016004015490508260001415801561220557508242105b80156122115750804210155b1561222257600193505050506107b6565b50600095945050505050565b6001600160a01b03828116600090815260c96020908152604080832085845290915281206002015490911615612266575060016107b6565b50600092915050565b6001600160a01b03838116600090815260c960209081526040808320868452909152812060028101546001909101549216916001600160801b0316906122b58686611dd8565b604051634f558e7960e01b8152600481018790529091506001600160a01b03871690634f558e7990602401602060405180830381865afa1580156122fd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061232191906138fe565b15612393578360ff16600103612351576001600160801b0382161561234c5761234c86868585612a00565b612463565b60405162461bcd60e51b8152602060048201526017602482015276151bdad95b881a5cc8185b1c9958591e481b5a5b9d1959604a1b6044820152606401610870565b6001600160801b038216156123bc5760cc546123bc90879087906001600160a01b031685612a00565b60405163399f900b60e21b81526001600160a01b0387169063e67e402c906123ec90889087908690600401613968565b600060405180830381600087803b15801561240657600080fd5b505af115801561241a573d6000803e3d6000fd5b5050505084866001600160a01b03167fecdc1a9f2d5709924193921a7138c0414b5192b522ffdebbb664cfb5505ad5dc848660405161245a929190613992565b60405180910390a35b505050506001600160a01b0391909116600090815260c96020908152604080832093835292905220428155600201805460ff60a01b1916600160a01b179055565b6001600160a01b038316600090815260c960209081526040808320858452909152902060020154600160a81b900460ff1615612596576001600160a01b038316600090815260c9602090815260408083208584529091529020544211801561253257506001600160a01b03838116600090815260c96020908152604080832086845290915290206002015416155b6125965760405162461bcd60e51b815260206004820152602f60248201527f41756374696f6e207374696c6c206f6e676f696e67206f72207468657265206960448201526e39903434b3b432b9ba2134b23232b960891b6064820152608401610870565b6001600160a01b038316600090815260c960209081526040808320858452909152902081815560048101859055600201805460ff60a81b1916600160a81b179055611911565b6125e4611f97565b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586120123390565b6000612626828433612ae1565b9392505050565b81816126398282612af7565b60ff1660011461268b5760405162461bcd60e51b815260206004820152601e60248201527f4e6f7420656e6f7567682066756e647320746f20626964206f6e204e465400006044820152606401610870565b6126958484612d30565b61269f8484612e0b565b6001600160a01b038416600090815260c96020908152604080832086845290915281206003018054916126d183613920565b9091555050604080513381526001600160801b0334166020820152429181019190915283906001600160a01b038616907f86eb12135b4767e80be549166e1b023eda3f1d5fe08c02964516bf6acf72ea3c90606001610954565b6001600160a01b038216600090815260c960209081526040808320848452909152812060040154600160cb8281548110612767576127676136a4565b906000526020600020906006020160020160159054906101000a900460ff1660028111156127975761279761334b565b141580156127f7575060cb81815481106127b3576127b36136a4565b6000918252602080832060016006909302018201546001600160a01b038816845260c982526040808520888652909252922001546001600160801b03918216911610155b156128065760019150506107b6565b5060009392505050565b61281c8282600061226f565b6001600160a01b03828116600081815260c96020908152604080832086845290915290819020600281015460019091015491519316926001600160801b039091169184917fa2797d9d0c0b85157b324b5092bbbac2874ad695dc2fe8eae9e882e87f6f5c49906109549085908790613992565b600054610100900460ff166128b65760405162461bcd60e51b8152600401610870906139b4565b610972612e2d565b600054610100900460ff166128e55760405162461bcd60e51b8152600401610870906139b4565b610972612e60565b600054610100900460ff166129145760405162461bcd60e51b8152600401610870906139b4565b610972612e87565b609780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6060600061297b83612eb7565b60010190506000816001600160401b0381111561299a5761299a6136e3565b6040519080825280601f01601f1916602001820160405280156129c4576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846129ce57509392505050565b6000826001600160a01b0316826001600160801b031661138890604051600060405180830381858888f193505050503d8060008114612a5b576040519150601f19603f3d011682016040523d82523d6000602084013e612a60565b606091505b505090508061219257816001600160801b031660cd6000828254612a8491906139ff565b9091555050604080516001600160a01b0385811682526001600160801b03851660208301528692908816917f828d6ed82f77bf7a60b33772a701df6a76530de0b00ec20d1a1eb7ef02073de9910160405180910390a35050505050565b600082612aee8584612f8d565b14949350505050565b6001600160a01b038216600090815260c96020908152604080832084845290915281206004015460cb805483919083908110612b3557612b356136a4565b6000918252602091829020604080516101208101825260069093029091018054835260018101546001600160801b0380821695850195909552600160801b9004909316908201526002808301546001600160a01b038116606084015260ff600160a01b82048116608085015292939260a0850192600160a81b9092041690811115612bc257612bc261334b565b6002811115612bd357612bd361334b565b815260038201546001600160801b0316602082015260048201546040820152600590910154606090910152905060008160a001516002811115612c1857612c1861334b565b03612c475780602001516001600160801b03163410612c3c576001925050506107b6565b6000925050506107b6565b600160cb8381548110612c5c57612c5c6136a4565b906000526020600020906006020160020160159054906101000a900460ff166002811115612c8c57612c8c61334b565b03612d25576001600160a01b03858116600090815260c960209081526040808320888452909152812060018101546002909101546001600160801b039091169216908115612cf15760c0840151612cec906001600160801b0316846139ff565b612d00565b83602001516001600160801b03165b9050803410612d17576001955050505050506107b6565b6000955050505050506107b6565b6001925050506107b6565b6001600160a01b03828116600090815260c9602090815260408083208584529091529020600281015460018201546004909201549216916001600160801b0390911690612d7d8585612fda565b6001600160a01b03831615612192576001600160801b03821615612da757612da785858585612a00565b6001600160a01b038316600090815260ca60209081526040808320848452909152812080546001600160801b031691612ddf83613a12565b91906101000a8154816001600160801b0302191690836001600160801b03160217905550505050505050565b612e15828261272b565b60ff16600103612e23575050565b61099f8282613085565b600054610100900460ff16612e545760405162461bcd60e51b8152600401610870906139b4565b6065805460ff19169055565b600054610100900460ff166121995760405162461bcd60e51b8152600401610870906139b4565b600054610100900460ff16612eae5760405162461bcd60e51b8152600401610870906139b4565b6109723361291c565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8310612ef65772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6904ee2d6d415b85acef8160201b8310612f20576904ee2d6d415b85acef8160201b830492506020015b662386f26fc100008310612f3e57662386f26fc10000830492506010015b6305f5e1008310612f56576305f5e100830492506008015b6127108310612f6a57612710830492506004015b60648310612f7c576064830492506002015b600a83106107b65760010192915050565b600081815b8451811015612fd257612fbe82868381518110612fb157612fb16136a4565b6020026020010151613154565b915080612fca81613920565b915050612f92565b509392505050565b6001600160a01b038216600090815260c96020908152604080832084845282528083206001810180546001600160801b033481166001600160801b0319909216919091179091556002820180546001600160a01b03191633908117909155855260ca845282852060049092015485529252822080549091169161305c83613a35565b91906101000a8154816001600160801b0302191690836001600160801b03160217905550505050565b6001600160a01b038216600090815260c96020908152604080832084845290915290205461012c906130b89042906138eb565b101561099f576001600160a01b038216600090815260c9602090815260408083208484529091528120805461012c92906130f39084906139ff565b90915550506001600160a01b038216600081815260c9602090815260408083208584528252918290205491519182528392917f86dfe42cdd55a98787dad0c1abd84accf1ff905d6d6aa754eb8f9033c3cd9e42910160405180910390a35050565b6000818310613170576000828152602084905260409020612626565b6000838152602083905260409020612626565b80356001600160a01b038116811461319a57600080fd5b919050565b600080604083850312156131b257600080fd5b6131bb83613183565b946020939093013593505050565b6001600160801b03169052565b60005b838110156131f15781810151838201526020016131d9565b50506000910152565b600081518084526132128160208601602086016131d6565b601f01601f19169290920160200192915050565b602081526132386020820183516131c9565b60006020830151613251604084018263ffffffff169052565b5060408301516060830152606083015161326e60808401826131c9565b50608083015161328160a08401826131c9565b5060a083015161329460c08401826131c9565b5060c083015160e083015260e08301516101006132bb818501836001600160a01b03169052565b808501519150506101c061012081818601526132db6101e08601846131fa565b908601519092506101406132f38682018360ff169052565b86015190506101606133088682018315159052565b860151610180868101919091528601516101a0808701919091529095015193019290925250919050565b60006020828403121561334457600080fd5b5035919050565b634e487b7160e01b600052602160045260246000fd5b8981526001600160801b038981166020830152881660408201526001600160a01b038716606082015260ff861660808201526101208101600386106133b657634e487b7160e01b600052602160045260246000fd5b8560a08301526133c960c08301866131c9565b60e08201939093526101000152979650505050505050565b803560ff8116811461319a57600080fd5b6000806000806060858703121561340857600080fd5b61341185613183565b935061341f602086016133e1565b925060408501356001600160401b038082111561343b57600080fd5b818701915087601f83011261344f57600080fd5b81358181111561345e57600080fd5b88602082850101111561347057600080fd5b95989497505060200194505050565b80356001600160801b038116811461319a57600080fd5b60008060008060008060008060006101208a8c0312156134b557600080fd5b8935985060208a0135600381106134cb57600080fd5b97506134d960408b0161347f565b96506134e760608b0161347f565b95506134f560808b01613183565b945061350360a08b016133e1565b935061351160c08b0161347f565b925060e08a013591506101008a013590509295985092959850929598565b6000806040838503121561354257600080fd5b61354b83613183565b9150613559602084016133e1565b90509250929050565b60ff8316815260406020820152600061357e60408301846131fa565b949350505050565b60008083601f84011261359857600080fd5b5081356001600160401b038111156135af57600080fd5b6020830191508360208260051b85010111156135ca57600080fd5b9250929050565b6000806000604084860312156135e657600080fd5b8335925060208401356001600160401b0381111561360357600080fd5b61360f86828701613586565b9497909650939450505050565b6001600160a01b0391909116815260200190565b6000806000806060858703121561364657600080fd5b61364f85613183565b93506020850135925060408501356001600160401b0381111561367157600080fd5b61367d87828801613586565b95989497509550505050565b60006020828403121561369b57600080fd5b61262682613183565b634e487b7160e01b600052603260045260246000fd5b6020808252600f908201526e496e76616c6964206164647265737360881b604082015260600190565b634e487b7160e01b600052604160045260246000fd5b600181811c9082168061370d57607f821691505b60208210810361372d57634e487b7160e01b600052602260045260246000fd5b50919050565b601f82111561377d57600081815260208120601f850160051c8101602086101561375a5750805b601f850160051c820191505b8181101561377957828155600101613766565b5050505b505050565b81516001600160401b0381111561379b5761379b6136e3565b6137af816137a984546136f9565b84613733565b602080601f8311600181146137e457600084156137cc5750858301515b600019600386901b1c1916600185901b178555613779565b600085815260208120601f198616915b82811015613813578886015182559484019460019091019084016137f4565b50858210156138315787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b604081528260408201528284606083013760006060848301015260006060601f19601f8601168301019050826020830152949350505050565b602080825260159082015274139bc81a1a59da195cdd08189a5919195c881e595d605a1b604082015260600190565b602080825260129082015271151bdad95b88185b1c9958591e481cdbdb1960721b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b818103818111156107b6576107b66138d5565b60006020828403121561391057600080fd5b8151801515811461262657600080fd5b600060018201613932576139326138d5565b5060010190565b6000835161394b8184602088016131d6565b83519083019061395f8183602088016131d6565b01949350505050565b8381526001600160a01b0383166020820152606060408201819052600090611f2f908301846131fa565b6001600160801b039290921682526001600160a01b0316602082015260400190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b808201808211156107b6576107b66138d5565b60006001600160801b03821680613a2b57613a2b6138d5565b6000190192915050565b60006001600160801b038281166002600160801b03198101613a5957613a596138d5565b600101939250505056fea264697066735822122042ad708a389ca161653fdbeef5b1dc096fe1bdedbac9bedacb71d3f9794e7d7164736f6c63430008110033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ 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.