Abstract Testnet

Contract

0x259A75B880d1ac494fC84D8b77bcb4754eeC3435

Overview

ETH Balance

0 ETH

Multichain Info

N/A
Transaction Hash
Method
Block
From
To

There are no matching entries

1 Internal Transaction found.

Latest 1 internal transaction

Parent Transaction Hash Block From To
56015362025-02-01 23:43:2177 days ago1738453401  Contract Creation0 ETH
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
NftVaultFactory

Compiler Version
v0.8.20+commit.a1b79de6

ZkSolc Version
v1.5.4

Optimization Enabled:
Yes with Mode 3

Other Settings:
paris EvmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 25 : NftVaultFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import "lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol";
import "lib/openzeppelin-contracts/contracts/utils/Strings.sol";

import "./INftVaultFactory.sol";
import "./NftVault.sol";

contract NftVaultFactory is INftVaultFactory {
    using EnumerableSet for EnumerableSet.AddressSet;
    using Strings for uint256;

    EnumerableSet.AddressSet private vaults;

    mapping(bytes32 => INftVault) public vaultHashMap;
    mapping(INftVault => uint256) public vaultIdMap;

    /// @inheritdoc INftVaultFactory
    function getAllVaults() external view returns (address[] memory) {
        return vaults.values();
    }

    /// @inheritdoc INftVaultFactory
    function getVaultAt(uint256 _index) external view returns (address) {
        return vaults.at(_index);
    }

    /// @inheritdoc INftVaultFactory
    function getVaultLength() external view returns (uint256) {
        return vaults.length();
    }

    /// @inheritdoc INftVaultFactory
    function isVault(address _vault) external view returns (bool) {
        return vaults.contains(_vault);
    }

    /// @inheritdoc INftVaultFactory
    function getVault(INftVault.CollectionData[] memory _collections) public view returns (INftVault vault) {
        vault = vaultHashMap[hashVault(_collections)];
        if (address(vault) == address(0)) revert VaultDoesNotExist();
    }

    /// @inheritdoc INftVaultFactory
    function exists(INftVault.CollectionData[] memory _collections) public view returns (bool) {
        return address(vaultHashMap[hashVault(_collections)]) != address(0);
    }

    /// @inheritdoc INftVaultFactory
    function hashVault(INftVault.CollectionData[] memory _collections) public pure returns (bytes32) {
        return keccak256(abi.encode(_collections));
    }

    /// @inheritdoc INftVaultFactory
    function createVault(INftVault.CollectionData[] memory _collections) external returns (INftVault vault) {
        bytes32 vaultHash = hashVault(_collections);
        vault = INftVault(vaultHashMap[vaultHash]);

        // if vault with _collections alredy exists, revert
        if (address(vault) != address(0)) revert VaultAlreadyDeployed();

        uint256 vaultId;
        string memory name;
        string memory symbol;

        vaultId = vaults.length();
        name = string.concat("Magic Vault ", vaultId.toString());
        symbol = string.concat("MagicVault", vaultId.toString());

        vault = INftVault(address(new NftVault(name, symbol)));
        vault.init(_collections);

        vaults.add(address(vault));
        vaultHashMap[vaultHash] = vault;
        vaultIdMap[vault] = vaultId;

        emit VaultCreated(name, symbol, vault, vaultId, _collections, msg.sender);
    }
}

File 2 of 25 : INftVaultFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import "./INftVault.sol";

/// @title Vault factory contract
interface INftVaultFactory {
    /// @notice Emitted when new vault is deployed
    /// @param name vault's name
    /// @param symbol vault's name
    /// @param vault vault's address as INftVault
    /// @param vaultId vault's index in `vaults` AddressSet
    /// @param collections configuration used for vault creation
    /// @param creator address of vault creator
    event VaultCreated(
        string name,
        string symbol,
        INftVault indexed vault,
        uint256 indexed vaultId,
        INftVault.CollectionData[] collections,
        address creator
    );

    /// @dev Vault does not exist
    error VaultDoesNotExist();

    /// @dev Vault with identical configuration is already deployed
    error VaultAlreadyDeployed();

    /// @notice Get vault by its config hash
    /// @param hash vault's config hash
    /// @return vault address
    function vaultHashMap(bytes32 hash) external view returns (INftVault vault);

    /// @return all deployed vaults
    function getAllVaults() external view returns (address[] memory);

    /// @notice Get vault by its EnumerableSet vaultId
    /// @param index vaultId or index in NftVaultFactory.vaults array
    /// @return vault address
    function getVaultAt(uint256 index) external view returns (address);

    /// @return length of vault's EnumerableSet
    function getVaultLength() external view returns (uint256);

    /// @notice Returns true if vault has been deployed by factory
    /// @param vault address
    /// @return true if vault is deployed by the factory
    function isVault(address vault) external view returns (bool);

    /// @notice Get vault by it's config
    /// @param collections vault's config
    /// @return vault address
    function getVault(INftVault.CollectionData[] memory collections) external view returns (INftVault vault);

    /// @notice Returns true if vault with given config exists
    /// @param collections vault's config
    /// @return true if vault with given config exists
    function exists(INftVault.CollectionData[] memory collections) external view returns (bool);

    /// @notice Get config hash
    /// @param collections vault's config
    /// @return config hash
    function hashVault(INftVault.CollectionData[] memory collections) external pure returns (bytes32);

    /// @notice Create new vault
    /// @dev If vault already exists, function reverts
    /// @param collections vault's config
    /// @return vault address of deployed vault
    function createVault(INftVault.CollectionData[] memory collections) external returns (INftVault vault);
}

File 3 of 25 : NftVault.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import "lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol";
import "lib/openzeppelin-contracts/contracts/token/ERC721/utils/ERC721Holder.sol";
import "lib/openzeppelin-contracts/contracts/token/ERC1155/IERC1155.sol";
import "lib/openzeppelin-contracts/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import "lib/openzeppelin-contracts/contracts/utils/structs/EnumerableSet.sol";
import "lib/openzeppelin-contracts/contracts/utils/structs/EnumerableMap.sol";
import "lib/openzeppelin-contracts/contracts/utils/introspection/ERC165Checker.sol";
import "lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol";
import "lib/openzeppelin-contracts/contracts/utils/Address.sol";

import "./INftVault.sol";
import "./INftVaultFactory.sol";

