ETH Price: $2,949.24 (-1.27%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading
Cross-Chain Transactions

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Validator Index Block Amount
View All Withdrawals

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

Contract Source Code Verified (Exact Match)

Contract Name:
CarbonOffsetBatches

Compiler Version
v0.8.14+commit.80d49f37

Optimization Enabled:
Yes with 100 runs

Other Settings:
default evmVersion
File 1 of 45 : CarbonOffsetBatches.sol
// SPDX-FileCopyrightText: 2021 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity 0.8.14;

import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol';
import '@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol';
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';

import './interfaces/ICarbonOffsetBatches.sol';
import './interfaces/ICarbonProjectVintages.sol';
import './interfaces/ICarbonCoreCarbonOffsets.sol';
import './interfaces/ICarbonCoreCarbonOffsetsFactory.sol';
import './interfaces/ICarbonCoreContractRegistry.sol';
import './carboncore/indexers/main/ICarbonIndexer.sol';

import './CarbonOffsetBatchesStorage.sol';
import {Errors} from './libraries/Errors.sol';
import './libraries/ProjectVintageUtils.sol';
import './libraries/Modifiers.sol';
import './libraries/Strings.sol';

/// @title A contract for managing batches of carbon credits
/// @notice Also referred to as Batch-Contract (formerly BatchCollection)
/// Contract that tokenizes retired/cancelled CO2 credits into NFTs via a claims process
contract CarbonOffsetBatches is
    ICarbonOffsetBatches,
    ERC721EnumerableUpgradeable,
    OwnableUpgradeable,
    PausableUpgradeable,
    AccessControlUpgradeable,
    UUPSUpgradeable,
    ProjectVintageUtils,
    Modifiers,
    CarbonOffsetBatchesStorage
{
    using SafeERC20Upgradeable for IERC20Upgradeable;
    using Strings for string;

    // ----------------------------------------
    //      Constants
    // ----------------------------------------

    /// @dev Version-related parameters. VERSION keeps track of production
    /// releases. VERSION_RELEASE_CANDIDATE keeps track of iterations
    /// of a VERSION in our staging environment.
    string public constant VERSION = '1.5.0';
    uint256 public constant VERSION_RELEASE_CANDIDATE = 1;

    /// @dev All roles related to accessing this contract
    bytes32 public constant VERIFIER_ROLE = keccak256('VERIFIER_ROLE');
    bytes32 public constant TOKENIZER_ROLE = keccak256('TOKENIZER_ROLE');

    // ----------------------------------------
    //      Events
    // ----------------------------------------

    event BatchMinted(address sender, uint256 tokenId);
    event BatchUpdated(uint256 tokenId, string serialNumber, uint256 quantity);
    event BatchLinkedWithVintage(
        uint256 tokenId,
        uint256 projectVintageTokenId
    );
    event BatchComment(
        uint256 tokenId,
        uint256 commentId,
        address sender,
        string comment
    );
    event BatchStatusUpdate(uint256 tokenId, BatchStatus status);
    event RegistrySupported(string registry, bool isSupported);
    event Tokenized(
        uint256 tokenId,
        address tcc,
        address indexed recipient,
        uint256 amount
    );

    event Split(uint256 tokenId, uint256 newTokenId);

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

    // ----------------------------------------
    //      Upgradable related functions
    // ----------------------------------------

    function initialize(address _contractRegistry)
        external
        virtual
        initializer
    {
        __Context_init_unchained();
        __ERC721_init_unchained(
            'CarbonCore Protocol: Carbon Offset Batches',
            'CARBONCORE-COB'
        );
        __Ownable_init_unchained();
        __Pausable_init_unchained();
        __AccessControl_init_unchained();
        __UUPSUpgradeable_init_unchained();

        contractRegistry = _contractRegistry;
        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
    }

    function _authorizeUpgrade(address newImplementation)
        internal
        virtual
        override
        onlyOwner
    {}

    // ------------------------
    // Poor person's modifiers
    // ------------------------

    function onlyWithRole(bytes32 role) internal view {
        if (!hasRole(role, msg.sender)) revert(Errors.COB_INVALID_CALLER);
    }

    function onlyEscrow() internal view {
        address escrow = ICarbonCoreContractRegistry(contractRegistry)
            .carboncoreCarbonOffsetsEscrowAddress();
        if (escrow != msg.sender) revert(Errors.COB_INVALID_CALLER);
    }

    function onlyPending(uint256 tokenId) internal view {
        if (nftList[tokenId].status != BatchStatus.Pending)
            revert(Errors.COB_INVALID_STATUS);
    }

    function onlyApprovedOrOwner(uint256 tokenId) internal view {
        if (!_isApprovedOrOwner(_msgSender(), tokenId))
            revert(Errors.COB_TRANSFER_NOT_APPROVED);
    }

    function onlyVerifierOrBatchOwner(uint256 tokenId) internal view {
        if (
            ownerOf(tokenId) != _msgSender() &&
            !hasRole(VERIFIER_ROLE, msg.sender)
        ) revert(Errors.COB_NOT_VERIFIER_OR_BATCH_OWNER);
    }

    function onlyValidNewStatus(BatchStatus statusA, BatchStatus statusB)
        internal
        pure
    {
        if (statusA != statusB) revert(Errors.COB_INVALID_NEW_STATUS);
    }

    function onlyUnpaused() internal view {
        if (paused()) revert(Errors.COB_PAUSED_CONTRACT);
    }

    // ------------------------
    //      Admin functions
    // ------------------------

    /// @notice Emergency function to disable contract's core functionality
    /// @dev wraps _pause(), callable only by the CarbonCore contract registry or the contract owner
    function pause() external onlyBy(contractRegistry, owner()) {
        _pause();
    }

    /// @notice Emergency function to re-enable contract's core functionality after being paused
    /// @dev wraps _unpause(), callable only by the CarbonCore contract registry or the contract owner
    function unpause() external onlyBy(contractRegistry, owner()) {
        _unpause();
    }

    /// @notice Admin function to set the contract registry
    /// @dev Callable only by the contract owner
    /// @param _address The address of the new contract registry
    function setCarbonCoreContractRegistry(address _address) external onlyOwner {
        contractRegistry = _address;
    }

    /// @notice Admin function to set whether a registry is supported
    /// @dev Callable only by the contract owner; executable only if the status can be changed
    /// @param registry The registry to set supported status for
    /// @param isSupported Whether the registry should be supported
    function setSupportedRegistry(string memory registry, bool isSupported)
        external
        onlyOwner
    {
        if (supportedRegistries[registry] == isSupported)
            revert(Errors.COB_ALREADY_SUPPORTED);

        supportedRegistries[registry] = isSupported;
        emit RegistrySupported(registry, isSupported);
    }

    /// @dev internal helper function to set the status and emit an event
    function _updateStatus(uint256 tokenId, BatchStatus newStatus)
        internal
        virtual
    {
        BatchStatus currentStatus = nftList[tokenId].status;
        nftList[tokenId].status = newStatus;


        emit BatchStatusUpdate(tokenId, newStatus);
    }
    
    /// @notice Set the status of a batch to a new status
    /// for detokenization or retirement requests.
    ///
    /// Valid transitions:
    /// - In case a user makes a request:
    ///   - Confirmed -> DetokenizationRequested
    ///   - Confirmed -> RetirementRequested
    /// - In case a DETOKENIZER_ROLE in TCC finalizes a request:
    ///   - DetokenizationRequested -> DetokenizationFinalized
    ///   - RetirementRequested -> RetirementFinalized
    /// - In case a DETOKENIZER_ROLE in TCC reverts a request:
    ///   - DetokenizationRequested -> Confirmed
    ///   - RetirementRequested -> Confirmed
    ///
    /// @dev Callable only by the escrow contract, only for batches owned by a TCC contract
    /// @param tokenId The token ID of the batch
    /// @param newStatus The new status to set
    function setStatusForDetokenizationOrRetirement(
        uint256 tokenId,
        BatchStatus newStatus
    ) external virtual override {
        onlyUnpaused();
        onlyEscrow();
        address tokenOwner = ownerOf(tokenId);
        if (!ICarbonCoreContractRegistry(contractRegistry).isValidERC20(tokenOwner))
            revert(Errors.COB_INVALID_BATCH_OWNER);
        BatchStatus currentStatus = nftList[tokenId].status;
        // Only valid transition to a requested status is from a confirmed batch
        if (
            newStatus == BatchStatus.DetokenizationRequested ||
            newStatus == BatchStatus.RetirementRequested
        ) {
            onlyValidNewStatus(currentStatus, BatchStatus.Confirmed);
            // Only valid transition to a finalized status is from a requested status
        } else if (newStatus == BatchStatus.DetokenizationFinalized) {
            onlyValidNewStatus(
                currentStatus,
                BatchStatus.DetokenizationRequested
            );
        } else if (newStatus == BatchStatus.RetirementFinalized) {
            onlyValidNewStatus(currentStatus, BatchStatus.RetirementRequested);
            // Only valid transition to a confirmed status is from a requested status
        } else if (newStatus == BatchStatus.Confirmed) {
            if (
                currentStatus != BatchStatus.DetokenizationRequested &&
                currentStatus != BatchStatus.RetirementRequested
            ) revert(Errors.COB_INVALID_NEW_STATUS);
        } else {
            revert(Errors.COB_INVALID_NEW_STATUS);
        }
        _updateStatus(tokenId, newStatus);
    }

    /// @notice Function to approve a Batch-NFT after validation.
    /// Fractionalization requires status Confirmed.
    /// @dev Callable only by verifiers, only for pending batches. This flow requires a previous linking with a vintage
    /// @param tokenId The token ID of the batch
    function confirmBatch(uint256 tokenId) external virtual {
        onlyUnpaused();
        onlyWithRole(VERIFIER_ROLE);
        _confirmBatch(tokenId);
    }

    /// @dev Internal function that requires a previous linking with a `projectVintageTokenId`.
    function _confirmBatch(uint256 _tokenId) internal {
        if (!_exists(_tokenId)) revert(Errors.COB_NOT_EXISTS);
        onlyPending(_tokenId);
        if (nftList[_tokenId].projectVintageTokenId == 0)
            revert(Errors.COB_MISSING_VINTAGE);
        if (serialNumberApproved[nftList[_tokenId].serialNumber])
            revert(Errors.COB_ALREADY_APPROVED);
        // setting serialnumber as unique after confirmation
        serialNumberApproved[nftList[_tokenId].serialNumber] = true;
        _updateStatus(_tokenId, BatchStatus.Confirmed);
        
    }

   

    
    /// @notice Reject Batch-NFTs, e.g. if the serial number entered is incorrect.
    /// @dev Callable only by verifiers, only for pending batches.
    /// @param tokenId The token ID of the batch
    function rejectBatch(uint256 tokenId) public virtual {
        onlyUnpaused();
        onlyWithRole(VERIFIER_ROLE);
        onlyPending(tokenId);

        // unsetting serialnumber with rejection
        serialNumberApproved[nftList[tokenId].serialNumber] = false;
        _updateStatus(tokenId, BatchStatus.Rejected);
    }

    /// @notice Function to reject Batch-NFTs, including a reason to be displayed to the user.
    function rejectWithComment(uint256 tokenId, string memory comment)
        external
        virtual
    {
        onlyUnpaused();
        rejectBatch(tokenId);
        _addComment(tokenId, comment);
    }

    /// @dev admin function to reject a previously approved batch
    /// Requires that the Batch-NFT has not been fractionalized yet
    function rejectApprovedWithComment(uint256 tokenId, string memory comment)
        external
    {
        onlyUnpaused();
        onlyWithRole(VERIFIER_ROLE);
        if (nftList[tokenId].status != BatchStatus.Confirmed)
            revert(Errors.COB_NOT_CONFIRMED);
        if (
            ICarbonCoreContractRegistry(contractRegistry).isValidERC20(
                ownerOf(tokenId)
            )
        ) revert(Errors.COB_ALREADY_FRACTIONALIZED);
        _updateStatus(tokenId, BatchStatus.Rejected);
        _addComment(tokenId, comment);
    }

    /// @notice Set batches back to pending after a rejection. This can
    /// be useful if there was an issue unrelated to the on-chain data of the
    /// batch, e.g. the batch was incorrectly rejected.
    /// @dev Callable only by verifiers, only for rejected batches.
    /// @param tokenId The token ID of the batch
    function setToPending(uint256 tokenId) external virtual {
        onlyUnpaused();
        onlyWithRole(VERIFIER_ROLE);
        if (nftList[tokenId].status != BatchStatus.Rejected)
            revert(Errors.COB_NOT_REJECTED);
        _updateStatus(tokenId, BatchStatus.Pending);
    }

    /// @notice Link Batch-NFT with Vintage
    /// @dev Function for alternative flow where Batch-NFT approval is done separately. Callable only by verifiers.
    /// @param tokenId The token ID of the batch
    /// @param projectVintageTokenId The token ID of the vintage
    function linkWithVintage(uint256 tokenId, uint256 projectVintageTokenId)
        external
        virtual
    {
        onlyUnpaused();
        onlyWithRole(VERIFIER_ROLE);
        _linkWithVintage(tokenId, projectVintageTokenId);
    }

    // @dev Function to internally link with Vintage when Batch-NFT approval is done seperately.
    function _linkWithVintage(uint256 _tokenId, uint256 _projectVintageTokenId)
        internal
    {
        checkProjectVintageTokenExists(
            contractRegistry,
            _projectVintageTokenId
        );
        nftList[_tokenId].projectVintageTokenId = _projectVintageTokenId;
        emit BatchLinkedWithVintage(_tokenId, _projectVintageTokenId);
    }

    /// @notice Link with vintage and confirm Batch-NFT
    /// @dev Function for main approval flow. Callable only by verifiers.
    /// @param tokenId The token ID of the batch
    /// @param projectVintageTokenId The token ID of the vintage
    function confirmBatchWithVintage(
        uint256 tokenId,
        uint256 projectVintageTokenId
    ) external virtual {
        onlyUnpaused();
        onlyWithRole(VERIFIER_ROLE);
        // We don't want this to be a "backdoor" for modifying the vintage; it
        // could be insecure or allow accidents to happen, and it would also
        // result in BatchLinkedWithVintage being emitted more than once per
        // batch.
        if (nftList[tokenId].projectVintageTokenId != 0)
            revert(Errors.COB_VINTAGE_ALREADY_SET);
        _linkWithVintage(tokenId, projectVintageTokenId);
        _confirmBatch(tokenId);
    }

    /// @notice Remove a previously approved serial number
    /// @dev Function to remove uniqueness for previously set serialnumbers. Callable only by verifiers.
    /// N.B. even though (technically speaking) calling this to complete the
    /// upgrade to a fixed contract is the responsibility of the contract's
    /// owner (deployer), in practice that is a multi-sig even before upgrade,
    /// and unsetting a bunch of serials via multi-sig is not practical.
    /// So instead we allow the verifiers to do it.
    /// @param serialNumber The serial number to unset
    function unsetSerialNumber(string memory serialNumber) external {
        onlyWithRole(VERIFIER_ROLE);
        serialNumberApproved[serialNumber] = false;
    }

    // ----------------------------------
    //  (Semi-)Permissionless functions
    // ----------------------------------

    /// @notice Permissionlessly mint empty Batch-NFTs
    /// Entry point to the carbon bridging process.
    /// @dev To be updated by NFT owner after serial number has been provided
    /// @param to The address the NFT should be minted to. This should be the user.
    /// @return The token ID of the newly minted NFT
    function mintEmptyBatch(address to) external virtual returns (uint256) {
        onlyUnpaused();
        return _mintEmptyBatch(to, to);
    }

    /// @notice Permissionlessly mint empty Batch-NFTs
    /// Entry point to the carbon bridging process.
    /// @dev To be updated by NFT owner after serial number has been provided
    /// @param to The address the NFT should be minted to. This should be the user
    /// but can also be the CarbonOffsetBatches contract itself in case the batch-NFT
    /// is held temporarily by the contract before fractionalization (see tokenize()).
    /// @param onBehalfOf The address of user on behalf of whom the batch is minted
    /// @return newItemId The token ID of the newly minted NFT
    function _mintEmptyBatch(address to, address onBehalfOf)
        internal
        returns (uint256 newItemId)
    {
        newItemId = batchTokenCounter;
        unchecked {
            ++newItemId;
        }
        batchTokenCounter = newItemId;

        _safeMint(to, newItemId);
        nftList[newItemId].status = BatchStatus.Pending;
        nftList[newItemId].quantity = 0;

        emit BatchMinted(onBehalfOf, newItemId);
    }

    /// @notice Update Batch-NFT after Serialnumber has been verified
    /// @dev Data is usually inserted by the user (NFT owner) via the UI. Callable only by verifiers or the batch-NFT
    /// owner.
    /// @param tokenId The token ID of the batch
    /// @param serialNumber The serial number received from the registry/credit cancellation
    /// @param quantity Quantity in TCC, greater than 0
    /// @param uri Optional tokenURI with additional information
    function updateBatchWithData(
        uint256 tokenId,
        string memory serialNumber,
        uint256 quantity,
        string memory uri
    ) external virtual {
        onlyUnpaused();
        onlyVerifierOrBatchOwner(tokenId);
        onlyPending(tokenId);
        _updateSerialAndQuantity(tokenId, serialNumber, quantity);

        if (!uri.equals(nftList[tokenId].uri)) nftList[tokenId].uri = uri;
    }

    /// @notice Internal function that updates batch-NFT after serial number has been verified
    function _updateSerialAndQuantity(
        uint256 tokenId,
        string memory serialNumber,
        uint256 quantity
    ) internal {
        if (serialNumberApproved[serialNumber])
            revert(Errors.COB_ALREADY_APPROVED);
        if (quantity == 0) revert(Errors.COB_INVALID_QUANTITY);
        nftList[tokenId].serialNumber = serialNumber;
        uint256 prevQuantity = nftList[tokenId].quantity;
        nftList[tokenId].quantity = quantity;

        BatchStatus status = nftList[tokenId].status;
        

        emit BatchUpdated(tokenId, serialNumber, quantity);
    }

    /// @notice Update batch-NFT with serial number and quantity only
    /// @dev Convenience function to only update serial number and quantity and not the serial/URI. Callable only by a
    /// verifier or the batch-NFT owner.
    /// @param tokenId The token ID of the batch
    /// @param newSerialNumber The serial number received from the registry/credit cancellation
    /// @param newQuantity Quantity in TCC, greater than 0
    function setSerialandQuantity(
        uint256 tokenId,
        string memory newSerialNumber,
        uint256 newQuantity
    ) external virtual {
        onlyUnpaused();
        onlyVerifierOrBatchOwner(tokenId);
        onlyPending(tokenId);
        _updateSerialAndQuantity(tokenId, newSerialNumber, newQuantity);
    }

    /// @notice Returns just the confirmation (approval) status of Batch-NFT
    /// @param tokenId The token ID of the batch
    function getConfirmationStatus(uint256 tokenId)
        external
        view
        virtual
        override
        returns (BatchStatus)
    {
        return nftList[tokenId].status;
    }

    function getSerialNumber(uint256 tokenId)
        external
        view
        virtual
        override
        returns (string memory)
    {
        return nftList[tokenId].serialNumber;
    }
    

    /// @notice Returns all data for Batch-NFT
    /// @dev Used in TCC contract's receive hook `onERC721Received`
    /// @param tokenId The token ID of the batch
    /// @return projectVintageTokenId The token ID of the vintage
    /// @return quantity Quantity in TCC
    /// @return status The status of the batch
    function getBatchNFTData(uint256 tokenId)
        external
        view
        virtual
        override
        returns (
            uint256,
            uint256,/*normalized amount*/
            BatchStatus
        )
    {
        if (!_exists(tokenId)) revert(Errors.COB_NOT_EXISTS);
        return (
            nftList[tokenId].projectVintageTokenId,
            nftList[tokenId].quantity,/*normalized amount*/
            nftList[tokenId].status
        );
    }

    /// @dev Overridden here because of function overloading issues with ethers.js
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override(ERC721Upgradeable, IERC721Upgradeable) {
        onlyApprovedOrOwner(tokenId);
        safeTransferFrom(from, to, tokenId, '');
    }

    /// @notice Automatically converts Batch-NFT to TCCs (ERC20)
    /// @dev Only by the batch-NFT owner or approved operator, only if batch is confirmed.
    /// Batch-NFT is sent from the sender and TCCs are transferred to the sender.
    /// Queries the factory to find the corresponding TCC contract
    /// Fractionalization happens via receive hook on `safeTransferFrom`
    /// @param tokenId The token ID of the batch
    function fractionalize(uint256 tokenId) external virtual {
        onlyApprovedOrOwner(tokenId);
        // Fractionalize by transferring the batch-NFT to the TCC contract.
        safeTransferFrom(
            _msgSender(),
            _getTCCForBatchTokenId(tokenId),
            tokenId,
            ''
        );
    }

    /// @dev returns the address of the TCC contract that corresponds to the batch-NFT
    function _getTCCForBatchTokenId(uint256 tokenId)
        internal
        view
        returns (address)
    {
        uint256 pvId = nftList[tokenId].projectVintageTokenId;
        ICarbonCoreContractRegistry tcnRegistry = ICarbonCoreContractRegistry(
            contractRegistry
        );

        // Fetch the registry from the vintage data first
        address vintages = tcnRegistry.carbonProjectVintagesAddress();
        VintageData memory data = ICarbonProjectVintages(vintages)
            .getProjectVintageDataByTokenId(pvId);

        // Now we can fetch the TCC factory for the carbon registry
        string memory carbonRegistry = data.registry;
        if (bytes(carbonRegistry).length == 0) {
            carbonRegistry = 'verra';
        }
        address tccFactory = tcnRegistry.carboncoreCarbonOffsetsFactoryAddress(
            carbonRegistry
        );

        return ICarbonCoreCarbonOffsetsFactory(tccFactory).pvIdtoERC20(pvId);
    }

    function supportsInterface(bytes4 interfaceId)
        public
        view
        virtual
        override(AccessControlUpgradeable, ERC721EnumerableUpgradeable)
        returns (bool)
    {
        return
            interfaceId == type(IAccessControlUpgradeable).interfaceId ||
            ERC721Upgradeable.supportsInterface(interfaceId);
    }

    function _baseURI() internal view virtual override returns (string memory) {
        return baseURI;
    }

    function setBaseURI(string memory gateway) external onlyOwner {
        baseURI = gateway;
    }

    /// @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
    /// based on the ERC721URIStorage implementation
    function tokenURI(uint256 tokenId)
        public
        view
        virtual
        override
        returns (string memory)
    {
        if (!_exists(tokenId)) revert(Errors.COB_NOT_EXISTS);

        string memory uri = nftList[tokenId].uri;
        // If there is no base URI, return the token URI.
        if (bytes(_baseURI()).length == 0) return uri;
        // If both are set, concatenate the baseURI and tokenURI
        if (bytes(uri).length > 0) return string.concat(_baseURI(), uri);

        return super.tokenURI(tokenId);
    }

    /// @dev Utilized here in order to disable transfers when paused
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount,
        uint256 batchSize
    ) internal virtual override {
        onlyUnpaused();
        super._beforeTokenTransfer(from, to, amount, batchSize);
    }

    /// @notice Append a comment to a Batch-NFT
    /// @dev Don't allow the contract owner to comment.  When the contract owner
    /// can also be a verifier they should add them as a verifier first; this
    /// should prevent accidental comments from the wrong account.
    function addComment(uint256 tokenId, string memory comment) external {
        // this also checks that tokenId exists, otherwise ERC721Upgradeable.ownerOf would revert on nonexistent token
        onlyVerifierOrBatchOwner(tokenId);
        _addComment(tokenId, comment);
    }

    function _addComment(uint256 tokenId, string memory comment) internal {
        nftList[tokenId].comments.push() = comment;
        nftList[tokenId].commentAuthors.push() = _msgSender();
        emit BatchComment(
            tokenId,
            nftList[tokenId].comments.length,
            _msgSender(),
            comment
        );
    }

    /// @notice This function allows external APIs to tokenize their carbon credits
    /// @dev Callable only by tokenizers. Performs the full tokenization process: minting a batch-NFT, linking it with a project
    /// vintage, setting the quantity and serial number, confirming the batch, and fractionalizing it. The TCCs are
    /// then transferred to the recipient.
    /// @param recipient Recipient of the tokens
    /// @param serialNumber Serial number of the carbon credits to be tokenized
    /// @param quantity Quantity to be tokenized in 1e18 format, greater than 0
    /// @param projectVintageTokenId The token ID of the vintage
    /// @return tokenId The token ID of the newly minted batch
    function tokenize(
        address recipient,
        string calldata serialNumber,
        uint256 quantity,
        uint256 projectVintageTokenId
    ) external returns (uint256 tokenId) {
        onlyUnpaused();
        onlyWithRole(TOKENIZER_ROLE);
        // Prepare and confirm batch
        
        tokenId = _mintEmptyBatch(address(this), recipient);
        _linkWithVintage(tokenId, projectVintageTokenId);
        ICarbonIndexer( ICarbonCoreContractRegistry(contractRegistry).carbonIndexerAddress() ).addMintedBatch(projectVintageTokenId, tokenId);

        _updateSerialAndQuantity(tokenId, serialNumber, quantity);
        _confirmBatch(tokenId);

        ICarbonIndexer indexer = ICarbonIndexer( ICarbonCoreContractRegistry(contractRegistry).carbonIndexerAddress() );
        indexer.addBatchToVintage(tokenId);


        // Check existing TCC balance; to be used at the end
        // to send the exact TCC needed to the recipient.
        address tcc = _getTCCForBatchTokenId(tokenId);
        if (tcc == address(0)) revert(Errors.COB_TCC_NOT_FOUND);
        string memory registry = ICarbonCoreCarbonOffsets(tcc).standardRegistry();
        if (!supportedRegistries[registry])
            revert(Errors.COB_REGISTRY_NOT_SUPPORTED);
        uint256 balanceBefore = IERC20Upgradeable(tcc).balanceOf(
            address(this)
        );

        // Fractionalize by transferring the batch-NFT to the TCC contract.
        _safeTransfer(address(this), tcc, tokenId, '');

        // Check that TCCs were minted
        uint256 balanceAfter = IERC20Upgradeable(tcc).balanceOf(address(this));
        uint256 amount = balanceAfter - balanceBefore;

        //slither-disable-next-line incorrect-equality
        if (amount == 0) revert(Errors.COB_NO_TCC_MINTED);

        // Transfer minted TCCs to recipient.
        IERC20Upgradeable(tcc).safeTransfer(recipient, amount);
        emit Tokenized(tokenId, tcc, recipient, amount);
    }

    /// @notice Split a batch-NFT into two batch-NFTs, by creating a new batch-NFT and updating the old one.
    /// The old batch will have a new serial number and quantity will be reduced by the quantity of the new batch.
    /// @dev Callable only by the escrow contract, only for batches with status
    /// RetirementRequested or DetokenizationRequested. The TCC contract will also be the owner of the new batch and
    /// its status will be the same as the old batch.
    /// @param tokenId The token ID of the batch to split
    /// @param newTokenIdQuantity The quantity for the new batch, must be smaller than the old quantity and greater
    /// than 0
    /// @return newTokenId The token ID of the new batch
    function split(
        uint256 tokenId,
        uint256 newTokenIdQuantity
    ) external returns (uint256 newTokenId) {
        onlyUnpaused();
        onlyEscrow();

        string memory serialNumber = nftList[tokenId].serialNumber;

        //address tcc = _getTCCForBatchTokenId(tokenId);
        address tcc = ownerOf(tokenId);
        if (tcc == address(0)) revert(Errors.COB_TCC_NOT_FOUND);

        (
            string memory newTokenIdSerialNumber,
            string memory tokenIdNewSerialNumber
        ) = ICarbonCoreCarbonOffsets(tcc).splitSerialNumber(serialNumber, newTokenIdQuantity);


        if (!ICarbonCoreContractRegistry(contractRegistry).isValidERC20(tcc))
            revert(Errors.COB_INVALID_BATCH_OWNER);
        // Validate batch status
        BatchStatus status = nftList[tokenId].status;
        if (
            status != BatchStatus.RetirementRequested &&
            status != BatchStatus.DetokenizationRequested
        ) revert(Errors.COB_INVALID_STATUS);
        // Validate batch quantity
        if (nftList[tokenId].quantity <= newTokenIdQuantity)
            revert(Errors.COB_INVALID_QUANTITY);

        // keep old serial number to be able to unapprove it after checking and approving the new ones
        string memory oldSerialNumber = nftList[tokenId].serialNumber;
        // this also performs the check that the new quantity is smaller than the old quantity, otherwise it would
        // underflow and revert. in case it is equal to the old quantity, _updateSerialAndQuantity would revert on
        // quantity == 0
        _updateSerialAndQuantity(
            tokenId,
            tokenIdNewSerialNumber,
            nftList[tokenId].quantity - newTokenIdQuantity
        );
        serialNumberApproved[tokenIdNewSerialNumber] = true;

        // mint a new batch to be owned by the TCC contract
        newTokenId = _mintEmptyBatch(address(this), tcc);
        _updateSerialAndQuantity(
            newTokenId,
            newTokenIdSerialNumber,
            newTokenIdQuantity
        ); // here we would revert in case newTokenIdQuantity == 0
        serialNumberApproved[newTokenIdSerialNumber] = true;

        // unapprove the old serial number
        serialNumberApproved[oldSerialNumber] = false;

        // link the new batch with the vintage of the old batch
        _linkWithVintage(newTokenId, nftList[tokenId].projectVintageTokenId);
        ICarbonIndexer( ICarbonCoreContractRegistry(contractRegistry).carbonIndexerAddress() ).addMintedBatch(nftList[tokenId].projectVintageTokenId, newTokenId);

        // Copy the status from the old batch
        _updateStatus(newTokenId, status);

        // transfer new batch to TCC contract with the right status so that
        // it will not be fractionalized
        _safeTransfer(address(this), tcc, newTokenId, '');

        emit Split(tokenId, newTokenId);
    }

    function onERC721Received(
        address, /* operator */
        address from, /* from */
        uint256, /* tokenId */
        bytes calldata /* data */
    ) external pure returns (bytes4) {
        // This hook is only used by the contract to mint batch-NFTs that
        // can be tokenized on behalf of end users.
        if (from != address(0)) revert(Errors.COB_ONLY_MINTS);
        return this.onERC721Received.selector;
    }
}

