ETH Price: $2,273.23 (-1.78%)
 

Overview

Max Total Supply

25 BQC

Holders

18

Transfers

-
0

Market

Volume (24H)

N/A

Min Price (24H)

N/A

Max Price (24H)

N/A

Other Info

Loading...
Loading
Loading...
Loading
Loading...
Loading

Click here to update the token information / general information

Contract Source Code Verified (Exact Match)

Contract Name:
Credentials

Compiler Version
v0.8.9+commit.e5eed63a

Optimization Enabled:
No with 200 runs

Other Settings:
default evmVersion
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

import "./TestCreator.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/interfaces/IERC721.sol";
import "@openzeppelin/contracts/interfaces/IERC721Enumerable.sol";
import "@openzeppelin/contracts/interfaces/IERC721Metadata.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

contract Credentials is ERC165Storage, IERC721, IERC721Metadata, IERC721Enumerable, Ownable {
    using SafeMath for uint256;
    using Address for address;
    using EnumerableSet for EnumerableSet.UintSet;
    using EnumerableSet for EnumerableSet.AddressSet;
    using Strings for uint256;

    // Token name
    string private _name = "Block Qualified Credentials";
    // Token symbol
    string private _symbol = "BQC";

    // Owner contract, the test creator
    TestCreator testContract;

    // Mapping from address to their (enumerable) set of received credentials
    mapping (address => EnumerableSet.UintSet) private _receivedCredentials;

    // Mapping from testId to a mapping from address to the result they got in the credential
    mapping(uint256 => mapping(address => uint256)) private _credentialReceiverResults;

    // Mapping from credential IDs to their (enumerable) set of receiver addresses
    mapping (uint256 => EnumerableSet.AddressSet) private _credentialReceivers;

    constructor () {

        testContract = TestCreator(msg.sender);

        // register the supported interfaces to conform to ERC721 via ERC165
        /*
        *     bytes4(keccak256('balanceOf(address)')) == 0x70a08231
        *     bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e
        *     bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3
        *     bytes4(keccak256('getApproved(uint256)')) == 0x081812fc
        *     bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
        *     bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5
        *     bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd
        *     bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e
        *     bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde
        *
        *     => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^
        *        0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd
        */
        _registerInterface(0x80ac58cd);

        /*
        *     bytes4(keccak256('name()')) == 0x06fdde03
        *     bytes4(keccak256('symbol()')) == 0x95d89b41
        *     bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd
        *
        *     => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f
        */
        _registerInterface(0x5b5e139f);

        /*
        *     bytes4(keccak256('totalSupply()')) == 0x18160ddd
        *     bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59
        *     bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7
        *
        *     => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63
        */
        _registerInterface(0x780e9d63);
    }

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

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

    /**
     * @dev Mints a new credentials NFT corresponding to the multiple choice test defined by its `testId`
     */
    function giveCredentials(address receiver, uint256 testId, uint256 results) external onlyOwner {
        // Sets or updates the receiver's test results
        _credentialReceiverResults[testId][receiver] = results;

        // Mints a new credential NFT if it does not exist yet
        if (!_receivedCredentials[receiver].contains(testId)) { 
            _receivedCredentials[receiver].add(testId);
            _credentialReceivers[testId].add(receiver);
            
            // Emits a transfer event giving the credentials from the test smart contract to the receiver
            emit Transfer(address(testContract), receiver, testId);
        }
    }

    /**
     * @dev Returns the credentials string, obtained from the test contract
     */
    function getCredential(uint256 testId) external view returns (string memory) {
        require(testContract.testExists(testId), "Test does not exist");

        return testContract.getTest(testId).credentialsGained;
    }

    /**
     * @dev Returns the original test type of the credential
     */
    function getCredentialType(uint256 testId) external view returns (uint8) {
        require(testContract.testExists(testId), "Test does not exist");

        return testContract.getTest(testId).testType;
    }

    /**
     * @dev Returns the credential result
     */
    function getResults(address receiver, uint256 testId) external view returns (uint) {
        return _credentialReceiverResults[testId][receiver];
    }

    /**
     * @dev Returns the credentials tokenURI, which is linked to the test contract
     */
    function tokenURI(uint256 testId) external view override returns (string memory) {
        return testContract.tokenURI(testId);
    }
    
    /**
     * @dev See {IERC721-ownerOf}.
     *
     * Here owner represents ownership of the original test NFT
     */
    function ownerOf(uint256 testId) public view virtual override returns (address) {
        return testContract.ownerOf(testId);
    }

    /**
     * @dev See {IERC721-balanceOf}.
     *
     * Returns the number of Credentials received by an address
     */
    function balanceOf(address _owner) public view virtual override returns (uint256) {
        require(_owner != address(0), "ERC721: balance query for the zero address");
        return _receivedCredentials[_owner].length();
    }

    /**
     * @dev See {IERC721Enumerable-totalSupply}.
     *
     * The `totalSupply` is defined as the number of VALID Credentials that have been given
     */
    function totalSupply() public view virtual override returns (uint256 count) {
        uint256 nTokens = testContract.totalSupply();
        for (uint256 i = 0; i < nTokens; ++i) {
            uint256 testId = testContract.tokenByIndex(i);
            count += _credentialReceivers[testId].length();
        }
    }

    /**
     * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
     *
     * Returns the Soulbound Card received by an address at a given index
     */
    function tokenOfOwnerByIndex(address _owner, uint256 index) public view virtual override returns (uint256) {
        require(index < balanceOf(_owner), "Index out of bounds");
        return _receivedCredentials[_owner].at(index);
    }

    /**
     * @dev See {IERC721Enumerable-tokenByIndex}.
     *
     * Returns the corresponding test by index
     */
    function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
        return testContract.tokenByIndex(index);
    }

    /**
     * @dev Returns the list of addresses that received a credential defined by a `testId`
     */
    function credentialReceivers(uint256 testId) public view returns (address[] memory) {
        return _credentialReceivers[testId].values();
    }

    /**
     * @dev Returns the list of credentials that an address `receiver` got
     */
    function receivedCredentials(address receiver) public view returns (uint256[] memory) {
        return _receivedCredentials[receiver].values();
    }

    /**
     * @dev See {IERC721-approve}.
     *
     * Only present to be ERC-721 compliant. Credentials cannot be transferred, and as such cannot be approved for spending.
     */
    function approve(address /* _approved */, uint256 /* _testId */) public view virtual override {
        revert("BQC: cannot approve credentials");
    }

    /**
     * @dev See {IERC721-getApproved}.
     *
     * Only present to be ERC-721 compliant. Credentials cannot be transferred, and as such are never approved for spending.
     */
    function getApproved(uint256 /* testId */) public view virtual override returns (address) {
        return address(0);
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     *
     * Only present to be ERC-721 compliant. Credentials cannot be transferred, and as such cannot be approved for spending.
     */
    function setApprovalForAll(address /* _operator */, bool /* _approved */) public view virtual override {
        revert("BQC: cannot approve credentials");
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     *
     * Only present to be ERC-721 compliant. Credentials cannot be transferred, and as such are never approved for spending.
     */
    function isApprovedForAll(address /* owner */, address /* operator */) public view virtual override returns (bool) {
        return false;
    }

    /**
     * @dev See {IERC721-transferFrom}.
     *
     * Only present to be ERC721 compliant. Credentials cannot be transferred.
     */
    function transferFrom(address /* from */, address /* to */, uint256 /* testId */) public view virtual override {
        revert("BQC: cannot transfer credentials");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     *
     * Only present to be ERC721 compliant. Credentials cannot be transferred.
     */
    function safeTransferFrom(address from, address to, uint256 testId) public virtual override {
        safeTransferFrom(from, to, testId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     *
     * Only present to be ERC721 compliant. Credentials cannot be transferred.
     */
    function safeTransferFrom(address /* from */, address /* to */, uint256 /* testId */, bytes memory /* _data */) public view virtual override {
        revert("BQC: cannot transfer credentials");
    }
}

// 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 3 of 22 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC721.sol)

pragma solidity ^0.8.0;

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

File 4 of 22 : IERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC721Enumerable.sol)

pragma solidity ^0.8.0;

import "../token/ERC721/extensions/IERC721Enumerable.sol";

File 5 of 22 : IERC721Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC721Metadata.sol)

pragma solidity ^0.8.0;

import "../token/ERC721/extensions/IERC721Metadata.sol";

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

pragma solidity ^0.8.0;

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

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

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

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

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

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

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

pragma solidity ^0.8.0;

import "../IERC721.sol";

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

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

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

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

pragma solidity ^0.8.0;

import "../IERC721.sol";

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated 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);
}

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

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

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

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

pragma solidity ^0.8.0;

import "./ERC165.sol";

/**
 * @dev Storage based implementation of the {IERC165} interface.
 *
 * Contracts may inherit from this and call {_registerInterface} to declare
 * their support of an interface.
 */
abstract contract ERC165Storage is ERC165 {
    /**
     * @dev Mapping of interface ids to whether or not it's supported.
     */
    mapping(bytes4 => bool) private _supportedInterfaces;

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

    /**
     * @dev Registers the contract as an implementer of the interface defined by
     * `interfaceId`. Support of the actual ERC165 interface is automatic and
     * registering its interface id is not required.
     *
     * See {IERC165-supportsInterface}.
     *
     * Requirements:
     *
     * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`).
     */
    function _registerInterface(bytes4 interfaceId) internal virtual {
        require(interfaceId != 0xffffffff, "ERC165: invalid interface id");
        _supportedInterfaces[interfaceId] = true;
    }
}

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

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

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