contract NftVault is INftVault, ERC20, ERC721Holder, ERC1155Holder {
    using EnumerableMap for EnumerableMap.AddressToUintMap;

    /// @notice value of 1 token, including decimals
    uint256 public immutable ONE;

    /// @notice amount of token required for last NFT to be redeemed
    uint256 public immutable LAST_NFT_AMOUNT;

    /// @notice unique ID of the vault generated using its configuration
    bytes32 public VAULT_HASH;

    /// @notice maps collection address to nft type
    EnumerableMap.AddressToUintMap private allowedCollections;

    /// @notice maps collection address to allowed tokens
    mapping(address => AllowedTokenIds) private allowedTokenIds;

    /// @notice maps collection address to tokenId to amount wrapped
    mapping(address => mapping(uint256 => uint256)) public balances;

    /// @param _name name of ERC20 Vault token
    /// @param _symbol symbol of ERC20 Vault token
    constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {
        ONE = 10 ** decimals();
        /// @dev last NFT can be redeemed for 99.9%
        LAST_NFT_AMOUNT = ONE * 999 / 1000;
    }

    /// @inheritdoc INftVault
    function init(CollectionData[] memory _collections) external {
        if (_collections.length == 0) revert InvalidCollections();
        if (allowedCollections.length() > 0) revert Initialized();

        VAULT_HASH = hashVault(_collections);

        for (uint256 i = 0; i < _collections.length; i++) {
            CollectionData memory collection = _collections[i];

            /// @dev if all Ids are allowed tokenIds must be empty, otherwise VAULT_HASH will not be correct
            if (collection.allowAllIds && collection.tokenIds.length > 0) revert TokenIdsMustBeEmpty();

            uint256 nftType = validateNftType(collection.addr, collection.nftType);

            if (!allowedCollections.set(collection.addr, nftType)) revert DuplicateCollection();
            allowedTokenIds[collection.addr].allowAllIds = collection.allowAllIds;

            emit CollectionAllowed(collection);

            if (collection.allowAllIds) continue;
            if (collection.tokenIds.length == 0) revert MissingTokenIds();

            uint256 lastTokenId = 0;

            for (uint256 j = 0; j < collection.tokenIds.length; j++) {
                uint256 tokenId = collection.tokenIds[j];

                /// @dev Make sure `uint256[] tokenIds` array is sorted,
                ///      otherwise VAULT_HASH will not be correct
                if (tokenId < lastTokenId) {
                    revert TokenIdsMustBeSorted();
                } else {
                    lastTokenId = tokenId;
                }

                /// @dev Check for duplicates
                if (allowedTokenIds[collection.addr].tokenIds[tokenId]) revert TokenIdAlreadySet();

                allowedTokenIds[collection.addr].tokenIds[tokenId] = true;
                allowedTokenIds[collection.addr].tokenIdList.push(tokenId);
            }
        }
    }

    /// @inheritdoc INftVault
    function hashVault(INftVault.CollectionData[] memory _collections) public pure returns (bytes32) {
        return keccak256(abi.encode(_collections));
    }

    /// @inheritdoc INftVault
    function getAllowedCollections() external view returns (address[] memory collections) {
        collections = new address[](allowedCollections.length());

        for (uint256 i = 0; i < collections.length; i++) {
            (address addr,) = allowedCollections.at(i);
            collections[i] = addr;
        }
    }

    /// @inheritdoc INftVault
    function getAllowedCollectionsLength() external view returns (uint256) {
        return allowedCollections.length();
    }

    /// @inheritdoc INftVault
    function getAllowedCollectionData(address _collectionAddr) external view returns (CollectionData memory) {
        return CollectionData({
            addr: _collectionAddr,
            nftType: NftType(allowedCollections.get(_collectionAddr)),
            allowAllIds: allowedTokenIds[_collectionAddr].allowAllIds,
            tokenIds: allowedTokenIds[_collectionAddr].tokenIdList
        });
    }

    /// @inheritdoc INftVault
    function validateNftType(address _collectionAddr, NftType _nftType) public view returns (uint256 nftType) {
        bool supportsERC721 = ERC165Checker.supportsInterface(_collectionAddr, type(IERC721).interfaceId);
        bool supportsERC1155 = ERC165Checker.supportsInterface(_collectionAddr, type(IERC1155).interfaceId);

        /// @dev if `_collectionAddr` supports both or neither token standard, trust user input
        ///      if `_collectionAddr` supports one of the token standards, NftType must match it
        if (supportsERC721 && !supportsERC1155 && _nftType != NftType.ERC721) revert ExpectedERC721();
        if (supportsERC1155 && !supportsERC721 && _nftType != NftType.ERC1155) revert ExpectedERC1155();

        nftType = uint256(_nftType);
    }

    /// @inheritdoc INftVault
    function isTokenAllowed(address _collection, uint256 _tokenId) public view returns (bool) {
        (bool isCollectionAllowed,) = allowedCollections.tryGet(_collection);

        return isCollectionAllowed
            && (allowedTokenIds[_collection].allowAllIds || allowedTokenIds[_collection].tokenIds[_tokenId]);
    }

    /// @inheritdoc INftVault
    function getSentTokenBalance(address _collection, uint256 _tokenId) public view returns (uint256) {
        uint256 currentBalance = balances[_collection][_tokenId];
        NftType nftType = NftType(allowedCollections.get(_collection));

        if (nftType == NftType.ERC721) {
            if (currentBalance == 0 && IERC721(_collection).ownerOf(_tokenId) == address(this)) {
                return 1;
            } else {
                return 0;
            }
        } else if (nftType == NftType.ERC1155) {
            return IERC1155(_collection).balanceOf(address(this), _tokenId) - currentBalance;
        } else {
            revert UnsupportedNft();
        }
    }

    /// @inheritdoc INftVault
    function deposit(address _to, address _collection, uint256 _tokenId, uint256 _amount)
        public
        returns (uint256 amountMinted)
    {
        if (!isTokenAllowed(_collection, _tokenId)) revert DisallowedToken();

        uint256 sentTokenBalance = getSentTokenBalance(_collection, _tokenId);
        if (_amount == 0 || sentTokenBalance < _amount) revert WrongAmount();

        balances[_collection][_tokenId] += _amount;
        emit Deposit(_to, _collection, _tokenId, _amount);

        amountMinted = ONE * _amount;
        uint256 totalSupply_ = totalSupply();

        /// @dev If vault ERC20 supply is "0 < totalSupply <= 0.01" it means that vault has been emptied and there
        ///      is leftover ERC20 token (most likely) locked in the univ2 pair. To prevent minting small amounts
        ///      of unbacked ERC20 tokens in a loop, which can lead to unexpected behaviour, vault mints
        ///      `ONE - totalSupply` amount of ERC20 token for the first NFT that is deposited after the vault was
        ///      emptied. This allows for the vault and univ2 pair to be reused safely.
        if (totalSupply_ > 0 && totalSupply_ <= ONE - LAST_NFT_AMOUNT) {
            amountMinted -= totalSupply_;
        }

        _mint(_to, amountMinted);
    }

    /// @inheritdoc INftVault
    function depositBatch(
        address _to,
        address[] memory _collection,
        uint256[] memory _tokenId,
        uint256[] memory _amount
    ) external returns (uint256 amountMinted) {
        for (uint256 i = 0; i < _collection.length; i++) {
            amountMinted += deposit(_to, _collection[i], _tokenId[i], _amount[i]);
        }
    }

    /// @inheritdoc INftVault
    function withdraw(address _to, address _collection, uint256 _tokenId, uint256 _amount)
        public
        returns (uint256 amountBurned)
    {
        if (_amount == 0 || balances[_collection][_tokenId] < _amount) revert WrongAmount();

        balances[_collection][_tokenId] -= _amount;
        amountBurned = ONE * _amount;

        // when withdrawing the last NFT from the vault, allow redeemeing for LAST_NFT_AMOUNT instead of ONE
        if (totalSupply() == amountBurned && balanceOf(address(this)) >= amountBurned - ONE + LAST_NFT_AMOUNT) {
            amountBurned = balanceOf(address(this));
        }

        _burn(address(this), amountBurned);

        NftType nftType = NftType(allowedCollections.get(_collection));
        if (nftType == NftType.ERC721) {
            if (_amount != 1) revert WrongERC721Amount();

            IERC721(_collection).safeTransferFrom(address(this), _to, _tokenId);
        } else if (nftType == NftType.ERC1155) {
            IERC1155(_collection).safeTransferFrom(address(this), _to, _tokenId, _amount, bytes(""));
        } else {
            revert UnsupportedNft();
        }

        emit Withdraw(_to, _collection, _tokenId, _amount);
    }

    /// @inheritdoc INftVault
    function withdrawBatch(
        address _to,
        address[] memory _collection,
        uint256[] memory _tokenId,
        uint256[] memory _amount
    ) external returns (uint256 amountBurned) {
        for (uint256 i = 0; i < _collection.length; i++) {
            amountBurned += withdraw(_to, _collection[i], _tokenId[i], _amount[i]);
        }
    }

    /// @inheritdoc INftVault
    function skim(address _to, NftType nftType, address _collection, uint256 _tokenId, uint256 _amount) external {
        // Cannot skim supported token
        if (isTokenAllowed(_collection, _tokenId)) revert MustBeDisallowedToken();

        if (nftType == NftType.ERC721) {
            IERC721(_collection).safeTransferFrom(address(this), _to, _tokenId);
        } else if (nftType == NftType.ERC1155) {
            IERC1155(_collection).safeTransferFrom(address(this), _to, _tokenId, _amount, bytes(""));
        } else {
            revert UnsupportedNft();
        }
    }
}

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

pragma solidity ^0.8.0;

import "./math/Math.sol";

/**
 * @dev String operations.
 */
library Strings {
    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 = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

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

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        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);
    }
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

            return true;
        } else {
            return false;
        }
    }

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

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

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

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }
}

File 6 of 25 : INftVault.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

/// @title Vault contract for wrapping NFTs (ERC721/ERC1155) to ERC20
interface INftVault {
    enum NftType {
        ERC721,
        ERC1155
    }

    /// @notice Vault configuration struct that specifies which NFTs are accepted in vault.
    /// @param addr address of nft contract
    /// @param nftType standard that NFT supports { ERC721, ERC1155 }
    /// @param allowAllIds if true, all tokens are allowed in the vault. If false, tokenIds must be
    ///        listed one by one.
    /// @param tokenIds list of tokens supported by vault. If allowAllIds is true, list must be empty.
    struct CollectionData {
        address addr;
        NftType nftType;
        bool allowAllIds;
        uint256[] tokenIds;
    }

    /// @notice Struct for allowed tokens. Stores data in an optimized way to read it in vault.
    /// @param tokenIds mapping from tokenid to is-allowed
    /// @param tokenIdList list of all tokens that are allowed
    /// @param allowAllIds if true, all tokens are allowed
    struct AllowedTokenIds {
        mapping(uint256 => bool) tokenIds;
        uint256[] tokenIdList;
        bool allowAllIds;
    }