// 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 {Initializable} from "../proxy/utils/Initializable.sol";

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

    function __AccessControl_init() internal onlyInitializing {
    }

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(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;
}

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

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

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import {Initializable} from "../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 5 of 45 : draft-IERC1822Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.0;

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822ProxiableUpgradeable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}

File 6 of 45 : IERC1967Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol)

pragma solidity ^0.8.0;

/**
 * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
 *
 * _Available since v4.8.3._
 */
interface IERC1967Upgradeable {
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);
}

File 7 of 45 : IBeaconUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.0;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeaconUpgradeable {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {BeaconProxy} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)

pragma solidity ^0.8.2;

import "../beacon/IBeaconUpgradeable.sol";
import "../../interfaces/IERC1967Upgradeable.sol";
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/StorageSlotUpgradeable.sol";
import {Initializable} from "../utils/Initializable.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 *
 * _Available since v4.1._
 */
abstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable {
    // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
    bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    function __ERC1967Upgrade_init() internal onlyInitializing {
    }

    function __ERC1967Upgrade_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Returns the current implementation address.
     */
    function _getImplementation() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
        StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Perform implementation upgrade
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeTo(address newImplementation) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);
    }

    /**
     * @dev Perform implementation upgrade with additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
        _upgradeTo(newImplementation);
        if (data.length > 0 || forceCall) {
            AddressUpgradeable.functionDelegateCall(newImplementation, data);
        }
    }

    /**
     * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
     *
     * Emits an {Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
        // Upgrades from old implementations will perform a rollback test. This test requires the new
        // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
        // this special case will break upgrade paths from old UUPS implementation to new ones.
        if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {
            _setImplementation(newImplementation);
        } else {
            try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {
                require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
            } catch {
                revert("ERC1967Upgrade: new implementation is not UUPS");
            }
            _upgradeToAndCall(newImplementation, data, forceCall);
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
     * validated in the constructor.
     */
    bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     */
    function _getAdmin() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        require(newAdmin != address(0), "ERC1967: new admin is the zero address");
        StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {AdminChanged} event.
     */
    function _changeAdmin(address newAdmin) internal {
        emit AdminChanged(_getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
     */
    bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function _getBeacon() internal view returns (address) {
        return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
        require(
            AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
            "ERC1967: beacon implementation is not a contract"
        );
        StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
    }

    /**
     * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
     * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
     *
     * Emits a {BeaconUpgraded} event.
     */
    function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);
        if (data.length > 0 || forceCall) {
            AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), 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;
}

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

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

pragma solidity ^0.8.0;

import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../ERC1967/ERC1967UpgradeUpgradeable.sol";
import {Initializable} from "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 *
 * _Available since v4.1._
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
    address private immutable __self = address(this);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        require(address(this) != __self, "Function must be called through delegatecall");
        require(_getImplementation() == __self, "Function must be called through active proxy");
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
        _;
    }

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
        return _IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeTo(address newImplementation) public virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data, true);
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeTo} and {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal override onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

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

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

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import {Initializable} from "../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;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";
import "../extensions/IERC20PermitUpgradeable.sol";
import "../../../utils/AddressUpgradeable.sol";

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

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

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

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20Upgradeable token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20Upgradeable token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20Upgradeable token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

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

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20PermitUpgradeable token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20Upgradeable token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

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

File 15 of 45 : 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 {Initializable} from "../../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;
}

// 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 {Initializable} from "../../../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 {
    // 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;

    function __ERC721Enumerable_init() internal onlyInitializing {
    }

    function __ERC721Enumerable_init_unchained() internal onlyInitializing {
    }
    /**
     * @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;
}

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

// 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 19 of 45 : 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);
}

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "./IERC165Upgradeable.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * 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;
}

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

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

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

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

pragma solidity ^0.8.0;

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

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

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

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

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

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

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

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

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

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

// 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 29 of 45 : CarbonIndexerTypes.sol
// SPDX-FileCopyrightText: 2021 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth

pragma solidity ^0.8.14;


struct Batch {
    uint256 id;
    uint256 amount; // available amount in this batch (full batch amount as stored)
}

struct Request {
    uint256 requestId;
    bool isRetirement;
}    

struct BatchUsage {
    uint256 tokenId; 
    uint256 amount; //amount used
    uint256 total; //amount in batch
    string serialNumber;
}

struct BatchSelection {
    BatchUsage[] batches;
    BatchUsage lastBatch;
    uint256 amount; // amount requested to detokenize or retire
}

// SPDX-FileCopyrightText: 2021 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity ^0.8.14;


import {DetokenizationRequest} from '../../../CarbonCoreCarbonOffsetsEscrowTypes.sol';
import {Batch, Request, BatchSelection} from "./CarbonIndexerTypes.sol";

interface ICarbonIndexer {
    function updateUserTCCHolding(address user, address tcc, uint256 newBalance) external;
    function addBatchToVintage(uint256 tokenId) external;
    function removeBatchFromVintage(uint256 tokenId) external;
    function updateBucketForNewAmount(uint256 tokenId) external;
    function resolveAmountByBatches(uint256 vintageId, uint256 requested/*normalized amount*/) external view returns (BatchSelection memory);
    function addMintedBatch(uint256 vintageId, uint256 batchId) external;

    function addBatchSyncronization(string memory registry, uint256 requestId, bool isRetirement) external; 
    function removeBatchSyncronization(string memory registry, uint256 requestId, bool isRetirement) external; 
    function getNextBachSyncronization(string memory registry) external view returns (Request memory);
    function contractRegistry() external view returns(address);

}