pragma solidity ^0.8.0;

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

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

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

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

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

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

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

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

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

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

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

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

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

// 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 18 of 22 : 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));
    }
}

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

// SPDX-License-Identifier: GPL-3.0
// Generated using circom - https://github.com/iden3/circom 
pragma solidity ^0.8.7;

library Pairing {
    struct G1Point {
        uint X;
        uint Y;
    }

    // Encoding of field elements is: X[0] * z + X[1]
    struct G2Point {
        uint[2] X;
        uint[2] Y;
    }

    /// @return the generator of G1
    function P1() internal pure returns (G1Point memory) {
        return G1Point(1, 2);
    }

    /// @return the generator of G2
    function P2() internal pure returns (G2Point memory) {
        // Original code point
        return G2Point(
            [11559732032986387107991004021392285783925812861821192530917403151452391805634,
             10857046999023057135944570762232829481370756359578518086990519993285655852781],
            [4082367875863433681332203403145435568316851327593401208105741076214120093531,
             8495653923123431417604973247489272438418190587263600148770280649306958101930]
        );
    }

    /// @return r the negation of p, i.e. p.addition(p.negate()) should be zero.
    function negate(G1Point memory p) internal pure returns (G1Point memory r) {
        // The prime q in the base field F_q for G1
        uint q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
        if (p.X == 0 && p.Y == 0)
            return G1Point(0, 0);
        return G1Point(p.X, q - (p.Y % q));
    }

    /// @return r the sum of two points of G1
    function addition(G1Point memory p1, G1Point memory p2) internal view returns (G1Point memory r) {
        uint[4] memory input;
        input[0] = p1.X;
        input[1] = p1.Y;
        input[2] = p2.X;
        input[3] = p2.Y;
        bool success;
        // solium-disable-next-line security/no-inline-assembly
        assembly {
            success := staticcall(sub(gas(), 2000), 6, input, 0xc0, r, 0x60)
            // Use "invalid" to make gas estimation work
            switch success case 0 { invalid() }
        }
        require(success,"pairing-add-failed");
    }

    /// @return r the product of a point on G1 and a scalar, i.e.
    /// p == p.scalar_mul(1) and p.addition(p) == p.scalar_mul(2) for all points p.
    function scalar_mul(G1Point memory p, uint s) internal view returns (G1Point memory r) {
        uint[3] memory input;
        input[0] = p.X;
        input[1] = p.Y;
        input[2] = s;
        bool success;
        // solium-disable-next-line security/no-inline-assembly
        assembly {
            success := staticcall(sub(gas(), 2000), 7, input, 0x80, r, 0x60)
            // Use "invalid" to make gas estimation work
            switch success case 0 { invalid() }
        }
        require (success,"pairing-mul-failed");
    }

    /// @return the result of computing the pairing check
    /// e(p1[0], p2[0]) *  .... * e(p1[n], p2[n]) == 1
    /// For example pairing([P1(), P1().negate()], [P2(), P2()]) should
    /// return true.
    function pairing(G1Point[] memory p1, G2Point[] memory p2) internal view returns (bool) {
        require(p1.length == p2.length,"pairing-lengths-failed");
        uint elements = p1.length;
        uint inputSize = elements * 6;
        uint[] memory input = new uint[](inputSize);
        for (uint i = 0; i < elements; i++)
        {
            input[i * 6 + 0] = p1[i].X;
            input[i * 6 + 1] = p1[i].Y;
            input[i * 6 + 2] = p2[i].X[0];
            input[i * 6 + 3] = p2[i].X[1];
            input[i * 6 + 4] = p2[i].Y[0];
            input[i * 6 + 5] = p2[i].Y[1];
        }
        uint[1] memory out;
        bool success;
        // solium-disable-next-line security/no-inline-assembly
        assembly {
            success := staticcall(sub(gas(), 2000), 8, add(input, 0x20), mul(inputSize, 0x20), out, 0x20)
            // Use "invalid" to make gas estimation work
            switch success case 0 { invalid() }
        }
        require(success,"pairing-opcode-failed");
        return out[0] != 0;
    }

    /// Convenience method for a pairing check for two pairs.
    function pairingProd2(G1Point memory a1, G2Point memory a2, G1Point memory b1, G2Point memory b2) internal view returns (bool) {
        G1Point[] memory p1 = new G1Point[](2);
        G2Point[] memory p2 = new G2Point[](2);
        p1[0] = a1;
        p1[1] = b1;
        p2[0] = a2;
        p2[1] = b2;
        return pairing(p1, p2);
    }

    /// Convenience method for a pairing check for three pairs.
    function pairingProd3(
            G1Point memory a1, G2Point memory a2,
            G1Point memory b1, G2Point memory b2,
            G1Point memory c1, G2Point memory c2
    ) internal view returns (bool) {
        G1Point[] memory p1 = new G1Point[](3);
        G2Point[] memory p2 = new G2Point[](3);
        p1[0] = a1;
        p1[1] = b1;
        p1[2] = c1;
        p2[0] = a2;
        p2[1] = b2;
        p2[2] = c2;
        return pairing(p1, p2);
    }
    
    /// Convenience method for a pairing check for four pairs.
    function pairingProd4(
            G1Point memory a1, G2Point memory a2,
            G1Point memory b1, G2Point memory b2,
            G1Point memory c1, G2Point memory c2,
            G1Point memory d1, G2Point memory d2
    ) internal view returns (bool) {
        G1Point[] memory p1 = new G1Point[](4);
        G2Point[] memory p2 = new G2Point[](4);
        p1[0] = a1;
        p1[1] = b1;
        p1[2] = c1;
        p1[3] = d1;
        p2[0] = a2;
        p2[1] = b2;
        p2[2] = c2;
        p2[3] = d2;
        return pairing(p1, p2);
    }
}

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

import "./Credentials.sol";
import "./TestVerifier.sol";
import "@openzeppelin/contracts/interfaces/IERC721.sol";
import "@openzeppelin/contracts/interfaces/IERC721Enumerable.sol";
import "@openzeppelin/contracts/interfaces/IERC721Metadata.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

interface RequiredPass {
    function balanceOf(address _owner) external view returns (uint256);
}