    /// @notice Emitted during initiation when collection added to allowed list
    /// @param collection collection details
    event CollectionAllowed(CollectionData collection);

    /// @notice Emitted on depositing NFT to vault
    /// @param to address that gets vault ERC20 tokens
    /// @param collection NFT address that is deposited
    /// @param tokenId token id that is deposited
    /// @param amount amount of token that is deposited, for ERC721 always 1
    event Deposit(address indexed to, address indexed collection, uint256 tokenId, uint256 amount);

    /// @notice Emitted on withdrawing NFT from vault
    /// @param to address that gets withdrawn NFTs
    /// @param collection NFT address that is withdrawn
    /// @param tokenId token id that is withdrawn
    /// @param amount amount of token that is withdrawn, for ERC721 always 1
    event Withdraw(address indexed to, address indexed collection, uint256 tokenId, uint256 amount);

    /// @dev Contract is already initialized
    error Initialized();
    /// @dev Collection data is empty
    error InvalidCollections();
    /// @dev Collection already added
    error DuplicateCollection();
    /// @dev Token id is listed twice in CollectionData.tokenIds array
    error TokenIdAlreadySet();
    /// @dev Token ids in CollectionData.tokenIds array are not sorted
    error TokenIdsMustBeSorted();
    /// @dev ERC165 suggests that NFT is supporting ERC721 but ERC1155 is claimed
    error ExpectedERC721();
    /// @dev ERC165 suggests that NFT is supporting ERC1155 but ERC721 is claimed
    error ExpectedERC1155();
    /// @dev Collection does not support all token IDs however list of IDs is empty.
    ///      CollectionData.tokenIds is empty and CollectionData.allowAllIds is false.
    error MissingTokenIds();
    /// @dev CollectionData.tokenIds is not empty however Collection supports all token IDs.
    error TokenIdsMustBeEmpty();
    /// @dev Token is not allowed in vault
    error DisallowedToken();
    /// @dev Token amount is invalid eg. amount == 0
    error WrongAmount();
    /// @dev Token amount is invalid for ERC721, amount != 1
    error WrongERC721Amount();
    /// @dev Trying to interact with token that does not support ERC721 nor ERC1155
    error UnsupportedNft();
    /// @dev Token is allowed in vault but must not be
    error MustBeDisallowedToken();

    /// @notice value of 1 token, including decimals
    function ONE() external view returns (uint256);

    /// @notice amount of token required for last NFT to be redeemed
    function LAST_NFT_AMOUNT() external view returns (uint256);

    /// @notice unique id of the vault generated using its configuration
    function VAULT_HASH() external view returns (bytes32);

    /// @notice Initialize Vault with collection config
    /// @dev Called by factory during deployment
    /// @param collections struct array of allowed collections and token IDs
    function init(CollectionData[] memory collections) external;

    /// @notice Returns hash of vault configuration
    /// @param collections struct array of allowed collections and token IDs
    /// @return configuration hash
    function hashVault(CollectionData[] memory collections) external pure returns (bytes32);

    /// @notice Returns balances of NFT deposited to the vault
    /// @param collectionAddr NFT address
    /// @param tokenId NFT's token ID
    /// @return amount amount of NFT deposited to the vault
    function balances(address collectionAddr, uint256 tokenId) external view returns (uint256 amount);

    /// @notice Get array of NFT addresses that are allowed to be deposited to the vault
    /// @dev Keep in mind that returned address(es) can be further restricted on token ID level
    /// @return collections array of NFT addresses that are allowed to be deposited to the vault
    function getAllowedCollections() external view returns (address[] memory collections);

    /// @return number of NFT addresses that are allowed to be deposited to the vault
    function getAllowedCollectionsLength() external view returns (uint256);

    /// @notice Get details of allowed collection
    /// @return struct with details of allowed collection
    function getAllowedCollectionData(address collectionAddr) external view returns (CollectionData memory);

    /// @notice Validates type of collection (ERC721 or ERC1155)
    /// @dev It uses ERC165 to check interface support. If support can not be detected without doubt, user input is trusted.
    /// @param collectionAddr NFT address
    /// @param nftType NFT type, ERC721 or ERC1155
    /// @return validatedNftType returns validated enum NftType as uint256
    function validateNftType(address collectionAddr, NftType nftType)
        external
        view
        returns (uint256 validatedNftType);

    /// @notice Returns if true token can be deposited
    /// @param collection NFT address
    /// @param tokenId NFT token ID
    /// @return true if allowed
    function isTokenAllowed(address collection, uint256 tokenId) external view returns (bool);

    /// @notice Returns balance of token sent to the vault
    /// @dev Reads balance of tokens freshy sent to the vault
    /// @param collection NFT address
    /// @param tokenId NFT token ID
    /// @return balance of sent token, for ERC721 it's always 1
    function getSentTokenBalance(address collection, uint256 tokenId) external view returns (uint256);

    /// @notice Deposit NFT to vault
    /// @dev This low-level function should be called from a contract which performs important safety checks
    /// @param to address that gets minted ERC20 token
    /// @param collection address of deposited NFT
    /// @param tokenId token ID of deposited NFT
    /// @param amount amount of deposited NFT, for ERC721 it's always 1
    /// @return amountMinted amount of minted ERC20 token
    function deposit(address to, address collection, uint256 tokenId, uint256 amount)
        external
        returns (uint256 amountMinted);

    /// @notice Deposit NFTs to vault
    /// @dev This low-level function should be called from a contract which performs important safety checks
    /// @param to address that gets minted ERC20 token
    /// @param collection array of addresses of deposited NFTs
    /// @param tokenId array of token IDs of deposited NFTs
    /// @param amount array if amounts of deposited NFTs, for ERC721 it's always 1
    /// @return amountMinted amount of minted ERC20 token
    function depositBatch(address to, address[] memory collection, uint256[] memory tokenId, uint256[] memory amount)
        external
        returns (uint256 amountMinted);

    /// @notice Withdraw NFT from vault
    /// @dev This low-level function should be called from a contract which performs important safety checks
    /// @param to address that gets NFT
    /// @param collection address of NFT to withdraw
    /// @param tokenId token ID of NFT to withdraw
    /// @param amount amount of NFT to withdraw, for ERC721 it's always 1
    /// @return amountBurned amount of burned ERC20
    function withdraw(address to, address collection, uint256 tokenId, uint256 amount)
        external
        returns (uint256 amountBurned);

    /// @notice Withdraw NFTs from vault
    /// @dev This low-level function should be called from a contract which performs important safety checks
    /// @param to address that gets NFT
    /// @param collection array of addresses of NFTs to withdraw
    /// @param tokenId array of token IDs of NFTs to withdraw
    /// @param amount array of amounts of NFTs to withdraw, for ERC721 it's always 1
    /// @return amountBurned amount of burned ERC20
    function withdrawBatch(address to, address[] memory collection, uint256[] memory tokenId, uint256[] memory amount)
        external
        returns (uint256 amountBurned);

    /// @notice Allow anyone to withdraw tokens sent to this vault by accident
    ///         Only unsupported NFTs can be skimmed.
    /// @param to address that gets NFT
    /// @param nftType NftType of skimmed NFT
    /// @param collection address of NFT to skim
    /// @param tokenId token ID of NFT to skim
    /// @param amount amount of NFT to skim, for ERC721 it's always 1
    function skim(address to, NftType nftType, address collection, uint256 tokenId, uint256 amount) external;
}

File 7 of 25 : Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.0;

import "./Ownable.sol";

/**
 * @dev Contract module which provides 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} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

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

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

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() external {
        address sender = _msgSender();
        require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
        _transferOwnership(sender);
    }
}

File 8 of 25 : ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

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

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

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

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

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _totalSupply -= amount;
        }

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

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

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

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

File 11 of 25 : IERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes calldata data
    ) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata amounts,
        bytes calldata data
    ) external;
}

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

pragma solidity ^0.8.0;

import "../IERC721Receiver.sol";

/**
 * @dev Implementation of the {IERC721Receiver} interface.
 *
 * Accepts all token transfers.
 * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.
 */