File 31 of 45 : CarbonCoreCarbonOffsetsEscrowTypes.sol
// SPDX-FileCopyrightText: 2023 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity 0.8.14;

import './carboncore/indexers/main/CarbonIndexerTypes.sol';

struct DetokenizationRequest {
    address user;
    RequestStatus status;
    BatchSelection batchSelection;
    uint256[] revertedBatchIds;
    uint256 revertedBatchesAmount;

    uint256 projectVintageTokenId;
}

struct RetirementRequest {
    address user;
    RequestStatus status;
    // The request may optionally be associated with one or more batches.
    // This may need to be limited to one batch for registries which don't
    // support atomic retirement of multiple batches in one go, since
    // retiring one batch at a time might create a situation where our
    // RetirementRequest is only partially fulfilled, and then we would be
    // stuck with no way forwards and no way to roll back.
    BatchSelection batchSelection;
    uint256[] revertedBatchIds;
    uint256 revertedBatchesAmount;


    // Optional
    string retiringEntityString;
    // Optional
    address beneficiary;
    // Optional
    string beneficiaryString;
    // Optional
    string retirementMessage;
    // Optional
    string beneficiaryLocation;
    // Optional
    string consumptionCountryCode;
    // Optional
    uint256 consumptionPeriodStart;
    // Optional
    uint256 consumptionPeriodEnd;
    uint256 projectVintageTokenId;
}

enum RequestStatus {
    Pending,
    Finalized,
    Reverted
}

File 32 of 45 : CarbonOffsetBatchesStorage.sol
// SPDX-FileCopyrightText: 2021 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

pragma solidity 0.8.14;

import {BatchStatus} from './CarbonOffsetBatchesTypes.sol';

/// @dev Separate storage contract to improve upgrade safety
abstract contract CarbonOffsetBatchesStorageV1 {
    uint256 public batchTokenCounter;
    /// @custom:oz-upgrades-renamed-from serialNumberExist
    mapping(string => bool) public serialNumberApproved;
    mapping(string => bool) private DEPRECATED_URIs;
    mapping(address => bool) private DEPRECATED_VERIFIERS;

    string internal baseURI;
    address public contractRegistry;

    struct NFTData {
        uint256 projectVintageTokenId;
        string serialNumber;
        uint256 quantity;
        BatchStatus status;
        string uri;
        string[] comments;
        address[] commentAuthors;
    }

    mapping(uint256 => NFTData) public nftList;
}

abstract contract CarbonOffsetBatchesStorageV2 {
    mapping(string => bool) internal supportedRegistries;
}

abstract contract CarbonOffsetBatchesStorage is
    CarbonOffsetBatchesStorageV1,
    CarbonOffsetBatchesStorageV2
{}

File 33 of 45 : CarbonOffsetBatchesTypes.sol
// SPDX-FileCopyrightText: 2021 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth

pragma solidity 0.8.14;

enum BatchStatus {
    Pending, // 0
    Rejected, // 1
    Confirmed, // 2
    DetokenizationRequested, // 3
    DetokenizationFinalized, // 4
    RetirementRequested, // 5
    RetirementFinalized // 6
}

File 34 of 45 : CarbonProjectTypes.sol
// SPDX-FileCopyrightText: 2021 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth

pragma solidity 0.8.14;

/// @dev CarbonProject related data and attributes
struct ProjectData {
    string projectId;
    string standard;
    string methodology;
    string region;
    string storageMethod;
    string method;
    string emissionType;
    string category;
    string uri;
    address beneficiary;
}

File 35 of 45 : CarbonProjectVintageTypes.sol
// SPDX-FileCopyrightText: 2021 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth

pragma solidity 0.8.14;

struct VintageData {
    /// @dev A human-readable string which differentiates this from other vintages in
    /// the same project, and helps build the corresponding TCC name and symbol.
    string name;
    uint64 startTime; // UNIX timestamp
    uint64 endTime; // UNIX timestamp
    uint256 projectTokenId;
    uint64 totalVintageQuantity;
    bool isCorsiaCompliant;
    bool isCCPcompliant;
    string coBenefits;
    string correspAdjustment;
    string additionalCertification;
    string uri;
    string registry;
}

// SPDX-FileCopyrightText: 2022 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity 0.8.14;

import {VintageData} from '../CarbonProjectVintageTypes.sol';
import {ProjectData} from '../CarbonProjectTypes.sol';
import {CreateRetirementRequestParams} from '../interfaces/ICarbonCoreCarbonOffsetsEscrow.sol';
import {BatchSelection} from "../carboncore/indexers/main/CarbonIndexerTypes.sol";

interface ICarbonCoreCarbonOffsets {
    function retireFrom(address account, uint256 amount)
        external
        returns (uint256 retirementEventId);

    function burnFrom(address account, uint256 amount) external;

    function getAttributes()
        external
        view
        returns (ProjectData memory, VintageData memory);

    /// @notice Get the vintage data of the TCC
    function getVintageData()
        external
        view
        returns (VintageData memory vintageData);

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

    function retireAndMintCertificate(
        string calldata retiringEntityString,
        address beneficiary,
        string calldata beneficiaryString,
        string calldata retirementMessage,
        uint256 amount
    ) external;

    function retireAndMintCertificateForEntity(
        address retiringEntity,
        uint256 amount, /*decimals*/
        uint256[] memory batchIds,
        CreateRetirementRequestParams calldata params
    ) external;

    function projectVintageTokenId() external view returns (uint256);


    function splitSerialNumber(string calldata serialNumber, uint256 amount)
        external
        pure
        returns (
            string memory balancingSerialNumber,
            string memory remainingSerialNumber
        );    
}

// SPDX-FileCopyrightText: 2023 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity 0.8.14;

import {DetokenizationRequest, RetirementRequest, RequestStatus} from '../CarbonCoreCarbonOffsetsEscrowTypes.sol';
import {BatchSelection} from "../carboncore/indexers/main/CarbonIndexerTypes.sol";

struct CreateRetirementRequestParams {
    string retiringEntityString;
    address beneficiary;
    string beneficiaryString;
    string retirementMessage;
    string beneficiaryLocation;
    string consumptionCountryCode;
    uint256 consumptionPeriodStart;
    uint256 consumptionPeriodEnd;
}

interface ICarbonCoreCarbonOffsetsEscrow {
    function createDetokenizationRequest(
        address user,
        BatchSelection memory batchSelection
    ) external returns (uint256);

    function createRetirementRequest(
        address user,
        BatchSelection memory batchSelection,
        CreateRetirementRequestParams calldata params
    ) external returns (uint256);

    function finalizeDetokenizationRequest(uint256 requestId, uint256 succededBatchesNum) external;

    function finalizeRetirementRequest(uint256 requestId, uint256 succededBatchesNum) external;

    function revertDetokenizationRequest(uint256 requestId) external;

    function revertRetirementRequest(uint256 requestId) external;

    function detokenizationRequests(uint256 requestId)
        external
        view
        returns (DetokenizationRequest memory);

    function retirementRequests(uint256 requestId)
        external
        view
        returns (RetirementRequest memory);
}

// SPDX-FileCopyrightText: 2022 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity 0.8.14;

import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol';

interface ICarbonCoreCarbonOffsetsFactory is IAccessControlUpgradeable {
    function bridgeFeeReceiverAddress()
        external
        view
        returns (address receiver);

    function bridgeFeeBurnAddress() external view returns (address burner);

    function getBridgeFeeAndBurnAmount(uint256 quantity)
        external
        view
        returns (uint256 feeAmount, uint256 burnAmount);

    function allowedBridges(address user) external view returns (bool);

    function owner() external view returns (address);

    function standardRegistry() external returns (string memory);

    function pvIdtoERC20(uint256 pvId) external view returns (address);
}

// SPDX-FileCopyrightText: 2021 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity 0.8.14;

interface ICarbonCoreContractRegistry {
    function carbonOffsetBatchesAddress() external view returns (address);

    function carbonProjectsAddress() external view returns (address);

    function carbonProjectVintagesAddress() external view returns (address);
    
    function carbonIndexerAddress() external view returns (address);

    function carbonPoolsIndexerAddress() external view returns (address);

    function carboncoreCarbonOffsetsFactoryAddress(string memory standardRegistry)
        external
        view
        returns (address);

    function retirementCertificatesAddress() external view returns (address);

    function carboncoreCarbonOffsetsEscrowAddress() external view returns (address);

    function retirementCertificateFractionalizerAddress()
        external
        view
        returns (address);

    function retirementCertificateFractionsAddress()
        external
        view
        returns (address);

    function isValidERC20(address erc20) external view returns (bool);

    function addERC20(address erc20, string memory standardRegistry) external;

    
}

// SPDX-FileCopyrightText: 2021 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity 0.8.14;

import {BatchStatus} from '../CarbonOffsetBatchesTypes.sol';

interface ICarbonOffsetBatches {
    function getConfirmationStatus(uint256 tokenId)
        external
        view
        returns (BatchStatus);

    function getSerialNumber(uint256 tokenId)
        external
        view
        returns (string memory);

    function getBatchNFTData(uint256 tokenId)
        external
        view
        returns (
            uint256,
            uint256,/*normalized amount*/
            BatchStatus
        );
        
    function setStatusForDetokenizationOrRetirement(
        uint256 tokenId,
        BatchStatus newStatus
    ) external;

    function split(
        uint256 tokenId,
        uint256 newTokenIdQuantity
    ) external returns (uint256);
}

// SPDX-FileCopyrightText: 2021 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity 0.8.14;

import '@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol';

import {VintageData} from '../CarbonProjectVintageTypes.sol';

interface ICarbonProjectVintages is IERC721Upgradeable {
    function addNewVintage(address to, VintageData memory _vintageData)
        external
        returns (uint256);

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

    function getProjectVintageDataByTokenId(uint256 tokenId)
        external
        view
        returns (VintageData memory);
}

File 42 of 45 : Errors.sol
// SPDX-FileCopyrightText: 2022 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity 0.8.14;

/**
 * @title Errors library
 * @notice Defines the error messages emitted by the different contracts of the CarbonCore protocol
 * @dev Inspired by the AAVE error library:
 * https://github.com/aave/protocol-v2/blob/5df59ec74a0c635d877dc1c5ee4a165d41488352/contracts/protocol/libraries/helpers/Errors.sol
 * Error messages prefix glossary:
 *  - CP = CarbonPool
 *  - COB = CarbonOffsetBatches
 *  - TCC = TCC
 */
library Errors {
    // User is not authorized
    string public constant CP_UNAUTHORIZED = '1';
    // Empty array provided as input
    string public constant CP_EMPTY_ARRAY = '2';
    // Pool is full of TCCs
    string public constant CP_FULL_POOL = '3';
    // ERC20 is blocklisted in the pool. This error
    // is returned for TCCs that have been blocklisted
    // like the HFC-23 project.
    string public constant CP_BLOCKLISTED = '4';
    // ERC20 is not allowlisted in the pool
    // This error is returned in case the ERC20 is
    // not a TCC in which case it has to be manually
    // allowlisted in order to be allowed in the pool.
    string public constant CP_NOT_ALLOWLISTED = '5';
    // Vintage start time of a TCC is too old
    string public constant CP_START_TIME_TOO_OLD = '6';
    string public constant CP_REGION_NOT_ACCEPTED = '7';
    string public constant CP_STANDARD_NOT_ACCEPTED = '8';
    string public constant CP_METHODOLOGY_NOT_ACCEPTED = '9';
    // Provided fee is invalid, not in a basis points format: [0,10000)
    string public constant CP_INVALID_FEE = '10';
    // Provided address needs to be non-zero
    string public constant CP_EMPTY_ADDRESS = '11';
    // Validation check to ensure array lengths match
    string public constant CP_LENGTH_MISMATCH = '12';
    // TCC not exempted from redeem fees
    string public constant CP_NOT_EXEMPTED = '13';
    // A contract has been paused
    string public constant CP_PAUSED_CONTRACT = '14';
    // Redemption has leftover unredeemed value
    string public constant CP_NON_ZERO_REMAINING = '15';
    // Redemption exceeds deposited TCC supply
    string public constant CP_EXCEEDS_TCC_SUPPLY = '16';
    // User must be a router
    string public constant CP_ONLY_ROUTER = '17';
    // User must be the owner
    string public constant CP_ONLY_OWNER = '18';
    // Zero destination address is invalid for pool token transfers
    string public constant CP_INVALID_DESTINATION_ZERO = '19';
    // Self destination address is invalid for pool token transfers
    string public constant CP_INVALID_DESTINATION_SELF = '20';
    // Zero amount provided as an input (eg., in redemptions) in invalid
    string public constant CP_ZERO_AMOUNT = '21';
    // ERC20 is not eligible to be pooled
    string public constant CP_NOT_ELIGIBLE = '22';
    // Carbon registry is already supported in COB
    string public constant COB_ALREADY_SUPPORTED = '23';
    // The caller is not granted the VERIFIER_ROLE in COB
    string public constant COB_NOT_VERIFIER_OR_BATCH_OWNER = '24';
    // The caller does not own the provided batch
    string public constant COB_NOT_BATCH_OWNER = '25';
    // The owner of the batch is invalid (not a TCC contract)
    string public constant COB_INVALID_BATCH_OWNER = '26';
    // The batch is not in Confirmed status
    string public constant COB_NOT_CONFIRMED = '27';
    // The batch is not in a requested status (DetokenizationRequested or RetirementRequested)
    string public constant COB_NOT_REQUESTED_STATUS = '28';
    // The batch does not exist
    string public constant COB_NOT_EXISTS = '29';
    // The batch has an invalid status based on the action requested
    string public constant COB_INVALID_STATUS = '30';
    // The batch is missing an associated project vintage
    string public constant COB_MISSING_VINTAGE = '31';
    // The serial number in the batch is already approved
    string public constant COB_ALREADY_APPROVED = '32';
    // The batch is not in Pending status
    string public constant COB_NOT_PENDING = '33';
    // The batch is already fractionalized
    string public constant COB_ALREADY_FRACTIONALIZED = '34';
    // The batch is not in Rejected status
    string public constant COB_NOT_REJECTED = '35';
    // The project vintage is already set in the batch
    string public constant COB_VINTAGE_ALREADY_SET = '36';
    // The transfer is not approved
    string public constant COB_TRANSFER_NOT_APPROVED = '37';
    // The COB contract is paused
    string public constant COB_PAUSED_CONTRACT = '38';
    // The caller is invalid
    string public constant COB_INVALID_CALLER = '39';
    // The TCC for the batch is not found
    string public constant COB_TCC_NOT_FOUND = '40';
    // The registry for the provided vintage is not supported
    string public constant COB_REGISTRY_NOT_SUPPORTED = '41';
    // No TCC was minted as part of tokenization
    string public constant COB_NO_TCC_MINTED = '42';
    // Only mints are supported for the batch contract to receive an NFT
    string public constant COB_ONLY_MINTS = '43';
    // New batch status is invalid
    string public constant COB_INVALID_NEW_STATUS = '44';
    // The TCC batch amount is invalid
    string public constant TCC_BATCH_AMT_INVALID = '45';
    // The TCC batch amount approval has failed
    string public constant TCC_APPROVAL_AMT_FAILED = '46';
    // The TCC batch not confirmed
    string public constant TCC_BATCH_NOT_CONFIRMED = '47';
    // The TCC batch not whitelisted
    string public constant TCC_BATCH_NOT_WHITELISTED = '48';
    // The TCC is non matching NFT
    string public constant TCC_NON_MATCHING_NFT = '49';
    // The TCC Quantity in batch is higher than total vintages
    string public constant TCC_QTY_HIGHER = '50';
    // The fee to be charged is too high
    string public constant CP_FEE_TOO_HIGH = '51';
    // The max fee to be paid is invalid
    string public constant CP_INVALID_MAX_FEE = '52';
    // The pool feature is not supported
    string public constant CP_NOT_SUPPORTED = '53';
    // Used for instance to check for sub-tonnage retirement requests
    string public constant TCC_INVALID_DECIMALS = '54';
    // The TCC Quantity in the batch is invalid
    string public constant COB_INVALID_QUANTITY = '55';
    // Splitting is required on detokenization/retirement finalization, but 2 new serial numbers
    // were not provided
    string public constant TCC_MISSING_SERIALS = '56';
    // The score set for the ERC-1155 token in the pool is invalid
    string public constant INVALID_ERC1155_SCORE = '57';
    // The score of the ERC-1155 token in the pool is not set
    string public constant EMPTY_ERC155_SCORE = '58';
    // The underlying decimals are too high for the pool
    string public constant UNDERLYING_DECIMALS_TOO_HIGH = '59';
    // The provided supply cap is invalid and should match the underlying token decimals
    // eg., for an ERC-1155 token whose smallest denomination is tonnes, the pool supply
    // cap should not include decimals of lower fidelity than tonnes.
    string public constant INVALID_SUPPLY_CAP = '60';
}

File 43 of 45 : Modifiers.sol
// SPDX-FileCopyrightText: 2021 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity 0.8.14;

contract Modifiers {
    modifier onlyBy(address _contractRegistry, address _owner) {
        require(
            _contractRegistry == msg.sender || _owner == msg.sender,
            'Caller is not the registry, nor owner'
        );
        _;
    }
}

// SPDX-FileCopyrightText: 2021 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity 0.8.14;

import '../interfaces/ICarbonCoreContractRegistry.sol';
import '../interfaces/ICarbonProjectVintages.sol';

contract ProjectVintageUtils {
    function checkProjectVintageTokenExists(
        address contractRegistry,
        uint256 tokenId
    ) internal virtual {
        address c = ICarbonCoreContractRegistry(contractRegistry)
            .carbonProjectVintagesAddress();
        require(
            ICarbonProjectVintages(c).exists(tokenId),
            'Carbon project vintage does not yet exist'
        );
    }
}

// SPDX-FileCopyrightText: 2023 CarbonCore Labs
//
// SPDX-License-Identifier: UNLICENSED