contract TestCreator is ERC165Storage, IERC721, IERC721Metadata, IERC721Enumerable, ReentrancyGuard {
    using SafeMath for uint8;
    using SafeMath for uint32;
    using SafeMath for uint256;
    using Address for address;
    using EnumerableSet for EnumerableSet.UintSet;
    using EnumerableMap for EnumerableMap.UintToAddressMap;
    using Strings for uint256;

    error TimeLimitInThePast();
    error InvalidNumberOfQuestions();
    error InvalidMinimumGrade();
    error InvalidTestType();

    error TestDoesNotExist();
    error TestDoesNotHaveMultipleChoiceComponent();
    error TestDoesNotHaveOpenAnswerComponent();
    error TestAlreadyVerified();
    error TestWasNotVerified();
    error VerifyingTestThatIsNotOwn();
    error InvalidatingTestThatIsNotOwn();

    error TestCannotBeSolvedByOwner();
    error MaximumNumberOfCredentialsReached();
    error TimeLimitReached();
    error RecipientDoesNotOwnRequiredToken();
    error SolvingForAnotherTest();
    error GradeBelowMinimum();
    error ExistingCredentialHasBetterResult();
    error TestWasInvalidated();
    
    // Token name
    string private _name = "Block Qualified Tests v1";
    // Token symbol
    string private _symbol = "BQT";

    // Smart contract for verifying tests
    TestVerifier public verifierContract;
    // Smart contract for giving credentials
    Credentials public credentialsContract;

    // Mapping from holder address to their (enumerable) set of owned tokens
    mapping (address => EnumerableSet.UintSet) private _holderTokens;

    // Enumerable mapping from token ids to their owners
    EnumerableMap.UintToAddressMap private _tokenOwners;

    // Number of tests that have been created
    uint256 private _ntests;

    struct Test {
        uint8 testType;
        uint8 nQuestions;  // number of open answer questions the test has
        uint8 minimumGrade;  // out of 100, minimum mark the user must get to obtain the credential
        uint24 solvers;
        uint24 credentialLimit;
        uint32 timeLimit;
        address requiredPass;
        string credentialsGained;
    }

    // Mapping defining each test
    mapping(uint256 => Test) private _tests;
    
    // Mapping with the necessary info for the different kinds of tests
    mapping(uint256 => uint256) private _multipleChoiceRoot;  // Merkle root of the multiple choice tree
    mapping(uint256 => uint256) private _openAnswersRoot;  // Merkle root of the answer hashes tree
    mapping(uint256 => uint256[]) private _openAnswersHashes;  // Array containing the correct answer hashes for open answer tests

    // Mapping for token URIs
    mapping (uint256 => string) private _tokenURIs;  // URL containing the test

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` and deploying the Credentials and TestVerifier contracts
     */
    constructor () {

        credentialsContract = new Credentials();
        verifierContract = new TestVerifier();

        // Register the supported interfaces to conform to ERC721 via ERC165
        /*
        *     bytes4(keccak256('balanceOf(address)')) == 0x70a08231
        *     bytes4(keccak256('ownerOf(uint256)')) == 0x6352211e
        *     bytes4(keccak256('approve(address,uint256)')) == 0x095ea7b3
        *     bytes4(keccak256('getApproved(uint256)')) == 0x081812fc
        *     bytes4(keccak256('setApprovalForAll(address,bool)')) == 0xa22cb465
        *     bytes4(keccak256('isApprovedForAll(address,address)')) == 0xe985e9c5
        *     bytes4(keccak256('transferFrom(address,address,uint256)')) == 0x23b872dd
        *     bytes4(keccak256('safeTransferFrom(address,address,uint256)')) == 0x42842e0e
        *     bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) == 0xb88d4fde
        *
        *     => 0x70a08231 ^ 0x6352211e ^ 0x095ea7b3 ^ 0x081812fc ^
        *        0xa22cb465 ^ 0xe985e9c5 ^ 0x23b872dd ^ 0x42842e0e ^ 0xb88d4fde == 0x80ac58cd
        */
        _registerInterface(0x80ac58cd);
        /*
        *     bytes4(keccak256('name()')) == 0x06fdde03
        *     bytes4(keccak256('symbol()')) == 0x95d89b41
        *     bytes4(keccak256('tokenURI(uint256)')) == 0xc87b56dd
        *
        *     => 0x06fdde03 ^ 0x95d89b41 ^ 0xc87b56dd == 0x5b5e139f
        */
        _registerInterface(0x5b5e139f);
        /*
        *     bytes4(keccak256('totalSupply()')) == 0x18160ddd
        *     bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) == 0x2f745c59
        *     bytes4(keccak256('tokenByIndex(uint256)')) == 0x4f6ccce7
        *
        *     => 0x18160ddd ^ 0x2f745c59 ^ 0x4f6ccce7 == 0x780e9d63
        */
        _registerInterface(0x780e9d63);
    }

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

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

    /**
     * @dev Creates a new multiple choice/open answer/mixed test, storing the defining hashes on chain
     *
     * We assume the credential issuer will provide a solvable test and specify the actual number of questions it has
     */
    function createTest(
        uint8 _testType,
        uint8 _nQuestions,
        uint8 _minimumGrade,
        uint24 _credentialLimit,  // a zero value renders them unlimited
        uint32 _timeLimit,  
        uint256[] calldata _solvingHashes,
        address _requiredPass,
        string memory _credentialsGained,
        string memory _testURI
    ) external {
        // Increase the number of tests available
        _ntests++;
        uint256 _testId = _ntests;

        // If time and credential limits are set to zero then these limits on solving do not get enforced
        if (
            _timeLimit != 0 
            &&
            _timeLimit <= block.timestamp
        ) {
            revert TimeLimitInThePast();
        }
        
        if(_requiredPass != address(0)) {
            require(RequiredPass(_requiredPass).balanceOf(msg.sender) >= 0);  // @dev: invalid required pass address provided
        }

        if (_nQuestions == 0 || _nQuestions > 64) { revert InvalidNumberOfQuestions(); }
        if (_minimumGrade == 0 || _minimumGrade > 100) { revert InvalidMinimumGrade(); }
        
        // Storing the test type information
        if (_testType == 0) {  // Open answers test, providing the [answerHashesRoot]
            _openAnswersRoot[_testId] = _solvingHashes[0];
        } else if (_testType > 0 && _testType < 100) {  /// Mixed test, providing [solutionHash, answerHashesRoot]
            _multipleChoiceRoot[_testId] = _solvingHashes[0];
            _openAnswersRoot[_testId] = _solvingHashes[1];
        } else if (_testType == 100) {  // Multiple choice test, providing the [solutionHash]
            if (_minimumGrade != 100) { revert InvalidMinimumGrade(); }  // @dev multiple choice tests must have 100 as minimum grade
            if (_nQuestions != 1) { revert InvalidNumberOfQuestions(); } // @dev multiple choice tests must have 1 as number of open questions
            _multipleChoiceRoot[_testId] = _solvingHashes[0];
        } else {
            revert InvalidTestType();
        }

        // Setting the given URI that holds all of the questions
        _tokenURIs[_testId] = _testURI;

        // Defining the test object for this testId
        _tests[_testId] = Test(
            _testType,
            _nQuestions,
            _minimumGrade,
            0,
            _credentialLimit,
            _timeLimit,
            _requiredPass,
            _credentialsGained
        );

        // Minting this new nft
        _holderTokens[msg.sender].add(_testId);
        _tokenOwners.set(_testId, msg.sender);
        emit Transfer(address(0), msg.sender, _testId);
    }

    /**
     * @dev Creates a new multiple choice/open answer/mixed test, storing the defining hashes on chain
     *
     * We assume the credential issuer will provide a solvable test and specify the actual number of questions it has
     * For the first iteration of the protocol, only the
     */
    function verifyTestAnswers(uint256 testId, uint256[] memory answerHashes) external {
        if (!_exists(testId)) { revert TestDoesNotExist(); }
        if (
            _tests[testId].testType == 100
        ) {
            revert TestDoesNotHaveOpenAnswerComponent();
        }
        if (_openAnswersHashes[testId].length > 0) {
            revert TestAlreadyVerified();
        }
        if (ownerOf(testId) != msg.sender) {
            revert VerifyingTestThatIsNotOwn();
        }
        if (answerHashes.length != _tests[testId].nQuestions) {
            revert InvalidNumberOfQuestions();
        }

        _openAnswersHashes[testId] = answerHashes;
    } 
    
    /**
     * @dev Returns the struct that defines a Test
     */
    function getTest(uint256 testId) external view returns (Test memory) {
        if (!_exists(testId)) { revert TestDoesNotExist(); }
        return _tests[testId];
    }

    /**
     * @dev Returns the solution hash that defines a multiple choice test
     * Also used with mixed tests
     */
    function getMultipleChoiceRoot(uint256 testId) external view returns (uint256) {
        if (!_exists(testId)) { revert TestDoesNotExist(); }
        if (
            _tests[testId].testType == 0
            || 
            _tests[testId].testType > 100
        ) {
            revert TestDoesNotHaveMultipleChoiceComponent();
        }
        return _multipleChoiceRoot[testId];
    }

    /**
     * @dev Returns the list of solution hashes that define an open answer test
     * Also used with mixed tests
     */
    function getOpenAnswersRoot(uint256 testId) external view returns (uint256) {
        if (!_exists(testId)) { revert TestDoesNotExist(); }
        if (
            _tests[testId].testType == 100
        ) {
            revert TestDoesNotHaveOpenAnswerComponent();
        }
        return _openAnswersRoot[testId];
    }

    /**
     * @dev Returns the list of solution hashes that define an open answer test, if specified
     * Also used with mixed tests
     */
    function getOpenAnswersHashes(uint256 testId) external view returns (uint256[] memory) {
        if (!_exists(testId)) { revert TestDoesNotExist(); }
        if (
            _tests[testId].testType == 100
        ) {
            revert TestDoesNotHaveOpenAnswerComponent();
        }
        if (_openAnswersHashes[testId].length == 0) { revert TestWasNotVerified(); }
        return _openAnswersHashes[testId];
    }

    /**
     * @dev Returns if a given test exists
     */
    function testExists(uint256 testId) external view returns (bool) {
        return _exists(testId);
    }

    /**
     * @dev Returns if a given test is still valid
     */
    function testIsValid(uint256 testId) external view returns (bool) {
        require(_exists(testId), "Test does not exist");
        return _tests[testId].testType != 255;
    }

    /**
     * @dev Returns the test URI, which contains inside the questions
     */
    function tokenURI(uint256 testId) external view override returns (string memory) {
        require(_exists(testId), "Test does not exist");
        return _tokenURIs[testId];
    }

    /**
     * @dev Allows the owner of a test to no longer recognize it as valid by making it impossible to solve
     * Invalidating a test is final
     */
    function invalidateTest(uint256 testId) external nonReentrant {
        if (!_exists(testId)) { revert TestDoesNotExist(); }
        if ( _tests[testId].testType == 255 ) {
            revert TestWasInvalidated();
        } 
        if (ownerOf(testId) != msg.sender) {
            revert InvalidatingTestThatIsNotOwn();
        }

        // Test still lives on chain for reference, but can no longer be solved.
        _tests[testId].testType = 255;
    }

    /**
     * @dev Allows users to attempt a test solution, minting a Credentials NFT if successful with their results
     */
    function solveTest(
        uint256 testId, 
        address recipient,
        uint[2] calldata a,
        uint[2][2] calldata b,
        uint[2] calldata c,
        uint[] calldata input  
    ) external nonReentrant {
        if (recipient == ownerOf(testId)) {
            revert TestCannotBeSolvedByOwner();
        }

        if (
            _tests[testId].credentialLimit != 0 
            && 
            _tests[testId].solvers == _tests[testId].credentialLimit
        ) {
            revert MaximumNumberOfCredentialsReached();
        }

        if (
            _tests[testId].timeLimit != 0 
            &&
            block.timestamp >= _tests[testId].timeLimit
        ) {
            revert TimeLimitReached();
        }

        if(
            _tests[testId].requiredPass != address(0)
            &&
            RequiredPass(_tests[testId].requiredPass).balanceOf(recipient) == 0
        ) {
            revert RecipientDoesNotOwnRequiredToken();
        }

        uint nullifier = uint(uint160(recipient));
        
        // Verify solution
        require(verifierContract.verifyProof(_tests[testId].testType, a, b, c, input, nullifier), "Invalid proof");

        uint256 result;

        if ( _tests[testId].testType == 0 ) {  // Open answers test, providing [results, answerHashesRoot]
            // Ensuring the open answer test being solved is the one selected
            if (input[1] != _openAnswersRoot[testId]) {
                revert SolvingForAnotherTest();
            }

            // Get result
            result = (input[0] + _tests[testId].nQuestions > 64) ?  // prevent underflow
                100 * (input[0] + _tests[testId].nQuestions - 64) / _tests[testId].nQuestions
            :
                0;
            if (result < _tests[testId].minimumGrade) {
                revert GradeBelowMinimum();
            }
        } else if ( _tests[testId].testType > 0 && _tests[testId].testType < 100 ) {  // Mixed test, providing [solutionHash, results, answersHashRoot]
            // Ensuring the open answer test being solved is the one selected
            if (input[2] != _openAnswersRoot[testId]) {
                revert SolvingForAnotherTest();
            }
            
            // The testType being below 100 means it is a mixed test, and its value represents the weight of the multiple choice test
            result = (input[0] == _multipleChoiceRoot[testId] ? _tests[testId].testType : 0) 
                + 
                (
                (input[1] + _tests[testId].nQuestions > 64) ?
                    (input[1] + _tests[testId].nQuestions - 64) * (100 - _tests[testId].testType) / _tests[testId].nQuestions
                :
                    0
                );
            if (result < _tests[testId].minimumGrade) {
                revert GradeBelowMinimum();
            }
        } else if ( _tests[testId].testType == 100 ) {  // Multiple choice test, providing [solutionHash]
            if (input[0] != _multipleChoiceRoot[testId]) {
                revert SolvingForAnotherTest();
            }
            
            result = 100;
        } else if ( _tests[testId].testType == 255 ) {
            revert TestWasInvalidated();
        } 

        if (credentialsContract.getResults(recipient, testId) == 0) {
            // If the user had not received this credential, it increases the number of solvers
            _tests[testId].solvers++;
        } else {
            if (result <= credentialsContract.getResults(recipient, testId)) {
                revert ExistingCredentialHasBetterResult();
            }
        }

        credentialsContract.giveCredentials(recipient, testId, result);
    }

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

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 testId) public view virtual override returns (address) {
        return _tokenOwners.get(testId, "Test does not exist");
    }

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

    /**
     * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
     */
    function tokenOfOwnerByIndex(address _owner, uint256 index) public view virtual override returns (uint256) {
        require(index < balanceOf(_owner), "Index out of bounds");
        return _holderTokens[_owner].at(index);
    }

    /**
     * @dev See {IERC721Enumerable-tokenByIndex}.
     */
    function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
        require(index < totalSupply(), "Index out of bounds");  
        (uint256 testId, ) = _tokenOwners.at(index);
        return testId;
    }

    /**
     * @dev See {IERC721-approve}.
     *
     * Only present to be ERC-721 compliant. tests cannot be transferred, and as such cannot be approved for spending.
     */
    function approve(address /* _approved */, uint256 /* _testId */) public view virtual override {
        revert("BQT: cannot approve tests");
    }

    /**
     * @dev See {IERC721-getApproved}.
     *
     * Only present to be ERC-721 compliant. tests cannot be transferred, and as such are never approved for spending.
     */
    function getApproved(uint256 /* testId */) public view virtual override returns (address) {
        return address(0);
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     *
     * Only present to be ERC721 compliant. tests cannot be transferred, and as such cannot be approved for spending.
     */
    function setApprovalForAll(address /* _operator */, bool /* _approved */) public view virtual override {
        revert("BQT: cannot approve tests");
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     *
     * Only present to be ERC-721 compliant. tests cannot be transferred, and as such are never approved for spending.
     */
    function isApprovedForAll(address /* owner */, address /* operator */) public view virtual override returns (bool) {
        return false;
    }

    /**
     * @dev See {IERC721-transferFrom}.
     *
     * Only present to be ERC721 compliant. tests cannot be transferred.
     */
    function transferFrom(address /* from */, address /* to */, uint256 /* testId */) public view virtual override {
        revert("BQT: cannot transfer tests");
    }

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

    /**
     * @dev See {IERC721-safeTransferFrom}.
     *
     * Only present to be ERC721 compliant. tests cannot be transferred.
     */
    function safeTransferFrom(address /* from */, address /* to */, uint256 /* testId */, bytes memory /* _data */) public view virtual override {
        revert("BQT: cannot transfer tests");
    }

    /**
     * @dev Returns whether `testId` exists.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 testId) internal view virtual returns (bool) {
        return _tokenOwners.contains(testId);
    }
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.7;

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

interface IPoseidon {
    function poseidon(uint256[2] calldata) external pure returns(uint256);
}

contract TestVerifier {
    using SafeMath for uint256;
    using SafeMath for uint32;
    using Pairing for *;

    uint256 snark_scalar_field = 21888242871839275222246405745257275088548364400416034343698204186575808495617;

    struct VerifyingKey {
        Pairing.G1Point alfa1;
        Pairing.G2Point beta2;
        Pairing.G2Point gamma2;
        Pairing.G2Point delta2;
        Pairing.G1Point[] IC;
    }
    
    struct Proof {
        Pairing.G1Point A;
        Pairing.G2Point B;
        Pairing.G1Point C;
    }
    
    /**
     * @dev Verifies that a solving proof is correct for any of the kinds of tests
     */
    function verifyProof(
        uint8 testType,
        uint[2] calldata a,
        uint[2][2] calldata b,
        uint[2] calldata c,
        uint[] calldata input,
        uint nullifier
    ) public view returns (bool r) {
        Proof memory proof;
        proof.A = Pairing.G1Point(a[0], a[1]);
        proof.B = Pairing.G2Point([b[0][0], b[0][1]], [b[1][0], b[1][1]]);
        proof.C = Pairing.G1Point(c[0], c[1]);

        VerifyingKey memory vk;
        if (testType == 0) {
            require(input.length == 2);  // @dev invalid input length
            vk = openVerifyingKey();
        } else if (testType > 0 && testType < 100) {
            require(input.length == 3);  // @dev invalid input length
            vk = mixedVerifyingKey();
        } else if (testType == 100) {
            require(input.length == 1);  // @dev invalid input length
            vk = multipleVerifyingKey();
        } else {
            revert();
        }
        
        Pairing.G1Point memory vk_x = vk.IC[0];

        for (uint i = 0; i < input.length; i++) {
            require(input[i] < snark_scalar_field,"verifier-gte-snark-scalar-field");
            vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.IC[i + 1], input[i]));
        }
        // Adding nullifier separetely, always the last of the public inputs of the proof
        require(nullifier < snark_scalar_field,"verifier-gte-snark-scalar-field");
        vk_x = Pairing.addition(vk_x, Pairing.scalar_mul(vk.IC[input.length + 1], nullifier));

        if (!Pairing.pairingProd4(
            Pairing.negate(proof.A), proof.B,
            vk.alfa1, vk.beta2,
            vk_x, vk.gamma2,
            proof.C, vk.delta2
        )) return false;
        return true;
    }

    function multipleVerifyingKey() internal pure returns (VerifyingKey memory vk) {
        vk.alfa1 = Pairing.G1Point(
            20491192805390485299153009773594534940189261866228447918068658471970481763042,
            9383485363053290200918347156157836566562967994039712273449902621266178545958
        );
        vk.beta2 = Pairing.G2Point(
            [4252822878758300859123897981450591353533073413197771768651442665752259397132,
             6375614351688725206403948262868962793625744043794305715222011528459656738731],
            [21847035105528745403288232691147584728191162732299865338377159692350059136679,
             10505242626370262277552901082094356697409835680220590971873171140371331206856]
        );
        vk.gamma2 = Pairing.G2Point(
            [11559732032986387107991004021392285783925812861821192530917403151452391805634,
             10857046999023057135944570762232829481370756359578518086990519993285655852781],
            [4082367875863433681332203403145435568316851327593401208105741076214120093531,
             8495653923123431417604973247489272438418190587263600148770280649306958101930]
        );
        vk.delta2 = Pairing.G2Point(
            [8521342259665813950734259773262613831958773301268863906293699426637242842279,
             13686539095956844087728711208603372036427829124302040186590361549008963564964],
            [18343201147632388619156092089176107531666634135092967919251498114555688963702,
             8967039363998139653169116772887311199120552930247783431598167821445906806339]
        );

        vk.IC = new Pairing.G1Point[](3);
        
        vk.IC[0] = Pairing.G1Point( 
            12003302397568222974419635637140073175967412217153380137968206402483244103290,
            9910023685584006386745197358089479098453724395516512195572705180756515221642
        );                                      
        vk.IC[1] = Pairing.G1Point( 
            21247887558809586397036146726178877375239911207903076203079084252885346428971,
            8159660199290498370633032160995837259052170217244132774976061252009717600961
        );                                      
        vk.IC[2] = Pairing.G1Point( 
            17546907458604639823539783798191577478265602336271088123304593774782601627408,
            17295184015622672469629974037056802329565968363239469425499743044963167282463
        );                                      
    }

    function openVerifyingKey() internal pure returns (VerifyingKey memory vk) {
        vk.alfa1 = Pairing.G1Point(
            20491192805390485299153009773594534940189261866228447918068658471970481763042,
            9383485363053290200918347156157836566562967994039712273449902621266178545958
        );
        vk.beta2 = Pairing.G2Point(
            [4252822878758300859123897981450591353533073413197771768651442665752259397132,
             6375614351688725206403948262868962793625744043794305715222011528459656738731],
            [21847035105528745403288232691147584728191162732299865338377159692350059136679,
             10505242626370262277552901082094356697409835680220590971873171140371331206856]
        );
        vk.gamma2 = Pairing.G2Point(
            [11559732032986387107991004021392285783925812861821192530917403151452391805634,
             10857046999023057135944570762232829481370756359578518086990519993285655852781],
            [4082367875863433681332203403145435568316851327593401208105741076214120093531,
             8495653923123431417604973247489272438418190587263600148770280649306958101930]
        );
        vk.delta2 = Pairing.G2Point(
            [8071419909206804094591849048502848755108701024788855475180771317175669313172,
             18551840086537397529057331748015269025930147153451448630273504434069550166528],
            [6586895893357821999764113875421398868940428311604208225003301420172799011978,
             11543130811852428839139789864770610971433523477073969081998608610072720922904]
        );

        vk.IC = new Pairing.G1Point[](4);
        
        vk.IC[0] = Pairing.G1Point( 
            21297939756107246116511552680387351930673058222001297095795981661706897735010,
            14146447007095851741508670274841801939805049964473733587978071594554762824809
        );                                      
        vk.IC[1] = Pairing.G1Point( 
            8648893803997054926531464223018425273119422899566805052119516571470542303114,
            9291031740534785184644085071308899529903605233301242616808285197492230034477
        );                                      
        vk.IC[2] = Pairing.G1Point( 
            1573719990390173098386861466007306416028170593135076393994568160231122288586,
            599114322511849502877160751052508857303741718205244132946500814250066676579
        );                                      
        vk.IC[3] = Pairing.G1Point( 
            20212035562860361052598509564037667491004279108684898865109044094033599689394,
            11718977736261763319294392670085432800905026796798810894229302716934605907230
        );                                         
    }

    function mixedVerifyingKey() internal pure returns (VerifyingKey memory vk) {
        vk.alfa1 = Pairing.G1Point(
            20491192805390485299153009773594534940189261866228447918068658471970481763042,
            9383485363053290200918347156157836566562967994039712273449902621266178545958
        );
        vk.beta2 = Pairing.G2Point(
            [4252822878758300859123897981450591353533073413197771768651442665752259397132,
             6375614351688725206403948262868962793625744043794305715222011528459656738731],
            [21847035105528745403288232691147584728191162732299865338377159692350059136679,
             10505242626370262277552901082094356697409835680220590971873171140371331206856]
        );
        vk.gamma2 = Pairing.G2Point(
            [11559732032986387107991004021392285783925812861821192530917403151452391805634,
             10857046999023057135944570762232829481370756359578518086990519993285655852781],
            [4082367875863433681332203403145435568316851327593401208105741076214120093531,
             8495653923123431417604973247489272438418190587263600148770280649306958101930]
        );
        vk.delta2 = Pairing.G2Point(
            [1398674077556833678603205869745338382511550197017630381065919344139460104494,
             3014141459090505000095030624372489917693795198773335116263491328276630340608],
            [13120479026136517116042114711188667637087197991302448027210388274283188943543,
             2574771322543516116015805901471831513661013547873595798463432239126309871117]
        );

        vk.IC = new Pairing.G1Point[](5);
        
        vk.IC[0] = Pairing.G1Point( 
            14155345604055684351163947724917572363108847821610365204579461296099680625381,
            19543653799576809482705428705528944656891684447819372864147170191951017492218
        );                                      
        vk.IC[1] = Pairing.G1Point( 
            20624197777557376468131647555770346775563608477840508747355293185166141661007,
            11619535823484280447784795416488920389615945400689208455300337490991179587908
        );                                      
        vk.IC[2] = Pairing.G1Point( 
            10879447754828881957950437551558208942626009411851829347069695902533194935886,
            19311203311908225941421562853455621078181860115135617405030256370530717686081
        );                                      
        vk.IC[3] = Pairing.G1Point( 
            4616964579542984904263001135438691960099359314679217465351513952475506094503,
            16288090011615554457693551706090018009744015529776207671087244901049307672496
        );                                      
        vk.IC[4] = Pairing.G1Point( 
            5082804802667679445422316896498188613190134367124049158170348187335333533166,
            18604442687066796988077159560553385165827087913330405728706188415927414340778
        );   
    }
}

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

Contract Security Audit

Contract ABI

API
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"testId","type":"uint256"}],"name":"credentialReceivers","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"testId","type":"uint256"}],"name":"getCredential","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"testId","type":"uint256"}],"name":"getCredentialType","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"testId","type":"uint256"}],"name":"getResults","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"testId","type":"uint256"},{"internalType":"uint256","name":"results","type":"uint256"}],"name":"giveCredentials","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"testId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"receivedCredentials","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"testId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"bool","name":"","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"testId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"count","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60806040526040518060400160405280601b81526020017f426c6f636b205175616c69666965642043726564656e7469616c730000000000815250600290805190602001906200005192919062000303565b506040518060400160405280600381526020017f4251430000000000000000000000000000000000000000000000000000000000815250600390805190602001906200009f92919062000303565b50348015620000ad57600080fd5b50620000ce620000c26200015d60201b60201c565b6200016560201b60201c565b33600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550620001276380ac58cd60e01b6200022b60201b60201c565b6200013f635b5e139f60e01b6200022b60201b60201c565b6200015763780e9d6360e01b6200022b60201b60201c565b6200049b565b600033905090565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b63ffffffff60e01b817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141562000297576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016200028e9062000414565b60405180910390fd5b6001600080837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060006101000a81548160ff02191690831515021790555050565b828054620003119062000465565b90600052602060002090601f01602090048101928262000335576000855562000381565b82601f106200035057805160ff191683800117855562000381565b8280016001018555821562000381579182015b828111156200038057825182559160200191906001019062000363565b5b50905062000390919062000394565b5090565b5b80821115620003af57600081600090555060010162000395565b5090565b600082825260208201905092915050565b7f4552433136353a20696e76616c696420696e7465726661636520696400000000600082015250565b6000620003fc601c83620003b3565b91506200040982620003c4565b602082019050919050565b600060208201905081810360008301526200042f81620003ed565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806200047e57607f821691505b6020821081141562000495576200049462000436565b5b50919050565b6127cb80620004ab6000396000f3fe608060405234801561001057600080fd5b50600436106101735760003560e01c80636352211e116100de578063a22cb46511610097578063e985e9c511610071578063e985e9c514610482578063f2fde38b146104b2578063f34071da146104ce578063ff4236f8146104fe57610173565b8063a22cb4651461041a578063b88d4fde14610436578063c87b56dd1461045257610173565b80636352211e1461034457806370a0823114610374578063715018a6146103a45780638da5cb5b146103ae5780638dd18d2d146103cc57806395d89b41146103fc57610173565b806323b872dd1161013057806323b872dd1461026057806329edae3a1461027c5780632f745c59146102ac57806332cbe31c146102dc57806342842e0e146102f85780634f6ccce71461031457610173565b806301ffc9a714610178578063061e4dde146101a857806306fdde03146101d8578063081812fc146101f6578063095ea7b31461022657806318160ddd14610242575b600080fd5b610192600480360381019061018d91906117ca565b61052e565b60405161019f9190611812565b60405180910390f35b6101c260048036038101906101bd919061188b565b6105a5565b6040516101cf9190611980565b60405180910390f35b6101e06105f5565b6040516101ed9190611a3b565b60405180910390f35b610210600480360381019061020b9190611a89565b610687565b60405161021d9190611ac5565b60405180910390f35b610240600480360381019061023b9190611ae0565b61068e565b005b61024a6106c9565b6040516102579190611b2f565b60405180910390f35b61027a60048036038101906102759190611b4a565b610867565b005b61029660048036038101906102919190611ae0565b6108a2565b6040516102a39190611b2f565b60405180910390f35b6102c660048036038101906102c19190611ae0565b6108fd565b6040516102d39190611b2f565b60405180910390f35b6102f660048036038101906102f19190611b9d565b6109a2565b005b610312600480360381019061030d9190611b4a565b610b4f565b005b61032e60048036038101906103299190611a89565b610b6f565b60405161033b9190611b2f565b60405180910390f35b61035e60048036038101906103599190611a89565b610c23565b60405161036b9190611ac5565b60405180910390f35b61038e6004803603810190610389919061188b565b610cd7565b60405161039b9190611b2f565b60405180910390f35b6103ac610d96565b005b6103b6610daa565b6040516103c39190611ac5565b60405180910390f35b6103e660048036038101906103e19190611a89565b610dd4565b6040516103f39190611a3b565b60405180910390f35b610404610f7b565b6040516104119190611a3b565b60405180910390f35b610434600480360381019061042f9190611c1c565b61100d565b005b610450600480360381019061044b9190611d91565b611048565b005b61046c60048036038101906104679190611a89565b611083565b6040516104799190611a3b565b60405180910390f35b61049c60048036038101906104979190611e14565b61113c565b6040516104a99190611812565b60405180910390f35b6104cc60048036038101906104c7919061188b565b611144565b005b6104e860048036038101906104e39190611a89565b6111c8565b6040516104f59190611f12565b60405180910390f35b61051860048036038101906105139190611a89565b6111ec565b6040516105259190611f50565b60405180910390f35b600061053982611393565b8061059e5750600080837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060009054906101000a900460ff165b9050919050565b60606105ee600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206113fd565b9050919050565b60606002805461060490611f9a565b80601f016020809104026020016040519081016040528092919081815260200182805461063090611f9a565b801561067d5780601f106106525761010080835404028352916020019161067d565b820191906000526020600020905b81548152906001019060200180831161066057829003601f168201915b5050505050905090565b6000919050565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106c090612018565b60405180910390fd5b600080600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561073457600080fd5b505afa158015610748573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061076c919061204d565b905060005b81811015610862576000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634f6ccce7836040518263ffffffff1660e01b81526004016107d69190611b2f565b60206040518083038186803b1580156107ee57600080fd5b505afa158015610802573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610826919061204d565b90506108436007600083815260200190815260200160002061141e565b8461084e91906120a9565b9350508061085b906120ff565b9050610771565b505090565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161089990612194565b60405180910390fd5b60006006600083815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600061090883610cd7565b8210610949576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161094090612200565b60405180910390fd5b61099a82600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002061143390919063ffffffff16565b905092915050565b6109aa61144d565b806006600084815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610a5082600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206114cb90919063ffffffff16565b610b4a57610aa582600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206114e590919063ffffffff16565b50610acb83600760008581526020019081526020016000206114ff90919063ffffffff16565b50818373ffffffffffffffffffffffffffffffffffffffff16600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45b505050565b610b6a83838360405180602001604052806000815250611048565b505050565b6000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634f6ccce7836040518263ffffffff1660e01b8152600401610bcc9190611b2f565b60206040518083038186803b158015610be457600080fd5b505afa158015610bf8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1c919061204d565b9050919050565b6000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b8152600401610c809190611b2f565b60206040518083038186803b158015610c9857600080fd5b505afa158015610cac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd09190612235565b9050919050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610d48576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d3f906122d4565b60405180910390fd5b610d8f600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002061152f565b9050919050565b610d9e61144d565b610da86000611544565b565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d8b05250836040518263ffffffff1660e01b8152600401610e319190611b2f565b60206040518083038186803b158015610e4957600080fd5b505afa158015610e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e819190612309565b610ec0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610eb790612382565b60405180910390fd5b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663edef019d836040518263ffffffff1660e01b8152600401610f1b9190611b2f565b60006040518083038186803b158015610f3357600080fd5b505afa158015610f47573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250810190610f7091906125d6565b60e001519050919050565b606060038054610f8a90611f9a565b80601f0160208091040260200160405190810160405280929190818152602001828054610fb690611f9a565b80156110035780601f10610fd857610100808354040283529160200191611003565b820191906000526020600020905b815481529060010190602001808311610fe657829003601f168201915b5050505050905090565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161103f90612018565b60405180910390fd5b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161107a90612194565b60405180910390fd5b6060600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663c87b56dd836040518263ffffffff1660e01b81526004016110e09190611b2f565b60006040518083038186803b1580156110f857600080fd5b505afa15801561110c573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250810190611135919061261f565b9050919050565b600092915050565b61114c61144d565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156111bc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111b3906126da565b60405180910390fd5b6111c581611544565b50565b60606111e56007600084815260200190815260200160002061160a565b9050919050565b6000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d8b05250836040518263ffffffff1660e01b81526004016112499190611b2f565b60206040518083038186803b15801561126157600080fd5b505afa158015611275573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112999190612309565b6112d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112cf90612382565b60405180910390fd5b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663edef019d836040518263ffffffff1660e01b81526004016113339190611b2f565b60006040518083038186803b15801561134b57600080fd5b505afa15801561135f573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f8201168201806040525081019061138891906125d6565b600001519050919050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b6060600061140d8360000161162b565b905060608190508092505050919050565b600061142c82600001611687565b9050919050565b60006114428360000183611698565b60001c905092915050565b6114556116c3565b73ffffffffffffffffffffffffffffffffffffffff16611473610daa565b73ffffffffffffffffffffffffffffffffffffffff16146114c9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114c090612746565b60405180910390fd5b565b60006114dd836000018360001b6116cb565b905092915050565b60006114f7836000018360001b6116ee565b905092915050565b6000611527836000018373ffffffffffffffffffffffffffffffffffffffff1660001b6116ee565b905092915050565b600061153d82600001611687565b9050919050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b6060600061161a8360000161162b565b905060608190508092505050919050565b60608160000180548060200260200160405190810160405280929190818152602001828054801561167b57602002820191906000526020600020905b815481526020019060010190808311611667575b50505050509050919050565b600081600001805490509050919050565b60008260000182815481106116b0576116af612766565b5b9060005260206000200154905092915050565b600033905090565b600080836001016000848152602001908152602001600020541415905092915050565b60006116fa83836116cb565b611753578260000182908060018154018082558091505060019003906000526020600020016000909190919091505582600001805490508360010160008481526020019081526020016000208190555060019050611758565b600090505b92915050565b6000604051905090565b600080fd5b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6117a781611772565b81146117b257600080fd5b50565b6000813590506117c48161179e565b92915050565b6000602082840312156117e0576117df611768565b5b60006117ee848285016117b5565b91505092915050565b60008115159050919050565b61180c816117f7565b82525050565b60006020820190506118276000830184611803565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006118588261182d565b9050919050565b6118688161184d565b811461187357600080fd5b50565b6000813590506118858161185f565b92915050565b6000602082840312156118a1576118a0611768565b5b60006118af84828501611876565b91505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6000819050919050565b6118f7816118e4565b82525050565b600061190983836118ee565b60208301905092915050565b6000602082019050919050565b600061192d826118b8565b61193781856118c3565b9350611942836118d4565b8060005b8381101561197357815161195a88826118fd565b975061196583611915565b925050600181019050611946565b5085935050505092915050565b6000602082019050818103600083015261199a8184611922565b905092915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156119dc5780820151818401526020810190506119c1565b838111156119eb576000848401525b50505050565b6000601f19601f8301169050919050565b6000611a0d826119a2565b611a1781856119ad565b9350611a278185602086016119be565b611a30816119f1565b840191505092915050565b60006020820190508181036000830152611a558184611a02565b905092915050565b611a66816118e4565b8114611a7157600080fd5b50565b600081359050611a8381611a5d565b92915050565b600060208284031215611a9f57611a9e611768565b5b6000611aad84828501611a74565b91505092915050565b611abf8161184d565b82525050565b6000602082019050611ada6000830184611ab6565b92915050565b60008060408385031215611af757611af6611768565b5b6000611b0585828601611876565b9250506020611b1685828601611a74565b9150509250929050565b611b29816118e4565b82525050565b6000602082019050611b446000830184611b20565b92915050565b600080600060608486031215611b6357611b62611768565b5b6000611b7186828701611876565b9350506020611b8286828701611876565b9250506040611b9386828701611a74565b9150509250925092565b600080600060608486031215611bb657611bb5611768565b5b6000611bc486828701611876565b9350506020611bd586828701611a74565b9250506040611be686828701611a74565b9150509250925092565b611bf9816117f7565b8114611c0457600080fd5b50565b600081359050611c1681611bf0565b92915050565b60008060408385031215611c3357611c32611768565b5b6000611c4185828601611876565b9250506020611c5285828601611c07565b9150509250929050565b600080fd5b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b611c9e826119f1565b810181811067ffffffffffffffff82111715611cbd57611cbc611c66565b5b80604052505050565b6000611cd061175e565b9050611cdc8282611c95565b919050565b600067ffffffffffffffff821115611cfc57611cfb611c66565b5b611d05826119f1565b9050602081019050919050565b82818337600083830152505050565b6000611d34611d2f84611ce1565b611cc6565b905082815260208101848484011115611d5057611d4f611c61565b5b611d5b848285611d12565b509392505050565b600082601f830112611d7857611d77611c5c565b5b8135611d88848260208601611d21565b91505092915050565b60008060008060808587031215611dab57611daa611768565b5b6000611db987828801611876565b9450506020611dca87828801611876565b9350506040611ddb87828801611a74565b925050606085013567ffffffffffffffff811115611dfc57611dfb61176d565b5b611e0887828801611d63565b91505092959194509250565b60008060408385031215611e2b57611e2a611768565b5b6000611e3985828601611876565b9250506020611e4a85828601611876565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b611e898161184d565b82525050565b6000611e9b8383611e80565b60208301905092915050565b6000602082019050919050565b6000611ebf82611e54565b611ec98185611e5f565b9350611ed483611e70565b8060005b83811015611f05578151611eec8882611e8f565b9750611ef783611ea7565b925050600181019050611ed8565b5085935050505092915050565b60006020820190508181036000830152611f2c8184611eb4565b905092915050565b600060ff82169050919050565b611f4a81611f34565b82525050565b6000602082019050611f656000830184611f41565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680611fb257607f821691505b60208210811415611fc657611fc5611f6b565b5b50919050565b7f4251433a2063616e6e6f7420617070726f76652063726564656e7469616c7300600082015250565b6000612002601f836119ad565b915061200d82611fcc565b602082019050919050565b6000602082019050818103600083015261203181611ff5565b9050919050565b60008151905061204781611a5d565b92915050565b60006020828403121561206357612062611768565b5b600061207184828501612038565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006120b4826118e4565b91506120bf836118e4565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156120f4576120f361207a565b5b828201905092915050565b600061210a826118e4565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561213d5761213c61207a565b5b600182019050919050565b7f4251433a2063616e6e6f74207472616e736665722063726564656e7469616c73600082015250565b600061217e6020836119ad565b915061218982612148565b602082019050919050565b600060208201905081810360008301526121ad81612171565b9050919050565b7f496e646578206f7574206f6620626f756e647300000000000000000000000000600082015250565b60006121ea6013836119ad565b91506121f5826121b4565b602082019050919050565b60006020820190508181036000830152612219816121dd565b9050919050565b60008151905061222f8161185f565b92915050565b60006020828403121561224b5761224a611768565b5b600061225984828501612220565b91505092915050565b7f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008201527f726f206164647265737300000000000000000000000000000000000000000000602082015250565b60006122be602a836119ad565b91506122c982612262565b604082019050919050565b600060208201905081810360008301526122ed816122b1565b9050919050565b60008151905061230381611bf0565b92915050565b60006020828403121561231f5761231e611768565b5b600061232d848285016122f4565b91505092915050565b7f5465737420646f6573206e6f7420657869737400000000000000000000000000600082015250565b600061236c6013836119ad565b915061237782612336565b602082019050919050565b6000602082019050818103600083015261239b8161235f565b9050919050565b600080fd5b600080fd5b6123b581611f34565b81146123c057600080fd5b50565b6000815190506123d2816123ac565b92915050565b600062ffffff82169050919050565b6123f0816123d8565b81146123fb57600080fd5b50565b60008151905061240d816123e7565b92915050565b600063ffffffff82169050919050565b61242c81612413565b811461243757600080fd5b50565b60008151905061244981612423565b92915050565b600067ffffffffffffffff82111561246a57612469611c66565b5b612473826119f1565b9050602081019050919050565b600061249361248e8461244f565b611cc6565b9050828152602081018484840111156124af576124ae611c61565b5b6124ba8482856119be565b509392505050565b600082601f8301126124d7576124d6611c5c565b5b81516124e7848260208601612480565b91505092915050565b60006101008284031215612507576125066123a2565b5b612512610100611cc6565b90506000612522848285016123c3565b6000830152506020612536848285016123c3565b602083015250604061254a848285016123c3565b604083015250606061255e848285016123fe565b6060830152506080612572848285016123fe565b60808301525060a06125868482850161243a565b60a08301525060c061259a84828501612220565b60c08301525060e082015167ffffffffffffffff8111156125be576125bd6123a7565b5b6125ca848285016124c2565b60e08301525092915050565b6000602082840312156125ec576125eb611768565b5b600082015167ffffffffffffffff81111561260a5761260961176d565b5b612616848285016124f0565b91505092915050565b60006020828403121561263557612634611768565b5b600082015167ffffffffffffffff8111156126535761265261176d565b5b61265f848285016124c2565b91505092915050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006126c46026836119ad565b91506126cf82612668565b604082019050919050565b600060208201905081810360008301526126f3816126b7565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b60006127306020836119ad565b915061273b826126fa565b602082019050919050565b6000602082019050818103600083015261275f81612723565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fdfea2646970667358221220d2c947844622f009cb514e28bc3f9e00f425f472bf4be56a0525e45802080c8f64736f6c63430008090033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101735760003560e01c80636352211e116100de578063a22cb46511610097578063e985e9c511610071578063e985e9c514610482578063f2fde38b146104b2578063f34071da146104ce578063ff4236f8146104fe57610173565b8063a22cb4651461041a578063b88d4fde14610436578063c87b56dd1461045257610173565b80636352211e1461034457806370a0823114610374578063715018a6146103a45780638da5cb5b146103ae5780638dd18d2d146103cc57806395d89b41146103fc57610173565b806323b872dd1161013057806323b872dd1461026057806329edae3a1461027c5780632f745c59146102ac57806332cbe31c146102dc57806342842e0e146102f85780634f6ccce71461031457610173565b806301ffc9a714610178578063061e4dde146101a857806306fdde03146101d8578063081812fc146101f6578063095ea7b31461022657806318160ddd14610242575b600080fd5b610192600480360381019061018d91906117ca565b61052e565b60405161019f9190611812565b60405180910390f35b6101c260048036038101906101bd919061188b565b6105a5565b6040516101cf9190611980565b60405180910390f35b6101e06105f5565b6040516101ed9190611a3b565b60405180910390f35b610210600480360381019061020b9190611a89565b610687565b60405161021d9190611ac5565b60405180910390f35b610240600480360381019061023b9190611ae0565b61068e565b005b61024a6106c9565b6040516102579190611b2f565b60405180910390f35b61027a60048036038101906102759190611b4a565b610867565b005b61029660048036038101906102919190611ae0565b6108a2565b6040516102a39190611b2f565b60405180910390f35b6102c660048036038101906102c19190611ae0565b6108fd565b6040516102d39190611b2f565b60405180910390f35b6102f660048036038101906102f19190611b9d565b6109a2565b005b610312600480360381019061030d9190611b4a565b610b4f565b005b61032e60048036038101906103299190611a89565b610b6f565b60405161033b9190611b2f565b60405180910390f35b61035e60048036038101906103599190611a89565b610c23565b60405161036b9190611ac5565b60405180910390f35b61038e6004803603810190610389919061188b565b610cd7565b60405161039b9190611b2f565b60405180910390f35b6103ac610d96565b005b6103b6610daa565b6040516103c39190611ac5565b60405180910390f35b6103e660048036038101906103e19190611a89565b610dd4565b6040516103f39190611a3b565b60405180910390f35b610404610f7b565b6040516104119190611a3b565b60405180910390f35b610434600480360381019061042f9190611c1c565b61100d565b005b610450600480360381019061044b9190611d91565b611048565b005b61046c60048036038101906104679190611a89565b611083565b6040516104799190611a3b565b60405180910390f35b61049c60048036038101906104979190611e14565b61113c565b6040516104a99190611812565b60405180910390f35b6104cc60048036038101906104c7919061188b565b611144565b005b6104e860048036038101906104e39190611a89565b6111c8565b6040516104f59190611f12565b60405180910390f35b61051860048036038101906105139190611a89565b6111ec565b6040516105259190611f50565b60405180910390f35b600061053982611393565b8061059e5750600080837bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200190815260200160002060009054906101000a900460ff165b9050919050565b60606105ee600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206113fd565b9050919050565b60606002805461060490611f9a565b80601f016020809104026020016040519081016040528092919081815260200182805461063090611f9a565b801561067d5780601f106106525761010080835404028352916020019161067d565b820191906000526020600020905b81548152906001019060200180831161066057829003601f168201915b5050505050905090565b6000919050565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106c090612018565b60405180910390fd5b600080600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b15801561073457600080fd5b505afa158015610748573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061076c919061204d565b905060005b81811015610862576000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634f6ccce7836040518263ffffffff1660e01b81526004016107d69190611b2f565b60206040518083038186803b1580156107ee57600080fd5b505afa158015610802573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610826919061204d565b90506108436007600083815260200190815260200160002061141e565b8461084e91906120a9565b9350508061085b906120ff565b9050610771565b505090565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161089990612194565b60405180910390fd5b60006006600083815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600061090883610cd7565b8210610949576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161094090612200565b60405180910390fd5b61099a82600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002061143390919063ffffffff16565b905092915050565b6109aa61144d565b806006600084815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610a5082600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206114cb90919063ffffffff16565b610b4a57610aa582600560008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206114e590919063ffffffff16565b50610acb83600760008581526020019081526020016000206114ff90919063ffffffff16565b50818373ffffffffffffffffffffffffffffffffffffffff16600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60405160405180910390a45b505050565b610b6a83838360405180602001604052806000815250611048565b505050565b6000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634f6ccce7836040518263ffffffff1660e01b8152600401610bcc9190611b2f565b60206040518083038186803b158015610be457600080fd5b505afa158015610bf8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1c919061204d565b9050919050565b6000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b8152600401610c809190611b2f565b60206040518083038186803b158015610c9857600080fd5b505afa158015610cac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd09190612235565b9050919050565b60008073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610d48576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d3f906122d4565b60405180910390fd5b610d8f600560008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002061152f565b9050919050565b610d9e61144d565b610da86000611544565b565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d8b05250836040518263ffffffff1660e01b8152600401610e319190611b2f565b60206040518083038186803b158015610e4957600080fd5b505afa158015610e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e819190612309565b610ec0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610eb790612382565b60405180910390fd5b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663edef019d836040518263ffffffff1660e01b8152600401610f1b9190611b2f565b60006040518083038186803b158015610f3357600080fd5b505afa158015610f47573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250810190610f7091906125d6565b60e001519050919050565b606060038054610f8a90611f9a565b80601f0160208091040260200160405190810160405280929190818152602001828054610fb690611f9a565b80156110035780601f10610fd857610100808354040283529160200191611003565b820191906000526020600020905b815481529060010190602001808311610fe657829003601f168201915b5050505050905090565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161103f90612018565b60405180910390fd5b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161107a90612194565b60405180910390fd5b6060600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663c87b56dd836040518263ffffffff1660e01b81526004016110e09190611b2f565b60006040518083038186803b1580156110f857600080fd5b505afa15801561110c573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250810190611135919061261f565b9050919050565b600092915050565b61114c61144d565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156111bc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111b3906126da565b60405180910390fd5b6111c581611544565b50565b60606111e56007600084815260200190815260200160002061160a565b9050919050565b6000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663d8b05250836040518263ffffffff1660e01b81526004016112499190611b2f565b60206040518083038186803b15801561126157600080fd5b505afa158015611275573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112999190612309565b6112d8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112cf90612382565b60405180910390fd5b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663edef019d836040518263ffffffff1660e01b81526004016113339190611b2f565b60006040518083038186803b15801561134b57600080fd5b505afa15801561135f573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f8201168201806040525081019061138891906125d6565b600001519050919050565b60007f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b6060600061140d8360000161162b565b905060608190508092505050919050565b600061142c82600001611687565b9050919050565b60006114428360000183611698565b60001c905092915050565b6114556116c3565b73ffffffffffffffffffffffffffffffffffffffff16611473610daa565b73ffffffffffffffffffffffffffffffffffffffff16146114c9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114c090612746565b60405180910390fd5b565b60006114dd836000018360001b6116cb565b905092915050565b60006114f7836000018360001b6116ee565b905092915050565b6000611527836000018373ffffffffffffffffffffffffffffffffffffffff1660001b6116ee565b905092915050565b600061153d82600001611687565b9050919050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b6060600061161a8360000161162b565b905060608190508092505050919050565b60608160000180548060200260200160405190810160405280929190818152602001828054801561167b57602002820191906000526020600020905b815481526020019060010190808311611667575b50505050509050919050565b600081600001805490509050919050565b60008260000182815481106116b0576116af612766565b5b9060005260206000200154905092915050565b600033905090565b600080836001016000848152602001908152602001600020541415905092915050565b60006116fa83836116cb565b611753578260000182908060018154018082558091505060019003906000526020600020016000909190919091505582600001805490508360010160008481526020019081526020016000208190555060019050611758565b600090505b92915050565b6000604051905090565b600080fd5b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6117a781611772565b81146117b257600080fd5b50565b6000813590506117c48161179e565b92915050565b6000602082840312156117e0576117df611768565b5b60006117ee848285016117b5565b91505092915050565b60008115159050919050565b61180c816117f7565b82525050565b60006020820190506118276000830184611803565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006118588261182d565b9050919050565b6118688161184d565b811461187357600080fd5b50565b6000813590506118858161185f565b92915050565b6000602082840312156118a1576118a0611768565b5b60006118af84828501611876565b91505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6000819050919050565b6118f7816118e4565b82525050565b600061190983836118ee565b60208301905092915050565b6000602082019050919050565b600061192d826118b8565b61193781856118c3565b9350611942836118d4565b8060005b8381101561197357815161195a88826118fd565b975061196583611915565b925050600181019050611946565b5085935050505092915050565b6000602082019050818103600083015261199a8184611922565b905092915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156119dc5780820151818401526020810190506119c1565b838111156119eb576000848401525b50505050565b6000601f19601f8301169050919050565b6000611a0d826119a2565b611a1781856119ad565b9350611a278185602086016119be565b611a30816119f1565b840191505092915050565b60006020820190508181036000830152611a558184611a02565b905092915050565b611a66816118e4565b8114611a7157600080fd5b50565b600081359050611a8381611a5d565b92915050565b600060208284031215611a9f57611a9e611768565b5b6000611aad84828501611a74565b91505092915050565b611abf8161184d565b82525050565b6000602082019050611ada6000830184611ab6565b92915050565b60008060408385031215611af757611af6611768565b5b6000611b0585828601611876565b9250506020611b1685828601611a74565b9150509250929050565b611b29816118e4565b82525050565b6000602082019050611b446000830184611b20565b92915050565b600080600060608486031215611b6357611b62611768565b5b6000611b7186828701611876565b9350506020611b8286828701611876565b9250506040611b9386828701611a74565b9150509250925092565b600080600060608486031215611bb657611bb5611768565b5b6000611bc486828701611876565b9350506020611bd586828701611a74565b9250506040611be686828701611a74565b9150509250925092565b611bf9816117f7565b8114611c0457600080fd5b50565b600081359050611c1681611bf0565b92915050565b60008060408385031215611c3357611c32611768565b5b6000611c4185828601611876565b9250506020611c5285828601611c07565b9150509250929050565b600080fd5b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b611c9e826119f1565b810181811067ffffffffffffffff82111715611cbd57611cbc611c66565b5b80604052505050565b6000611cd061175e565b9050611cdc8282611c95565b919050565b600067ffffffffffffffff821115611cfc57611cfb611c66565b5b611d05826119f1565b9050602081019050919050565b82818337600083830152505050565b6000611d34611d2f84611ce1565b611cc6565b905082815260208101848484011115611d5057611d4f611c61565b5b611d5b848285611d12565b509392505050565b600082601f830112611d7857611d77611c5c565b5b8135611d88848260208601611d21565b91505092915050565b60008060008060808587031215611dab57611daa611768565b5b6000611db987828801611876565b9450506020611dca87828801611876565b9350506040611ddb87828801611a74565b925050606085013567ffffffffffffffff811115611dfc57611dfb61176d565b5b611e0887828801611d63565b91505092959194509250565b60008060408385031215611e2b57611e2a611768565b5b6000611e3985828601611876565b9250506020611e4a85828601611876565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b611e898161184d565b82525050565b6000611e9b8383611e80565b60208301905092915050565b6000602082019050919050565b6000611ebf82611e54565b611ec98185611e5f565b9350611ed483611e70565b8060005b83811015611f05578151611eec8882611e8f565b9750611ef783611ea7565b925050600181019050611ed8565b5085935050505092915050565b60006020820190508181036000830152611f2c8184611eb4565b905092915050565b600060ff82169050919050565b611f4a81611f34565b82525050565b6000602082019050611f656000830184611f41565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680611fb257607f821691505b60208210811415611fc657611fc5611f6b565b5b50919050565b7f4251433a2063616e6e6f7420617070726f76652063726564656e7469616c7300600082015250565b6000612002601f836119ad565b915061200d82611fcc565b602082019050919050565b6000602082019050818103600083015261203181611ff5565b9050919050565b60008151905061204781611a5d565b92915050565b60006020828403121561206357612062611768565b5b600061207184828501612038565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006120b4826118e4565b91506120bf836118e4565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156120f4576120f361207a565b5b828201905092915050565b600061210a826118e4565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561213d5761213c61207a565b5b600182019050919050565b7f4251433a2063616e6e6f74207472616e736665722063726564656e7469616c73600082015250565b600061217e6020836119ad565b915061218982612148565b602082019050919050565b600060208201905081810360008301526121ad81612171565b9050919050565b7f496e646578206f7574206f6620626f756e647300000000000000000000000000600082015250565b60006121ea6013836119ad565b91506121f5826121b4565b602082019050919050565b60006020820190508181036000830152612219816121dd565b9050919050565b60008151905061222f8161185f565b92915050565b60006020828403121561224b5761224a611768565b5b600061225984828501612220565b91505092915050565b7f4552433732313a2062616c616e636520717565727920666f7220746865207a6560008201527f726f206164647265737300000000000000000000000000000000000000000000602082015250565b60006122be602a836119ad565b91506122c982612262565b604082019050919050565b600060208201905081810360008301526122ed816122b1565b9050919050565b60008151905061230381611bf0565b92915050565b60006020828403121561231f5761231e611768565b5b600061232d848285016122f4565b91505092915050565b7f5465737420646f6573206e6f7420657869737400000000000000000000000000600082015250565b600061236c6013836119ad565b915061237782612336565b602082019050919050565b6000602082019050818103600083015261239b8161235f565b9050919050565b600080fd5b600080fd5b6123b581611f34565b81146123c057600080fd5b50565b6000815190506123d2816123ac565b92915050565b600062ffffff82169050919050565b6123f0816123d8565b81146123fb57600080fd5b50565b60008151905061240d816123e7565b92915050565b600063ffffffff82169050919050565b61242c81612413565b811461243757600080fd5b50565b60008151905061244981612423565b92915050565b600067ffffffffffffffff82111561246a57612469611c66565b5b612473826119f1565b9050602081019050919050565b600061249361248e8461244f565b611cc6565b9050828152602081018484840111156124af576124ae611c61565b5b6124ba8482856119be565b509392505050565b600082601f8301126124d7576124d6611c5c565b5b81516124e7848260208601612480565b91505092915050565b60006101008284031215612507576125066123a2565b5b612512610100611cc6565b90506000612522848285016123c3565b6000830152506020612536848285016123c3565b602083015250604061254a848285016123c3565b604083015250606061255e848285016123fe565b6060830152506080612572848285016123fe565b60808301525060a06125868482850161243a565b60a08301525060c061259a84828501612220565b60c08301525060e082015167ffffffffffffffff8111156125be576125bd6123a7565b5b6125ca848285016124c2565b60e08301525092915050565b6000602082840312156125ec576125eb611768565b5b600082015167ffffffffffffffff81111561260a5761260961176d565b5b612616848285016124f0565b91505092915050565b60006020828403121561263557612634611768565b5b600082015167ffffffffffffffff8111156126535761265261176d565b5b61265f848285016124c2565b91505092915050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b60006126c46026836119ad565b91506126cf82612668565b604082019050919050565b600060208201905081810360008301526126f3816126b7565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b60006127306020836119ad565b915061273b826126fa565b602082019050919050565b6000602082019050818103600083015261275f81612723565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fdfea2646970667358221220d2c947844622f009cb514e28bc3f9e00f425f472bf4be56a0525e45802080c8f64736f6c63430008090033

Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.