contract ERC721Holder is IERC721Receiver {
    /**
     * @dev See {IERC721Receiver-onERC721Received}.
     *
     * Always returns `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address,
        address,
        uint256,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC721Received.selector;
    }
}

File 13 of 25 : ERC165Checker.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/introspection/ERC165Checker.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Library used to query support of an interface declared via {IERC165}.
 *
 * Note that these functions return the actual result of the query: they do not
 * `revert` if an interface is not supported. It is up to the caller to decide
 * what to do in these cases.
 */
library ERC165Checker {
    // As per the EIP-165 spec, no interface should ever match 0xffffffff
    bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;

    /**
     * @dev Returns true if `account` supports the {IERC165} interface.
     */
    function supportsERC165(address account) internal view returns (bool) {
        // Any contract that implements ERC165 must explicitly indicate support of
        // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid
        return
            supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) &&
            !supportsERC165InterfaceUnchecked(account, _INTERFACE_ID_INVALID);
    }

    /**
     * @dev Returns true if `account` supports the interface defined by
     * `interfaceId`. Support for {IERC165} itself is queried automatically.
     *
     * See {IERC165-supportsInterface}.
     */
    function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) {
        // query support of both ERC165 as per the spec and support of _interfaceId
        return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId);
    }

    /**
     * @dev Returns a boolean array where each value corresponds to the
     * interfaces passed in and whether they're supported or not. This allows
     * you to batch check interfaces for a contract where your expectation
     * is that some interfaces may not be supported.
     *
     * See {IERC165-supportsInterface}.
     *
     * _Available since v3.4._
     */
    function getSupportedInterfaces(address account, bytes4[] memory interfaceIds)
        internal
        view
        returns (bool[] memory)
    {
        // an array of booleans corresponding to interfaceIds and whether they're supported or not
        bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);

        // query support of ERC165 itself
        if (supportsERC165(account)) {
            // query support of each interface in interfaceIds
            for (uint256 i = 0; i < interfaceIds.length; i++) {
                interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]);
            }
        }

        return interfaceIdsSupported;
    }

    /**
     * @dev Returns true if `account` supports all the interfaces defined in
     * `interfaceIds`. Support for {IERC165} itself is queried automatically.
     *
     * Batch-querying can lead to gas savings by skipping repeated checks for
     * {IERC165} support.
     *
     * See {IERC165-supportsInterface}.
     */
    function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) {
        // query support of ERC165 itself
        if (!supportsERC165(account)) {
            return false;
        }

        // query support of each interface in interfaceIds
        for (uint256 i = 0; i < interfaceIds.length; i++) {
            if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) {
                return false;
            }
        }

        // all interfaces supported
        return true;
    }

    /**
     * @notice Query if a contract implements an interface, does not check ERC165 support
     * @param account The address of the contract to query for support of an interface
     * @param interfaceId The interface identifier, as specified in ERC-165
     * @return true if the contract at account indicates support of the interface with
     * identifier interfaceId, false otherwise
     * @dev Assumes that account contains a contract that supports ERC165, otherwise
     * the behavior of this method is undefined. This precondition can be checked
     * with {supportsERC165}.
     * Interface identification is specified in ERC-165.
     */
    function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) {
        // prepare call
        bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId);

        // perform static call
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly {
            success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0x00)
        }

        return success && returnSize >= 0x20 && returnValue > 0;
    }
}

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

pragma solidity ^0.8.0;

import "./EnumerableSet.sol";

/**
 * @dev Library for managing an enumerable variant of Solidity's
 * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
 * type.
 *
 * Maps have the following properties:
 *
 * - Entries are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Entries are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableMap for EnumerableMap.UintToAddressMap;
 *
 *     // Declare a set state variable
 *     EnumerableMap.UintToAddressMap private myMap;
 * }
 * ```
 *
 * The following map types are supported:
 *
 * - `uint256 -> address` (`UintToAddressMap`) since v3.0.0
 * - `address -> uint256` (`AddressToUintMap`) since v4.6.0
 * - `bytes32 -> bytes32` (`Bytes32ToBytes32Map`) since v4.6.0
 * - `uint256 -> uint256` (`UintToUintMap`) since v4.7.0
 * - `bytes32 -> uint256` (`Bytes32ToUintMap`) since v4.7.0
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableMap, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableMap.
 * ====
 */
library EnumerableMap {
    using EnumerableSet for EnumerableSet.Bytes32Set;

    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Map type with
    // bytes32 keys and values.
    // The Map implementation uses private functions, and user-facing
    // implementations (such as Uint256ToAddressMap) are just wrappers around
    // the underlying Map.
    // This means that we can only create new EnumerableMaps for types that fit
    // in bytes32.

    struct Bytes32ToBytes32Map {
        // Storage of keys
        EnumerableSet.Bytes32Set _keys;
        mapping(bytes32 => bytes32) _values;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        Bytes32ToBytes32Map storage map,
        bytes32 key,
        bytes32 value
    ) internal returns (bool) {
        map._values[key] = value;
        return map._keys.add(key);
    }

    /**
     * @dev Removes a key-value pair from a map. O(1).
     *
     * Returns true if the key was removed from the map, that is if it was present.
     */
    function remove(Bytes32ToBytes32Map storage map, bytes32 key) internal returns (bool) {
        delete map._values[key];
        return map._keys.remove(key);
    }

    /**
     * @dev Returns true if the key is in the map. O(1).
     */
    function contains(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool) {
        return map._keys.contains(key);
    }

    /**
     * @dev Returns the number of key-value pairs in the map. O(1).
     */
    function length(Bytes32ToBytes32Map storage map) internal view returns (uint256) {
        return map._keys.length();
    }

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

    /**
     * @dev Tries to returns the value associated with `key`. O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool, bytes32) {
        bytes32 value = map._values[key];
        if (value == bytes32(0)) {
            return (contains(map, key), bytes32(0));
        } else {
            return (true, value);
        }
    }

    /**
     * @dev Returns the value associated with `key`. O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bytes32) {
        bytes32 value = map._values[key];
        require(value != 0 || contains(map, key), "EnumerableMap: nonexistent key");
        return value;
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryGet}.
     */
    function get(
        Bytes32ToBytes32Map storage map,
        bytes32 key,
        string memory errorMessage
    ) internal view returns (bytes32) {
        bytes32 value = map._values[key];
        require(value != 0 || contains(map, key), errorMessage);
        return value;
    }

    // UintToUintMap

    struct UintToUintMap {
        Bytes32ToBytes32Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        UintToUintMap storage map,
        uint256 key,
        uint256 value
    ) internal returns (bool) {
        return set(map._inner, bytes32(key), bytes32(value));
    }

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

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

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(UintToUintMap storage map) internal view returns (uint256) {
        return length(map._inner);
    }

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

    /**
     * @dev Tries to returns the value associated with `key`. O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(UintToUintMap storage map, uint256 key) internal view returns (bool, uint256) {
        (bool success, bytes32 value) = tryGet(map._inner, bytes32(key));
        return (success, uint256(value));
    }

    /**
     * @dev Returns the value associated with `key`. O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(UintToUintMap storage map, uint256 key) internal view returns (uint256) {
        return uint256(get(map._inner, bytes32(key)));
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryGet}.
     */
    function get(
        UintToUintMap storage map,
        uint256 key,
        string memory errorMessage
    ) internal view returns (uint256) {
        return uint256(get(map._inner, bytes32(key), errorMessage));
    }

    // UintToAddressMap

    struct UintToAddressMap {
        Bytes32ToBytes32Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        UintToAddressMap storage map,
        uint256 key,
        address value
    ) internal returns (bool) {
        return set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
    }

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

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

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(UintToAddressMap storage map) internal view returns (uint256) {
        return length(map._inner);
    }

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

    /**
     * @dev Tries to returns the value associated with `key`. O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) {
        (bool success, bytes32 value) = tryGet(map._inner, bytes32(key));
        return (success, address(uint160(uint256(value))));
    }

    /**
     * @dev Returns the value associated with `key`. O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
        return address(uint160(uint256(get(map._inner, bytes32(key)))));
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryGet}.
     */
    function get(
        UintToAddressMap storage map,
        uint256 key,
        string memory errorMessage
    ) internal view returns (address) {
        return address(uint160(uint256(get(map._inner, bytes32(key), errorMessage))));
    }

    // AddressToUintMap

    struct AddressToUintMap {
        Bytes32ToBytes32Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        AddressToUintMap storage map,
        address key,
        uint256 value
    ) internal returns (bool) {
        return set(map._inner, bytes32(uint256(uint160(key))), bytes32(value));
    }

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

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

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(AddressToUintMap storage map) internal view returns (uint256) {
        return length(map._inner);
    }

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

    /**
     * @dev Tries to returns the value associated with `key`. O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(AddressToUintMap storage map, address key) internal view returns (bool, uint256) {
        (bool success, bytes32 value) = tryGet(map._inner, bytes32(uint256(uint160(key))));
        return (success, uint256(value));
    }

    /**
     * @dev Returns the value associated with `key`. O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(AddressToUintMap storage map, address key) internal view returns (uint256) {
        return uint256(get(map._inner, bytes32(uint256(uint160(key)))));
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryGet}.
     */
    function get(
        AddressToUintMap storage map,
        address key,
        string memory errorMessage
    ) internal view returns (uint256) {
        return uint256(get(map._inner, bytes32(uint256(uint160(key))), errorMessage));
    }

    // Bytes32ToUintMap

    struct Bytes32ToUintMap {
        Bytes32ToBytes32Map _inner;
    }

    /**
     * @dev Adds a key-value pair to a map, or updates the value for an existing
     * key. O(1).
     *
     * Returns true if the key was added to the map, that is if it was not
     * already present.
     */
    function set(
        Bytes32ToUintMap storage map,
        bytes32 key,
        uint256 value
    ) internal returns (bool) {
        return set(map._inner, key, bytes32(value));
    }

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

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

    /**
     * @dev Returns the number of elements in the map. O(1).
     */
    function length(Bytes32ToUintMap storage map) internal view returns (uint256) {
        return length(map._inner);
    }

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

    /**
     * @dev Tries to returns the value associated with `key`. O(1).
     * Does not revert if `key` is not in the map.
     */
    function tryGet(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool, uint256) {
        (bool success, bytes32 value) = tryGet(map._inner, key);
        return (success, uint256(value));
    }

    /**
     * @dev Returns the value associated with `key`. O(1).
     *
     * Requirements:
     *
     * - `key` must be in the map.
     */
    function get(Bytes32ToUintMap storage map, bytes32 key) internal view returns (uint256) {
        return uint256(get(map._inner, key));
    }

    /**
     * @dev Same as {get}, with a custom error message when `key` is not in the map.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryGet}.
     */
    function get(
        Bytes32ToUintMap storage map,
        bytes32 key,
        string memory errorMessage
    ) internal view returns (uint256) {
        return uint256(get(map._inner, key, errorMessage));
    }
}