// If you encounter a vulnerability or an issue, please contact <[email protected]> or visit security.carboncore.earth
pragma solidity 0.8.14;

import '@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol';

library Strings {
    /// @notice Compare two strings
    /// @param a The string to compare
    /// @param b The string to compare to
    /// @return True if the strings are equal, false otherwise
    function equals(string memory a, string memory b)
        internal
        pure
        returns (bool)
    {
        return
            (bytes(a).length == bytes(b).length) &&
            (keccak256(bytes(a)) == keccak256(bytes(b)));
    }

    /// @notice Convert a string to an integer
    /// @param numString The string to convert
    /// @return The integer value of the string
    function toInteger(string memory numString)
        internal
        pure
        returns (uint256)
    {
        uint256 val = 0;
        bytes memory stringBytes = bytes(numString);
        uint256 stringBytesLen = stringBytes.length;
        for (uint256 i = 0; i < stringBytesLen; ++i) {
            uint256 exp = stringBytesLen - i;
            bytes1 ival = stringBytes[i];
            uint8 uval = uint8(ival);
            uint256 jval = uval - uint256(0x30);

            val += (uint256(jval) * (10**(exp - 1)));
        }
        return val;
    }

    /// @notice Convert an integer to a string
    /// @param value The integer to convert
    /// @return The string value of the integer
    function toString(uint256 value) internal pure returns (string memory) {
        return StringsUpgradeable.toString(value);
    }

    /// @notice Get a substring of a string
    /// @param text The string to get a substring from
    /// @param begin The start index of the substring
    /// @param end The end index of the substring
    /// @return The substring
    function slice(
        string memory text,
        uint256 begin,
        uint256 end
    ) internal pure returns (string memory) {
        uint256 length = end - begin;
        bytes memory a = new bytes(length);
        for (uint256 i = 0; i < length; ++i) {
            a[i] = bytes(text)[i + begin];
        }
        return string(a);
    }

    /// @notice Pad a string with a character
    /// @param text The string to pad
    /// @param length The length to pad to
    /// @param padChar The character to pad with
    /// @return The padded string
    function pad(
        string memory text,
        uint256 length,
        string memory padChar
    ) internal pure returns (string memory) {
        uint256 textLen = bytes(text).length;
        require(bytes(padChar).length == 1, 'Invalid padChar length');
        require(length >= textLen, 'Invalid text length');

        for (uint256 i = textLen; i < length; ++i) {
            text = string.concat(padChar, text);
        }

        return text;
    }

    /// @notice Count the occurrences of a character in a string
    /// @param text The string to count occurrences of char in
    /// @param char The character to count
    /// @return nums The number of occurrences
    function count(string memory text, string memory char)
        internal
        pure
        returns (uint256 nums)
    {
        require(bytes(char).length == 1, 'Invalid char length');
        bytes1 c = bytes(char)[0];

        uint256 textLen = bytes(text).length;
        for (uint256 i = 0; i < textLen; ++i) {
            if (bytes(text)[i] == c) {
                ++nums;
            }
        }
    }

    /// @notice Split a string into two parts. The first occurrence of the delimiter
    /// is used to split the string into first and last.
    /// @param text The string to split
    /// @param delimiter The character to split on
    /// @return first last The two parts of the string
    function split(string memory text, string memory delimiter, uint256 occur)
        internal
        pure
        returns (string memory first, string memory last)
    {
        uint256  num = 0;
        if (occur == 0) occur = 1;
        require(bytes(delimiter).length == 1, 'Invalid delimiter length');
        bytes1 d = bytes(delimiter)[0];

        uint256 textLen = bytes(text).length;
        for (uint256 i = 0; i < textLen; ++i) {
            if (bytes(text)[i] == d) num ++;

            if (num == occur) {
                first = slice(text, 0, i);
                last = slice(text, i + 1, textLen);
                return (first, last);
            }
        }
    }

    function split(string memory text, string memory delimiter)
        internal
        pure
        returns (string memory first, string memory last)
    {
        return split(text, delimiter, 1);
    }    
}

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

Contract Security Audit

Contract ABI

API
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"commentId","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"string","name":"comment","type":"string"}],"name":"BatchComment","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"projectVintageTokenId","type":"uint256"}],"name":"BatchLinkedWithVintage","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"BatchMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"enum BatchStatus","name":"status","type":"uint8"}],"name":"BatchStatusUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"string","name":"serialNumber","type":"string"},{"indexed":false,"internalType":"uint256","name":"quantity","type":"uint256"}],"name":"BatchUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","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":false,"internalType":"string","name":"registry","type":"string"},{"indexed":false,"internalType":"bool","name":"isSupported","type":"bool"}],"name":"RegistrySupported","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newTokenId","type":"uint256"}],"name":"Split","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"tcc","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Tokenized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKENIZER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VERIFIER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VERSION_RELEASE_CANDIDATE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"string","name":"comment","type":"string"}],"name":"addComment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"batchTokenCounter","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"confirmBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"projectVintageTokenId","type":"uint256"}],"name":"confirmBatchWithVintage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"contractRegistry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"fractionalize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getBatchNFTData","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"enum BatchStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getConfirmationStatus","outputs":[{"internalType":"enum BatchStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getSerialNumber","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_contractRegistry","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"projectVintageTokenId","type":"uint256"}],"name":"linkWithVintage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"mintEmptyBatch","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"nftList","outputs":[{"internalType":"uint256","name":"projectVintageTokenId","type":"uint256"},{"internalType":"string","name":"serialNumber","type":"string"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"enum BatchStatus","name":"status","type":"uint8"},{"internalType":"string","name":"uri","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","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":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"string","name":"comment","type":"string"}],"name":"rejectApprovedWithComment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"rejectBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"string","name":"comment","type":"string"}],"name":"rejectWithComment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"serialNumberApproved","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"gateway","type":"string"}],"name":"setBaseURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"setCarbonCoreContractRegistry","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"string","name":"newSerialNumber","type":"string"},{"internalType":"uint256","name":"newQuantity","type":"uint256"}],"name":"setSerialandQuantity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"enum BatchStatus","name":"newStatus","type":"uint8"}],"name":"setStatusForDetokenizationOrRetirement","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"registry","type":"string"},{"internalType":"bool","name":"isSupported","type":"bool"}],"name":"setSupportedRegistry","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"setToPending","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"newTokenIdQuantity","type":"uint256"}],"name":"split","outputs":[{"internalType":"uint256","name":"newTokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"string","name":"serialNumber","type":"string"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"uint256","name":"projectVintageTokenId","type":"uint256"}],"name":"tokenize","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"serialNumber","type":"string"}],"name":"unsetSerialNumber","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"string","name":"serialNumber","type":"string"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"string","name":"uri","type":"string"}],"name":"updateBatchWithData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"}]