File 15 of 25 : ERC1155Holder.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/utils/ERC1155Holder.sol)

pragma solidity ^0.8.0;

import "./ERC1155Receiver.sol";

/**
 * Simple implementation of `ERC1155Receiver` that will allow a contract to hold ERC1155 tokens.
 *
 * IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be
 * stuck.
 *
 * @dev _Available since v3.1._
 */
contract ERC1155Holder is ERC1155Receiver {
    function onERC1155Received(
        address,
        address,
        uint256,
        uint256,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address,
        address,
        uint256[] memory,
        uint256[] memory,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC1155BatchReceived.selector;
    }
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

pragma solidity ^0.8.0;

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

File 19 of 25 : IERC721Receiver.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 IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

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

pragma solidity ^0.8.0;

import "../utils/Context.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 Ownable is Context {
    address private _owner;

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

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

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

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

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

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

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

File 21 of 25 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

File 22 of 25 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

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

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

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

File 23 of 25 : ERC1155Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Receiver.sol)

pragma solidity ^0.8.0;

import "../IERC1155Receiver.sol";
import "../../../utils/introspection/ERC165.sol";

/**
 * @dev _Available since v3.1._
 */
abstract contract ERC1155Receiver is ERC165, IERC1155Receiver {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
    }
}

File 24 of 25 : IERC1155Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)

pragma solidity ^0.8.0;

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

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

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

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

pragma solidity ^0.8.0;

import "./IERC165.sol";

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

Settings
{
  "evmVersion": "paris",
  "optimizer": {
    "enabled": true,
    "mode": "3"
  },
  "outputSelection": {
    "*": {
      "*": [
        "abi"
      ]
    }
  },
  "detectMissingLibraries": false,
  "forceEVMLA": false,
  "enableEraVMExtensions": false,
  "libraries": {}
}

Contract ABI

API
[{"inputs":[],"name":"VaultAlreadyDeployed","type":"error"},{"inputs":[],"name":"VaultDoesNotExist","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"string","name":"symbol","type":"string"},{"indexed":true,"internalType":"contract INftVault","name":"vault","type":"address"},{"indexed":true,"internalType":"uint256","name":"vaultId","type":"uint256"},{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"enum INftVault.NftType","name":"nftType","type":"uint8"},{"internalType":"bool","name":"allowAllIds","type":"bool"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"indexed":false,"internalType":"struct INftVault.CollectionData[]","name":"collections","type":"tuple[]"},{"indexed":false,"internalType":"address","name":"creator","type":"address"}],"name":"VaultCreated","type":"event"},{"inputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"enum INftVault.NftType","name":"nftType","type":"uint8"},{"internalType":"bool","name":"allowAllIds","type":"bool"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"internalType":"struct INftVault.CollectionData[]","name":"_collections","type":"tuple[]"}],"name":"createVault","outputs":[{"internalType":"contract INftVault","name":"vault","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"enum INftVault.NftType","name":"nftType","type":"uint8"},{"internalType":"bool","name":"allowAllIds","type":"bool"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"internalType":"struct INftVault.CollectionData[]","name":"_collections","type":"tuple[]"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAllVaults","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"enum INftVault.NftType","name":"nftType","type":"uint8"},{"internalType":"bool","name":"allowAllIds","type":"bool"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"internalType":"struct INftVault.CollectionData[]","name":"_collections","type":"tuple[]"}],"name":"getVault","outputs":[{"internalType":"contract INftVault","name":"vault","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"getVaultAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVaultLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"enum INftVault.NftType","name":"nftType","type":"uint8"},{"internalType":"bool","name":"allowAllIds","type":"bool"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"internalType":"struct INftVault.CollectionData[]","name":"_collections","type":"tuple[]"}],"name":"hashVault","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"}],"name":"isVault","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"vaultHashMap","outputs":[{"internalType":"contract INftVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract INftVault","name":"","type":"address"}],"name":"vaultIdMap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

9c4d535b0000000000000000000000000000000000000000000000000000000000000000010001db5d767185714cc92b45e71aa204d217485b14dabe76b1c480a7f435a500000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000

Deployed Bytecode

0x0004000000000002000800000000000200000000030100190000006004300270000001a40340019700030000003103550002000000010355000001a40040019d0000008004000039000000400040043f0000000100200190000000210000c13d000000040030008c0000012c0000413d000000000201043b000000e002200270000001a60020009c000000290000213d000001ad0020009c000000420000a13d000001ae0020009c0000006d0000613d000001af0020009c000000fe0000613d000001b00020009c0000012c0000c13d0000000001000416000000000001004b0000012c0000c13d000000000100041a000000800010043f000001be010000410000068b0001042e0000000001000416000000000001004b0000012c0000c13d000000200100003900000100001004430000012000000443000001a5010000410000068b0001042e000001a70020009c0000005c0000a13d000001a80020009c0000007b0000613d000001a90020009c0000010f0000613d000001aa0020009c0000012c0000c13d0000000001000416000000000001004b0000012c0000c13d0000000001030019068a05700000040f068a06030000040f000000000010043f0000000201000039000000200010043f00000040020000390000000001000019068a066b0000040f000000000101041a000001b3001001980000000001000039000000010100c039000000660000013d000001b10020009c0000008e0000613d000001b20020009c0000012c0000c13d000000240030008c0000012c0000413d0000000002000416000000000002004b0000012c0000c13d0000000401100370000000000101043b000001b30010009c0000012c0000213d000000000010043f0000000101000039000000200010043f00000040020000390000000001000019068a066b0000040f000000000101041a000000000001004b0000000001000039000000010100c039000000800010043f000001be010000410000068b0001042e000001ab0020009c000000f20000613d000001ac0020009c0000012c0000c13d0000000001000416000000000001004b0000012c0000c13d0000000001030019068a05700000040f068a06030000040f000000400200043d0000000000120435000001a40020009c000001a4020080410000004001200210000001b4011001c70000068b0001042e000000240030008c0000012c0000413d0000000002000416000000000002004b0000012c0000c13d0000000401100370000000000101043b000000000010043f0000000201000039000000200010043f00000040020000390000000001000019068a066b0000040f0000010a0000013d000000240030008c0000012c0000413d0000000002000416000000000002004b0000012c0000c13d0000000401100370000000000101043b000001b30010009c0000012c0000213d000000000010043f0000000301000039000000200010043f00000040020000390000000001000019068a066b0000040f000000000101041a000000800010043f000001be010000410000068b0001042e000000240230008c0000012c0000413d0000000004000416000000000004004b0000012c0000c13d0000000404100370000000000404043b000001b50040009c0000012c0000213d0000002305400039000000000035004b0000012c0000813d0000000405400039000000000551034f000000000805043b000001c30080009c0000013c0000813d00000005068002100000003f05600039000001b605500197000001b70050009c0000013c0000213d0000008007500039000000400070043f000000800080043f00000024054000390000000006560019000000000036004b0000012c0000213d000000000008004b000002090000c13d0000002001700039000000200200003900000000002104350000004002700039000000800300043d0000000000320435000000600470003900000005023002100000000002420019000000000003004b0000026b0000c13d0000000002720049000000200320008a00000000003704350000001f02200039000001d9032001970000000002730019000000000032004b00000000030000390000000103004039000001b50020009c0000013c0000213d00000001003001900000013c0000c13d000000400020043f000001a40010009c000001a40100804100000040011002100000000002070433000001a40020009c000001a4020080410000006002200210000000000112019f0000000002000414000001a40020009c000001a402008041000000c002200210000000000112019f000001ba011001c70000801002000039068a06850000040f00000001002001900000012c0000613d000000000101043b000800000001001d000000000010043f0000000201000039000000200010043f0000000001000414000001a40010009c000001a401008041000000c001100210000001bb011001c70000801002000039068a06850000040f00000001002001900000012c0000613d000000000101043b000000000101041a000001b300100198000002c70000c13d000000000100041a000700000001001d000001c50010009c000002d20000413d00000040020000390000000701000029000001c50110012a000002db0000013d0000000001000416000000000001004b0000012c0000c13d0000002002000039000000000100041a000000800010043f000000000000043f000000000001004b0000012e0000c13d000000a0010000390000000004020019000001490000013d000000240030008c0000012c0000413d0000000002000416000000000002004b0000012c0000c13d0000000401100370000000000101043b000000000200041a000000000021004b000001420000813d000000000000043f000001c20110009a000000000101041a000001b301100197000000800010043f000001be010000410000068b0001042e000000240230008c0000012c0000413d0000000005000416000000000005004b0000012c0000c13d0000000405100370000000000505043b000001b50050009c0000012c0000213d0000002306500039000000000036004b0000012c0000813d0000000406500039000000000661034f000000000906043b000001b50090009c0000013c0000213d00000005079002100000003f06700039000001b606600197000001b70060009c0000013c0000213d0000008008600039000000400080043f000000800090043f00000024065000390000000007670019000000000037004b000001620000a13d00000000010000190000068c00010430000000a005000039000001bf0300004100000000040000190000000006050019000000000503041a000000000556043600000001033000390000000104400039000000000014004b000001310000413d000000410160008a000001d904100197000001b70040009c000001480000a13d000001c001000041000000000010043f0000004101000039000000040010043f000001c1010000410000068c00010430000001c001000041000000000010043f0000003201000039000000040010043f000001c1010000410000068c000104300000008001400039000000400010043f0000000000210435000000a002400039000000800300043d0000000000320435000000c002400039000000000003004b000001590000613d000000a00400003900000000050000190000000046040434000001b30660019700000000026204360000000105500039000000000035004b000001530000413d0000000002120049000001a40020009c000001a4020080410000006002200210000001a40010009c000001a4010080410000004001100210000000000112019f0000068b0001042e000000000009004b000001b00000c13d0000002001800039000000200200003900000000002104350000004002800039000000800300043d0000000000320435000000600480003900000005023002100000000002420019000000000003004b000002970000c13d0000000002820049000000200320008a00000000003804350000001f02200039000001d9032001970000000002830019000000000032004b00000000030000390000000103004039000001b50020009c0000013c0000213d00000001003001900000013c0000c13d000000400020043f000001a40010009c000001a40100804100000040011002100000000002080433000001a40020009c000001a4020080410000006002200210000000000112019f0000000002000414000001a40020009c000001a402008041000000c002200210000000000112019f000001ba011001c70000801002000039068a06850000040f00000001002001900000012c0000613d000000000101043b000000000010043f0000000201000039000000200010043f0000000001000414000001a40010009c000001a401008041000000c001100210000001bb011001c70000801002000039068a06850000040f00000001002001900000012c0000613d000000400200043d000001a40020009c000001a40300004100000000030240190000004003300210000000000101043b000000000101041a000001b301100198000002cf0000c13d000001bc010000410000000000120435000001bd013001c70000068c000104300000002004400039000000600a80003900000000009a043500000000008404350000002006600039000000000076004b000002c30000813d000000000861034f000000000808043b000001b50080009c0000012c0000213d00000000095800190000000008920049000001b80080009c0000012c0000213d000000800080008c0000012c0000413d000000400800043d000001b70080009c0000013c0000213d000000800a8000390000004000a0043f000000240a900039000000000ba1034f000000000b0b043b000001b300b0009c0000012c0000213d000000000bb80436000000200aa00039000000000ca1034f000000000c0c043b0000000100c0008c0000012c0000213d0000000000cb0435000000200aa00039000000000ba1034f000000000b0b043b00000000000b004b000000000c000039000000010c00c0390000000000cb004b0000012c0000c13d000000400c8000390000000000bc0435000000200aa00039000000000aa1034f000000000a0a043b000001b500a0009c0000012c0000213d000000000a9a00190000004309a00039000000000039004b000000000b000019000001b90b008041000001b909900197000000000009004b000000000c000019000001b90c004041000001b90090009c000000000c0bc01900000000000c004b0000012c0000c13d0000002409a00039000000000991034f000000000b09043b000001b500b0009c0000013c0000213d000000050cb002100000003f09c00039000001b60d900197000000400900043d000000000dd9001900000000009d004b000000000e000039000000010e004039000001b500d0009c0000013c0000213d0000000100e001900000013c0000c13d0000004000d0043f0000000000b90435000000440aa00039000000000bac001900000000003b004b0000012c0000213d0000000000ba004b000001a90000813d000000000c090019000000000da1034f000000000d0d043b000000200cc000390000000000dc0435000000200aa000390000000000ba004b000002010000413d000001a90000013d0000008007000039000002120000013d0000002007700039000000600a80003900000000009a043500000000008704350000002005500039000000000065004b000002c50000813d000000000851034f000000000808043b000001b50080009c0000012c0000213d00000000094800190000000008920049000001b80080009c0000012c0000213d000000800080008c0000012c0000413d000000400800043d000001b70080009c0000013c0000213d000000800a8000390000004000a0043f000000240a900039000000000ba1034f000000000b0b043b000001b300b0009c0000012c0000213d000000000bb80436000000200aa00039000000000ca1034f000000000c0c043b0000000100c0008c0000012c0000213d0000000000cb0435000000200aa00039000000000ba1034f000000000b0b043b00000000000b004b000000000c000039000000010c00c0390000000000cb004b0000012c0000c13d000000400c8000390000000000bc0435000000200aa00039000000000aa1034f000000000a0a043b000001b500a0009c0000012c0000213d000000000a9a00190000004309a00039000000000039004b000000000b000019000001b90b008041000001b909900197000000000009004b000000000c000019000001b90c004041000001b90090009c000000000c0bc01900000000000c004b0000012c0000c13d0000002409a00039000000000991034f000000000b09043b000001b500b0009c0000013c0000213d000000050cb002100000003f09c00039000001b60d900197000000400900043d000000000dd9001900000000009d004b000000000e000039000000010e004039000001b500d0009c0000013c0000213d0000000100e001900000013c0000c13d0000004000d0043f0000000000b90435000000440aa00039000000000bac001900000000003b004b0000012c0000213d0000000000ba004b0000020b0000813d000000000c090019000000000da1034f000000000d0d043b000000200cc000390000000000dc0435000000200aa000390000000000ba004b000002630000413d0000020b0000013d0000008005000039000000000605001900000000080000190000000009040019000002730000013d0000000108800039000000000038004b000000b80000813d000000000a4200490000000009a904360000002006600039000000000a06043300000000cb0a0434000001b30bb00197000000000bb20436000000000c0c04330000000200c0008c0000056a0000813d0000000000cb0435000000400ba00039000000000b0b043300000000000b004b000000000b000039000000010b00c039000000400c2000390000000000bc0435000000600aa00039000000000a0a0433000000600b20003900000000005b0435000000800c200039000000000b0a04330000000000bc0435000000a00220003900000000000b004b000002700000613d000000000c000019000000200aa00039000000000d0a04330000000002d20436000000010cc000390000000000bc004b000002900000413d000002700000013d00000080050000390000000006050019000000000700001900000000090400190000029f0000013d0000000107700039000000000037004b0000016f0000813d000000000a4200490000000009a904360000002006600039000000000a06043300000000cb0a0434000001b30bb00197000000000bb20436000000000c0c04330000000100c0008c0000056a0000213d0000000000cb0435000000400ba00039000000000b0b043300000000000b004b000000000b000039000000010b00c039000000400c2000390000000000bc0435000000600aa00039000000000a0a0433000000600b20003900000000005b0435000000800c200039000000000b0a04330000000000bc0435000000a00220003900000000000b004b0000029c0000613d000000000c000019000000200aa00039000000000d0a04330000000002d20436000000010cc000390000000000bc004b000002bc0000413d0000029c0000013d000000400800043d000001640000013d000000400700043d000000ad0000013d000000400100043d000001c4020000410000000000210435000001a40010009c000001a4010080410000004001100210000001bd011001c70000068c000104300000000000120435000001b4013001c70000068b0001042e0000000701000029000001c70010009c000001c60110212a00000000020000390000002002002039000001c80010009c00000010022081bf000001c901108197000001c80110812a000001ca0010009c0000000802208039000001b501108197000001ca0110812a000027100010008c0000000402208039000001a401108197000027100110811a000000640010008c00000002022080390000ffff0110818f000000640110811a000000090010008c0000000102202039000001d9012001970000005f03100039000001d905300197000000400400043d0000000003450019000000000053004b00000000050000390000000105004039000001b50030009c0000013c0000213d00000001005001900000013c0000c13d000000400030043f000000010320003900000000033404360000002001100039000001d9061001980000001f0510018f00000000010000310000000201100367000003050000613d0000000006630019000000000701034f0000000008030019000000007907043c0000000008980436000000000068004b000003010000c13d000000000005004b000000000224001900000021022000390000000705000029000000090050008c0000000a6550011a0000000306600210000000010220008a0000000007020433000001cb07700197000001cc0660021f000001cd06600197000000000676019f0000000000620435000003090000213d000000400600043d0000002005600039000001ce02000041000500000005001d0000000000250435000600000006001d0000002c056000390000000002040433000000000002004b000003260000613d000000000400001900000000065400190000000007340019000000000707043300000000007604350000002004400039000000000024004b0000031f0000413d000000000352001900000000000304350000000c03200039000000060400002900000000003404350000004b02200039000001d9032001970000000002430019000000000032004b00000000030000390000000103004039000001b50020009c0000013c0000213d00000001003001900000013c0000c13d000000400020043f0000000703000029000001c50030009c0000033d0000413d00000040030000390000000704000029000001c50440012a000003460000013d0000000704000029000001c70040009c000001c60440212a00000000030000390000002003002039000001c80040009c00000010033081bf000001c904408197000001c80440812a000001ca0040009c0000000803308039000001b504408197000001ca0440812a000027100040008c0000000403308039000001a404408197000027100440811a000000640040008c00000002033080390000ffff0440818f000000640440811a000000090040008c0000000103302039000001d9053001970000005f04500039000001d9044001970000000004240019000001b50040009c0000013c0000213d000000400040043f000000010430003900000000044204360000002005500039000001d9065001980000001f0550018f000003670000613d00000000066400190000000007040019000000001801043c0000000007870436000000000067004b000003630000c13d000000000005004b000000000132001900000021011000390000000703000029000000090030008c0000000a5330011a0000000305500210000000010110008a0000000006010433000001cb06600197000001cc0550021f000001cd05500197000000000565019f00000000005104350000036b0000213d000000400500043d0000002003500039000001cf01000041000300000003001d0000000000130435000400000005001d0000002a035000390000000001020433000000000001004b000003880000613d000000000200001900000000053200190000000006420019000000000606043300000000006504350000002002200039000000000012004b000003810000413d000000000231001900000000000204350000000a02100039000000040300002900000000002304350000004901100039000001d9021001970000000001320019000000000021004b00000000020000390000000102004039000001b50010009c0000013c0000213d00000001002001900000013c0000c13d000000400010043f000001d00010009c0000013c0000213d00000084021000390000002403100039000001d10400004100000000004304350000004003000039000000000032043500000006030000290000000003030433000000c4041000390000000000340435000000e404100039000000000003004b0000000508000029000003b00000613d000000000500001900000000064500190000000007850019000000000707043300000000007604350000002005500039000000000035004b000003a90000413d000000000543001900000000000504350000001f03300039000001d90330019700000000044300190000000002240049000000a4031000390000000000230435000000040200002900000000030204330000000002340436000000000003004b0000000307000029000003c60000613d000000000400001900000000052400190000000006740019000000000606043300000000006504350000002004400039000000000034004b000003bf0000413d0000000004230019000000000004043500000044041000390000000005000414000000600600003900000000006404350000001f03300039000001d90330019700000000021200490000000002230019000000840320008a00000064041000390000000000340435000001d203000041000000000031043500000004031000390000000000030435000001a40020009c000001a4020080410000006002200210000001a40010009c000001a4010080410000004001100210000000000112019f000001a40050009c000001a405008041000000c002500210000000000112019f000001ba011001c70000800602000039068a06800000040f0000000100200190000003ed0000613d000000000101043b000000000001004b000004120000c13d00000003010003670000000102000031000003f20000013d000300000001035500000000020100190000006002200270000101a40020019d000001a402200197000001d9052001980000001f0620018f000000400300043d0000000004530019000003fd0000613d000000000701034f0000000008030019000000007907043c0000000008980436000000000048004b000003f90000c13d000000000006004b0000040a0000613d000000000151034f0000000305600210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f0000000000140435000001a40020009c000001a4020080410000006001200210000001a40030009c000001a4030080410000004002300210000000000112019f0000068c00010430000001d3020000410000000000200443000001b301100197000200000001001d00000004001004430000000001000414000001a40010009c000001a401008041000000c001100210000001d4011001c70000800202000039068a06850000040f0000000100200190000004f30000613d000000000101043b000000000001004b0000012c0000613d000000400300043d000001d50100004100000000001304350000000401300039000000200200003900000000002104350000002401300039000000800200043d0000000000210435000100000003001d000000440330003900000005012002100000000001310019000000000002004b000004f40000c13d00000000020004140000000203000029000000040030008c0000044b0000613d00000001030000290000000001310049000001a40010009c000001a4010080410000006001100210000001a40030009c000001a4030080410000004003300210000000000131019f000001a40020009c000001a402008041000000c002200210000000000121019f0000000202000029068a06800000040f00000000030100190000006003300270000101a40030019d00030000000103550000000100200190000005200000613d0000000101000029000001b50010009c0000013c0000213d0000000101000029000000400010043f0000000201000029000000000010043f0000000101000039000000200010043f0000000001000414000001a40010009c000001a401008041000000c001100210000001bb011001c70000801002000039068a06850000040f00000001002001900000012c0000613d000000000101043b000000000101041a000000000001004b0000047a0000c13d000000000100041a000001b50010009c0000013c0000213d0000000102100039000000000020041b000001c20110009a0000000202000029000000000021041b000000000100041a000100000001001d000000000020043f0000000101000039000000200010043f0000000001000414000001a40010009c000001a401008041000000c001100210000001bb011001c70000801002000039068a06850000040f00000001002001900000012c0000613d000000000101043b0000000102000029000000000021041b0000000801000029000000000010043f0000000201000039000000200010043f0000000001000414000001a40010009c000001a401008041000000c001100210000001bb011001c70000801002000039068a06850000040f00000001002001900000012c0000613d000000000101043b000000000201041a000001d7022001970000000203000029000000000232019f000000000021041b000000000030043f0000000301000039000000200010043f0000000001000414000001a40010009c000001a401008041000000c001100210000001bb011001c70000801002000039068a06850000040f00000001002001900000012c0000613d000000000101043b0000000702000029000000000021041b0000008002000039000000400100043d00000000032104360000000604000029000000000404043300000080051000390000000000450435000000a005100039000000000004004b0000000509000029000004af0000613d000000000600001900000000075600190000000008960019000000000808043300000000008704350000002006600039000000000046004b000004a80000413d000000000654001900000000000604350000001f04400039000001d904400197000000000554001900000000041500490000000000430435000000040300002900000000040304330000000003450436000000000004004b0000000308000029000004c40000613d000000000500001900000000063500190000000007850019000000000707043300000000007604350000002005500039000000000045004b000004bd0000413d000000000534001900000000000504350000001f04400039000001d9044001970000000003340019000000000413004900000040051000390000000000450435000000800400043d000000000543043600000005034002100000000003530019000000000004004b0000053f0000c13d0000006002100039000000000400041100000000004204350000000002130049000001a40020009c000001a4020080410000006002200210000001a40010009c000001a4010080410000004001100210000000000112019f0000000002000414000001a40020009c000001a402008041000000c002200210000000000112019f000001ba011001c70000800d020000390000000303000039000001d80400004100000002050000290000000706000029068a06800000040f00000001002001900000012c0000613d000000400100043d00000002020000290000000000210435000001a40010009c000001a4010080410000004001100210000001b4011001c70000068b0001042e000000000001042f0000008004000039000000000504001900000000060000190000000007030019000004fc0000013d0000000106600039000000000026004b000004320000813d000000000831004900000000078704360000002005500039000000000805043300000000a9080434000001b3099001970000000009910436000000000a0a04330000000100a0008c0000056a0000213d0000000000a9043500000040098000390000000009090433000000000009004b0000000009000039000000010900c039000000400a10003900000000009a04350000006008800039000000000808043300000060091000390000000000490435000000800a100039000000000908043300000000009a0435000000a001100039000000000009004b000004f90000613d000000000a0000190000002008800039000000000b0804330000000001b10436000000010aa0003900000000009a004b000005190000413d000004f90000013d000001a4033001970000001f0530018f000001d606300198000000400200043d00000000046200190000052c0000613d000000000701034f0000000008020019000000007907043c0000000008980436000000000048004b000005280000c13d000000000005004b000005390000613d000000000161034f0000000305500210000000000604043300000000065601cf000000000656022f000000000101043b0000010005500089000000000151022f00000000015101cf000000000161019f00000000001404350000006001300210000001a40020009c000001a4020080410000004002200210000000000112019f0000068c00010430000000000602001900000000070000190000000008050019000005460000013d0000000107700039000000000047004b000004d20000813d000000000953004900000000089804360000002006600039000000000906043300000000ba090434000001b30aa00197000000000aa30436000000000b0b04330000000100b0008c0000056a0000213d0000000000ba0435000000400a900039000000000a0a043300000000000a004b000000000a000039000000010a00c039000000400b3000390000000000ab043500000060099000390000000009090433000000600a30003900000000002a0435000000800b300039000000000a0904330000000000ab0435000000a00330003900000000000a004b000005430000613d000000000b0000190000002009900039000000000c0904330000000003c30436000000010bb000390000000000ab004b000005630000413d000005430000013d000001c001000041000000000010043f0000002101000039000000040010043f000001c1010000410000068c00010430000001b80010009c000005fb0000213d000000240310008c000005fb0000413d00000002040003670000000402400370000000000502043b000001b50050009c000005fb0000213d0000002302500039000000000012004b000005fb0000813d0000000402500039000000000224034f000000000802043b000001c30080009c000005fd0000813d00000005078002100000003f02700039000001b606200197000000400200043d0000000006620019000000000026004b00000000090000390000000109004039000001b50060009c000005fd0000213d0000000100900190000005fd0000c13d000000400060043f000000000082043500000024065000390000000007760019000000000017004b000005fb0000213d000000000008004b000005f90000613d00000000080200190000059e0000013d0000002008800039000000600b9000390000000000ab043500000000009804350000002006600039000000000076004b000005f90000813d000000000964034f000000000909043b000001b50090009c000005fb0000213d000000000a5900190000000009a30049000001b80090009c000005fb0000213d000000800090008c000005fb0000413d000000400900043d000001b70090009c000005fd0000213d000000800b9000390000004000b0043f000000240ba00039000000000cb4034f000000000c0c043b000001b300c0009c000005fb0000213d000000000cc90436000000200bb00039000000000db4034f000000000d0d043b0000000100d0008c000005fb0000213d0000000000dc0435000000200bb00039000000000cb4034f000000000c0c043b00000000000c004b000000000d000039000000010d00c0390000000000dc004b000005fb0000c13d000000400d9000390000000000cd0435000000200bb00039000000000bb4034f000000000b0b043b000001b500b0009c000005fb0000213d000000000bab0019000000430ab0003900000000001a004b000000000c000019000001b90c008041000001b90aa00197000001b90d100197000000000eda013f0000000000da004b000000000a000019000001b90a004041000001b900e0009c000000000a0cc01900000000000a004b000005fb0000c13d000000240ab00039000000000aa4034f000000000c0a043b000001b500c0009c000005fd0000213d000000050dc002100000003f0ad00039000001b60ea00197000000400a00043d000000000eea00190000000000ae004b000000000f000039000000010f004039000001b500e0009c000005fd0000213d0000000100f00190000005fd0000c13d0000004000e0043f0000000000ca0435000000440bb00039000000000cdb001900000000001c004b000005fb0000213d0000000000cb004b000005970000813d000000000d0a0019000000000eb4034f000000000e0e043b000000200dd000390000000000ed0435000000200bb000390000000000cb004b000005f10000413d000005970000013d0000000001020019000000000001042d00000000010000190000068c00010430000001c001000041000000000010043f0000004101000039000000040010043f000001c1010000410000068c00010430000000400200043d000000200320003900000020040000390000000000430435000000000501043300000040042000390000000000540435000000600620003900000005045002100000000004640019000000000005004b0000063a0000613d000000800700003900000000080000190000000009060019000006160000013d0000000108800039000000000058004b0000063a0000813d000000000a6400490000000009a904360000002001100039000000000a01043300000000cb0a0434000001b30bb00197000000000bb40436000000000c0c04330000000200c0008c0000065c0000813d0000000000cb0435000000400ba00039000000000b0b043300000000000b004b000000000b000039000000010b00c039000000400c4000390000000000bc0435000000600aa00039000000000a0a0433000000600b40003900000000007b0435000000800c400039000000000b0a04330000000000bc0435000000a00440003900000000000b004b000006130000613d000000000c000019000000200aa00039000000000d0a04330000000004d40436000000010cc000390000000000bc004b000006330000413d000006130000013d0000000001240049000000200410008a00000000004204350000001f01100039000001d9041001970000000001240019000000000041004b00000000040000390000000104004039000001b50010009c000006620000213d0000000100400190000006620000c13d000000400010043f000001a40030009c000001a40300804100000040013002100000000002020433000001a40020009c000001a4020080410000006002200210000000000112019f0000000002000414000001a40020009c000001a402008041000000c002200210000000000112019f000001ba011001c70000801002000039068a06850000040f0000000100200190000006680000613d000000000101043b000000000001042d000001c001000041000000000010043f0000002101000039000000040010043f000001c1010000410000068c00010430000001c001000041000000000010043f0000004101000039000000040010043f000001c1010000410000068c0001043000000000010000190000068c00010430000000000001042f000001a40010009c000001a4010080410000004001100210000001a40020009c000001a4020080410000006002200210000000000112019f0000000002000414000001a40020009c000001a402008041000000c002200210000000000112019f000001ba011001c70000801002000039068a06850000040f00000001002001900000067e0000613d000000000101043b000000000001042d00000000010000190000068c0001043000000683002104210000000102000039000000000001042d0000000002000019000000000001042d00000688002104230000000102000039000000000001042d0000000002000019000000000001042d0000068a000004320000068b0001042e0000068c0001043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000002000000000000000000000000000000400000010000000000000000000000000000000000000000000000000000000000000000000000000097331bf800000000000000000000000000000000000000000000000000000000d126fc1800000000000000000000000000000000000000000000000000000000d126fc1900000000000000000000000000000000000000000000000000000000f396455100000000000000000000000000000000000000000000000000000000f68790c70000000000000000000000000000000000000000000000000000000097331bf9000000000000000000000000000000000000000000000000000000009ac246870000000000000000000000000000000000000000000000000000000074449c5f0000000000000000000000000000000000000000000000000000000074449c60000000000000000000000000000000000000000000000000000000007a98742d00000000000000000000000000000000000000000000000000000000812617c70000000000000000000000000000000000000000000000000000000054af84a100000000000000000000000000000000000000000000000000000000652b9b41000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0000000000000000000000000000000000000000000000000ffffffffffffff7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000400000000000000000000000004d827f170000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000020000000800000000000000000290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5634e487b71000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024000000000000000000000000d6f21326ab749d5729fcba5677c79037b459436ab7bff709c9d06ce9f10c1a9d0000000000000000000000000000000000000000000000010000000000000000ce992a36000000000000000000000000000000000000000000000000000000000000000000184f03e93ff9f4daa797ed6e38ed64bf6a1f01000000000000000000000000000000000000000000000000000004ee2d6d415b85acef810000000000000000000000000000000000000000000004ee2d6d415b85acef80ffffffff000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000ffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000005f5e10000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff30313233343536373839616263646566000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000004d61676963205661756c742000000000000000000000000000000000000000004d616769635661756c7400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffff7b010006bd265cfb8414cd1a78014372734283c20cac8d9c94c32661a6876ae1b79c4d535bdea7cd8a978f128b93471df48c7dbab89d703809115bdc118c235bfd1806aa1896bbf26568e884a7374b41e002500962caba6a15023a8d90e8508b8302000002000000000000000000000000000000240000000000000000000000007ccc2ec20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffe0ffffffffffffffffffffffff0000000000000000000000000000000000000000cb0452bbe0e1599038236fd7a1588dd53cef35a83f2c1a6aeb71f42c3160b982ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe053b071427d6e39e69bd15cc8fbbfbc18da99e794edeb23979325c516c8771252

Block Transaction Gas Used Reward
view all blocks produced

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

Validator Index Block Amount
View All Withdrawals

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

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