60a0604052306080523480156200001557600080fd5b506200002062000026565b620000e7565b600054610100900460ff1615620000935760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff90811614620000e5576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b608051615e786200011f600039600081816114e40152818161152401528181611e2a01528181611e6a0152611ffd0152615e786000f3fe6080604052600436106103385760003560e01c80635e9fae13116101b2578063a5c65963116100ed578063c8694d1211610090578063c8694d1214610a66578063c87b56dd14610a86578063d547741f14610aa6578063dff35e8314610ac6578063e7705db614610af5578063e985e9c514610b17578063f2fde38b14610b37578063ffa1ad7414610b5757600080fd5b8063a5c659631461096e578063aa7e56831461098e578063abf410e5146109ae578063b3057025146109cf578063b722e533146109e6578063b88d4fde14610a06578063c2170e5c14610a26578063c4d66de814610a4657600080fd5b80638456cb59116101555780638456cb59146108915780638a6166f0146108a65780638da5cb5b146108c657806391d14854146108e457806395d89b41146109045780639bd905f814610919578063a217fddf14610939578063a22cb4651461094e57600080fd5b80635e9fae13146107965780636352211e146107b65780636ca0b0d7146107d65780636d1f73d6146107eb57806370a082311461080b578063715018a61461082b57806375bea16614610840578063838b1da31461087157600080fd5b806334844b42116102825780634b19becc116102255780634b19becc146106b65780634f1ef286146106d65780634f6ccce7146106e95780634f8a317c1461070957806352d1902d1461072957806354d77ad91461073e57806355f804b31461075e5780635c975abb1461077e57600080fd5b806334844b42146105a5578063362ab1b9146105e157806336568abe146106015780633659cfe6146106215780633a484efd146106415780633b2b203e146106615780633f4ba83a1461068157806342842e0e1461069657600080fd5b80630c634e67116102ea5780630c634e67146104655780630f979c2814610485578063150b7a02146104c657806318160ddd146104ff57806323b872dd14610514578063248a9ca3146105345780632f2ff15d146105655780632f745c591461058557600080fd5b806301ffc9a71461033d57806302451414146103725780630605a334146103a057806306fdde03146103d4578063081812fc146103f6578063095ea7b3146104235780630c1902fe14610445575b600080fd5b34801561034957600080fd5b5061035d610358366004614e7c565b610b88565b60405190151581526020015b60405180910390f35b34801561037e57600080fd5b5061039261038d366004614ef6565b610bb3565b604051908152602001610369565b3480156103ac57600080fd5b506103927fe70d28ebd9d7d9a3dd77d46ae2481f301c80806f395b08de31d8e095b1c46cee81565b3480156103e057600080fd5b506103e96110ba565b6040516103699190614fb4565b34801561040257600080fd5b50610416610411366004614fc7565b61114c565b6040516103699190614fe0565b34801561042f57600080fd5b5061044361043e366004614ff4565b611173565b005b34801561045157600080fd5b50610443610460366004614fc7565b611288565b34801561047157600080fd5b50610443610480366004615020565b6112b3565b34801561049157600080fd5b506104b96104a0366004614fc7565b60009081526101c9602052604090206003015460ff1690565b604051610369919061507a565b3480156104d257600080fd5b506104e66104e1366004615088565b6112e0565b6040516001600160e01b03199091168152602001610369565b34801561050b57600080fd5b50609954610392565b34801561052057600080fd5b5061044361052f3660046150fa565b611333565b34801561054057600080fd5b5061039261054f366004614fc7565b600090815261012d602052604090206001015490565b34801561057157600080fd5b5061044361058036600461513b565b611357565b34801561059157600080fd5b506103926105a0366004614ff4565b61137d565b3480156105b157600080fd5b5061035d6105c0366004615257565b80516020818301810180516101c48252928201919093012091525460ff1681565b3480156105ed57600080fd5b506104436105fc366004615257565b611413565b34801561060d57600080fd5b5061044361061c36600461513b565b611460565b34801561062d57600080fd5b5061044361063c36600461528b565b6114da565b34801561064d57600080fd5b5061044361065c3660046152a8565b61159f565b34801561066d57600080fd5b5061044361067c3660046152d1565b6117c8565b34801561068d57600080fd5b506104436117ed565b3480156106a257600080fd5b506104436106b13660046150fa565b61133c565b3480156106c257600080fd5b506103926106d1366004615020565b61184f565b6104436106e4366004615320565b611e20565b3480156106f557600080fd5b50610392610704366004614fc7565b611ed5565b34801561071557600080fd5b50610443610724366004614fc7565b611f68565b34801561073557600080fd5b50610392611ff0565b34801561074a57600080fd5b5061044361075936600461528b565b61209e565b34801561076a57600080fd5b50610443610779366004615257565b6120c9565b34801561078a57600080fd5b5060fb5460ff1661035d565b3480156107a257600080fd5b506104436107b136600461536f565b6120e5565b3480156107c257600080fd5b506104166107d1366004614fc7565b6121ea565b3480156107e257600080fd5b50610392600181565b3480156107f757600080fd5b50610443610806366004615020565b61221f565b34801561081757600080fd5b5061039261082636600461528b565b612296565b34801561083757600080fd5b5061044361231c565b34801561084c57600080fd5b5061086061085b366004614fc7565b612330565b6040516103699594939291906153e5565b34801561087d57600080fd5b5061044361088c366004614fc7565b612478565b34801561089d57600080fd5b506104436124f0565b3480156108b257600080fd5b506104436108c1366004615423565b612552565b3480156108d257600080fd5b5060c9546001600160a01b0316610416565b3480156108f057600080fd5b5061035d6108ff36600461513b565b612691565b34801561091057600080fd5b506103e96126bd565b34801561092557600080fd5b506103e9610934366004614fc7565b6126cc565b34801561094557600080fd5b50610392600081565b34801561095a57600080fd5b50610443610969366004615461565b612772565b34801561097a57600080fd5b5061039261098936600461528b565b61277d565b34801561099a57600080fd5b506104436109a9366004615423565b612791565b3480156109ba57600080fd5b506101c854610416906001600160a01b031681565b3480156109db57600080fd5b506103926101c35481565b3480156109f257600080fd5b50610443610a01366004614fc7565b61279a565b348015610a1257600080fd5b50610443610a2136600461548f565b6127c2565b348015610a3257600080fd5b50610443610a413660046154ee565b61283a565b348015610a5257600080fd5b50610443610a6136600461528b565b61290e565b348015610a7257600080fd5b50610443610a81366004615423565b612aa7565b348015610a9257600080fd5b506103e9610aa1366004614fc7565b612ab8565b348015610ab257600080fd5b50610443610ac136600461513b565b612bf2565b348015610ad257600080fd5b50610ae6610ae1366004614fc7565b612c18565b60405161036993929190615534565b348015610b0157600080fd5b50610392600080516020615e2383398151915281565b348015610b2357600080fd5b5061035d610b3236600461554f565b612c83565b348015610b4357600080fd5b50610443610b5236600461528b565b612cb1565b348015610b6357600080fd5b506103e9604051806040016040528060058152602001640312e352e360dc1b81525081565b60006001600160e01b03198216637965db0b60e01b1480610bad5750610bad82612d27565b92915050565b6000610bbd612d77565b610be67fe70d28ebd9d7d9a3dd77d46ae2481f301c80806f395b08de31d8e095b1c46cee612db2565b610bf03087612df0565b9050610bfc8183612e70565b6101c860009054906101000a90046001600160a01b03166001600160a01b031663fe5d6fe56040518163ffffffff1660e01b8152600401602060405180830381865afa158015610c50573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c74919061557d565b604051633218026360e11b815260048101849052602481018390526001600160a01b03919091169063643004c690604401600060405180830381600087803b158015610cbf57600080fd5b505af1158015610cd3573d6000803e3d6000fd5b50505050610d198186868080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250889250612ed0915050565b610d2281612ff1565b6101c8546040805163fe5d6fe560e01b815290516000926001600160a01b03169163fe5d6fe59160048083019260209291908290030181865afa158015610d6d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d91919061557d565b604051633139cbb560e11b8152600481018490529091506001600160a01b03821690636273976a90602401600060405180830381600087803b158015610dd657600080fd5b505af1158015610dea573d6000803e3d6000fd5b505050506000610df983613140565b90506001600160a01b038116610e42576040805180820182526002815261034360f41b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60405180910390fd5b6000816001600160a01b0316633c31175e6040518163ffffffff1660e01b8152600401600060405180830381865afa158015610e82573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610eaa91908101906155df565b90506101ca81604051610ebd9190615613565b9081526040519081900360200190205460ff16610f04576040805180820182526002815261343160f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6040516370a0823160e01b81526000906001600160a01b038416906370a0823190610f33903090600401614fe0565b602060405180830381865afa158015610f50573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f74919061562f565b9050610f913084876040518060200160405280600081525061334d565b6040516370a0823160e01b81526000906001600160a01b038516906370a0823190610fc0903090600401614fe0565b602060405180830381865afa158015610fdd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611001919061562f565b9050600061100f838361565e565b9050806000036110495760408051808201825260028152611a1960f11b6020820152905162461bcd60e51b8152610e399190600401614fb4565b61105d6001600160a01b0386168d83613380565b604080518881526001600160a01b038781166020830152918101839052908d16907ffc57e3cd27cd7fbd6b9bfca9a3ab5dc6414002431c17d40274c60bbfbc672a2d9060600160405180910390a250505050505095945050505050565b6060606580546110c990615675565b80601f01602080910402602001604051908101604052809291908181526020018280546110f590615675565b80156111425780601f1061111757610100808354040283529160200191611142565b820191906000526020600020905b81548152906001019060200180831161112557829003601f168201915b5050505050905090565b6000611157826133d2565b506000908152606960205260409020546001600160a01b031690565b600061117e826121ea565b9050806001600160a01b0316836001600160a01b0316036111eb5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610e39565b336001600160a01b038216148061120757506112078133612c83565b6112795760405162461bcd60e51b815260206004820152603d60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c0000006064820152608401610e39565b61128383836133f7565b505050565b611290612d77565b6112a7600080516020615e23833981519152612db2565b6112b081612ff1565b50565b6112bb612d77565b6112d2600080516020615e23833981519152612db2565b6112dc8282612e70565b5050565b60006001600160a01b03851615611321576040805180820182526002815261343360f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b50630a85bd0160e11b95945050505050565b61133c81613465565b611283838383604051806020016040528060008152506127c2565b600082815261012d6020526040902060010154611373816134a3565b61128383836134ad565b600061138883612296565b82106113ea5760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610e39565b506001600160a01b03919091166000908152609760209081526040808320938352929052205490565b61142a600080516020615e23833981519152612db2565b60006101c48260405161143d9190615613565b908152604051908190036020019020805491151560ff1990921691909117905550565b6001600160a01b03811633146114d05760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610e39565b6112dc8282613534565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036115225760405162461bcd60e51b8152600401610e39906156af565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031661155461359c565b6001600160a01b03161461157a5760405162461bcd60e51b8152600401610e39906156fb565b611583816135b8565b604080516000808252602082019092526112b0918391906135c0565b6115a7612d77565b6115af61372b565b60006115ba836121ea565b6101c854604051633a37b16d60e11b81529192506001600160a01b03169063746f62da906115ec908490600401614fe0565b602060405180830381865afa158015611609573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061162d9190615757565b611661576040805180820182526002815261191b60f11b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008381526101c96020526040902060039081015460ff169083600681111561168c5761168c615042565b14806116a9575060058360068111156116a7576116a7615042565b145b156116be576116b98160026137dc565b6117b8565b60048360068111156116d2576116d2615042565b036116e2576116b98160036137dc565b60068360068111156116f6576116f6615042565b03611706576116b98160056137dc565b600283600681111561171a5761171a615042565b0361178857600381600681111561173357611733615042565b141580156117535750600581600681111561175057611750615042565b14155b156116b95760408051808201825260028152610d0d60f21b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60408051808201825260028152610d0d60f21b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6117c28484613835565b50505050565b6117d0612d77565b6117d9836138ab565b6117e283613916565b611283838383612ed0565b6101c8546001600160a01b031661180c60c9546001600160a01b031690565b6001600160a01b03821633148061182b57506001600160a01b03811633145b6118475760405162461bcd60e51b8152600401610e3990615774565b6112dc613972565b6000611859612d77565b61186161372b565b60008381526101c960205260408120600101805461187e90615675565b80601f01602080910402602001604051908101604052809291908181526020018280546118aa90615675565b80156118f75780601f106118cc576101008083540402835291602001916118f7565b820191906000526020600020905b8154815290600101906020018083116118da57829003601f168201915b505050505090506000611909856121ea565b90506001600160a01b038116611949576040805180820182526002815261034360f41b6020820152905162461bcd60e51b8152610e399190600401614fb4565b600080826001600160a01b0316634e395ea885886040518363ffffffff1660e01b815260040161197a9291906157b9565b600060405180830381865afa158015611997573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526119bf91908101906157db565b6101c854604051633a37b16d60e11b81529294509092506001600160a01b03169063746f62da906119f4908690600401614fe0565b602060405180830381865afa158015611a11573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a359190615757565b611a69576040805180820182526002815261191b60f11b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008781526101c9602052604090206003015460ff166005816006811115611a9357611a93615042565b14158015611ab357506003816006811115611ab057611ab0615042565b14155b15611ae8576040805180820182526002815261033360f41b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008881526101c960205260409020600201548710611b31576040805180820182526002815261353560f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008881526101c9602052604081206001018054611b4e90615675565b80601f0160208091040260200160405190810160405280929190818152602001828054611b7a90615675565b8015611bc75780601f10611b9c57610100808354040283529160200191611bc7565b820191906000526020600020905b815481529060010190602001808311611baa57829003601f168201915b50505050509050611bfb89848a6101c960008e815260200190815260200160002060020154611bf6919061565e565b612ed0565b60016101c484604051611c0e9190615613565b908152604051908190036020019020805491151560ff19909216919091179055611c383086612df0565b9650611c4587858a612ed0565b60016101c485604051611c589190615613565b908152604051908190036020018120805492151560ff19909316929092179091556000906101c490611c8b908490615613565b9081526040805160209281900383019020805460ff19169315159390931790925560008b81526101c99091522054611cc4908890612e70565b6101c860009054906101000a90046001600160a01b03166001600160a01b031663fe5d6fe56040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d3c919061557d565b60008a81526101c9602052604090819020549051633218026360e11b81526001600160a01b03929092169163643004c691611d84918b90600401918252602082015260400190565b600060405180830381600087803b158015611d9e57600080fd5b505af1158015611db2573d6000803e3d6000fd5b50505050611dc08783613835565b611ddb3086896040518060200160405280600081525061334d565b604080518a8152602081018990527fb20b10d17e0e2505af41fd37a6a1b46824a76d7d940afce430c7ee4aba19a959910160405180910390a150505050505092915050565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163003611e685760405162461bcd60e51b8152600401610e39906156af565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316611e9a61359c565b6001600160a01b031614611ec05760405162461bcd60e51b8152600401610e39906156fb565b611ec9826135b8565b6112dc828260016135c0565b6000611ee060995490565b8210611f435760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610e39565b60998281548110611f5657611f56615834565b90600052602060002001549050919050565b611f70612d77565b611f87600080516020615e23833981519152612db2565b600160008281526101c9602052604090206003015460ff166006811115611fb057611fb0615042565b14611fe5576040805180820182526002815261333560f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6112b0816000613835565b6000306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461208b5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c6044820152771b1959081d1a1c9bdd59da0819195b1959d85d1958d85b1b60421b6064820152608401610e39565b50600080516020615ddc83398151915290565b6120a66139be565b6101c880546001600160a01b0319166001600160a01b0392909216919091179055565b6120d16139be565b80516112dc906101c7906020840190614dcd565b6120ed612d77565b6120f6846138ab565b6120ff84613916565b61210a848484612ed0565b60008481526101c96020526040902060040180546121b9919061212c90615675565b80601f016020809104026020016040519081016040528092919081815260200182805461215890615675565b80156121a55780601f1061217a576101008083540402835291602001916121a5565b820191906000526020600020905b81548152906001019060200180831161218857829003601f168201915b505050505082613a1890919063ffffffff16565b6117c25760008481526101c96020908152604090912082516121e392600490920191840190614dcd565b5050505050565b6000818152606760205260408120546001600160a01b031680610bad5760405162461bcd60e51b8152600401610e399061584a565b612227612d77565b61223e600080516020615e23833981519152612db2565b60008281526101c9602052604090205415612283576040805180820182526002815261199b60f11b6020820152905162461bcd60e51b8152610e399190600401614fb4565b61228d8282612e70565b6112dc82612ff1565b60006001600160a01b0382166123005760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b6064820152608401610e39565b506001600160a01b031660009081526068602052604090205490565b6123246139be565b61232e6000613a3e565b565b6101c9602052600090815260409020805460018201805491929161235390615675565b80601f016020809104026020016040519081016040528092919081815260200182805461237f90615675565b80156123cc5780601f106123a1576101008083540402835291602001916123cc565b820191906000526020600020905b8154815290600101906020018083116123af57829003601f168201915b50505050600283015460038401546004850180549495929460ff9092169350906123f590615675565b80601f016020809104026020016040519081016040528092919081815260200182805461242190615675565b801561246e5780601f106124435761010080835404028352916020019161246e565b820191906000526020600020905b81548152906001019060200180831161245157829003601f168201915b5050505050905085565b612480612d77565b612497600080516020615e23833981519152612db2565b6124a081613916565b60008181526101c9602052604080822090516101c4916124c59160019091019061587c565b908152604051908190036020019020805491151560ff199092169190911790556112b0816001613835565b6101c8546001600160a01b031661250f60c9546001600160a01b031690565b6001600160a01b03821633148061252e57506001600160a01b03811633145b61254a5760405162461bcd60e51b8152600401610e3990615774565b6112dc613a90565b61255a612d77565b612571600080516020615e23833981519152612db2565b600260008381526101c9602052604090206003015460ff16600681111561259a5761259a615042565b146125cf576040805180820182526002815261323760f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6101c8546001600160a01b031663746f62da6125ea846121ea565b6040518263ffffffff1660e01b81526004016126069190614fe0565b602060405180830381865afa158015612623573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126479190615757565b1561267c5760408051808201825260028152610ccd60f21b6020820152905162461bcd60e51b8152610e399190600401614fb4565b612687826001613835565b6112dc8282613acd565b600091825261012d602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6060606680546110c990615675565b60008181526101c9602052604090206001018054606091906126ed90615675565b80601f016020809104026020016040519081016040528092919081815260200182805461271990615675565b80156127665780601f1061273b57610100808354040283529160200191612766565b820191906000526020600020905b81548152906001019060200180831161274957829003601f168201915b50505050509050919050565b6112dc338383613b7c565b6000612787612d77565b610bad8283612df0565b612687826138ab565b6127a381613465565b6112b0336127b083613140565b83604051806020016040528060008152505b6127cc3383613c46565b61282e5760405162461bcd60e51b815260206004820152602d60248201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560448201526c1c881bdc88185c1c1c9bdd9959609a1b6064820152608401610e39565b6117c28484848461334d565b6128426139be565b8015156101ca836040516128569190615613565b9081526040519081900360200190205460ff161515036128a0576040805180820182526002815261323360f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b806101ca836040516128b29190615613565b908152604051908190036020018120805492151560ff19909316929092179091557fd1ccc86b3ecebee24bd889691724999af4141f85d8bf0c59a60112e18173f6a0906129029084908490615917565b60405180910390a15050565b600054610100900460ff161580801561292e5750600054600160ff909116105b806129485750303b158015612948575060005460ff166001145b6129ab5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610e39565b6000805460ff1916600117905580156129ce576000805461ff0019166101001790555b6129d6613ca5565b612a1e6040518060600160405280602a8152602001615db2602a91396040518060400160405280600e81526020016d21a0a92127a721a7a92296a1a7a160911b815250613ccc565b612a26613d1a565b612a2e613d4a565b612a36613ca5565b612a3e613ca5565b6101c880546001600160a01b0319166001600160a01b038416179055612a656000336134ad565b80156112dc576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001612902565b612aaf612d77565b61268782612478565b6060612ac382613d7d565b612af7576040805180820182526002815261323960f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008281526101c9602052604081206004018054612b1490615675565b80601f0160208091040260200160405190810160405280929190818152602001828054612b4090615675565b8015612b8d5780601f10612b6257610100808354040283529160200191612b8d565b820191906000526020600020905b815481529060010190602001808311612b7057829003601f168201915b50505050509050612b9c613d9a565b51600003612baa5792915050565b805115612be257612bb9613d9a565b81604051602001612bcb92919061593b565b604051602081830303815290604052915050919050565b612beb83613daa565b9392505050565b600082815261012d6020526040902060010154612c0e816134a3565b6112838383613534565b6000806000612c2684613d7d565b612c5a576040805180820182526002815261323960f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b50505060009081526101c96020526040902080546002820154600390920154909260ff90911690565b6001600160a01b039182166000908152606a6020908152604080832093909416825291909152205460ff1690565b612cb96139be565b6001600160a01b038116612d1e5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610e39565b6112b081613a3e565b60006001600160e01b031982166380ac58cd60e01b1480612d5857506001600160e01b03198216635b5e139f60e01b145b80610bad57506301ffc9a760e01b6001600160e01b0319831614610bad565b60fb5460ff161561232e576040805180820182526002815261066760f31b6020820152905162461bcd60e51b8152610e399190600401614fb4565b612dbc8133612691565b6112b0576040805180820182526002815261333960f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6101c3805460010190819055612e068382613dfa565b60008181526101c96020908152604080832060038101805460ff191690556002019290925581516001600160a01b03851681529081018390527f6174e73d7eb2fee6c482f87f81961b83cfa577f50c963bd1516f282497260fcd910160405180910390a192915050565b6101c854612e87906001600160a01b031682613e14565b60008281526101c9602090815260409182902083905581518481529081018390527fe16bc7d72176e78ab56068f816d35b70dfcb41bb492ca0da0bcfc064b2439f6c9101612902565b6101c482604051612ee19190615613565b9081526040519081900360200190205460ff1615612f29576040805180820182526002815261199960f11b6020820152905162461bcd60e51b8152610e399190600401614fb4565b80600003612f61576040805180820182526002815261353560f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008381526101c9602090815260409091208351612f8792600190920191850190614dcd565b5060008381526101c9602052604090819020600281018054908490556003909101549151909160ff16907fd680d89587cd5af07a9a0280107488c8b2db5f86aec57b869f0933fb4a99c05b90612fe29087908790879061596a565b60405180910390a15050505050565b612ffa81613d7d565b61302e576040805180820182526002815261323960f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b61303781613916565b60008181526101c96020526040812054900361307d576040805180820182526002815261333160f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6101c46101c960008381526020019081526020016000206001016040516130a4919061587c565b9081526040519081900360200190205460ff16156130ec576040805180820182526002815261199960f11b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60016101c46101c96000848152602001908152602001600020600101604051613115919061587c565b908152604051908190036020019020805491151560ff199092169190911790556112b0816002613835565b60008181526101c960209081526040808320546101c8548251630505792b60e51b8152925191936001600160a01b03909116928592849263a0af256092600480820193918290030181865afa15801561319d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131c1919061557d565b60405163056efc1d60e21b8152600481018590529091506000906001600160a01b038316906315bbf07490602401600060405180830381865afa15801561320c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261323491908101906159aa565b6101608101518051919250906000036132655750604080518082019091526005815264766572726160d81b60208201525b604051630d2c231160e01b81526000906001600160a01b03861690630d2c231190613294908590600401614fb4565b602060405180830381865afa1580156132b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132d5919061557d565b6040516317a04f4f60e21b8152600481018890529091506001600160a01b03821690635e813d3c90602401602060405180830381865afa15801561331d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613341919061557d565b98975050505050505050565b613358848484613f42565b613364848484846140b3565b6117c25760405162461bcd60e51b8152600401610e3990615b34565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526112839084906141b4565b6133db81613d7d565b6112b05760405162461bcd60e51b8152600401610e399061584a565b600081815260696020526040902080546001600160a01b0319166001600160a01b038416908117909155819061342c826121ea565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b61346f3382613c46565b6112b0576040805180820182526002815261333760f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6112b08133614289565b6134b78282612691565b6112dc57600082815261012d602090815260408083206001600160a01b03851684529091529020805460ff191660011790556134f03390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b61353e8282612691565b156112dc57600082815261012d602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600080516020615ddc833981519152546001600160a01b031690565b6112b06139be565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156135f357611283836142e2565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561364d575060408051601f3d908101601f1916820190925261364a9181019061562f565b60015b6136b05760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610e39565b600080516020615ddc833981519152811461371f5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610e39565b5061128383838361437e565b6101c8546040805163a370e16960e01b815290516000926001600160a01b03169163a370e1699160048083019260209291908290030181865afa158015613776573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061379a919061557d565b90506001600160a01b03811633146112b0576040805180820182526002815261333960f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b8060068111156137ee576137ee615042565b82600681111561380057613800615042565b146112dc5760408051808201825260028152610d0d60f21b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008281526101c960205260409020600301805460ff811691839160ff1916600183600681111561386857613868615042565b02179055507f132d48207d6b10897066f0b98b98325907e8a0d491390e141c7377772b47a9d6838360405161389e929190615b86565b60405180910390a1505050565b336138b5826121ea565b6001600160a01b0316141580156138e157506138df600080516020615e2383398151915233612691565b155b156112b05760408051808201825260028152610c8d60f21b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008181526101c9602052604081206003015460ff16600681111561393d5761393d615042565b146112b0576040805180820182526002815261033360f41b6020820152905162461bcd60e51b8152610e399190600401614fb4565b61397a6143a3565b60fb805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516139b49190614fe0565b60405180910390a1565b60c9546001600160a01b0316331461232e5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610e39565b600081518351148015612beb575081805190602001208380519060200120149392505050565b60c980546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b613a986143ec565b60fb805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586139a73390565b60008281526101c96020908152604082206005018054600181018255908352918190208351613b03939190910191840190614dcd565b5060008281526101c96020908152604080832060068101805460018101825590855292842090920180546001600160a01b031916339081179091559285905260059091015490517f08740f41d4d7e855ea188e78846ad3e8665dd6d0b088f899025991c1ee8c2c47926129029286929091908690615b9a565b816001600160a01b0316836001600160a01b031603613bd95760405162461bcd60e51b815260206004820152601960248201527822a9219b99189d1030b8383937bb32903a379031b0b63632b960391b6044820152606401610e39565b6001600160a01b038381166000818152606a6020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b600080613c52836121ea565b9050806001600160a01b0316846001600160a01b03161480613c795750613c798185612c83565b80613c9d5750836001600160a01b0316613c928461114c565b6001600160a01b0316145b949350505050565b600054610100900460ff1661232e5760405162461bcd60e51b8152600401610e3990615bc7565b600054610100900460ff16613cf35760405162461bcd60e51b8152600401610e3990615bc7565b8151613d06906065906020850190614dcd565b508051611283906066906020840190614dcd565b600054610100900460ff16613d415760405162461bcd60e51b8152600401610e3990615bc7565b61232e33613a3e565b600054610100900460ff16613d715760405162461bcd60e51b8152600401610e3990615bc7565b60fb805460ff19169055565b6000908152606760205260409020546001600160a01b0316151590565b60606101c780546110c990615675565b6060613db5826133d2565b6000613dbf613d9a565b90506000815111613ddf5760405180602001604052806000815250612beb565b80613de984614432565b604051602001612bcb92919061593b565b6112dc8282604051806020016040528060008152506144c4565b6000826001600160a01b031663a0af25606040518163ffffffff1660e01b8152600401602060405180830381865afa158015613e54573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e78919061557d565b604051634f558e7960e01b8152600481018490529091506001600160a01b03821690634f558e7990602401602060405180830381865afa158015613ec0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ee49190615757565b6112835760405162461bcd60e51b815260206004820152602960248201527f436172626f6e2070726f6a6563742076696e7461676520646f6573206e6f74206044820152681e595d08195e1a5cdd60ba1b6064820152608401610e39565b826001600160a01b0316613f55826121ea565b6001600160a01b031614613f7b5760405162461bcd60e51b8152600401610e3990615c12565b6001600160a01b038216613fdd5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610e39565b613fea83838360016144f7565b826001600160a01b0316613ffd826121ea565b6001600160a01b0316146140235760405162461bcd60e51b8152600401610e3990615c12565b600081815260696020908152604080832080546001600160a01b03199081169091556001600160a01b0387811680865260688552838620805460001901905590871680865283862080546001019055868652606790945282852080549092168417909155905184937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b60006001600160a01b0384163b156141a957604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906140f7903390899088908890600401615c57565b6020604051808303816000875af1925050508015614132575060408051601f3d908101601f1916820190925261412f91810190615c8a565b60015b61418f573d808015614160576040519150601f19603f3d011682016040523d82523d6000602084013e614165565b606091505b5080516000036141875760405162461bcd60e51b8152600401610e3990615b34565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050613c9d565b506001949350505050565b6000614209826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661450b9092919063ffffffff16565b905080516000148061422a57508080602001905181019061422a9190615757565b6112835760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610e39565b6142938282612691565b6112dc576142a08161451a565b6142ab83602061452c565b6040516020016142bc929190615ca7565b60408051601f198184030181529082905262461bcd60e51b8252610e3991600401614fb4565b6001600160a01b0381163b61434f5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610e39565b600080516020615ddc83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b614387836146c7565b6000825111806143945750805b15611283576117c28383614707565b60fb5460ff1661232e5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610e39565b60fb5460ff161561232e5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610e39565b6060600061443f8361472c565b60010190506000816001600160401b0381111561445e5761445e61516b565b6040519080825280601f01601f191660200182016040528015614488576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a850494508461449257509392505050565b6144ce8383614804565b6144db60008484846140b3565b6112835760405162461bcd60e51b8152600401610e3990615b34565b6144ff612d77565b6117c28484848461491f565b6060613c9d8484600085614a4c565b6060610bad6001600160a01b03831660145b6060600061453b836002615d16565b614546906002615d35565b6001600160401b0381111561455d5761455d61516b565b6040519080825280601f01601f191660200182016040528015614587576020820181803683370190505b509050600360fc1b816000815181106145a2576145a2615834565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106145d1576145d1615834565b60200101906001600160f81b031916908160001a90535060006145f5846002615d16565b614600906001615d35565b90505b6001811115614678576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061463457614634615834565b1a60f81b82828151811061464a5761464a615834565b60200101906001600160f81b031916908160001a90535060049490941c9361467181615d4d565b9050614603565b508315612beb5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610e39565b6146d0816142e2565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6060612beb8383604051806060016040528060278152602001615dfc60279139614b27565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b831061476b5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310614797576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106147b557662386f26fc10000830492506010015b6305f5e10083106147cd576305f5e100830492506008015b61271083106147e157612710830492506004015b606483106147f3576064830492506002015b600a8310610bad5760010192915050565b6001600160a01b03821661485a5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610e39565b61486381613d7d565b156148805760405162461bcd60e51b8152600401610e3990615d64565b61488e6000838360016144f7565b61489781613d7d565b156148b45760405162461bcd60e51b8152600401610e3990615d64565b6001600160a01b038216600081815260686020908152604080832080546001019055848352606790915280822080546001600160a01b0319168417905551839291907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b600181111561498e5760405162461bcd60e51b815260206004820152603560248201527f455243373231456e756d657261626c653a20636f6e7365637574697665207472604482015274185b9cd9995c9cc81b9bdd081cdd5c1c1bdc9d1959605a1b6064820152608401610e39565b816001600160a01b0385166149ea576149e581609980546000838152609a60205260408120829055600182018355919091527f72a152ddfb8e864297c917af52ea6c1c68aead0fee1a62673fcc7e0c94979d000155565b614a0d565b836001600160a01b0316856001600160a01b031614614a0d57614a0d8582614b9f565b6001600160a01b038416614a2957614a2481614c3c565b6121e3565b846001600160a01b0316846001600160a01b0316146121e3576121e38482614ceb565b606082471015614aad5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610e39565b600080866001600160a01b03168587604051614ac99190615613565b60006040518083038185875af1925050503d8060008114614b06576040519150601f19603f3d011682016040523d82523d6000602084013e614b0b565b606091505b5091509150614b1c87838387614d2f565b979650505050505050565b6060600080856001600160a01b031685604051614b449190615613565b600060405180830381855af49150503d8060008114614b7f576040519150601f19603f3d011682016040523d82523d6000602084013e614b84565b606091505b5091509150614b9586838387614d2f565b9695505050505050565b60006001614bac84612296565b614bb6919061565e565b600083815260986020526040902054909150808214614c09576001600160a01b03841660009081526097602090815260408083208584528252808320548484528184208190558352609890915290208190555b5060009182526098602090815260408084208490556001600160a01b039094168352609781528383209183525290812055565b609954600090614c4e9060019061565e565b6000838152609a602052604081205460998054939450909284908110614c7657614c76615834565b906000526020600020015490508060998381548110614c9757614c97615834565b6000918252602080832090910192909255828152609a90915260408082208490558582528120556099805480614ccf57614ccf615d9b565b6001900381819060005260206000200160009055905550505050565b6000614cf683612296565b6001600160a01b039093166000908152609760209081526040808320868452825280832085905593825260989052919091209190915550565b60608315614d9e578251600003614d97576001600160a01b0385163b614d975760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610e39565b5081613c9d565b613c9d8383815115614db35781518083602001fd5b8060405162461bcd60e51b8152600401610e399190614fb4565b828054614dd990615675565b90600052602060002090601f016020900481019282614dfb5760008555614e41565b82601f10614e1457805160ff1916838001178555614e41565b82800160010185558215614e41579182015b82811115614e41578251825591602001919060010190614e26565b50614e4d929150614e51565b5090565b5b80821115614e4d5760008155600101614e52565b6001600160e01b0319811681146112b057600080fd5b600060208284031215614e8e57600080fd5b8135612beb81614e66565b6001600160a01b03811681146112b057600080fd5b60008083601f840112614ec057600080fd5b5081356001600160401b03811115614ed757600080fd5b602083019150836020828501011115614eef57600080fd5b9250929050565b600080600080600060808688031215614f0e57600080fd5b8535614f1981614e99565b945060208601356001600160401b03811115614f3457600080fd5b614f4088828901614eae565b9699909850959660408101359660609091013595509350505050565b60005b83811015614f77578181015183820152602001614f5f565b838111156117c25750506000910152565b60008151808452614fa0816020860160208601614f5c565b601f01601f19169290920160200192915050565b602081526000612beb6020830184614f88565b600060208284031215614fd957600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6000806040838503121561500757600080fd5b823561501281614e99565b946020939093013593505050565b6000806040838503121561503357600080fd5b50508035926020909101359150565b634e487b7160e01b600052602160045260246000fd5b6007811061507657634e487b7160e01b600052602160045260246000fd5b9052565b60208101610bad8284615058565b6000806000806000608086880312156150a057600080fd5b85356150ab81614e99565b945060208601356150bb81614e99565b93506040860135925060608601356001600160401b038111156150dd57600080fd5b6150e988828901614eae565b969995985093965092949392505050565b60008060006060848603121561510f57600080fd5b833561511a81614e99565b9250602084013561512a81614e99565b929592945050506040919091013590565b6000806040838503121561514e57600080fd5b82359150602083013561516081614e99565b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b60405161018081016001600160401b03811182821017156151a4576151a461516b565b60405290565b604051601f8201601f191681016001600160401b03811182821017156151d2576151d261516b565b604052919050565b60006001600160401b038211156151f3576151f361516b565b50601f01601f191660200190565b600082601f83011261521257600080fd5b8135615225615220826151da565b6151aa565b81815284602083860101111561523a57600080fd5b816020850160208301376000918101602001919091529392505050565b60006020828403121561526957600080fd5b81356001600160401b0381111561527f57600080fd5b613c9d84828501615201565b60006020828403121561529d57600080fd5b8135612beb81614e99565b600080604083850312156152bb57600080fd5b8235915060208301356007811061516057600080fd5b6000806000606084860312156152e657600080fd5b8335925060208401356001600160401b0381111561530357600080fd5b61530f86828701615201565b925050604084013590509250925092565b6000806040838503121561533357600080fd5b823561533e81614e99565b915060208301356001600160401b0381111561535957600080fd5b61536585828601615201565b9150509250929050565b6000806000806080858703121561538557600080fd5b8435935060208501356001600160401b03808211156153a357600080fd5b6153af88838901615201565b94506040870135935060608701359150808211156153cc57600080fd5b506153d987828801615201565b91505092959194509250565b85815260a0602082015260006153fe60a0830187614f88565b8560408401526154116060840186615058565b82810360808401526133418185614f88565b6000806040838503121561543657600080fd5b8235915060208301356001600160401b0381111561535957600080fd5b80151581146112b057600080fd5b6000806040838503121561547457600080fd5b823561547f81614e99565b9150602083013561516081615453565b600080600080608085870312156154a557600080fd5b84356154b081614e99565b935060208501356154c081614e99565b92506040850135915060608501356001600160401b038111156154e257600080fd5b6153d987828801615201565b6000806040838503121561550157600080fd5b82356001600160401b0381111561551757600080fd5b61552385828601615201565b925050602083013561516081615453565b8381526020810183905260608101613c9d6040830184615058565b6000806040838503121561556257600080fd5b823561556d81614e99565b9150602083013561516081614e99565b60006020828403121561558f57600080fd5b8151612beb81614e99565b600082601f8301126155ab57600080fd5b81516155b9615220826151da565b8181528460208386010111156155ce57600080fd5b613c9d826020830160208701614f5c565b6000602082840312156155f157600080fd5b81516001600160401b0381111561560757600080fd5b613c9d8482850161559a565b60008251615625818460208701614f5c565b9190910192915050565b60006020828403121561564157600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008282101561567057615670615648565b500390565b600181811c9082168061568957607f821691505b6020821081036156a957634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b805161575281615453565b919050565b60006020828403121561576957600080fd5b8151612beb81615453565b60208082526025908201527f43616c6c6572206973206e6f74207468652072656769737472792c206e6f722060408201526437bbb732b960d91b606082015260800190565b6040815260006157cc6040830185614f88565b90508260208301529392505050565b600080604083850312156157ee57600080fd5b82516001600160401b038082111561580557600080fd5b6158118683870161559a565b9350602085015191508082111561582757600080fd5b506153658582860161559a565b634e487b7160e01b600052603260045260246000fd5b602080825260189082015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b604082015260600190565b600080835481600182811c91508083168061589857607f831692505b602080841082036158b757634e487b7160e01b86526022600452602486fd5b8180156158cb57600181146158dc57615909565b60ff19861689528489019650615909565b60008a81526020902060005b868110156159015781548b8201529085019083016158e8565b505084890196505b509498975050505050505050565b60408152600061592a6040830185614f88565b905082151560208301529392505050565b6000835161594d818460208801614f5c565b835190830190615961818360208801614f5c565b01949350505050565b8381526060602082015260006159836060830185614f88565b9050826040830152949350505050565b80516001600160401b038116811461575257600080fd5b6000602082840312156159bc57600080fd5b81516001600160401b03808211156159d357600080fd5b9083019061018082860312156159e857600080fd5b6159f0615181565b8251828111156159ff57600080fd5b615a0b8782860161559a565b825250615a1a60208401615993565b6020820152615a2b60408401615993565b604082015260608301516060820152615a4660808401615993565b6080820152615a5760a08401615747565b60a0820152615a6860c08401615747565b60c082015260e083015182811115615a7f57600080fd5b615a8b8782860161559a565b60e0830152506101008084015183811115615aa557600080fd5b615ab18882870161559a565b8284015250506101208084015183811115615acb57600080fd5b615ad78882870161559a565b8284015250506101408084015183811115615af157600080fd5b615afd8882870161559a565b8284015250506101608084015183811115615b1757600080fd5b615b238882870161559a565b918301919091525095945050505050565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b82815260408101612beb6020830184615058565b84815283602082015260018060a01b0383166040820152608060608201526000614b956080830184614f88565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60208082526025908201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060408201526437bbb732b960d91b606082015260800190565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090614b9590830184614f88565b600060208284031215615c9c57600080fd5b8151612beb81614e66565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260008351615cd9816017850160208801614f5c565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351615d0a816028840160208801614f5c565b01602801949350505050565b6000816000190483118215151615615d3057615d30615648565b500290565b60008219821115615d4857615d48615648565b500190565b600081615d5c57615d5c615648565b506000190190565b6020808252601c908201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604082015260600190565b634e487b7160e01b600052603160045260246000fdfe436172626f6e436f72652050726f746f636f6c3a20436172626f6e204f66667365742042617463686573360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c65640ce23c3e399818cfee81a7ab0880f714e53d7672b08df0fa62f2843416e1ea09a26469706673582212201971fa13705c575a623b224717871037d9cb3e112b75de082aeacd0080b4810464736f6c634300080e0033

Deployed Bytecode

0x6080604052600436106103385760003560e01c80635e9fae13116101b2578063a5c65963116100ed578063c8694d1211610090578063c8694d1214610a66578063c87b56dd14610a86578063d547741f14610aa6578063dff35e8314610ac6578063e7705db614610af5578063e985e9c514610b17578063f2fde38b14610b37578063ffa1ad7414610b5757600080fd5b8063a5c659631461096e578063aa7e56831461098e578063abf410e5146109ae578063b3057025146109cf578063b722e533146109e6578063b88d4fde14610a06578063c2170e5c14610a26578063c4d66de814610a4657600080fd5b80638456cb59116101555780638456cb59146108915780638a6166f0146108a65780638da5cb5b146108c657806391d14854146108e457806395d89b41146109045780639bd905f814610919578063a217fddf14610939578063a22cb4651461094e57600080fd5b80635e9fae13146107965780636352211e146107b65780636ca0b0d7146107d65780636d1f73d6146107eb57806370a082311461080b578063715018a61461082b57806375bea16614610840578063838b1da31461087157600080fd5b806334844b42116102825780634b19becc116102255780634b19becc146106b65780634f1ef286146106d65780634f6ccce7146106e95780634f8a317c1461070957806352d1902d1461072957806354d77ad91461073e57806355f804b31461075e5780635c975abb1461077e57600080fd5b806334844b42146105a5578063362ab1b9146105e157806336568abe146106015780633659cfe6146106215780633a484efd146106415780633b2b203e146106615780633f4ba83a1461068157806342842e0e1461069657600080fd5b80630c634e67116102ea5780630c634e67146104655780630f979c2814610485578063150b7a02146104c657806318160ddd146104ff57806323b872dd14610514578063248a9ca3146105345780632f2ff15d146105655780632f745c591461058557600080fd5b806301ffc9a71461033d57806302451414146103725780630605a334146103a057806306fdde03146103d4578063081812fc146103f6578063095ea7b3146104235780630c1902fe14610445575b600080fd5b34801561034957600080fd5b5061035d610358366004614e7c565b610b88565b60405190151581526020015b60405180910390f35b34801561037e57600080fd5b5061039261038d366004614ef6565b610bb3565b604051908152602001610369565b3480156103ac57600080fd5b506103927fe70d28ebd9d7d9a3dd77d46ae2481f301c80806f395b08de31d8e095b1c46cee81565b3480156103e057600080fd5b506103e96110ba565b6040516103699190614fb4565b34801561040257600080fd5b50610416610411366004614fc7565b61114c565b6040516103699190614fe0565b34801561042f57600080fd5b5061044361043e366004614ff4565b611173565b005b34801561045157600080fd5b50610443610460366004614fc7565b611288565b34801561047157600080fd5b50610443610480366004615020565b6112b3565b34801561049157600080fd5b506104b96104a0366004614fc7565b60009081526101c9602052604090206003015460ff1690565b604051610369919061507a565b3480156104d257600080fd5b506104e66104e1366004615088565b6112e0565b6040516001600160e01b03199091168152602001610369565b34801561050b57600080fd5b50609954610392565b34801561052057600080fd5b5061044361052f3660046150fa565b611333565b34801561054057600080fd5b5061039261054f366004614fc7565b600090815261012d602052604090206001015490565b34801561057157600080fd5b5061044361058036600461513b565b611357565b34801561059157600080fd5b506103926105a0366004614ff4565b61137d565b3480156105b157600080fd5b5061035d6105c0366004615257565b80516020818301810180516101c48252928201919093012091525460ff1681565b3480156105ed57600080fd5b506104436105fc366004615257565b611413565b34801561060d57600080fd5b5061044361061c36600461513b565b611460565b34801561062d57600080fd5b5061044361063c36600461528b565b6114da565b34801561064d57600080fd5b5061044361065c3660046152a8565b61159f565b34801561066d57600080fd5b5061044361067c3660046152d1565b6117c8565b34801561068d57600080fd5b506104436117ed565b3480156106a257600080fd5b506104436106b13660046150fa565b61133c565b3480156106c257600080fd5b506103926106d1366004615020565b61184f565b6104436106e4366004615320565b611e20565b3480156106f557600080fd5b50610392610704366004614fc7565b611ed5565b34801561071557600080fd5b50610443610724366004614fc7565b611f68565b34801561073557600080fd5b50610392611ff0565b34801561074a57600080fd5b5061044361075936600461528b565b61209e565b34801561076a57600080fd5b50610443610779366004615257565b6120c9565b34801561078a57600080fd5b5060fb5460ff1661035d565b3480156107a257600080fd5b506104436107b136600461536f565b6120e5565b3480156107c257600080fd5b506104166107d1366004614fc7565b6121ea565b3480156107e257600080fd5b50610392600181565b3480156107f757600080fd5b50610443610806366004615020565b61221f565b34801561081757600080fd5b5061039261082636600461528b565b612296565b34801561083757600080fd5b5061044361231c565b34801561084c57600080fd5b5061086061085b366004614fc7565b612330565b6040516103699594939291906153e5565b34801561087d57600080fd5b5061044361088c366004614fc7565b612478565b34801561089d57600080fd5b506104436124f0565b3480156108b257600080fd5b506104436108c1366004615423565b612552565b3480156108d257600080fd5b5060c9546001600160a01b0316610416565b3480156108f057600080fd5b5061035d6108ff36600461513b565b612691565b34801561091057600080fd5b506103e96126bd565b34801561092557600080fd5b506103e9610934366004614fc7565b6126cc565b34801561094557600080fd5b50610392600081565b34801561095a57600080fd5b50610443610969366004615461565b612772565b34801561097a57600080fd5b5061039261098936600461528b565b61277d565b34801561099a57600080fd5b506104436109a9366004615423565b612791565b3480156109ba57600080fd5b506101c854610416906001600160a01b031681565b3480156109db57600080fd5b506103926101c35481565b3480156109f257600080fd5b50610443610a01366004614fc7565b61279a565b348015610a1257600080fd5b50610443610a2136600461548f565b6127c2565b348015610a3257600080fd5b50610443610a413660046154ee565b61283a565b348015610a5257600080fd5b50610443610a6136600461528b565b61290e565b348015610a7257600080fd5b50610443610a81366004615423565b612aa7565b348015610a9257600080fd5b506103e9610aa1366004614fc7565b612ab8565b348015610ab257600080fd5b50610443610ac136600461513b565b612bf2565b348015610ad257600080fd5b50610ae6610ae1366004614fc7565b612c18565b60405161036993929190615534565b348015610b0157600080fd5b50610392600080516020615e2383398151915281565b348015610b2357600080fd5b5061035d610b3236600461554f565b612c83565b348015610b4357600080fd5b50610443610b5236600461528b565b612cb1565b348015610b6357600080fd5b506103e9604051806040016040528060058152602001640312e352e360dc1b81525081565b60006001600160e01b03198216637965db0b60e01b1480610bad5750610bad82612d27565b92915050565b6000610bbd612d77565b610be67fe70d28ebd9d7d9a3dd77d46ae2481f301c80806f395b08de31d8e095b1c46cee612db2565b610bf03087612df0565b9050610bfc8183612e70565b6101c860009054906101000a90046001600160a01b03166001600160a01b031663fe5d6fe56040518163ffffffff1660e01b8152600401602060405180830381865afa158015610c50573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c74919061557d565b604051633218026360e11b815260048101849052602481018390526001600160a01b03919091169063643004c690604401600060405180830381600087803b158015610cbf57600080fd5b505af1158015610cd3573d6000803e3d6000fd5b50505050610d198186868080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250889250612ed0915050565b610d2281612ff1565b6101c8546040805163fe5d6fe560e01b815290516000926001600160a01b03169163fe5d6fe59160048083019260209291908290030181865afa158015610d6d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d91919061557d565b604051633139cbb560e11b8152600481018490529091506001600160a01b03821690636273976a90602401600060405180830381600087803b158015610dd657600080fd5b505af1158015610dea573d6000803e3d6000fd5b505050506000610df983613140565b90506001600160a01b038116610e42576040805180820182526002815261034360f41b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60405180910390fd5b6000816001600160a01b0316633c31175e6040518163ffffffff1660e01b8152600401600060405180830381865afa158015610e82573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610eaa91908101906155df565b90506101ca81604051610ebd9190615613565b9081526040519081900360200190205460ff16610f04576040805180820182526002815261343160f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6040516370a0823160e01b81526000906001600160a01b038416906370a0823190610f33903090600401614fe0565b602060405180830381865afa158015610f50573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f74919061562f565b9050610f913084876040518060200160405280600081525061334d565b6040516370a0823160e01b81526000906001600160a01b038516906370a0823190610fc0903090600401614fe0565b602060405180830381865afa158015610fdd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611001919061562f565b9050600061100f838361565e565b9050806000036110495760408051808201825260028152611a1960f11b6020820152905162461bcd60e51b8152610e399190600401614fb4565b61105d6001600160a01b0386168d83613380565b604080518881526001600160a01b038781166020830152918101839052908d16907ffc57e3cd27cd7fbd6b9bfca9a3ab5dc6414002431c17d40274c60bbfbc672a2d9060600160405180910390a250505050505095945050505050565b6060606580546110c990615675565b80601f01602080910402602001604051908101604052809291908181526020018280546110f590615675565b80156111425780601f1061111757610100808354040283529160200191611142565b820191906000526020600020905b81548152906001019060200180831161112557829003601f168201915b5050505050905090565b6000611157826133d2565b506000908152606960205260409020546001600160a01b031690565b600061117e826121ea565b9050806001600160a01b0316836001600160a01b0316036111eb5760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b6064820152608401610e39565b336001600160a01b038216148061120757506112078133612c83565b6112795760405162461bcd60e51b815260206004820152603d60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c0000006064820152608401610e39565b61128383836133f7565b505050565b611290612d77565b6112a7600080516020615e23833981519152612db2565b6112b081612ff1565b50565b6112bb612d77565b6112d2600080516020615e23833981519152612db2565b6112dc8282612e70565b5050565b60006001600160a01b03851615611321576040805180820182526002815261343360f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b50630a85bd0160e11b95945050505050565b61133c81613465565b611283838383604051806020016040528060008152506127c2565b600082815261012d6020526040902060010154611373816134a3565b61128383836134ad565b600061138883612296565b82106113ea5760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b6064820152608401610e39565b506001600160a01b03919091166000908152609760209081526040808320938352929052205490565b61142a600080516020615e23833981519152612db2565b60006101c48260405161143d9190615613565b908152604051908190036020019020805491151560ff1990921691909117905550565b6001600160a01b03811633146114d05760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610e39565b6112dc8282613534565b6001600160a01b037f0000000000000000000000007743a05fe5864fdca324da147cbae41d44a601801630036115225760405162461bcd60e51b8152600401610e39906156af565b7f0000000000000000000000007743a05fe5864fdca324da147cbae41d44a601806001600160a01b031661155461359c565b6001600160a01b03161461157a5760405162461bcd60e51b8152600401610e39906156fb565b611583816135b8565b604080516000808252602082019092526112b0918391906135c0565b6115a7612d77565b6115af61372b565b60006115ba836121ea565b6101c854604051633a37b16d60e11b81529192506001600160a01b03169063746f62da906115ec908490600401614fe0565b602060405180830381865afa158015611609573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061162d9190615757565b611661576040805180820182526002815261191b60f11b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008381526101c96020526040902060039081015460ff169083600681111561168c5761168c615042565b14806116a9575060058360068111156116a7576116a7615042565b145b156116be576116b98160026137dc565b6117b8565b60048360068111156116d2576116d2615042565b036116e2576116b98160036137dc565b60068360068111156116f6576116f6615042565b03611706576116b98160056137dc565b600283600681111561171a5761171a615042565b0361178857600381600681111561173357611733615042565b141580156117535750600581600681111561175057611750615042565b14155b156116b95760408051808201825260028152610d0d60f21b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60408051808201825260028152610d0d60f21b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6117c28484613835565b50505050565b6117d0612d77565b6117d9836138ab565b6117e283613916565b611283838383612ed0565b6101c8546001600160a01b031661180c60c9546001600160a01b031690565b6001600160a01b03821633148061182b57506001600160a01b03811633145b6118475760405162461bcd60e51b8152600401610e3990615774565b6112dc613972565b6000611859612d77565b61186161372b565b60008381526101c960205260408120600101805461187e90615675565b80601f01602080910402602001604051908101604052809291908181526020018280546118aa90615675565b80156118f75780601f106118cc576101008083540402835291602001916118f7565b820191906000526020600020905b8154815290600101906020018083116118da57829003601f168201915b505050505090506000611909856121ea565b90506001600160a01b038116611949576040805180820182526002815261034360f41b6020820152905162461bcd60e51b8152610e399190600401614fb4565b600080826001600160a01b0316634e395ea885886040518363ffffffff1660e01b815260040161197a9291906157b9565b600060405180830381865afa158015611997573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526119bf91908101906157db565b6101c854604051633a37b16d60e11b81529294509092506001600160a01b03169063746f62da906119f4908690600401614fe0565b602060405180830381865afa158015611a11573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a359190615757565b611a69576040805180820182526002815261191b60f11b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008781526101c9602052604090206003015460ff166005816006811115611a9357611a93615042565b14158015611ab357506003816006811115611ab057611ab0615042565b14155b15611ae8576040805180820182526002815261033360f41b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008881526101c960205260409020600201548710611b31576040805180820182526002815261353560f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008881526101c9602052604081206001018054611b4e90615675565b80601f0160208091040260200160405190810160405280929190818152602001828054611b7a90615675565b8015611bc75780601f10611b9c57610100808354040283529160200191611bc7565b820191906000526020600020905b815481529060010190602001808311611baa57829003601f168201915b50505050509050611bfb89848a6101c960008e815260200190815260200160002060020154611bf6919061565e565b612ed0565b60016101c484604051611c0e9190615613565b908152604051908190036020019020805491151560ff19909216919091179055611c383086612df0565b9650611c4587858a612ed0565b60016101c485604051611c589190615613565b908152604051908190036020018120805492151560ff19909316929092179091556000906101c490611c8b908490615613565b9081526040805160209281900383019020805460ff19169315159390931790925560008b81526101c99091522054611cc4908890612e70565b6101c860009054906101000a90046001600160a01b03166001600160a01b031663fe5d6fe56040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d3c919061557d565b60008a81526101c9602052604090819020549051633218026360e11b81526001600160a01b03929092169163643004c691611d84918b90600401918252602082015260400190565b600060405180830381600087803b158015611d9e57600080fd5b505af1158015611db2573d6000803e3d6000fd5b50505050611dc08783613835565b611ddb3086896040518060200160405280600081525061334d565b604080518a8152602081018990527fb20b10d17e0e2505af41fd37a6a1b46824a76d7d940afce430c7ee4aba19a959910160405180910390a150505050505092915050565b6001600160a01b037f0000000000000000000000007743a05fe5864fdca324da147cbae41d44a60180163003611e685760405162461bcd60e51b8152600401610e39906156af565b7f0000000000000000000000007743a05fe5864fdca324da147cbae41d44a601806001600160a01b0316611e9a61359c565b6001600160a01b031614611ec05760405162461bcd60e51b8152600401610e39906156fb565b611ec9826135b8565b6112dc828260016135c0565b6000611ee060995490565b8210611f435760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b6064820152608401610e39565b60998281548110611f5657611f56615834565b90600052602060002001549050919050565b611f70612d77565b611f87600080516020615e23833981519152612db2565b600160008281526101c9602052604090206003015460ff166006811115611fb057611fb0615042565b14611fe5576040805180820182526002815261333560f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6112b0816000613835565b6000306001600160a01b037f0000000000000000000000007743a05fe5864fdca324da147cbae41d44a60180161461208b5760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c6044820152771b1959081d1a1c9bdd59da0819195b1959d85d1958d85b1b60421b6064820152608401610e39565b50600080516020615ddc83398151915290565b6120a66139be565b6101c880546001600160a01b0319166001600160a01b0392909216919091179055565b6120d16139be565b80516112dc906101c7906020840190614dcd565b6120ed612d77565b6120f6846138ab565b6120ff84613916565b61210a848484612ed0565b60008481526101c96020526040902060040180546121b9919061212c90615675565b80601f016020809104026020016040519081016040528092919081815260200182805461215890615675565b80156121a55780601f1061217a576101008083540402835291602001916121a5565b820191906000526020600020905b81548152906001019060200180831161218857829003601f168201915b505050505082613a1890919063ffffffff16565b6117c25760008481526101c96020908152604090912082516121e392600490920191840190614dcd565b5050505050565b6000818152606760205260408120546001600160a01b031680610bad5760405162461bcd60e51b8152600401610e399061584a565b612227612d77565b61223e600080516020615e23833981519152612db2565b60008281526101c9602052604090205415612283576040805180820182526002815261199b60f11b6020820152905162461bcd60e51b8152610e399190600401614fb4565b61228d8282612e70565b6112dc82612ff1565b60006001600160a01b0382166123005760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b6064820152608401610e39565b506001600160a01b031660009081526068602052604090205490565b6123246139be565b61232e6000613a3e565b565b6101c9602052600090815260409020805460018201805491929161235390615675565b80601f016020809104026020016040519081016040528092919081815260200182805461237f90615675565b80156123cc5780601f106123a1576101008083540402835291602001916123cc565b820191906000526020600020905b8154815290600101906020018083116123af57829003601f168201915b50505050600283015460038401546004850180549495929460ff9092169350906123f590615675565b80601f016020809104026020016040519081016040528092919081815260200182805461242190615675565b801561246e5780601f106124435761010080835404028352916020019161246e565b820191906000526020600020905b81548152906001019060200180831161245157829003601f168201915b5050505050905085565b612480612d77565b612497600080516020615e23833981519152612db2565b6124a081613916565b60008181526101c9602052604080822090516101c4916124c59160019091019061587c565b908152604051908190036020019020805491151560ff199092169190911790556112b0816001613835565b6101c8546001600160a01b031661250f60c9546001600160a01b031690565b6001600160a01b03821633148061252e57506001600160a01b03811633145b61254a5760405162461bcd60e51b8152600401610e3990615774565b6112dc613a90565b61255a612d77565b612571600080516020615e23833981519152612db2565b600260008381526101c9602052604090206003015460ff16600681111561259a5761259a615042565b146125cf576040805180820182526002815261323760f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6101c8546001600160a01b031663746f62da6125ea846121ea565b6040518263ffffffff1660e01b81526004016126069190614fe0565b602060405180830381865afa158015612623573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126479190615757565b1561267c5760408051808201825260028152610ccd60f21b6020820152905162461bcd60e51b8152610e399190600401614fb4565b612687826001613835565b6112dc8282613acd565b600091825261012d602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6060606680546110c990615675565b60008181526101c9602052604090206001018054606091906126ed90615675565b80601f016020809104026020016040519081016040528092919081815260200182805461271990615675565b80156127665780601f1061273b57610100808354040283529160200191612766565b820191906000526020600020905b81548152906001019060200180831161274957829003601f168201915b50505050509050919050565b6112dc338383613b7c565b6000612787612d77565b610bad8283612df0565b612687826138ab565b6127a381613465565b6112b0336127b083613140565b83604051806020016040528060008152505b6127cc3383613c46565b61282e5760405162461bcd60e51b815260206004820152602d60248201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560448201526c1c881bdc88185c1c1c9bdd9959609a1b6064820152608401610e39565b6117c28484848461334d565b6128426139be565b8015156101ca836040516128569190615613565b9081526040519081900360200190205460ff161515036128a0576040805180820182526002815261323360f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b806101ca836040516128b29190615613565b908152604051908190036020018120805492151560ff19909316929092179091557fd1ccc86b3ecebee24bd889691724999af4141f85d8bf0c59a60112e18173f6a0906129029084908490615917565b60405180910390a15050565b600054610100900460ff161580801561292e5750600054600160ff909116105b806129485750303b158015612948575060005460ff166001145b6129ab5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610e39565b6000805460ff1916600117905580156129ce576000805461ff0019166101001790555b6129d6613ca5565b612a1e6040518060600160405280602a8152602001615db2602a91396040518060400160405280600e81526020016d21a0a92127a721a7a92296a1a7a160911b815250613ccc565b612a26613d1a565b612a2e613d4a565b612a36613ca5565b612a3e613ca5565b6101c880546001600160a01b0319166001600160a01b038416179055612a656000336134ad565b80156112dc576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001612902565b612aaf612d77565b61268782612478565b6060612ac382613d7d565b612af7576040805180820182526002815261323960f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008281526101c9602052604081206004018054612b1490615675565b80601f0160208091040260200160405190810160405280929190818152602001828054612b4090615675565b8015612b8d5780601f10612b6257610100808354040283529160200191612b8d565b820191906000526020600020905b815481529060010190602001808311612b7057829003601f168201915b50505050509050612b9c613d9a565b51600003612baa5792915050565b805115612be257612bb9613d9a565b81604051602001612bcb92919061593b565b604051602081830303815290604052915050919050565b612beb83613daa565b9392505050565b600082815261012d6020526040902060010154612c0e816134a3565b6112838383613534565b6000806000612c2684613d7d565b612c5a576040805180820182526002815261323960f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b50505060009081526101c96020526040902080546002820154600390920154909260ff90911690565b6001600160a01b039182166000908152606a6020908152604080832093909416825291909152205460ff1690565b612cb96139be565b6001600160a01b038116612d1e5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610e39565b6112b081613a3e565b60006001600160e01b031982166380ac58cd60e01b1480612d5857506001600160e01b03198216635b5e139f60e01b145b80610bad57506301ffc9a760e01b6001600160e01b0319831614610bad565b60fb5460ff161561232e576040805180820182526002815261066760f31b6020820152905162461bcd60e51b8152610e399190600401614fb4565b612dbc8133612691565b6112b0576040805180820182526002815261333960f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6101c3805460010190819055612e068382613dfa565b60008181526101c96020908152604080832060038101805460ff191690556002019290925581516001600160a01b03851681529081018390527f6174e73d7eb2fee6c482f87f81961b83cfa577f50c963bd1516f282497260fcd910160405180910390a192915050565b6101c854612e87906001600160a01b031682613e14565b60008281526101c9602090815260409182902083905581518481529081018390527fe16bc7d72176e78ab56068f816d35b70dfcb41bb492ca0da0bcfc064b2439f6c9101612902565b6101c482604051612ee19190615613565b9081526040519081900360200190205460ff1615612f29576040805180820182526002815261199960f11b6020820152905162461bcd60e51b8152610e399190600401614fb4565b80600003612f61576040805180820182526002815261353560f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008381526101c9602090815260409091208351612f8792600190920191850190614dcd565b5060008381526101c9602052604090819020600281018054908490556003909101549151909160ff16907fd680d89587cd5af07a9a0280107488c8b2db5f86aec57b869f0933fb4a99c05b90612fe29087908790879061596a565b60405180910390a15050505050565b612ffa81613d7d565b61302e576040805180820182526002815261323960f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b61303781613916565b60008181526101c96020526040812054900361307d576040805180820182526002815261333160f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6101c46101c960008381526020019081526020016000206001016040516130a4919061587c565b9081526040519081900360200190205460ff16156130ec576040805180820182526002815261199960f11b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60016101c46101c96000848152602001908152602001600020600101604051613115919061587c565b908152604051908190036020019020805491151560ff199092169190911790556112b0816002613835565b60008181526101c960209081526040808320546101c8548251630505792b60e51b8152925191936001600160a01b03909116928592849263a0af256092600480820193918290030181865afa15801561319d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131c1919061557d565b60405163056efc1d60e21b8152600481018590529091506000906001600160a01b038316906315bbf07490602401600060405180830381865afa15801561320c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261323491908101906159aa565b6101608101518051919250906000036132655750604080518082019091526005815264766572726160d81b60208201525b604051630d2c231160e01b81526000906001600160a01b03861690630d2c231190613294908590600401614fb4565b602060405180830381865afa1580156132b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132d5919061557d565b6040516317a04f4f60e21b8152600481018890529091506001600160a01b03821690635e813d3c90602401602060405180830381865afa15801561331d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613341919061557d565b98975050505050505050565b613358848484613f42565b613364848484846140b3565b6117c25760405162461bcd60e51b8152600401610e3990615b34565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526112839084906141b4565b6133db81613d7d565b6112b05760405162461bcd60e51b8152600401610e399061584a565b600081815260696020526040902080546001600160a01b0319166001600160a01b038416908117909155819061342c826121ea565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b61346f3382613c46565b6112b0576040805180820182526002815261333760f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b6112b08133614289565b6134b78282612691565b6112dc57600082815261012d602090815260408083206001600160a01b03851684529091529020805460ff191660011790556134f03390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b61353e8282612691565b156112dc57600082815261012d602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600080516020615ddc833981519152546001600160a01b031690565b6112b06139be565b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156135f357611283836142e2565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa92505050801561364d575060408051601f3d908101601f1916820190925261364a9181019061562f565b60015b6136b05760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610e39565b600080516020615ddc833981519152811461371f5760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610e39565b5061128383838361437e565b6101c8546040805163a370e16960e01b815290516000926001600160a01b03169163a370e1699160048083019260209291908290030181865afa158015613776573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061379a919061557d565b90506001600160a01b03811633146112b0576040805180820182526002815261333960f01b6020820152905162461bcd60e51b8152610e399190600401614fb4565b8060068111156137ee576137ee615042565b82600681111561380057613800615042565b146112dc5760408051808201825260028152610d0d60f21b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008281526101c960205260409020600301805460ff811691839160ff1916600183600681111561386857613868615042565b02179055507f132d48207d6b10897066f0b98b98325907e8a0d491390e141c7377772b47a9d6838360405161389e929190615b86565b60405180910390a1505050565b336138b5826121ea565b6001600160a01b0316141580156138e157506138df600080516020615e2383398151915233612691565b155b156112b05760408051808201825260028152610c8d60f21b6020820152905162461bcd60e51b8152610e399190600401614fb4565b60008181526101c9602052604081206003015460ff16600681111561393d5761393d615042565b146112b0576040805180820182526002815261033360f41b6020820152905162461bcd60e51b8152610e399190600401614fb4565b61397a6143a3565b60fb805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516139b49190614fe0565b60405180910390a1565b60c9546001600160a01b0316331461232e5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610e39565b600081518351148015612beb575081805190602001208380519060200120149392505050565b60c980546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b613a986143ec565b60fb805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586139a73390565b60008281526101c96020908152604082206005018054600181018255908352918190208351613b03939190910191840190614dcd565b5060008281526101c96020908152604080832060068101805460018101825590855292842090920180546001600160a01b031916339081179091559285905260059091015490517f08740f41d4d7e855ea188e78846ad3e8665dd6d0b088f899025991c1ee8c2c47926129029286929091908690615b9a565b816001600160a01b0316836001600160a01b031603613bd95760405162461bcd60e51b815260206004820152601960248201527822a9219b99189d1030b8383937bb32903a379031b0b63632b960391b6044820152606401610e39565b6001600160a01b038381166000818152606a6020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b600080613c52836121ea565b9050806001600160a01b0316846001600160a01b03161480613c795750613c798185612c83565b80613c9d5750836001600160a01b0316613c928461114c565b6001600160a01b0316145b949350505050565b600054610100900460ff1661232e5760405162461bcd60e51b8152600401610e3990615bc7565b600054610100900460ff16613cf35760405162461bcd60e51b8152600401610e3990615bc7565b8151613d06906065906020850190614dcd565b508051611283906066906020840190614dcd565b600054610100900460ff16613d415760405162461bcd60e51b8152600401610e3990615bc7565b61232e33613a3e565b600054610100900460ff16613d715760405162461bcd60e51b8152600401610e3990615bc7565b60fb805460ff19169055565b6000908152606760205260409020546001600160a01b0316151590565b60606101c780546110c990615675565b6060613db5826133d2565b6000613dbf613d9a565b90506000815111613ddf5760405180602001604052806000815250612beb565b80613de984614432565b604051602001612bcb92919061593b565b6112dc8282604051806020016040528060008152506144c4565b6000826001600160a01b031663a0af25606040518163ffffffff1660e01b8152600401602060405180830381865afa158015613e54573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e78919061557d565b604051634f558e7960e01b8152600481018490529091506001600160a01b03821690634f558e7990602401602060405180830381865afa158015613ec0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ee49190615757565b6112835760405162461bcd60e51b815260206004820152602960248201527f436172626f6e2070726f6a6563742076696e7461676520646f6573206e6f74206044820152681e595d08195e1a5cdd60ba1b6064820152608401610e39565b826001600160a01b0316613f55826121ea565b6001600160a01b031614613f7b5760405162461bcd60e51b8152600401610e3990615c12565b6001600160a01b038216613fdd5760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b6064820152608401610e39565b613fea83838360016144f7565b826001600160a01b0316613ffd826121ea565b6001600160a01b0316146140235760405162461bcd60e51b8152600401610e3990615c12565b600081815260696020908152604080832080546001600160a01b03199081169091556001600160a01b0387811680865260688552838620805460001901905590871680865283862080546001019055868652606790945282852080549092168417909155905184937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b60006001600160a01b0384163b156141a957604051630a85bd0160e11b81526001600160a01b0385169063150b7a02906140f7903390899088908890600401615c57565b6020604051808303816000875af1925050508015614132575060408051601f3d908101601f1916820190925261412f91810190615c8a565b60015b61418f573d808015614160576040519150601f19603f3d011682016040523d82523d6000602084013e614165565b606091505b5080516000036141875760405162461bcd60e51b8152600401610e3990615b34565b805181602001fd5b6001600160e01b031916630a85bd0160e11b149050613c9d565b506001949350505050565b6000614209826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661450b9092919063ffffffff16565b905080516000148061422a57508080602001905181019061422a9190615757565b6112835760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610e39565b6142938282612691565b6112dc576142a08161451a565b6142ab83602061452c565b6040516020016142bc929190615ca7565b60408051601f198184030181529082905262461bcd60e51b8252610e3991600401614fb4565b6001600160a01b0381163b61434f5760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610e39565b600080516020615ddc83398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b614387836146c7565b6000825111806143945750805b15611283576117c28383614707565b60fb5460ff1661232e5760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610e39565b60fb5460ff161561232e5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610e39565b6060600061443f8361472c565b60010190506000816001600160401b0381111561445e5761445e61516b565b6040519080825280601f01601f191660200182016040528015614488576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a850494508461449257509392505050565b6144ce8383614804565b6144db60008484846140b3565b6112835760405162461bcd60e51b8152600401610e3990615b34565b6144ff612d77565b6117c28484848461491f565b6060613c9d8484600085614a4c565b6060610bad6001600160a01b03831660145b6060600061453b836002615d16565b614546906002615d35565b6001600160401b0381111561455d5761455d61516b565b6040519080825280601f01601f191660200182016040528015614587576020820181803683370190505b509050600360fc1b816000815181106145a2576145a2615834565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106145d1576145d1615834565b60200101906001600160f81b031916908160001a90535060006145f5846002615d16565b614600906001615d35565b90505b6001811115614678576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061463457614634615834565b1a60f81b82828151811061464a5761464a615834565b60200101906001600160f81b031916908160001a90535060049490941c9361467181615d4d565b9050614603565b508315612beb5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610e39565b6146d0816142e2565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a250565b6060612beb8383604051806060016040528060278152602001615dfc60279139614b27565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b831061476b5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310614797576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106147b557662386f26fc10000830492506010015b6305f5e10083106147cd576305f5e100830492506008015b61271083106147e157612710830492506004015b606483106147f3576064830492506002015b600a8310610bad5760010192915050565b6001600160a01b03821661485a5760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f20616464726573736044820152606401610e39565b61486381613d7d565b156148805760405162461bcd60e51b8152600401610e3990615d64565b61488e6000838360016144f7565b61489781613d7d565b156148b45760405162461bcd60e51b8152600401610e3990615d64565b6001600160a01b038216600081815260686020908152604080832080546001019055848352606790915280822080546001600160a01b0319168417905551839291907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b600181111561498e5760405162461bcd60e51b815260206004820152603560248201527f455243373231456e756d657261626c653a20636f6e7365637574697665207472604482015274185b9cd9995c9cc81b9bdd081cdd5c1c1bdc9d1959605a1b6064820152608401610e39565b816001600160a01b0385166149ea576149e581609980546000838152609a60205260408120829055600182018355919091527f72a152ddfb8e864297c917af52ea6c1c68aead0fee1a62673fcc7e0c94979d000155565b614a0d565b836001600160a01b0316856001600160a01b031614614a0d57614a0d8582614b9f565b6001600160a01b038416614a2957614a2481614c3c565b6121e3565b846001600160a01b0316846001600160a01b0316146121e3576121e38482614ceb565b606082471015614aad5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610e39565b600080866001600160a01b03168587604051614ac99190615613565b60006040518083038185875af1925050503d8060008114614b06576040519150601f19603f3d011682016040523d82523d6000602084013e614b0b565b606091505b5091509150614b1c87838387614d2f565b979650505050505050565b6060600080856001600160a01b031685604051614b449190615613565b600060405180830381855af49150503d8060008114614b7f576040519150601f19603f3d011682016040523d82523d6000602084013e614b84565b606091505b5091509150614b9586838387614d2f565b9695505050505050565b60006001614bac84612296565b614bb6919061565e565b600083815260986020526040902054909150808214614c09576001600160a01b03841660009081526097602090815260408083208584528252808320548484528184208190558352609890915290208190555b5060009182526098602090815260408084208490556001600160a01b039094168352609781528383209183525290812055565b609954600090614c4e9060019061565e565b6000838152609a602052604081205460998054939450909284908110614c7657614c76615834565b906000526020600020015490508060998381548110614c9757614c97615834565b6000918252602080832090910192909255828152609a90915260408082208490558582528120556099805480614ccf57614ccf615d9b565b6001900381819060005260206000200160009055905550505050565b6000614cf683612296565b6001600160a01b039093166000908152609760209081526040808320868452825280832085905593825260989052919091209190915550565b60608315614d9e578251600003614d97576001600160a01b0385163b614d975760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610e39565b5081613c9d565b613c9d8383815115614db35781518083602001fd5b8060405162461bcd60e51b8152600401610e399190614fb4565b828054614dd990615675565b90600052602060002090601f016020900481019282614dfb5760008555614e41565b82601f10614e1457805160ff1916838001178555614e41565b82800160010185558215614e41579182015b82811115614e41578251825591602001919060010190614e26565b50614e4d929150614e51565b5090565b5b80821115614e4d5760008155600101614e52565b6001600160e01b0319811681146112b057600080fd5b600060208284031215614e8e57600080fd5b8135612beb81614e66565b6001600160a01b03811681146112b057600080fd5b60008083601f840112614ec057600080fd5b5081356001600160401b03811115614ed757600080fd5b602083019150836020828501011115614eef57600080fd5b9250929050565b600080600080600060808688031215614f0e57600080fd5b8535614f1981614e99565b945060208601356001600160401b03811115614f3457600080fd5b614f4088828901614eae565b9699909850959660408101359660609091013595509350505050565b60005b83811015614f77578181015183820152602001614f5f565b838111156117c25750506000910152565b60008151808452614fa0816020860160208601614f5c565b601f01601f19169290920160200192915050565b602081526000612beb6020830184614f88565b600060208284031215614fd957600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6000806040838503121561500757600080fd5b823561501281614e99565b946020939093013593505050565b6000806040838503121561503357600080fd5b50508035926020909101359150565b634e487b7160e01b600052602160045260246000fd5b6007811061507657634e487b7160e01b600052602160045260246000fd5b9052565b60208101610bad8284615058565b6000806000806000608086880312156150a057600080fd5b85356150ab81614e99565b945060208601356150bb81614e99565b93506040860135925060608601356001600160401b038111156150dd57600080fd5b6150e988828901614eae565b969995985093965092949392505050565b60008060006060848603121561510f57600080fd5b833561511a81614e99565b9250602084013561512a81614e99565b929592945050506040919091013590565b6000806040838503121561514e57600080fd5b82359150602083013561516081614e99565b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b60405161018081016001600160401b03811182821017156151a4576151a461516b565b60405290565b604051601f8201601f191681016001600160401b03811182821017156151d2576151d261516b565b604052919050565b60006001600160401b038211156151f3576151f361516b565b50601f01601f191660200190565b600082601f83011261521257600080fd5b8135615225615220826151da565b6151aa565b81815284602083860101111561523a57600080fd5b816020850160208301376000918101602001919091529392505050565b60006020828403121561526957600080fd5b81356001600160401b0381111561527f57600080fd5b613c9d84828501615201565b60006020828403121561529d57600080fd5b8135612beb81614e99565b600080604083850312156152bb57600080fd5b8235915060208301356007811061516057600080fd5b6000806000606084860312156152e657600080fd5b8335925060208401356001600160401b0381111561530357600080fd5b61530f86828701615201565b925050604084013590509250925092565b6000806040838503121561533357600080fd5b823561533e81614e99565b915060208301356001600160401b0381111561535957600080fd5b61536585828601615201565b9150509250929050565b6000806000806080858703121561538557600080fd5b8435935060208501356001600160401b03808211156153a357600080fd5b6153af88838901615201565b94506040870135935060608701359150808211156153cc57600080fd5b506153d987828801615201565b91505092959194509250565b85815260a0602082015260006153fe60a0830187614f88565b8560408401526154116060840186615058565b82810360808401526133418185614f88565b6000806040838503121561543657600080fd5b8235915060208301356001600160401b0381111561535957600080fd5b80151581146112b057600080fd5b6000806040838503121561547457600080fd5b823561547f81614e99565b9150602083013561516081615453565b600080600080608085870312156154a557600080fd5b84356154b081614e99565b935060208501356154c081614e99565b92506040850135915060608501356001600160401b038111156154e257600080fd5b6153d987828801615201565b6000806040838503121561550157600080fd5b82356001600160401b0381111561551757600080fd5b61552385828601615201565b925050602083013561516081615453565b8381526020810183905260608101613c9d6040830184615058565b6000806040838503121561556257600080fd5b823561556d81614e99565b9150602083013561516081614e99565b60006020828403121561558f57600080fd5b8151612beb81614e99565b600082601f8301126155ab57600080fd5b81516155b9615220826151da565b8181528460208386010111156155ce57600080fd5b613c9d826020830160208701614f5c565b6000602082840312156155f157600080fd5b81516001600160401b0381111561560757600080fd5b613c9d8482850161559a565b60008251615625818460208701614f5c565b9190910192915050565b60006020828403121561564157600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008282101561567057615670615648565b500390565b600181811c9082168061568957607f821691505b6020821081036156a957634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b805161575281615453565b919050565b60006020828403121561576957600080fd5b8151612beb81615453565b60208082526025908201527f43616c6c6572206973206e6f74207468652072656769737472792c206e6f722060408201526437bbb732b960d91b606082015260800190565b6040815260006157cc6040830185614f88565b90508260208301529392505050565b600080604083850312156157ee57600080fd5b82516001600160401b038082111561580557600080fd5b6158118683870161559a565b9350602085015191508082111561582757600080fd5b506153658582860161559a565b634e487b7160e01b600052603260045260246000fd5b602080825260189082015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b604082015260600190565b600080835481600182811c91508083168061589857607f831692505b602080841082036158b757634e487b7160e01b86526022600452602486fd5b8180156158cb57600181146158dc57615909565b60ff19861689528489019650615909565b60008a81526020902060005b868110156159015781548b8201529085019083016158e8565b505084890196505b509498975050505050505050565b60408152600061592a6040830185614f88565b905082151560208301529392505050565b6000835161594d818460208801614f5c565b835190830190615961818360208801614f5c565b01949350505050565b8381526060602082015260006159836060830185614f88565b9050826040830152949350505050565b80516001600160401b038116811461575257600080fd5b6000602082840312156159bc57600080fd5b81516001600160401b03808211156159d357600080fd5b9083019061018082860312156159e857600080fd5b6159f0615181565b8251828111156159ff57600080fd5b615a0b8782860161559a565b825250615a1a60208401615993565b6020820152615a2b60408401615993565b604082015260608301516060820152615a4660808401615993565b6080820152615a5760a08401615747565b60a0820152615a6860c08401615747565b60c082015260e083015182811115615a7f57600080fd5b615a8b8782860161559a565b60e0830152506101008084015183811115615aa557600080fd5b615ab18882870161559a565b8284015250506101208084015183811115615acb57600080fd5b615ad78882870161559a565b8284015250506101408084015183811115615af157600080fd5b615afd8882870161559a565b8284015250506101608084015183811115615b1757600080fd5b615b238882870161559a565b918301919091525095945050505050565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b82815260408101612beb6020830184615058565b84815283602082015260018060a01b0383166040820152608060608201526000614b956080830184614f88565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b60208082526025908201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060408201526437bbb732b960d91b606082015260800190565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090614b9590830184614f88565b600060208284031215615c9c57600080fd5b8151612beb81614e66565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260008351615cd9816017850160208801614f5c565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351615d0a816028840160208801614f5c565b01602801949350505050565b6000816000190483118215151615615d3057615d30615648565b500290565b60008219821115615d4857615d48615648565b500190565b600081615d5c57615d5c615648565b506000190190565b6020808252601c908201527f4552433732313a20746f6b656e20616c7265616479206d696e74656400000000604082015260600190565b634e487b7160e01b600052603160045260246000fdfe436172626f6e436f72652050726f746f636f6c3a20436172626f6e204f66667365742042617463686573360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c65640ce23c3e399818cfee81a7ab0880f714e53d7672b08df0fa62f2843416e1ea09a26469706673582212201971fa13705c575a623b224717871037d9cb3e112b75de082aeacd0080b4810464736f6c634300080e0033

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

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.