- We're indexing this chain right now. Some of the counts may be inaccurate.

Contract Address Details

0x4Aed2F242E806c58758677059340e29E6B5b7619

Contract Name
PKPPermissions
Creator
0x046bf7–da7b9c at 0x08c3e3–bf7695
Balance
0 LIT
Tokens
Fetching tokens...
Transactions
3,155 Transactions
Transfers
0 Transfers
Gas Used
549,199,577
Last Balance Update
2767453
Contract name:
PKPPermissions




Optimization enabled
false
Compiler version
v0.8.17+commit.8df45f5f




Verified at
2023-04-27T22:51:11.576715Z

Constructor Arguments

0000000000000000000000008f75a53f65e31dd0d2e40d0827becaae2299d111

Arg [0] (address) : 0x8f75a53f65e31dd0d2e40d0827becaae2299d111

              

contracts/lit-node/PKPPermissions.sol

//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { BitMaps } from "@openzeppelin/contracts/utils/structs/BitMaps.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

import { PKPNFT } from "./PKPNFT.sol";
import "solidity-bytes-utils/contracts/BytesLib.sol";

import "hardhat/console.sol";

contract PKPPermissions is Ownable {
    using EnumerableSet for EnumerableSet.AddressSet;
    using EnumerableSet for EnumerableSet.Bytes32Set;
    using EnumerableSet for EnumerableSet.UintSet;
    using BytesLib for bytes;
    using BitMaps for BitMaps.BitMap;

    /* ========== STATE VARIABLES ========== */

    PKPNFT public pkpNFT;

    enum AuthMethodType {
        NULLMETHOD, // 0
        ADDRESS, // 1
        ACTION, // 2
        WEBAUTHN, // 3
        DISCORD, // 4
        GOOGLE, // 5
        GOOGLE_JWT // 6
    }

    struct AuthMethod {
        uint256 authMethodType; // 1 = address, 2 = action, 3 = WebAuthn, 4 = Discord, 5 = Google, 6 = Google JWT.  Not doing this in an enum so that we can add more auth methods in the future without redeploying.
        bytes id; // the id of the auth method.  For address, this is an eth address.  For action, this is an IPFS CID.  For WebAuthn, this is the credentialId.  For Discord, this is the user's Discord ID.  For Google, this is the user's Google ID.
        bytes userPubkey; // the user's pubkey.  This is used for WebAuthn.
    }

    // map the keccack256(uncompressed pubkey) -> set of auth methods
    mapping(uint256 => EnumerableSet.UintSet) permittedAuthMethods;

    // map the keccack256(uncompressed pubkey) -> auth_method_id -> scope id
    mapping(uint256 => mapping(uint256 => BitMaps.BitMap)) permittedAuthMethodScopes;

    // map the keccack256(authMethodType, userId) -> the actual AuthMethod struct
    mapping(uint256 => AuthMethod) public authMethods;

    // map the AuthMethod hash to the pubkeys that it's allowed to sign for
    // this makes it possible to be given a discord id and then lookup all the pubkeys that are allowed to sign for that discord id
    mapping(uint256 => EnumerableSet.UintSet) authMethodToPkpIds;

    // map the keccack256(uncompressed pubkey) -> (group => merkle tree root hash)
    mapping(uint256 => mapping(uint256 => bytes32)) private _rootHashes;

    /* ========== CONSTRUCTOR ========== */
    constructor(address _pkpNft) {
        pkpNFT = PKPNFT(_pkpNft);
    }

    /* ========== Modifier ========== */
    modifier onlyPKPOwner(uint256 tokenId) {
        // check that user is allowed to set this
        address nftOwner = pkpNFT.ownerOf(tokenId);
        require(msg.sender == nftOwner, "Not PKP NFT owner");
        _;
    }

    /* ========== VIEWS ========== */

    /// get the eth address for the keypair, as long as it's an ecdsa keypair
    function getEthAddress(uint256 tokenId) public view returns (address) {
        return pkpNFT.getEthAddress(tokenId);
    }

    /// includes the 0x04 prefix so you can pass this directly to ethers.utils.computeAddress
    function getPubkey(uint256 tokenId) public view returns (bytes memory) {
        return pkpNFT.getPubkey(tokenId);
    }

    function getAuthMethodId(
        uint256 authMethodType,
        bytes memory id
    ) public pure returns (uint256) {
        return uint256(keccak256(abi.encode(authMethodType, id)));
    }

    /// get the user's pubkey given their authMethodType and userId
    function getUserPubkeyForAuthMethod(
        uint256 authMethodType,
        bytes calldata id
    ) external view returns (bytes memory) {
        uint256 authMethodId = getAuthMethodId(authMethodType, id);
        AuthMethod memory am = authMethods[authMethodId];
        return am.userPubkey;
    }

    function getTokenIdsForAuthMethod(
        uint256 authMethodType,
        bytes calldata id
    ) external view returns (uint256[] memory) {
        uint256 authMethodId = getAuthMethodId(authMethodType, id);

        uint256 pkpIdsLength = authMethodToPkpIds[authMethodId].length();
        uint256[] memory allPkpIds = new uint256[](pkpIdsLength);

        for (uint256 i = 0; i < pkpIdsLength; i++) {
            allPkpIds[i] = authMethodToPkpIds[authMethodId].at(i);
        }

        return allPkpIds;
    }

    function getPermittedAuthMethods(
        uint256 tokenId
    ) external view returns (AuthMethod[] memory) {
        uint256 permittedAuthMethodsLength = permittedAuthMethods[tokenId]
            .length();
        AuthMethod[] memory allPermittedAuthMethods = new AuthMethod[](
            permittedAuthMethodsLength
        );

        for (uint256 i = 0; i < permittedAuthMethodsLength; i++) {
            uint256 authMethodHash = permittedAuthMethods[tokenId].at(i);
            allPermittedAuthMethods[i] = authMethods[authMethodHash];
        }

        return allPermittedAuthMethods;
    }

    function getPermittedAuthMethodScopes(
        uint256 tokenId,
        uint256 authMethodType,
        bytes calldata id,
        uint256 maxScopeId
    ) public view returns (bool[] memory) {
        uint256 authMethodId = getAuthMethodId(authMethodType, id);
        BitMaps.BitMap
            storage permittedScopesBitMap = permittedAuthMethodScopes[tokenId][
                authMethodId
            ];
        bool[] memory allScopes = new bool[](maxScopeId);

        for (uint256 i = 0; i < maxScopeId; i++) {
            allScopes[i] = permittedScopesBitMap.get(i);
        }

        return allScopes;
    }

    function getPermittedActions(
        uint256 tokenId
    ) public view returns (bytes[] memory) {
        uint256 permittedAuthMethodsLength = permittedAuthMethods[tokenId]
            .length();

        // count the number of auth methods that are actions
        uint256 permittedActionsLength = 0;
        for (uint256 i = 0; i < permittedAuthMethodsLength; i++) {
            uint256 authMethodHash = permittedAuthMethods[tokenId].at(i);
            AuthMethod memory am = authMethods[authMethodHash];
            if (am.authMethodType == uint256(AuthMethodType.ACTION)) {
                permittedActionsLength++;
            }
        }

        bytes[] memory allPermittedActions = new bytes[](
            permittedActionsLength
        );

        uint256 permittedActionsIndex = 0;
        for (uint256 i = 0; i < permittedAuthMethodsLength; i++) {
            uint256 authMethodHash = permittedAuthMethods[tokenId].at(i);
            AuthMethod memory am = authMethods[authMethodHash];
            if (am.authMethodType == uint256(AuthMethodType.ACTION)) {
                allPermittedActions[permittedActionsIndex] = am.id;
                permittedActionsIndex++;
            }
        }

        return allPermittedActions;
    }

    function getPermittedAddresses(
        uint256 tokenId
    ) public view returns (address[] memory) {
        uint256 permittedAuthMethodsLength = permittedAuthMethods[tokenId]
            .length();

        // count the number of auth methods that are addresses
        uint256 permittedAddressLength = 0;
        for (uint256 i = 0; i < permittedAuthMethodsLength; i++) {
            uint256 authMethodHash = permittedAuthMethods[tokenId].at(i);
            AuthMethod memory am = authMethods[authMethodHash];
            if (am.authMethodType == uint256(AuthMethodType.ADDRESS)) {
                permittedAddressLength++;
            }
        }

        bool tokenExists = pkpNFT.exists(tokenId);
        address[] memory allPermittedAddresses;
        uint256 permittedAddressIndex = 0;
        if (tokenExists) {
            // token is not burned, so add the owner address
            allPermittedAddresses = new address[](permittedAddressLength + 1);

            // always add nft owner in first slot
            address nftOwner = pkpNFT.ownerOf(tokenId);
            allPermittedAddresses[0] = nftOwner;
            permittedAddressIndex++;
        } else {
            // token is burned, so don't add the owner address
            allPermittedAddresses = new address[](permittedAddressLength);
        }

        for (uint256 i = 0; i < permittedAuthMethodsLength; i++) {
            uint256 authMethodHash = permittedAuthMethods[tokenId].at(i);
            AuthMethod memory am = authMethods[authMethodHash];
            if (am.authMethodType == uint256(AuthMethodType.ADDRESS)) {
                address parsed;
                bytes memory id = am.id;

                // address was packed using abi.encodedPacked(address), so you need to pad left to get the correct bytes back
                assembly {
                    parsed := div(
                        mload(add(id, 32)),
                        0x1000000000000000000000000
                    )
                }
                allPermittedAddresses[permittedAddressIndex] = parsed;
                permittedAddressIndex++;
            }
        }

        return allPermittedAddresses;
    }

    /// get if a user is permitted to use a given pubkey.  returns true if it is permitted to use the pubkey in the permittedAuthMethods[tokenId] struct.
    function isPermittedAuthMethod(
        uint256 tokenId,
        uint256 authMethodType,
        bytes memory id
    ) public view returns (bool) {
        uint256 authMethodId = getAuthMethodId(authMethodType, id);
        bool permitted = permittedAuthMethods[tokenId].contains(authMethodId);
        if (!permitted) {
            return false;
        }
        return true;
    }

    function isPermittedAuthMethodScopePresent(
        uint256 tokenId,
        uint256 authMethodType,
        bytes calldata id,
        uint256 scopeId
    ) public view returns (bool) {
        uint256 authMethodId = getAuthMethodId(authMethodType, id);
        bool present = permittedAuthMethodScopes[tokenId][authMethodId].get(
            scopeId
        );
        return present;
    }

    function isPermittedAction(
        uint256 tokenId,
        bytes calldata ipfsCID
    ) public view returns (bool) {
        return
            isPermittedAuthMethod(
                tokenId,
                uint256(AuthMethodType.ACTION),
                ipfsCID
            );
    }

    function isPermittedAddress(
        uint256 tokenId,
        address user
    ) public view returns (bool) {
        return
            isPermittedAuthMethod(
                tokenId,
                uint256(AuthMethodType.ADDRESS),
                abi.encodePacked(user)
            ) || pkpNFT.ownerOf(tokenId) == user;
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    /// Add a permitted auth method for a given pubkey
    function addPermittedAuthMethod(
        uint256 tokenId,
        AuthMethod memory authMethod,
        uint256[] calldata scopes
    ) public onlyPKPOwner(tokenId) {
        uint256 authMethodId = getAuthMethodId(
            authMethod.authMethodType,
            authMethod.id
        );

        // we need to ensure that someone with the same auth method type and id can't add a different pubkey
        require(
            authMethods[authMethodId].userPubkey.length == 0 ||
                keccak256(authMethods[authMethodId].userPubkey) ==
                keccak256(authMethod.userPubkey),
            "Cannot add a different pubkey for the same auth method type and id"
        );

        authMethods[authMethodId] = authMethod;

        EnumerableSet.UintSet
            storage newPermittedAuthMethods = permittedAuthMethods[tokenId];
        newPermittedAuthMethods.add(authMethodId);

        EnumerableSet.UintSet storage newPkpIds = authMethodToPkpIds[
            authMethodId
        ];
        newPkpIds.add(tokenId);

        for (uint256 i = 0; i < scopes.length; i++) {
            uint256 scopeId = scopes[i];

            permittedAuthMethodScopes[tokenId][authMethodId].set(scopeId);

            emit PermittedAuthMethodScopeAdded(
                tokenId,
                authMethodId,
                authMethod.id,
                scopeId
            );
        }

        emit PermittedAuthMethodAdded(
            tokenId,
            authMethod.authMethodType,
            authMethod.id,
            authMethod.userPubkey
        );
    }

    // Remove a permitted auth method for a given pubkey
    function removePermittedAuthMethod(
        uint256 tokenId,
        uint256 authMethodType,
        bytes memory id
    ) public onlyPKPOwner(tokenId) {
        uint256 authMethodId = getAuthMethodId(authMethodType, id);

        EnumerableSet.UintSet
            storage newPermittedAuthMethods = permittedAuthMethods[tokenId];
        newPermittedAuthMethods.remove(authMethodId);

        EnumerableSet.UintSet storage newPkpIds = authMethodToPkpIds[
            authMethodId
        ];
        newPkpIds.remove(tokenId);

        emit PermittedAuthMethodRemoved(tokenId, authMethodId, id);
    }

    function addPermittedAuthMethodScope(
        uint256 tokenId,
        uint256 authMethodType,
        bytes calldata id,
        uint256 scopeId
    ) public onlyPKPOwner(tokenId) {
        uint256 authMethodId = getAuthMethodId(authMethodType, id);

        permittedAuthMethodScopes[tokenId][authMethodId].set(scopeId);

        emit PermittedAuthMethodScopeAdded(tokenId, authMethodId, id, scopeId);
    }

    function removePermittedAuthMethodScope(
        uint256 tokenId,
        uint256 authMethodType,
        bytes calldata id,
        uint256 scopeId
    ) public onlyPKPOwner(tokenId) {
        uint256 authMethodId = getAuthMethodId(authMethodType, id);

        permittedAuthMethodScopes[tokenId][authMethodId].unset(scopeId);

        emit PermittedAuthMethodScopeRemoved(
            tokenId,
            authMethodType,
            id,
            scopeId
        );
    }

    /// Add a permitted action for a given pubkey
    function addPermittedAction(
        uint256 tokenId,
        bytes calldata ipfsCID,
        uint256[] calldata scopes
    ) public {
        addPermittedAuthMethod(
            tokenId,
            AuthMethod(uint256(AuthMethodType.ACTION), ipfsCID, ""),
            scopes
        );
    }

    function removePermittedAction(
        uint256 tokenId,
        bytes calldata ipfsCID
    ) public {
        removePermittedAuthMethod(
            tokenId,
            uint256(AuthMethodType.ACTION),
            ipfsCID
        );
    }

    function addPermittedAddress(
        uint256 tokenId,
        address user,
        uint256[] calldata scopes
    ) public {
        addPermittedAuthMethod(
            tokenId,
            AuthMethod(
                uint256(AuthMethodType.ADDRESS),
                abi.encodePacked(user),
                ""
            ),
            scopes
        );
    }

    function removePermittedAddress(uint256 tokenId, address user) public {
        removePermittedAuthMethod(
            tokenId,
            uint256(AuthMethodType.ADDRESS),
            abi.encodePacked(user)
        );
    }

    function setPkpNftAddress(address newPkpNftAddress) public onlyOwner {
        pkpNFT = PKPNFT(newPkpNftAddress);
    }

    /**
     * Update the root hash of the merkle tree representing off-chain states for the PKP
     */
    function setRootHash(
        uint256 tokenId,
        uint256 group,
        bytes32 root
    ) public onlyPKPOwner(tokenId) {
        _rootHashes[tokenId][group] = root;
        emit RootHashUpdated(tokenId, group, root);
    }

    /**
     * Verify the given leaf existing in the merkle tree
     */
    function verifyState(
        uint256 tokenId,
        uint256 group,
        bytes32[] memory proof,
        bytes32 leaf
    ) public view returns (bool) {
        bytes32 root = _rootHashes[tokenId][group];
        if (root == bytes32(0)) return false;
        return MerkleProof.verify(proof, root, leaf);
    }

    /**
     * Verify the given leaves existing in the merkle tree
     */
    function verifyStates(
        uint256 tokenId,
        uint256 group,
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32[] memory leaves
    ) public view returns (bool) {
        bytes32 root = _rootHashes[tokenId][group];
        if (root == bytes32(0)) return false;
        return MerkleProof.multiProofVerify(proof, proofFlags, root, leaves);
    }

    /* ========== EVENTS ========== */

    event PermittedAuthMethodAdded(
        uint256 indexed tokenId,
        uint256 authMethodType,
        bytes id,
        bytes userPubkey
    );
    event PermittedAuthMethodRemoved(
        uint256 indexed tokenId,
        uint256 authMethodType,
        bytes id
    );
    event PermittedAuthMethodScopeAdded(
        uint256 indexed tokenId,
        uint256 authMethodType,
        bytes id,
        uint256 scopeId
    );
    event PermittedAuthMethodScopeRemoved(
        uint256 indexed tokenId,
        uint256 authMethodType,
        bytes id,
        uint256 scopeId
    );
    event RootHashUpdated(
        uint256 indexed tokenId,
        uint256 indexed group,
        bytes32 root
    );
}
        

@openzeppelin/contracts/utils/introspection/ERC165.sol

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

pragma solidity ^0.8.0;

import "./IERC165.sol";

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

@openzeppelin/contracts/utils/Strings.sol

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

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_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) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @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] = _HEX_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);
    }
}
          

@openzeppelin/contracts/utils/Context.sol

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

pragma solidity ^0.8.0;

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

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

solidity-bytes-utils/contracts/BytesLib.sol

// SPDX-License-Identifier: Unlicense
/*
 * @title Solidity Bytes Arrays Utils
 * @author Gonçalo Sá <goncalo.sa@consensys.net>
 *
 * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
 *      The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
 */
pragma solidity >=0.8.0 <0.9.0;


library BytesLib {
    function concat(
        bytes memory _preBytes,
        bytes memory _postBytes
    )
        internal
        pure
        returns (bytes memory)
    {
        bytes memory tempBytes;

        assembly {
            // Get a location of some free memory and store it in tempBytes as
            // Solidity does for memory variables.
            tempBytes := mload(0x40)

            // Store the length of the first bytes array at the beginning of
            // the memory for tempBytes.
            let length := mload(_preBytes)
            mstore(tempBytes, length)

            // Maintain a memory counter for the current write location in the
            // temp bytes array by adding the 32 bytes for the array length to
            // the starting location.
            let mc := add(tempBytes, 0x20)
            // Stop copying when the memory counter reaches the length of the
            // first bytes array.
            let end := add(mc, length)

            for {
                // Initialize a copy counter to the start of the _preBytes data,
                // 32 bytes into its memory.
                let cc := add(_preBytes, 0x20)
            } lt(mc, end) {
                // Increase both counters by 32 bytes each iteration.
                mc := add(mc, 0x20)
                cc := add(cc, 0x20)
            } {
                // Write the _preBytes data into the tempBytes memory 32 bytes
                // at a time.
                mstore(mc, mload(cc))
            }

            // Add the length of _postBytes to the current length of tempBytes
            // and store it as the new length in the first 32 bytes of the
            // tempBytes memory.
            length := mload(_postBytes)
            mstore(tempBytes, add(length, mload(tempBytes)))

            // Move the memory counter back from a multiple of 0x20 to the
            // actual end of the _preBytes data.
            mc := end
            // Stop copying when the memory counter reaches the new combined
            // length of the arrays.
            end := add(mc, length)

            for {
                let cc := add(_postBytes, 0x20)
            } lt(mc, end) {
                mc := add(mc, 0x20)
                cc := add(cc, 0x20)
            } {
                mstore(mc, mload(cc))
            }

            // Update the free-memory pointer by padding our last write location
            // to 32 bytes: add 31 bytes to the end of tempBytes to move to the
            // next 32 byte block, then round down to the nearest multiple of
            // 32. If the sum of the length of the two arrays is zero then add
            // one before rounding down to leave a blank 32 bytes (the length block with 0).
            mstore(0x40, and(
              add(add(end, iszero(add(length, mload(_preBytes)))), 31),
              not(31) // Round down to the nearest 32 bytes.
            ))
        }

        return tempBytes;
    }

    function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal {
        assembly {
            // Read the first 32 bytes of _preBytes storage, which is the length
            // of the array. (We don't need to use the offset into the slot
            // because arrays use the entire slot.)
            let fslot := sload(_preBytes.slot)
            // Arrays of 31 bytes or less have an even value in their slot,
            // while longer arrays have an odd value. The actual length is
            // the slot divided by two for odd values, and the lowest order
            // byte divided by two for even values.
            // If the slot is even, bitwise and the slot with 255 and divide by
            // two to get the length. If the slot is odd, bitwise and the slot
            // with -1 and divide by two.
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)
            let newlength := add(slength, mlength)
            // slength can contain both the length and contents of the array
            // if length < 32 bytes so let's prepare for that
            // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
            switch add(lt(slength, 32), lt(newlength, 32))
            case 2 {
                // Since the new array still fits in the slot, we just need to
                // update the contents of the slot.
                // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length
                sstore(
                    _preBytes.slot,
                    // all the modifications to the slot are inside this
                    // next block
                    add(
                        // we can just add to the slot contents because the
                        // bytes we want to change are the LSBs
                        fslot,
                        add(
                            mul(
                                div(
                                    // load the bytes from memory
                                    mload(add(_postBytes, 0x20)),
                                    // zero all bytes to the right
                                    exp(0x100, sub(32, mlength))
                                ),
                                // and now shift left the number of bytes to
                                // leave space for the length in the slot
                                exp(0x100, sub(32, newlength))
                            ),
                            // increase length by the double of the memory
                            // bytes length
                            mul(mlength, 2)
                        )
                    )
                )
            }
            case 1 {
                // The stored value fits in the slot, but the combined value
                // will exceed it.
                // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

                // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

                // The contents of the _postBytes array start 32 bytes into
                // the structure. Our first read should obtain the `submod`
                // bytes that can fit into the unused space in the last word
                // of the stored array. To get this, we read 32 bytes starting
                // from `submod`, so the data we read overlaps with the array
                // contents by `submod` bytes. Masking the lowest-order
                // `submod` bytes allows us to add that value directly to the
                // stored value.

                let submod := sub(32, slength)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(
                    sc,
                    add(
                        and(
                            fslot,
                            0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00
                        ),
                        and(mload(mc), mask)
                    )
                )

                for {
                    mc := add(mc, 0x20)
                    sc := add(sc, 1)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } {
                    sstore(sc, mload(mc))
                }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
            default {
                // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                // Start copying to the last used word of the stored array.
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

                // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

                // Copy over the first `submod` bytes of the new data as in
                // case 1 above.
                let slengthmod := mod(slength, 32)
                let mlengthmod := mod(mlength, 32)
                let submod := sub(32, slengthmod)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(sc, add(sload(sc), and(mload(mc), mask)))

                for {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } {
                    sstore(sc, mload(mc))
                }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
        }
    }

    function slice(
        bytes memory _bytes,
        uint256 _start,
        uint256 _length
    )
        internal
        pure
        returns (bytes memory)
    {
        require(_length + 31 >= _length, "slice_overflow");
        require(_bytes.length >= _start + _length, "slice_outOfBounds");

        bytes memory tempBytes;

        assembly {
            switch iszero(_length)
            case 0 {
                // Get a location of some free memory and store it in tempBytes as
                // Solidity does for memory variables.
                tempBytes := mload(0x40)

                // The first word of the slice result is potentially a partial
                // word read from the original array. To read it, we calculate
                // the length of that partial word and start copying that many
                // bytes into the array. The first word we copy will start with
                // data we don't care about, but the last `lengthmod` bytes will
                // land at the beginning of the contents of the new array. When
                // we're done copying, we overwrite the full first word with
                // the actual length of the slice.
                let lengthmod := and(_length, 31)

                // The multiplication in the next line is necessary
                // because when slicing multiples of 32 bytes (lengthmod == 0)
                // the following copy loop was copying the origin's length
                // and then ending prematurely not copying everything it should.
                let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
                let end := add(mc, _length)

                for {
                    // The multiplication in the next line has the same exact purpose
                    // as the one above.
                    let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
                } lt(mc, end) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    mstore(mc, mload(cc))
                }

                mstore(tempBytes, _length)

                //update free-memory pointer
                //allocating the array padded to 32 bytes like the compiler does now
                mstore(0x40, and(add(mc, 31), not(31)))
            }
            //if we want a zero-length slice let's just return a zero-length array
            default {
                tempBytes := mload(0x40)
                //zero out the 32 bytes slice we are about to return
                //we need to do it because Solidity does not garbage collect
                mstore(tempBytes, 0)

                mstore(0x40, add(tempBytes, 0x20))
            }
        }

        return tempBytes;
    }

    function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
        require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
        address tempAddress;

        assembly {
            tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
        }

        return tempAddress;
    }

    function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) {
        require(_bytes.length >= _start + 1 , "toUint8_outOfBounds");
        uint8 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x1), _start))
        }

        return tempUint;
    }

    function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) {
        require(_bytes.length >= _start + 2, "toUint16_outOfBounds");
        uint16 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x2), _start))
        }

        return tempUint;
    }

    function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) {
        require(_bytes.length >= _start + 4, "toUint32_outOfBounds");
        uint32 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x4), _start))
        }

        return tempUint;
    }

    function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) {
        require(_bytes.length >= _start + 8, "toUint64_outOfBounds");
        uint64 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x8), _start))
        }

        return tempUint;
    }

    function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) {
        require(_bytes.length >= _start + 12, "toUint96_outOfBounds");
        uint96 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0xc), _start))
        }

        return tempUint;
    }

    function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) {
        require(_bytes.length >= _start + 16, "toUint128_outOfBounds");
        uint128 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x10), _start))
        }

        return tempUint;
    }

    function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) {
        require(_bytes.length >= _start + 32, "toUint256_outOfBounds");
        uint256 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x20), _start))
        }

        return tempUint;
    }

    function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) {
        require(_bytes.length >= _start + 32, "toBytes32_outOfBounds");
        bytes32 tempBytes32;

        assembly {
            tempBytes32 := mload(add(add(_bytes, 0x20), _start))
        }

        return tempBytes32;
    }

    function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {
        bool success = true;

        assembly {
            let length := mload(_preBytes)

            // if lengths don't match the arrays are not equal
            switch eq(length, mload(_postBytes))
            case 1 {
                // cb is a circuit breaker in the for loop since there's
                //  no said feature for inline assembly loops
                // cb = 1 - don't breaker
                // cb = 0 - break
                let cb := 1

                let mc := add(_preBytes, 0x20)
                let end := add(mc, length)

                for {
                    let cc := add(_postBytes, 0x20)
                // the next line is the loop condition:
                // while(uint256(mc < end) + cb == 2)
                } eq(add(lt(mc, end), cb), 2) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    // if any of these checks fails then arrays are not equal
                    if iszero(eq(mload(mc), mload(cc))) {
                        // unsuccess:
                        success := 0
                        cb := 0
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }

    function equalStorage(
        bytes storage _preBytes,
        bytes memory _postBytes
    )
        internal
        view
        returns (bool)
    {
        bool success = true;

        assembly {
            // we know _preBytes_offset is 0
            let fslot := sload(_preBytes.slot)
            // Decode the length of the stored array like in concatStorage().
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)

            // if lengths don't match the arrays are not equal
            switch eq(slength, mlength)
            case 1 {
                // slength can contain both the length and contents of the array
                // if length < 32 bytes so let's prepare for that
                // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
                if iszero(iszero(slength)) {
                    switch lt(slength, 32)
                    case 1 {
                        // blank the last byte which is the length
                        fslot := mul(div(fslot, 0x100), 0x100)

                        if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) {
                            // unsuccess:
                            success := 0
                        }
                    }
                    default {
                        // cb is a circuit breaker in the for loop since there's
                        //  no said feature for inline assembly loops
                        // cb = 1 - don't breaker
                        // cb = 0 - break
                        let cb := 1

                        // get the keccak hash to get the contents of the array
                        mstore(0x0, _preBytes.slot)
                        let sc := keccak256(0x0, 0x20)

                        let mc := add(_postBytes, 0x20)
                        let end := add(mc, mlength)

                        // the next line is the loop condition:
                        // while(uint256(mc < end) + cb == 2)
                        for {} eq(add(lt(mc, end), cb), 2) {
                            sc := add(sc, 1)
                            mc := add(mc, 0x20)
                        } {
                            if iszero(eq(sload(sc), mload(mc))) {
                                // unsuccess:
                                success := 0
                                cb := 0
                            }
                        }
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }
}
          

@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol

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

@openzeppelin/contracts/access/AccessControl.sol

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

pragma solidity ^0.8.0;

import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

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

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

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

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

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

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

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

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

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

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

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

        _revokeRole(role, account);
    }

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

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

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

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

@openzeppelin/contracts/utils/cryptography/ECDSA.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.3) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        } else if (error == RecoverError.InvalidSignatureV) {
            revert("ECDSA: invalid signature 'v' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }
        if (v != 27 && v != 28) {
            return (address(0), RecoverError.InvalidSignatureV);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}
          

@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol

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

@openzeppelin/contracts/token/ERC721/IERC721.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * 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);
}
          

@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol

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

pragma solidity ^0.8.0;

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

@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol

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

pragma solidity ^0.8.0;

import "../ERC20.sol";
import "../../../utils/Context.sol";

/**
 * @dev Extension of {ERC20} that allows token holders to destroy both their own
 * tokens and those that they have an allowance for, in a way that can be
 * recognized off-chain (via event analysis).
 */
abstract contract ERC20Burnable is Context, ERC20 {
    /**
     * @dev Destroys `amount` tokens from the caller.
     *
     * See {ERC20-_burn}.
     */
    function burn(uint256 amount) public virtual {
        _burn(_msgSender(), amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, deducting from the caller's
     * allowance.
     *
     * See {ERC20-_burn} and {ERC20-allowance}.
     *
     * Requirements:
     *
     * - the caller must have allowance for ``accounts``'s tokens of at least
     * `amount`.
     */
    function burnFrom(address account, uint256 amount) public virtual {
        _spendAllowance(account, _msgSender(), amount);
        _burn(account, amount);
    }
}
          

@openzeppelin/contracts/utils/introspection/IERC165.sol

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

pragma solidity ^0.8.0;

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

contracts/lit-node/PKPNFT.sol

//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { PubkeyRouter } from "./PubkeyRouter.sol";
import { PKPPermissions } from "./PKPPermissions.sol";
import { PKPNFTMetadata } from "./PKPNFTMetadata.sol";
import { ERC721Burnable } from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import { ERC721Enumerable } from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import { IERC721Enumerable } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";

import "hardhat/console.sol";

// TODO: tests for the mintGrantAndBurn function, withdraw function, some of the setters, transfer function, freeMint and freeMintGrantAndBurn

/// @title Programmable Keypair NFT
///
/// @dev This is the contract for the PKP NFTs
///
/// Simply put, whomever owns a PKP NFT can ask that PKP to sign a message.
/// The owner can also grant signing permissions to other eth addresses
/// or lit actions
contract PKPNFT is
    ERC721("Programmable Keypair", "PKP"),
    Ownable,
    ERC721Burnable,
    ERC721Enumerable,
    ReentrancyGuard
{
    /* ========== STATE VARIABLES ========== */

    PubkeyRouter public router;
    PKPPermissions public pkpPermissions;
    PKPNFTMetadata public pkpNftMetadata;
    uint256 public mintCost;
    address public freeMintSigner;

    // maps keytype to array of unminted routed token ids
    mapping(uint256 => uint256[]) public unmintedRoutedTokenIds;

    mapping(uint256 => bool) public redeemedFreeMintIds;

    /* ========== CONSTRUCTOR ========== */
    constructor() {
        mintCost = 1; // 1 wei aka 0.000000000000000001 eth
        freeMintSigner = msg.sender;
    }

    /* ========== VIEWS ========== */

    /// get the eth address for the keypair, as long as it's an ecdsa keypair
    function getEthAddress(uint256 tokenId) public view returns (address) {
        return router.getEthAddress(tokenId);
    }

    /// includes the 0x04 prefix so you can pass this directly to ethers.utils.computeAddress
    function getPubkey(uint256 tokenId) public view returns (bytes memory) {
        return router.getPubkey(tokenId);
    }

    /// throws if the sig is bad or msg doesn't match
    function freeMintSigTest(
        uint256 freeMintId,
        bytes32 msgHash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public view {
        bytes32 expectedHash = prefixed(
            keccak256(abi.encodePacked(address(this), freeMintId))
        );
        require(
            expectedHash == msgHash,
            "The msgHash is not a hash of the tokenId.  Explain yourself!"
        );

        // make sure it was actually signed by freeMintSigner
        address recovered = ecrecover(msgHash, v, r, s);
        require(
            recovered == freeMintSigner,
            "This freeMint was not signed by freeMintSigner.  How embarassing."
        );

        // prevent reuse
        require(
            redeemedFreeMintIds[freeMintId] == false,
            "This free mint ID has already been redeemed"
        );
    }

    function supportsInterface(
        bytes4 interfaceId
    ) public view virtual override(ERC721, ERC721Enumerable) returns (bool) {
        return
            interfaceId == type(IERC721Enumerable).interfaceId ||
            interfaceId == type(IERC721Metadata).interfaceId ||
            interfaceId == type(IERC721).interfaceId;
    }

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual override(ERC721, ERC721Enumerable) {
        ERC721Enumerable._beforeTokenTransfer(from, to, tokenId);
    }

    function tokenURI(
        uint256 tokenId
    ) public view override returns (string memory) {
        console.log("getting token uri");
        bytes memory pubKey = router.getPubkey(tokenId);
        console.log("got pubkey, getting eth address");
        address ethAddress = router.getEthAddress(tokenId);
        console.log("calling tokenURI");

        return pkpNftMetadata.tokenURI(tokenId, pubKey, ethAddress);
    }

    function getUnmintedRoutedTokenIdCount(
        uint256 keyType
    ) public view returns (uint256) {
        return unmintedRoutedTokenIds[keyType].length;
    }

    // Builds a prefixed hash to mimic the behavior of eth_sign.
    function prefixed(bytes32 hash) public pure returns (bytes32) {
        return
            keccak256(
                abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)
            );
    }

    function exists(uint256 tokenId) public view returns (bool) {
        return _exists(tokenId);
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    function mintNext(uint256 keyType) public payable returns (uint256) {
        require(msg.value == mintCost, "You must pay exactly mint cost");
        uint256 tokenId = _getNextTokenIdToMint(keyType);
        _mintWithoutValueCheck(tokenId, msg.sender);
        return tokenId;
    }

    function mintGrantAndBurnNext(
        uint256 keyType,
        bytes memory ipfsCID
    ) public payable returns (uint256) {
        require(msg.value == mintCost, "You must pay exactly mint cost");
        uint256 tokenId = _getNextTokenIdToMint(keyType);
        _mintWithoutValueCheck(tokenId, address(this));
        pkpPermissions.addPermittedAction(tokenId, ipfsCID, new uint256[](0));
        _burn(tokenId);
        return tokenId;
    }

    function freeMintNext(
        uint256 keyType,
        uint256 freeMintId,
        bytes32 msgHash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public returns (uint256) {
        uint256 tokenId = _getNextTokenIdToMint(keyType);
        freeMint(freeMintId, tokenId, msgHash, v, r, s);
        return tokenId;
    }

    function freeMintGrantAndBurnNext(
        uint256 keyType,
        uint256 freeMintId,
        bytes memory ipfsCID,
        bytes32 msgHash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public returns (uint256) {
        uint256 tokenId = _getNextTokenIdToMint(keyType);
        freeMintGrantAndBurn(freeMintId, tokenId, ipfsCID, msgHash, v, r, s);
        return tokenId;
    }

    /// create a valid token for a given public key.
    function mintSpecific(uint256 tokenId) public onlyOwner {
        _mintWithoutValueCheck(tokenId, msg.sender);
    }

    /// mint a PKP, grant access to a Lit Action, and then burn the PKP
    /// this happens in a single txn, so it's provable that only that lit action
    /// has ever had access to use the PKP.
    /// this is useful in the context of something like a "prime number certification lit action"
    /// where you could just trust the sig that a number is prime.
    /// without this function, a user could mint a PKP, sign a bunch of junk, and then burn the
    /// PKP to make it looks like only the Lit Action can use it.
    function mintGrantAndBurnSpecific(
        uint256 tokenId,
        bytes memory ipfsCID
    ) public onlyOwner {
        _mintWithoutValueCheck(tokenId, address(this));
        pkpPermissions.addPermittedAction(tokenId, ipfsCID, new uint256[](0));
        _burn(tokenId);
    }

    function freeMint(
        uint256 freeMintId,
        uint256 tokenId,
        bytes32 msgHash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        // this will panic if the sig is bad
        freeMintSigTest(freeMintId, msgHash, v, r, s);
        _mintWithoutValueCheck(tokenId, msg.sender);
        redeemedFreeMintIds[freeMintId] = true;
    }

    function freeMintGrantAndBurn(
        uint256 freeMintId,
        uint256 tokenId,
        bytes memory ipfsCID,
        bytes32 msgHash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        // this will panic if the sig is bad
        freeMintSigTest(freeMintId, msgHash, v, r, s);
        _mintWithoutValueCheck(tokenId, address(this));
        redeemedFreeMintIds[freeMintId] = true;
        pkpPermissions.addPermittedAction(tokenId, ipfsCID, new uint256[](0));
        _burn(tokenId);
    }

    function _mintWithoutValueCheck(uint256 tokenId, address to) internal {
        require(router.isRouted(tokenId), "This PKP has not been routed yet");

        if (to == address(this)) {
            // permit unsafe transfer only to this contract, because it's going to be burned
            _mint(to, tokenId);
        } else {
            _safeMint(to, tokenId);
        }
        emit PKPMinted(tokenId, getPubkey(tokenId));
    }

    /// Take a tokenId off the stack
    function _getNextTokenIdToMint(uint256 keyType) internal returns (uint256) {
        require(
            unmintedRoutedTokenIds[keyType].length > 0,
            "There are no unminted routed token ids to mint"
        );
        uint256 tokenId = unmintedRoutedTokenIds[keyType][
            unmintedRoutedTokenIds[keyType].length - 1
        ];

        unmintedRoutedTokenIds[keyType].pop();

        return tokenId;
    }

    function setRouterAddress(address routerAddress) public onlyOwner {
        router = PubkeyRouter(routerAddress);
        emit RouterAddressSet(routerAddress);
    }

    function setPkpNftMetadataAddress(
        address pkpNftMetadataAddress
    ) public onlyOwner {
        pkpNftMetadata = PKPNFTMetadata(pkpNftMetadataAddress);
        emit PkpNftMetadataAddressSet(pkpNftMetadataAddress);
    }

    function setPkpPermissionsAddress(
        address pkpPermissionsAddress
    ) public onlyOwner {
        pkpPermissions = PKPPermissions(pkpPermissionsAddress);
        emit PkpPermissionsAddressSet(pkpPermissionsAddress);
    }

    function setMintCost(uint256 newMintCost) public onlyOwner {
        mintCost = newMintCost;
        emit MintCostSet(newMintCost);
    }

    function setFreeMintSigner(address newFreeMintSigner) public onlyOwner {
        freeMintSigner = newFreeMintSigner;
        emit FreeMintSignerSet(newFreeMintSigner);
    }

    function withdraw() public onlyOwner nonReentrant {
        uint256 withdrawAmount = address(this).balance;
        (bool sent, ) = payable(msg.sender).call{ value: withdrawAmount }("");
        require(sent);
        emit Withdrew(withdrawAmount);
    }

    /// Push a tokenId onto the stack
    function pkpRouted(uint256 tokenId, uint256 keyType) public {
        require(
            msg.sender == address(router),
            "Only the routing contract can call this function"
        );
        unmintedRoutedTokenIds[keyType].push(tokenId);
        emit PkpRouted(tokenId, keyType);
    }

    /* ========== EVENTS ========== */

    event RouterAddressSet(address indexed routerAddress);
    event PkpNftMetadataAddressSet(address indexed pkpNftMetadataAddress);
    event PkpPermissionsAddressSet(address indexed pkpPermissionsAddress);
    event MintCostSet(uint256 newMintCost);
    event FreeMintSignerSet(address indexed newFreeMintSigner);
    event Withdrew(uint256 amount);
    event PkpRouted(uint256 indexed tokenId, uint256 indexed keyType);
    event PKPMinted(uint256 indexed tokenId, bytes pubkey);
}
          

@openzeppelin/contracts/utils/cryptography/MerkleProof.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/cryptography/MerkleProof.sol)

pragma solidity ^0.8.0;

/**
 * @dev These functions deal with verification of Merkle Tree proofs.
 *
 * The proofs can be generated using the JavaScript library
 * https://github.com/miguelmota/merkletreejs[merkletreejs].
 * Note: the hashing algorithm should be keccak256 and pair sorting should be enabled.
 *
 * See `test/utils/cryptography/MerkleProof.test.js` for some examples.
 *
 * WARNING: You should avoid using leaf values that are 64 bytes long prior to
 * hashing, or use a hash function other than keccak256 for hashing leaves.
 * This is because the concatenation of a sorted pair of internal nodes in
 * the merkle tree could be reinterpreted as a leaf value.
 */
library MerkleProof {
    /**
     * @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
     * defined by `root`. For this, a `proof` must be provided, containing
     * sibling hashes on the branch from the leaf to the root of the tree. Each
     * pair of leaves and each pair of pre-images are assumed to be sorted.
     */
    function verify(
        bytes32[] memory proof,
        bytes32 root,
        bytes32 leaf
    ) internal pure returns (bool) {
        return processProof(proof, leaf) == root;
    }

    /**
     * @dev Calldata version of {verify}
     *
     * _Available since v4.7._
     */
    function verifyCalldata(
        bytes32[] calldata proof,
        bytes32 root,
        bytes32 leaf
    ) internal pure returns (bool) {
        return processProofCalldata(proof, leaf) == root;
    }

    /**
     * @dev Returns the rebuilt hash obtained by traversing a Merkle tree up
     * from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
     * hash matches the root of the tree. When processing the proof, the pairs
     * of leafs & pre-images are assumed to be sorted.
     *
     * _Available since v4.4._
     */
    function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Calldata version of {processProof}
     *
     * _Available since v4.7._
     */
    function processProofCalldata(bytes32[] calldata proof, bytes32 leaf) internal pure returns (bytes32) {
        bytes32 computedHash = leaf;
        for (uint256 i = 0; i < proof.length; i++) {
            computedHash = _hashPair(computedHash, proof[i]);
        }
        return computedHash;
    }

    /**
     * @dev Returns true if the `leaves` can be proved to be a part of a Merkle tree defined by
     * `root`, according to `proof` and `proofFlags` as described in {processMultiProof}.
     *
     * _Available since v4.7._
     */
    function multiProofVerify(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProof(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Calldata version of {multiProofVerify}
     *
     * _Available since v4.7._
     */
    function multiProofVerifyCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32 root,
        bytes32[] memory leaves
    ) internal pure returns (bool) {
        return processMultiProofCalldata(proof, proofFlags, leaves) == root;
    }

    /**
     * @dev Returns the root of a tree reconstructed from `leaves` and the sibling nodes in `proof`,
     * consuming from one or the other at each step according to the instructions given by
     * `proofFlags`.
     *
     * _Available since v4.7._
     */
    function processMultiProof(
        bytes32[] memory proof,
        bool[] memory proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 totalHashes = proofFlags.length;

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

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

        if (totalHashes > 0) {
            return hashes[totalHashes - 1];
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

    /**
     * @dev Calldata version of {processMultiProof}
     *
     * _Available since v4.7._
     */
    function processMultiProofCalldata(
        bytes32[] calldata proof,
        bool[] calldata proofFlags,
        bytes32[] memory leaves
    ) internal pure returns (bytes32 merkleRoot) {
        // This function rebuild the root hash by traversing the tree up from the leaves. The root is rebuilt by
        // consuming and producing values on a queue. The queue starts with the `leaves` array, then goes onto the
        // `hashes` array. At the end of the process, the last hash in the `hashes` array should contain the root of
        // the merkle tree.
        uint256 leavesLen = leaves.length;
        uint256 totalHashes = proofFlags.length;

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

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

        if (totalHashes > 0) {
            return hashes[totalHashes - 1];
        } else if (leavesLen > 0) {
            return leaves[0];
        } else {
            return proof[0];
        }
    }

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

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

contracts/lit-node/PKPNFTMetadata.sol

//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";

import "hardhat/console.sol";

/// @title Programmable Keypair NFT Metadata
///
/// @dev This is the contract for the PKP NFTs
///
/// Simply put, whomever owns a PKP NFT can ask that PKP to sign a message.
/// The owner can also grant signing permissions to other eth addresses
/// or lit actions
contract PKPNFTMetadata {
    using Strings for uint256;

    /* ========== STATE VARIABLES ========== */

    /* ========== CONSTRUCTOR ========== */
    constructor() {}

    /* ========== VIEWS ========== */

    function bytesToHex(
        bytes memory buffer
    ) public pure returns (string memory) {
        // Fixed buffer size for hexadecimal convertion
        bytes memory converted = new bytes(buffer.length * 2);

        bytes memory _base = "0123456789abcdef";

        for (uint256 i = 0; i < buffer.length; i++) {
            converted[i * 2] = _base[uint8(buffer[i]) / _base.length];
            converted[i * 2 + 1] = _base[uint8(buffer[i]) % _base.length];
        }

        return string(abi.encodePacked("0x", converted));
    }

    function tokenURI(
        uint256 tokenId,
        bytes memory pubKey,
        address ethAddress
    ) public pure returns (string memory) {
        string
            memory svgData = "<svg xmlns='http://www.w3.org/2000/svg' width='1080' height='1080' fill='none' xmlns:v='https://vecta.io/nano'><path d='M363.076 392.227s-.977 18.524-36.874 78.947c-41.576 70.018-45.481 151.978-3.017 220.4 89.521 144.245 332.481 141.52 422.556.089 34.832-54.707 44.816-117.479 32.924-181.248 0 0-28.819-133.144-127.237-217.099 1.553 1.308 5.369 19.122 6.101 26.722 2.241 23.354.045 47.838-7.787 70.062-5.746 16.33-13.711 30.467-27.178 41.368 0-3.811-.954-10.635-.976-12.918-.644-46.508-18.659-89.582-48.011-125.743-25.647-31.552-60.812-53.089-97.84-68.932.931 3.191 2.662 16.419 2.906 19.033 1.908 21.958 2.263 52.713-.621 74.649s-7.832 33.878-14.554 54.441c-10.184 31.175-24.05 54.285-41.621 82.004-3.24 5.096-12.913 19.078-18.082 26.146 0 0-8.897-56.191-40.667-87.921h-.022z' fill='#000'/><path d='M562.5 27.28l410.279 236.874c13.923 8.039 22.5 22.895 22.5 38.971v473.75c0 16.076-8.577 30.932-22.5 38.971L562.5 1052.72c-13.923 8.04-31.077 8.04-45 0L107.221 815.846c-13.923-8.039-22.5-22.895-22.5-38.971v-473.75a45 45 0 0 1 22.5-38.971L517.5 27.28a45 45 0 0 1 45 0z' stroke='#000' stroke-width='24.75'/></svg>";

        string memory pubkeyStr = bytesToHex(pubKey);
        // console.log("pubkeyStr");
        // console.log(pubkeyStr);

        string memory ethAddressStr = Strings.toHexString(ethAddress);
        // console.log("ethAddressStr");
        // console.log(ethAddressStr);

        string memory tokenIdStr = Strings.toString(tokenId);

        string memory json = Base64.encode(
            bytes(
                string(
                    abi.encodePacked(
                        '{"name": "Lit PKP #',
                        tokenIdStr,
                        '", "description": "This NFT entitles the holder to use a Lit Protocol PKP, and to grant access to other users and Lit Actions to use this PKP", "image_data": "',
                        bytes(svgData),
                        '","attributes": [{"trait_type": "Public Key", "value": "',
                        pubkeyStr,
                        '"}, {"trait_type": "ETH Wallet Address", "value": "',
                        ethAddressStr,
                        '"}, {"trait_type": "Token ID", "value": "',
                        tokenIdStr,
                        '"}]}'
                    )
                )
            )
        );
        return string(abi.encodePacked("data:application/json;base64,", json));
    }
}
          

@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol

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

pragma solidity ^0.8.0;

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

/**
 * @dev This implements an optional extension of {ERC721} defined in the EIP that adds
 * enumerability of all the token ids in the contract as well as all token ids owned by each
 * account.
 */
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
    // Mapping from owner to list of owned token IDs
    mapping(address => mapping(uint256 => uint256)) private _ownedTokens;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@openzeppelin/contracts/token/ERC721/ERC721.sol

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

pragma solidity ^0.8.0;

import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
    using Address for address;
    using Strings for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

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

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

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

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

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

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

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

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

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

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

        _approve(to, tokenId);
    }

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

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        _setApprovalForAll(_msgSender(), operator, approved);
    }

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

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

        _transfer(from, to, tokenId);
    }

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

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

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * `data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(
        address from,
        address to,
        uint256 tokenId,
        bytes memory data
    ) internal virtual {
        _transfer(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
    }

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

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

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

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

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

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

        _balances[to] += 1;
        _owners[tokenId] = to;

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

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

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId);

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

        // Clear approvals
        _approve(address(0), tokenId);

        _balances[owner] -= 1;
        delete _owners[tokenId];

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

        _afterTokenTransfer(owner, address(0), tokenId);
    }

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

        _beforeTokenTransfer(from, to, tokenId);

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

        _balances[from] -= 1;
        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);

        _afterTokenTransfer(from, to, tokenId);
    }

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

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

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

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

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

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

hardhat/console.sol

// SPDX-License-Identifier: MIT
pragma solidity >= 0.4.22 <0.9.0;

library console {
	address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);

	function _sendLogPayload(bytes memory payload) private view {
		uint256 payloadLength = payload.length;
		address consoleAddress = CONSOLE_ADDRESS;
		assembly {
			let payloadStart := add(payload, 32)
			let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0)
		}
	}

	function log() internal view {
		_sendLogPayload(abi.encodeWithSignature("log()"));
	}

	function logInt(int256 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(int256)", p0));
	}

	function logUint(uint256 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256)", p0));
	}

	function logString(string memory p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
	}

	function logBool(bool p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
	}

	function logAddress(address p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
	}

	function logBytes(bytes memory p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes)", p0));
	}

	function logBytes1(bytes1 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0));
	}

	function logBytes2(bytes2 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0));
	}

	function logBytes3(bytes3 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0));
	}

	function logBytes4(bytes4 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0));
	}

	function logBytes5(bytes5 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0));
	}

	function logBytes6(bytes6 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0));
	}

	function logBytes7(bytes7 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0));
	}

	function logBytes8(bytes8 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0));
	}

	function logBytes9(bytes9 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0));
	}

	function logBytes10(bytes10 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0));
	}

	function logBytes11(bytes11 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0));
	}

	function logBytes12(bytes12 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0));
	}

	function logBytes13(bytes13 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0));
	}

	function logBytes14(bytes14 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0));
	}

	function logBytes15(bytes15 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0));
	}

	function logBytes16(bytes16 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0));
	}

	function logBytes17(bytes17 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0));
	}

	function logBytes18(bytes18 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0));
	}

	function logBytes19(bytes19 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0));
	}

	function logBytes20(bytes20 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0));
	}

	function logBytes21(bytes21 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0));
	}

	function logBytes22(bytes22 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0));
	}

	function logBytes23(bytes23 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0));
	}

	function logBytes24(bytes24 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0));
	}

	function logBytes25(bytes25 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0));
	}

	function logBytes26(bytes26 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0));
	}

	function logBytes27(bytes27 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0));
	}

	function logBytes28(bytes28 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0));
	}

	function logBytes29(bytes29 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0));
	}

	function logBytes30(bytes30 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0));
	}

	function logBytes31(bytes31 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0));
	}

	function logBytes32(bytes32 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0));
	}

	function log(uint256 p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256)", p0));
	}

	function log(string memory p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
	}

	function log(bool p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
	}

	function log(address p0) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
	}

	function log(uint256 p0, uint256 p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256)", p0, p1));
	}

	function log(uint256 p0, string memory p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string)", p0, p1));
	}

	function log(uint256 p0, bool p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool)", p0, p1));
	}

	function log(uint256 p0, address p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address)", p0, p1));
	}

	function log(string memory p0, uint256 p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256)", p0, p1));
	}

	function log(string memory p0, string memory p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1));
	}

	function log(string memory p0, bool p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1));
	}

	function log(string memory p0, address p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1));
	}

	function log(bool p0, uint256 p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256)", p0, p1));
	}

	function log(bool p0, string memory p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1));
	}

	function log(bool p0, bool p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1));
	}

	function log(bool p0, address p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1));
	}

	function log(address p0, uint256 p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256)", p0, p1));
	}

	function log(address p0, string memory p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1));
	}

	function log(address p0, bool p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1));
	}

	function log(address p0, address p1) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1));
	}

	function log(uint256 p0, uint256 p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256)", p0, p1, p2));
	}

	function log(uint256 p0, uint256 p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string)", p0, p1, p2));
	}

	function log(uint256 p0, uint256 p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool)", p0, p1, p2));
	}

	function log(uint256 p0, uint256 p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address)", p0, p1, p2));
	}

	function log(uint256 p0, string memory p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256)", p0, p1, p2));
	}

	function log(uint256 p0, string memory p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string)", p0, p1, p2));
	}

	function log(uint256 p0, string memory p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool)", p0, p1, p2));
	}

	function log(uint256 p0, string memory p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address)", p0, p1, p2));
	}

	function log(uint256 p0, bool p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256)", p0, p1, p2));
	}

	function log(uint256 p0, bool p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string)", p0, p1, p2));
	}

	function log(uint256 p0, bool p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool)", p0, p1, p2));
	}

	function log(uint256 p0, bool p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address)", p0, p1, p2));
	}

	function log(uint256 p0, address p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256)", p0, p1, p2));
	}

	function log(uint256 p0, address p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string)", p0, p1, p2));
	}

	function log(uint256 p0, address p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool)", p0, p1, p2));
	}

	function log(uint256 p0, address p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address)", p0, p1, p2));
	}

	function log(string memory p0, uint256 p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256)", p0, p1, p2));
	}

	function log(string memory p0, uint256 p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string)", p0, p1, p2));
	}

	function log(string memory p0, uint256 p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool)", p0, p1, p2));
	}

	function log(string memory p0, uint256 p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address)", p0, p1, p2));
	}

	function log(string memory p0, string memory p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256)", p0, p1, p2));
	}

	function log(string memory p0, string memory p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2));
	}

	function log(string memory p0, string memory p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2));
	}

	function log(string memory p0, string memory p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2));
	}

	function log(string memory p0, bool p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256)", p0, p1, p2));
	}

	function log(string memory p0, bool p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2));
	}

	function log(string memory p0, bool p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2));
	}

	function log(string memory p0, bool p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2));
	}

	function log(string memory p0, address p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256)", p0, p1, p2));
	}

	function log(string memory p0, address p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2));
	}

	function log(string memory p0, address p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2));
	}

	function log(string memory p0, address p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2));
	}

	function log(bool p0, uint256 p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256)", p0, p1, p2));
	}

	function log(bool p0, uint256 p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string)", p0, p1, p2));
	}

	function log(bool p0, uint256 p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool)", p0, p1, p2));
	}

	function log(bool p0, uint256 p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address)", p0, p1, p2));
	}

	function log(bool p0, string memory p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256)", p0, p1, p2));
	}

	function log(bool p0, string memory p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2));
	}

	function log(bool p0, string memory p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2));
	}

	function log(bool p0, string memory p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2));
	}

	function log(bool p0, bool p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256)", p0, p1, p2));
	}

	function log(bool p0, bool p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2));
	}

	function log(bool p0, bool p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2));
	}

	function log(bool p0, bool p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2));
	}

	function log(bool p0, address p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256)", p0, p1, p2));
	}

	function log(bool p0, address p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2));
	}

	function log(bool p0, address p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2));
	}

	function log(bool p0, address p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2));
	}

	function log(address p0, uint256 p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256)", p0, p1, p2));
	}

	function log(address p0, uint256 p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string)", p0, p1, p2));
	}

	function log(address p0, uint256 p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool)", p0, p1, p2));
	}

	function log(address p0, uint256 p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address)", p0, p1, p2));
	}

	function log(address p0, string memory p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256)", p0, p1, p2));
	}

	function log(address p0, string memory p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2));
	}

	function log(address p0, string memory p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2));
	}

	function log(address p0, string memory p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2));
	}

	function log(address p0, bool p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256)", p0, p1, p2));
	}

	function log(address p0, bool p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2));
	}

	function log(address p0, bool p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2));
	}

	function log(address p0, bool p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2));
	}

	function log(address p0, address p1, uint256 p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256)", p0, p1, p2));
	}

	function log(address p0, address p1, string memory p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2));
	}

	function log(address p0, address p1, bool p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2));
	}

	function log(address p0, address p1, address p2) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2));
	}

	function log(uint256 p0, uint256 p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, uint256 p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, string memory p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, bool p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,address)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,uint256)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,string)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,bool)", p0, p1, p2, p3));
	}

	function log(uint256 p0, address p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, uint256 p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, string memory p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, bool p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint256)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3));
	}

	function log(string memory p0, address p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,string)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,address)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,string)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,address)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,string)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,address)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,string)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, uint256 p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,address)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,string)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,address)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, string memory p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,string)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,address)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, bool p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,string)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,address)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint256)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3));
	}

	function log(bool p0, address p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,string)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,bool)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,address)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,string)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,bool)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,address)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,string)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,bool)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,address)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,string)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,bool)", p0, p1, p2, p3));
	}

	function log(address p0, uint256 p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,address)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,string)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,bool)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,address)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3));
	}

	function log(address p0, string memory p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,string)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,bool)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,address)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3));
	}

	function log(address p0, bool p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, uint256 p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, uint256 p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,string)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, uint256 p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,bool)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, uint256 p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,address)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, string memory p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, string memory p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, string memory p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, string memory p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, bool p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, bool p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, bool p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, bool p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, address p2, uint256 p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint256)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, address p2, string memory p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, address p2, bool p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3));
	}

	function log(address p0, address p1, address p2, address p3) internal view {
		_sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3));
	}

}
          

@openzeppelin/contracts/security/Pausable.sol

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

pragma solidity ^0.8.0;

import "../utils/Context.sol";

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

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

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

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

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

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

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

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

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

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

@openzeppelin/contracts/utils/Base64.sol

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

pragma solidity ^0.8.0;

/**
 * @dev Provides a set of functions to operate with Base64 strings.
 *
 * _Available since v4.5._
 */
library Base64 {
    /**
     * @dev Base64 Encoding/Decoding Table
     */
    string internal constant _TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

    /**
     * @dev Converts a `bytes` to its Bytes64 `string` representation.
     */
    function encode(bytes memory data) internal pure returns (string memory) {
        /**
         * Inspired by Brecht Devos (Brechtpd) implementation - MIT licence
         * https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol
         */
        if (data.length == 0) return "";

        // Loads the table into memory
        string memory table = _TABLE;

        // Encoding takes 3 bytes chunks of binary data from `bytes` data parameter
        // and split into 4 numbers of 6 bits.
        // The final Base64 length should be `bytes` data length multiplied by 4/3 rounded up
        // - `data.length + 2`  -> Round up
        // - `/ 3`              -> Number of 3-bytes chunks
        // - `4 *`              -> 4 characters for each chunk
        string memory result = new string(4 * ((data.length + 2) / 3));

        /// @solidity memory-safe-assembly
        assembly {
            // Prepare the lookup table (skip the first "length" byte)
            let tablePtr := add(table, 1)

            // Prepare result pointer, jump over length
            let resultPtr := add(result, 32)

            // Run over the input, 3 bytes at a time
            for {
                let dataPtr := data
                let endPtr := add(data, mload(data))
            } lt(dataPtr, endPtr) {

            } {
                // Advance 3 bytes
                dataPtr := add(dataPtr, 3)
                let input := mload(dataPtr)

                // To write each character, shift the 3 bytes (18 bits) chunk
                // 4 times in blocks of 6 bits for each character (18, 12, 6, 0)
                // and apply logical AND with 0x3F which is the number of
                // the previous character in the ASCII table prior to the Base64 Table
                // The result is then added to the table to get the character to write,
                // and finally write it in the result pointer but with a left shift
                // of 256 (1 byte) - 8 (1 ASCII char) = 248 bits

                mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))
                resultPtr := add(resultPtr, 1) // Advance

                mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))
                resultPtr := add(resultPtr, 1) // Advance

                mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F))))
                resultPtr := add(resultPtr, 1) // Advance

                mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F))))
                resultPtr := add(resultPtr, 1) // Advance
            }

            // When data `bytes` is not exactly 3 bytes long
            // it is padded with `=` characters at the end
            switch mod(mload(data), 3)
            case 1 {
                mstore8(sub(resultPtr, 1), 0x3d)
                mstore8(sub(resultPtr, 2), 0x3d)
            }
            case 2 {
                mstore8(sub(resultPtr, 1), 0x3d)
            }
        }

        return result;
    }
}
          

contracts/lit-node/PubkeyRouter.sol

//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { PKPNFT } from "./PKPNFT.sol";
import { Staking } from "./Staking.sol";
import "solidity-bytes-utils/contracts/BytesLib.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";

import "hardhat/console.sol";

// TODO: make the tests send PKPNFT into the constructor
// TODO: test interaction between PKPNFT and this contract, like mint a keypair and see if you can access it
// TODO: setRoutingData() for a batch of keys

contract PubkeyRouter is AccessControl {
    using EnumerableSet for EnumerableSet.AddressSet;
    using EnumerableSet for EnumerableSet.Bytes32Set;
    using EnumerableSet for EnumerableSet.UintSet;
    using BytesLib for bytes;

    /* ========== TYPE DEFINITIONS ========== */

    bytes32 public constant ADMIN_ROLE = keccak256("ADMIN"); // 0xdf8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec42
    bytes32 public constant ROUTER_ROLE = keccak256("ROUTER"); // 0xeb4fd9f47c063b511700e1c8e94e2fa4088ffca1fdcef1e60edf1beecd1b2e64

    /* ========== STATE VARIABLES ========== */

    PKPNFT public pkpNFT;

    struct PubkeyRoutingData {
        bytes pubkey;
        address stakingContract;
        uint256 keyType; // 1 = BLS, 2 = ECDSA.  Not doing this in an enum so we can add more keytypes in the future without redeploying.
    }

    struct Signature {
        bytes32 r;
        bytes32 s;
        uint8 v;
    }

    // map the keccack256(uncompressed pubkey) -> PubkeyRoutingData
    mapping(uint256 => PubkeyRoutingData) public pubkeys;

    // map the eth address to a pkp id
    mapping(address => uint256) public ethAddressToPkpId;

    /* ========== CONSTRUCTOR ========== */
    constructor(address _pkpNft) {
        pkpNFT = PKPNFT(_pkpNft);
        _grantRole(ADMIN_ROLE, msg.sender);
        _grantRole(ROUTER_ROLE, msg.sender);
        _setRoleAdmin(ADMIN_ROLE, ADMIN_ROLE);
        _setRoleAdmin(ROUTER_ROLE, ADMIN_ROLE);
    }

    /* ========== VIEWS ========== */

    /// get the routing data for a given key hash
    function getRoutingData(
        uint256 tokenId
    ) external view returns (PubkeyRoutingData memory) {
        return pubkeys[tokenId];
    }

    /// get if a given pubkey has routing data associated with it or not
    function isRouted(uint256 tokenId) public view returns (bool) {
        PubkeyRoutingData memory prd = pubkeys[tokenId];
        return
            prd.pubkey.length != 0 &&
            prd.keyType != 0 &&
            prd.stakingContract != address(0);
    }

    /// get the eth address for the keypair, as long as it's an ecdsa keypair
    function getEthAddress(uint256 tokenId) public view returns (address) {
        // only return addresses for ECDSA keys so that people don't
        // send funds to a BLS key that would be irretrieveably lost
        if (pubkeys[tokenId].keyType != 2) {
            return address(0);
        }
        return deriveEthAddressFromPubkey(pubkeys[tokenId].pubkey);
    }

    /// includes the 0x04 prefix so you can pass this directly to ethers.utils.computeAddress
    function getPubkey(uint256 tokenId) public view returns (bytes memory) {
        return pubkeys[tokenId].pubkey;
    }

    function deriveEthAddressFromPubkey(
        bytes memory pubkey
    ) public pure returns (address) {
        // remove 0x04 prefix
        bytes32 hashed = keccak256(pubkey.slice(1, 64));
        return address(uint160(uint256(hashed)));
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    /// register a pubkey and routing data for a given key hash
    // the person asking the nodes to generate the keys will collect signatures from them and then call this function to route the key

    // FIXME this is vulnerable to passing the same signature in 10 times.  we don't check that the sigs are unique, or that they're from independent nodes.
    // FIXME this is also vulnerable to an attack where someone sets up their own staking contract with a threshold of 1 and then goes around claiming tokenIds and filling them with junk.  we probably need to verify that the staking contract is legit.  i'm not sure how to do that though.  like we can check various things from the staking contract, that the staked token is the real Lit token, and that the user has staked a significant amount.  But how do we know that staking contract isn't a custom fork that lies about all that stuff?  Maybe we need a mapping of valid staking contracts somewhere, and when we deploy a new one we add it manually.
    function setRoutingData(
        uint256 tokenId,
        bytes memory pubkey,
        address stakingContractAddress,
        uint256 keyType,
        Signature[] memory signatures
    ) public {
        require(
            hasRole(ROUTER_ROLE, msg.sender),
            "PubkeyRouter: must have router role"
        );
        Staking stakingContract = Staking(stakingContractAddress);
        require(
            signatures.length ==
                stakingContract.getValidatorsInCurrentEpochLength(),
            "PubkeyRouter: incorrect number of signatures"
        );
        require(
            tokenId == uint256(keccak256(pubkey)),
            "tokenId does not match hashed pubkey"
        );
        require(
            !isRouted(tokenId),
            "PubkeyRouter: pubkey already has routing data"
        );

        // check the signatures
        for (uint256 i = 0; i < signatures.length; i++) {
            Signature memory sig = signatures[i];
            address signer = ECDSA.recover(
                ECDSA.toEthSignedMessageHash(pubkey),
                sig.v,
                sig.r,
                sig.s
            );
            // console.log("signer: ");
            // console.log(signer);
            require(
                stakingContract.isActiveValidatorByNodeAddress(signer),
                "PubkeyRouter: signer is not active validator"
            );
        }

        pubkeys[tokenId].pubkey = pubkey;
        pubkeys[tokenId].stakingContract = stakingContractAddress;
        pubkeys[tokenId].keyType = keyType;

        if (keyType == 2) {
            address pkpAddress = deriveEthAddressFromPubkey(pubkey);
            ethAddressToPkpId[pkpAddress] = tokenId;
        }

        pkpNFT.pkpRouted(tokenId, keyType);

        emit PubkeyRoutingDataSet(
            tokenId,
            pubkey,
            stakingContractAddress,
            keyType
        );
    }

    // a batch version of the above function
    function setRoutingDataBatch(
        uint256[] memory tokenIds,
        bytes[] memory _pubkeys,
        address stakingContract,
        uint256 keyType,
        Signature[][] memory signatures
    ) public {
        require(
            tokenIds.length == _pubkeys.length &&
                tokenIds.length == signatures.length,
            "PubkeyRouter: incorrect number of arguments"
        );
        for (uint256 i = 0; i < tokenIds.length; i++) {
            setRoutingData(
                tokenIds[i],
                _pubkeys[i],
                stakingContract,
                keyType,
                signatures[i]
            );
        }
    }

    /// Set the pubkey and routing data for a given key hash
    // this is only used by an admin in case of emergency.  can prob be removed.
    function setRoutingDataAsAdmin(
        uint256 tokenId,
        bytes memory pubkey,
        address stakingContract,
        uint256 keyType
    ) public {
        require(
            hasRole(ADMIN_ROLE, msg.sender),
            "PubkeyRouter: must have admin role"
        );
        pubkeys[tokenId].pubkey = pubkey;
        pubkeys[tokenId].stakingContract = stakingContract;
        pubkeys[tokenId].keyType = keyType;

        if (keyType == 2) {
            address pkpAddress = deriveEthAddressFromPubkey(pubkey);
            ethAddressToPkpId[pkpAddress] = tokenId;
        }

        pkpNFT.pkpRouted(tokenId, keyType);

        emit PubkeyRoutingDataSet(tokenId, pubkey, stakingContract, keyType);
    }

    function setPkpNftAddress(address newPkpNftAddress) public {
        require(
            hasRole(ADMIN_ROLE, msg.sender),
            "PubkeyRouter: must have admin role"
        );
        pkpNFT = PKPNFT(newPkpNftAddress);
        emit PkpNftAddressSet(newPkpNftAddress);
    }

    /* ========== EVENTS ========== */

    event PubkeyRoutingDataSet(
        uint256 indexed tokenId,
        bytes pubkey,
        address stakingContract,
        uint256 keyType
    );

    event PkpNftAddressSet(address newPkpNftAddress);
}
          

@openzeppelin/contracts/utils/Address.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.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 functionCall(target, data, "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");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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);
            }
        }
    }
}
          

contracts/lit-node/Staking.sol

//SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { ERC20Burnable } from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import "hardhat/console.sol";

contract Staking is ReentrancyGuard, Pausable, Ownable {
    using EnumerableSet for EnumerableSet.AddressSet;

    /* ========== STATE VARIABLES ========== */

    enum States {
        Active,
        NextValidatorSetLocked,
        ReadyForNextEpoch,
        Unlocked,
        Paused
    }

    // this enum is not used, and instead we use an integer so that
    // we can add more reasons after the contract is deployed.
    // This enum is kept in the comments here for reference.
    // enum KickReason {
    //     NULLREASON, // 0
    //     UNRESPONSIVE, // 1
    //     BAD_ATTESTATION // 2
    // }

    States public state = States.Active;

    ERC20Burnable public stakingToken;

    struct Epoch {
        uint256 epochLength;
        uint256 number;
        uint256 endBlock; //
        uint256 retries; // incremented upon failure to advance and subsequent unlock
        uint256 timeout; // timeout in blocks, where the nodes can be unlocked.
    }

    Epoch public epoch;

    uint256 public tokenRewardPerTokenPerEpoch;

    uint256 public minimumStake;
    uint256 public totalStaked;

    // tokens slashed when kicked
    uint256 public kickPenaltyPercent;

    EnumerableSet.AddressSet validatorsInCurrentEpoch;
    EnumerableSet.AddressSet validatorsInNextEpoch;
    EnumerableSet.AddressSet validatorsKickedFromNextEpoch;

    struct Validator {
        uint32 ip;
        uint128 ipv6;
        uint32 port;
        address nodeAddress;
        uint256 balance;
        uint256 reward;
        uint256 senderPubKey;
        uint256 receiverPubKey;
    }

    struct VoteToKickValidatorInNextEpoch {
        uint256 votes;
        mapping(address => bool) voted;
    }

    // list of all validators, even ones that are not in the current or next epoch
    // maps STAKER address to Validator struct
    mapping(address => Validator) public validators;

    // stakers join by staking, but nodes need to be able to vote to kick.
    // to avoid node operators having to run a hotwallet with their staking private key,
    // the node gets it's own private key that it can use to vote to kick,
    // or signal that the next epoch is ready.
    // this mapping lets you go from the nodeAddressto the stakingAddress.
    mapping(address => address) public nodeAddressToStakerAddress;

    // after the validator set is locked, nodes vote that they have successfully completed the PSS
    // operation.  Once a threshold of nodes have voted that they are ready, then the epoch can advance
    mapping(address => bool) public readyForNextEpoch;

    // nodes can vote to kick another node.  If a threshold of nodes vote to kick someone, they
    // are removed from the next validator set
    mapping(uint256 => mapping(address => VoteToKickValidatorInNextEpoch))
        public votesToKickValidatorsInNextEpoch;

    // resolver contract address. the resolver contract is used to lookup other contract addresses.
    address public resolverContractAddress;

    /* ========== CONSTRUCTOR ========== */
    constructor(address _stakingToken) {
        stakingToken = ERC20Burnable(_stakingToken);
        epoch = Epoch({
            epochLength: 80,
            number: 1,
            endBlock: block.number + 1,
            retries: 0,
            timeout: 80
        });
        // 0.05 tokens per token staked meaning a 5% per epoch inflation rate
        tokenRewardPerTokenPerEpoch = (10 ** stakingToken.decimals()) / 20;
        // 1 token minimum stake
        minimumStake = 1 * (10 ** stakingToken.decimals());
        kickPenaltyPercent = 0;
    }

    /* ========== VIEWS ========== */
    function isActiveValidator(address account) external view returns (bool) {
        return validatorsInCurrentEpoch.contains(account);
    }

    function isActiveValidatorByNodeAddress(
        address account
    ) external view returns (bool) {
        return
            validatorsInCurrentEpoch.contains(
                nodeAddressToStakerAddress[account]
            );
    }

    function rewardOf(address account) external view returns (uint256) {
        return validators[account].reward;
    }

    function balanceOf(address account) external view returns (uint256) {
        return validators[account].balance;
    }

    function getVotingStatusToKickValidator(
        uint256 epochNumber,
        address validatorStakerAddress,
        address voterStakerAddress
    ) external view returns (uint256, bool) {
        VoteToKickValidatorInNextEpoch
            storage votingStatus = votesToKickValidatorsInNextEpoch[
                epochNumber
            ][validatorStakerAddress];
        return (votingStatus.votes, votingStatus.voted[voterStakerAddress]);
    }

    function getValidatorsInCurrentEpoch()
        public
        view
        returns (address[] memory)
    {
        address[] memory values = new address[](
            validatorsInCurrentEpoch.length()
        );
        uint256 validatorLength = validatorsInCurrentEpoch.length();
        for (uint256 i = 0; i < validatorLength; i++) {
            values[i] = validatorsInCurrentEpoch.at(i);
        }
        return values;
    }

    function getValidatorsInCurrentEpochLength()
        external
        view
        returns (uint256)
    {
        return validatorsInCurrentEpoch.length();
    }

    function getValidatorsInNextEpoch() public view returns (address[] memory) {
        address[] memory values = new address[](validatorsInNextEpoch.length());
        uint256 validatorLength = validatorsInNextEpoch.length();
        for (uint256 i = 0; i < validatorLength; i++) {
            values[i] = validatorsInNextEpoch.at(i);
        }
        return values;
    }

    function getValidatorsStructs(
        address[] memory addresses
    ) public view returns (Validator[] memory) {
        Validator[] memory values = new Validator[](addresses.length);
        for (uint256 i = 0; i < addresses.length; i++) {
            values[i] = validators[addresses[i]];
        }
        return values;
    }

    function getValidatorsStructsInCurrentEpoch()
        external
        view
        returns (Validator[] memory)
    {
        address[] memory addresses = getValidatorsInCurrentEpoch();
        return getValidatorsStructs(addresses);
    }

    function getValidatorsStructsInNextEpoch()
        external
        view
        returns (Validator[] memory)
    {
        address[] memory addresses = getValidatorsInNextEpoch();
        return getValidatorsStructs(addresses);
    }

    function isReadyForNextEpoch() public view returns (bool) {
        uint256 total = 0;
        uint256 validatorLength = validatorsInNextEpoch.length();
        for (uint256 i = 0; i < validatorLength; i++) {
            if (readyForNextEpoch[validatorsInNextEpoch.at(i)]) {
                total++;
            }
        }
        if ((total >= validatorCountForConsensus())) {
            // 2/3 of validators must be ready
            return true;
        }
        return false;
    }

    function shouldKickValidator(
        address stakerAddress
    ) public view returns (bool) {
        VoteToKickValidatorInNextEpoch
            storage vk = votesToKickValidatorsInNextEpoch[epoch.number][
                stakerAddress
            ];
        if (vk.votes >= validatorCountForConsensus()) {
            // 2/3 of validators must vote
            return true;
        }
        return false;
    }

    // these could be checked with uint return value with the state getter, but included defensively in case more states are added.
    function validatorsInNextEpochAreLocked() public view returns (bool) {
        return state == States.NextValidatorSetLocked;
    }

    function validatorStateIsActive() public view returns (bool) {
        return state == States.Active;
    }

    function validatorStateIsUnlocked() public view returns (bool) {
        return state == States.Unlocked;
    }

    // currently set to 2/3.  this could be changed to be configurable.
    function validatorCountForConsensus() public view returns (uint256) {
        if (validatorsInCurrentEpoch.length() <= 2) {
            return 1;
        }
        return (validatorsInCurrentEpoch.length() * 2) / 3;
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    /// Lock in the validators for the next epoch
    function lockValidatorsForNextEpoch() public {
        require(
            block.number >= epoch.endBlock,
            "Enough blocks have not elapsed since the last epoch"
        );
        require(
            state == States.Active || state == States.Unlocked,
            "Must be in active or unlocked state"
        );

        state = States.NextValidatorSetLocked;
        emit StateChanged(state);
    }

    /// After proactive secret sharing is complete, the nodes may signal that they are ready for the next epoch.  Note that this function is called by the node itself, and so msg.sender is the nodeAddress and not the stakerAddress.
    function signalReadyForNextEpoch() public {
        address stakerAddress = nodeAddressToStakerAddress[msg.sender];
        require(
            state == States.NextValidatorSetLocked ||
                state == States.ReadyForNextEpoch,
            "Must be in state NextValidatorSetLocked or ReadyForNextEpoch"
        );
        // at the first epoch, validatorsInCurrentEpoch is empty
        if (epoch.number != 1) {
            require(
                validatorsInNextEpoch.contains(stakerAddress),
                "Validator is not in the next epoch"
            );
        }
        readyForNextEpoch[stakerAddress] = true;
        emit ReadyForNextEpoch(stakerAddress);

        if (isReadyForNextEpoch()) {
            state = States.ReadyForNextEpoch;
            emit StateChanged(state);
        }
    }

    /// If the nodes fail to advance (e.g. because dkg failed), anyone can call to unlock and allow retry
    function unlockValidatorsForNextEpoch() public {
        // the deadline to advance is thus epoch.endBlock + epoch.timeout
        require(
            block.number >= epoch.endBlock + epoch.timeout,
            "Enough blocks have not elapsed since the last epoch"
        );
        require(
            state == States.NextValidatorSetLocked,
            "Must be in NextValidatorSetLocked"
        );

        uint256 validatorLength = validatorsInNextEpoch.length();
        for (uint256 i = 0; i < validatorLength; i++) {
            readyForNextEpoch[validatorsInNextEpoch.at(i)] = false;
        }

        epoch.retries++;

        state = States.Unlocked;
        emit StateChanged(state);
    }

    /// Advance to the next Epoch.  Rewards validators, adds the joiners, and removes the leavers
    function advanceEpoch() public {
        require(
            block.number >= epoch.endBlock,
            "Enough blocks have not elapsed since the last epoch"
        );
        require(
            state == States.ReadyForNextEpoch,
            "Must be in ready for next epoch state"
        );
        require(
            isReadyForNextEpoch() == true,
            "Not enough validators are ready for the next epoch"
        );

        // reward the validators
        uint256 validatorLength = validatorsInCurrentEpoch.length();
        for (uint256 i = 0; i < validatorLength; i++) {
            address validatorAddress = validatorsInCurrentEpoch.at(i);
            validators[validatorAddress].reward +=
                (tokenRewardPerTokenPerEpoch *
                    validators[validatorAddress].balance) /
                10 ** stakingToken.decimals();
        }

        // set the validators to the new validator set
        // ideally we could just do this:
        // validatorsInCurrentEpoch = validatorsInNextEpoch;
        // but solidity doesn't allow that, so we have to do it manually

        // clear out validators in current epoch
        while (validatorsInCurrentEpoch.length() > 0) {
            validatorsInCurrentEpoch.remove(validatorsInCurrentEpoch.at(0));
        }

        // copy validators from next epoch to current epoch
        validatorLength = validatorsInNextEpoch.length();
        for (uint256 i = 0; i < validatorLength; i++) {
            validatorsInCurrentEpoch.add(validatorsInNextEpoch.at(i));

            // clear out readyForNextEpoch
            readyForNextEpoch[validatorsInNextEpoch.at(i)] = false;
        }

        epoch.number++;
        epoch.endBlock = block.number + epoch.epochLength; // not epoch.endBlock +

        state = States.Active;
        emit StateChanged(state);
    }

    /// Stake and request to join the validator set
    /// @param amount The amount of tokens to stake
    /// @param ip The IP address of the node
    /// @param port The port of the node
    function stakeAndJoin(
        uint256 amount,
        uint32 ip,
        uint128 ipv6,
        uint32 port,
        address nodeAddress,
        uint256 senderPubKey,
        uint256 receiverPubKey
    ) public whenNotPaused {
        stake(amount);
        requestToJoin(
            ip,
            ipv6,
            port,
            nodeAddress,
            senderPubKey,
            receiverPubKey
        );
    }

    /// Stake tokens for a validator
    function stake(uint256 amount) public nonReentrant {
        require(amount > 0, "Cannot stake 0");

        stakingToken.transferFrom(msg.sender, address(this), amount);
        validators[msg.sender].balance += amount;

        totalStaked += amount;

        emit Staked(msg.sender, amount);
    }

    function requestToJoin(
        uint32 ip,
        uint128 ipv6,
        uint32 port,
        address nodeAddress,
        uint256 senderPubKey,
        uint256 receiverPubKey
    ) public nonReentrant {
        uint256 amountStaked = validators[msg.sender].balance;
        require(
            amountStaked >= minimumStake,
            "Stake must be greater than or equal to minimumStake"
        );
        require(
            state == States.Active ||
                state == States.Unlocked ||
                state == States.Paused,
            "Must be in Active or Unlocked state to request to join"
        );

        // make sure they haven't been kicked
        require(
            validatorsKickedFromNextEpoch.contains(msg.sender) == false,
            "You cannot rejoin if you have been kicked until the next epoch"
        );

        validators[msg.sender].ip = ip;
        validators[msg.sender].ipv6 = ipv6;
        validators[msg.sender].port = port;
        validators[msg.sender].nodeAddress = nodeAddress;
        validators[msg.sender].senderPubKey = senderPubKey;
        validators[msg.sender].receiverPubKey = receiverPubKey;
        nodeAddressToStakerAddress[nodeAddress] = msg.sender;

        validatorsInNextEpoch.add(msg.sender);

        emit RequestToJoin(msg.sender);
    }

    /// Withdraw staked tokens.  This can only be done by users who are not active in the validator set.
    /// @param amount The amount of tokens to withdraw
    function withdraw(uint256 amount) public nonReentrant {
        require(amount > 0, "Cannot withdraw 0");

        require(
            validatorsInCurrentEpoch.contains(msg.sender) == false,
            "Active validators cannot leave.  Please use the leave() function and wait for the next epoch to leave"
        );

        require(
            validators[msg.sender].balance >= amount,
            "Not enough tokens to withdraw"
        );

        totalStaked = totalStaked - amount;
        validators[msg.sender].balance =
            validators[msg.sender].balance -
            amount;
        stakingToken.transfer(msg.sender, amount);
        emit Withdrawn(msg.sender, amount);
    }

    /// Request to leave in the next Epoch
    function requestToLeave() public nonReentrant {
        require(
            state == States.Active ||
                state == States.Unlocked ||
                state == States.Paused,
            "Must be in Active or Unlocked state to request to leave"
        );
        if (validatorsInNextEpoch.contains(msg.sender)) {
            // remove them
            validatorsInNextEpoch.remove(msg.sender);
        }
        emit RequestToLeave(msg.sender);
    }

    /// Transfer any outstanding reward tokens
    function getReward() public nonReentrant {
        uint256 reward = validators[msg.sender].reward;
        if (reward > 0) {
            validators[msg.sender].reward = 0;
            stakingToken.transfer(msg.sender, reward);
            emit RewardPaid(msg.sender, reward);
        }
    }

    /// Exit staking and get any outstanding rewards
    function exit() public {
        withdraw(validators[msg.sender].balance);
        getReward();
    }

    /// If more than the threshold of validators vote to kick someone, kick them.
    /// It's expected that this will be called by the node directly, so msg.sender will be the nodeAddress
    function kickValidatorInNextEpoch(
        address validatorStakerAddress,
        uint256 reason,
        bytes calldata data
    ) public nonReentrant {
        address stakerAddressOfSender = nodeAddressToStakerAddress[msg.sender];
        require(
            stakerAddressOfSender != address(0),
            "Could not map your nodeAddress to your stakerAddress"
        );
        require(
            validatorsInNextEpoch.contains(stakerAddressOfSender),
            "You must be a validator in the next epoch to kick someone from the next epoch"
        );
        require(
            votesToKickValidatorsInNextEpoch[epoch.number][
                validatorStakerAddress
            ].voted[stakerAddressOfSender] == false,
            "You can only vote to kick someone once per epoch"
        );

        // Vote to kick
        votesToKickValidatorsInNextEpoch[epoch.number][validatorStakerAddress]
            .votes++;
        votesToKickValidatorsInNextEpoch[epoch.number][validatorStakerAddress]
            .voted[stakerAddressOfSender] = true;

        if (
            validatorsInNextEpoch.contains(validatorStakerAddress) &&
            shouldKickValidator(validatorStakerAddress)
        ) {
            // remove from next validator set
            validatorsInNextEpoch.remove(validatorStakerAddress);
            // block them from rejoining the next epoch
            validatorsKickedFromNextEpoch.add(validatorStakerAddress);
            // slash the stake
            uint256 amountToBurn = (validators[validatorStakerAddress].balance *
                kickPenaltyPercent) / 100;
            validators[validatorStakerAddress].balance -= amountToBurn;
            totalStaked -= amountToBurn;
            stakingToken.burn(amountToBurn);
            // shame them with an event
            emit ValidatorKickedFromNextEpoch(
                validatorStakerAddress,
                amountToBurn
            );
        }

        emit VotedToKickValidatorInNextEpoch(
            stakerAddressOfSender,
            validatorStakerAddress,
            reason,
            data
        );
    }

    /// Set the IP and port of your node
    /// @param ip The ip address of your node
    /// @param port The port of your node
    function setIpPortNodeAddressAndCommunicationPubKeys(
        uint32 ip,
        uint128 ipv6,
        uint32 port,
        address nodeAddress,
        uint256 senderPubKey,
        uint256 receiverPubKey
    ) public {
        validators[msg.sender].ip = ip;
        validators[msg.sender].ipv6 = ipv6;
        validators[msg.sender].port = port;
        validators[msg.sender].nodeAddress = nodeAddress;
        validators[msg.sender].senderPubKey = senderPubKey;
        validators[msg.sender].receiverPubKey = receiverPubKey;
    }

    function setEpochLength(uint256 newEpochLength) public onlyOwner {
        epoch.epochLength = newEpochLength;
        emit EpochLengthSet(newEpochLength);
    }

    function setEpochTimeout(uint256 newEpochTimeout) public onlyOwner {
        epoch.timeout = newEpochTimeout;
        emit EpochTimeoutSet(newEpochTimeout);
    }

    function setStakingToken(address newStakingTokenAddress) public onlyOwner {
        stakingToken = ERC20Burnable(newStakingTokenAddress);
        emit StakingTokenSet(newStakingTokenAddress);
    }

    function setTokenRewardPerTokenPerEpoch(
        uint256 newTokenRewardPerTokenPerEpoch
    ) public onlyOwner {
        tokenRewardPerTokenPerEpoch = newTokenRewardPerTokenPerEpoch;
        emit TokenRewardPerTokenPerEpochSet(newTokenRewardPerTokenPerEpoch);
    }

    function setMinimumStake(uint256 newMinimumStake) public onlyOwner {
        minimumStake = newMinimumStake;
        emit MinimumStakeSet(newMinimumStake);
    }

    function setKickPenaltyPercent(
        uint256 newKickPenaltyPercent
    ) public onlyOwner {
        kickPenaltyPercent = newKickPenaltyPercent;
        emit KickPenaltyPercentSet(newKickPenaltyPercent);
    }

    function setResolverContractAddress(
        address newResolverContractAddress
    ) public onlyOwner {
        resolverContractAddress = newResolverContractAddress;

        emit ResolverContractAddressSet(newResolverContractAddress);
    }

    function setEpochState(States newState) public onlyOwner {
        state = newState;
        emit StateChanged(newState);
    }

    function pauseEpoch() public onlyOwner {
        state = States.Paused;
        emit StateChanged(States.Paused);
    }

    function adminKickValidatorInNextEpoch(
        address validatorStakerAddress
    ) public nonReentrant onlyOwner {
        // remove from next validator set
        validatorsInNextEpoch.remove(validatorStakerAddress);
        // block them from rejoining the next epoch
        validatorsKickedFromNextEpoch.add(validatorStakerAddress);
        emit ValidatorKickedFromNextEpoch(validatorStakerAddress, 0);
    }

    function adminSlashValidator(
        address validatorStakerAddress,
        uint256 amountToBurn
    ) public nonReentrant onlyOwner {
        validators[validatorStakerAddress].balance -= amountToBurn;
        totalStaked -= amountToBurn;
        stakingToken.burn(amountToBurn);
        emit ValidatorKickedFromNextEpoch(validatorStakerAddress, amountToBurn);
    }

    /* ========== EVENTS ========== */

    event Staked(address indexed staker, uint256 amount);
    event Withdrawn(address indexed staker, uint256 amount);
    event RewardPaid(address indexed staker, uint256 reward);
    event RewardsDurationUpdated(uint256 newDuration);
    event RequestToJoin(address indexed staker);
    event RequestToLeave(address indexed staker);
    event Recovered(address token, uint256 amount);
    event ReadyForNextEpoch(address indexed staker);
    event StateChanged(States newState);
    event VotedToKickValidatorInNextEpoch(
        address indexed reporter,
        address indexed validatorStakerAddress,
        uint256 indexed reason,
        bytes data
    );
    event ValidatorKickedFromNextEpoch(
        address indexed staker,
        uint256 amountBurned
    );

    // onlyOwner events
    event EpochLengthSet(uint256 newEpochLength);
    event EpochTimeoutSet(uint256 newEpochTimeout);
    event StakingTokenSet(address newStakingTokenAddress);
    event TokenRewardPerTokenPerEpochSet(
        uint256 newTokenRewardPerTokenPerEpoch
    );
    event MinimumStakeSet(uint256 newMinimumStake);
    event KickPenaltyPercentSet(uint256 newKickPenaltyPercent);
    event ResolverContractAddressSet(address newResolverContractAddress);
}
          

@openzeppelin/contracts/token/ERC20/ERC20.sol

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

pragma solidity ^0.8.0;

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

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

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

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

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

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

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

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

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

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

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

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

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

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

        return true;
    }

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

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

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

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

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

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

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

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

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

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

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

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

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

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

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

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

@openzeppelin/contracts/utils/structs/EnumerableSet.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)

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) {
        return _values(set._inner);
    }

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

@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol

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

pragma solidity ^0.8.0;

import "../IERC20.sol";

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

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

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

@openzeppelin/contracts/access/Ownable.sol

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

pragma solidity ^0.8.0;

import "../utils/Context.sol";

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

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

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

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

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

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

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

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

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

@openzeppelin/contracts/security/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

        _;

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

@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol

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

pragma solidity ^0.8.0;

import "../ERC721.sol";
import "../../../utils/Context.sol";

/**
 * @title ERC721 Burnable Token
 * @dev ERC721 Token that can be burned (destroyed).
 */
abstract contract ERC721Burnable is Context, ERC721 {
    /**
     * @dev Burns `tokenId`. See {ERC721-_burn}.
     *
     * Requirements:
     *
     * - The caller must own `tokenId` or be an approved operator.
     */
    function burn(uint256 tokenId) public virtual {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner nor approved");
        _burn(tokenId);
    }
}
          

@openzeppelin/contracts/utils/structs/BitMaps.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/structs/BitMaps.sol)
pragma solidity ^0.8.0;

/**
 * @dev Library for managing uint256 to bool mapping in a compact and efficient way, providing the keys are sequential.
 * Largelly inspired by Uniswap's https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol[merkle-distributor].
 */
library BitMaps {
    struct BitMap {
        mapping(uint256 => uint256) _data;
    }

    /**
     * @dev Returns whether the bit at `index` is set.
     */
    function get(BitMap storage bitmap, uint256 index) internal view returns (bool) {
        uint256 bucket = index >> 8;
        uint256 mask = 1 << (index & 0xff);
        return bitmap._data[bucket] & mask != 0;
    }

    /**
     * @dev Sets the bit at `index` to the boolean `value`.
     */
    function setTo(
        BitMap storage bitmap,
        uint256 index,
        bool value
    ) internal {
        if (value) {
            set(bitmap, index);
        } else {
            unset(bitmap, index);
        }
    }

    /**
     * @dev Sets the bit at `index`.
     */
    function set(BitMap storage bitmap, uint256 index) internal {
        uint256 bucket = index >> 8;
        uint256 mask = 1 << (index & 0xff);
        bitmap._data[bucket] |= mask;
    }

    /**
     * @dev Unsets the bit at `index`.
     */
    function unset(BitMap storage bitmap, uint256 index) internal {
        uint256 bucket = index >> 8;
        uint256 mask = 1 << (index & 0xff);
        bitmap._data[bucket] &= ~mask;
    }
}
          

@openzeppelin/contracts/token/ERC20/IERC20.sol

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

@openzeppelin/contracts/access/IAccessControl.sol

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_pkpNft","internalType":"address"}]},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"PermittedAuthMethodAdded","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":true},{"type":"uint256","name":"authMethodType","internalType":"uint256","indexed":false},{"type":"bytes","name":"id","internalType":"bytes","indexed":false},{"type":"bytes","name":"userPubkey","internalType":"bytes","indexed":false}],"anonymous":false},{"type":"event","name":"PermittedAuthMethodRemoved","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":true},{"type":"uint256","name":"authMethodType","internalType":"uint256","indexed":false},{"type":"bytes","name":"id","internalType":"bytes","indexed":false}],"anonymous":false},{"type":"event","name":"PermittedAuthMethodScopeAdded","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":true},{"type":"uint256","name":"authMethodType","internalType":"uint256","indexed":false},{"type":"bytes","name":"id","internalType":"bytes","indexed":false},{"type":"uint256","name":"scopeId","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"PermittedAuthMethodScopeRemoved","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":true},{"type":"uint256","name":"authMethodType","internalType":"uint256","indexed":false},{"type":"bytes","name":"id","internalType":"bytes","indexed":false},{"type":"uint256","name":"scopeId","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RootHashUpdated","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":true},{"type":"uint256","name":"group","internalType":"uint256","indexed":true},{"type":"bytes32","name":"root","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addPermittedAction","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"bytes","name":"ipfsCID","internalType":"bytes"},{"type":"uint256[]","name":"scopes","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addPermittedAddress","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"address","name":"user","internalType":"address"},{"type":"uint256[]","name":"scopes","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addPermittedAuthMethod","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"tuple","name":"authMethod","internalType":"struct PKPPermissions.AuthMethod","components":[{"type":"uint256","name":"authMethodType","internalType":"uint256"},{"type":"bytes","name":"id","internalType":"bytes"},{"type":"bytes","name":"userPubkey","internalType":"bytes"}]},{"type":"uint256[]","name":"scopes","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addPermittedAuthMethodScope","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"authMethodType","internalType":"uint256"},{"type":"bytes","name":"id","internalType":"bytes"},{"type":"uint256","name":"scopeId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"authMethodType","internalType":"uint256"},{"type":"bytes","name":"id","internalType":"bytes"},{"type":"bytes","name":"userPubkey","internalType":"bytes"}],"name":"authMethods","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getAuthMethodId","inputs":[{"type":"uint256","name":"authMethodType","internalType":"uint256"},{"type":"bytes","name":"id","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getEthAddress","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes[]","name":"","internalType":"bytes[]"}],"name":"getPermittedActions","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address[]","name":"","internalType":"address[]"}],"name":"getPermittedAddresses","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool[]","name":"","internalType":"bool[]"}],"name":"getPermittedAuthMethodScopes","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"authMethodType","internalType":"uint256"},{"type":"bytes","name":"id","internalType":"bytes"},{"type":"uint256","name":"maxScopeId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"","internalType":"struct PKPPermissions.AuthMethod[]","components":[{"type":"uint256","name":"authMethodType","internalType":"uint256"},{"type":"bytes","name":"id","internalType":"bytes"},{"type":"bytes","name":"userPubkey","internalType":"bytes"}]}],"name":"getPermittedAuthMethods","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes","name":"","internalType":"bytes"}],"name":"getPubkey","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256[]","name":"","internalType":"uint256[]"}],"name":"getTokenIdsForAuthMethod","inputs":[{"type":"uint256","name":"authMethodType","internalType":"uint256"},{"type":"bytes","name":"id","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes","name":"","internalType":"bytes"}],"name":"getUserPubkeyForAuthMethod","inputs":[{"type":"uint256","name":"authMethodType","internalType":"uint256"},{"type":"bytes","name":"id","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isPermittedAction","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"bytes","name":"ipfsCID","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isPermittedAddress","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"address","name":"user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isPermittedAuthMethod","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"authMethodType","internalType":"uint256"},{"type":"bytes","name":"id","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"isPermittedAuthMethodScopePresent","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"authMethodType","internalType":"uint256"},{"type":"bytes","name":"id","internalType":"bytes"},{"type":"uint256","name":"scopeId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract PKPNFT"}],"name":"pkpNFT","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removePermittedAction","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"bytes","name":"ipfsCID","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removePermittedAddress","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"address","name":"user","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removePermittedAuthMethod","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"authMethodType","internalType":"uint256"},{"type":"bytes","name":"id","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removePermittedAuthMethodScope","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"authMethodType","internalType":"uint256"},{"type":"bytes","name":"id","internalType":"bytes"},{"type":"uint256","name":"scopeId","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setPkpNftAddress","inputs":[{"type":"address","name":"newPkpNftAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setRootHash","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"group","internalType":"uint256"},{"type":"bytes32","name":"root","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"verifyState","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"group","internalType":"uint256"},{"type":"bytes32[]","name":"proof","internalType":"bytes32[]"},{"type":"bytes32","name":"leaf","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"verifyStates","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"group","internalType":"uint256"},{"type":"bytes32[]","name":"proof","internalType":"bytes32[]"},{"type":"bool[]","name":"proofFlags","internalType":"bool[]"},{"type":"bytes32[]","name":"leaves","internalType":"bytes32[]"}]}]
            

Contract Creation Code

0x60806040523480156200001157600080fd5b5060405162005087380380620050878339818101604052810190620000379190620001d5565b620000576200004b6200009f60201b60201c565b620000a760201b60201c565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505062000207565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006200019d8262000170565b9050919050565b620001af8162000190565b8114620001bb57600080fd5b50565b600081519050620001cf81620001a4565b92915050565b600060208284031215620001ee57620001ed6200016b565b5b6000620001fe84828501620001be565b91505092915050565b614e7080620002176000396000f3fe608060405234801561001057600080fd5b50600436106101d75760003560e01c80638a43157811610104578063bb7a1070116100a2578063f2fde38b11610071578063f2fde38b146105be578063f34f21ba146105da578063fceb39831461060a578063ffa2e9531461063a576101d7565b8063bb7a107014610512578063bd4986a014610542578063d41a327214610572578063ef6fd8781461058e576101d7565b8063a1afdc6f116100de578063a1afdc6f14610466578063a1c805fa14610496578063abc541ae146104c6578063b997606f146104f6576101d7565b80638a431578146104105780638da5cb5b1461042c5780639dd4349b1461044a576101d7565b80635521c4521161017c5780636821c8e21161014b5780636821c8e21461039e578063715018a6146103ba57806378c49efa146103c457806382559561146103f4576101d7565b80635521c45214610306578063557b5eba1461033657806366fc6541146103665780636705c6f214610382576101d7565b80631663c121116101b85780631663c1211461026c578063176354fd146102885780632657768b146102a457806345b72bde146102d6576101d7565b80618b4f146101dc578062221c081461020c5780630a60950d1461023c575b600080fd5b6101f660048036038101906101f19190613309565b610658565b6040516102039190613364565b60405180910390f35b610226600480360381019061022191906133e4565b610770565b604051610233919061352a565b60405180910390f35b6102566004803603810190610251919061368d565b61089f565b60405161026391906136f8565b60405180910390f35b61028660048036038101906102819190613769565b6108d5565b005b6102a2600480360381019061029d91906137dd565b610942565b005b6102be60048036038101906102b9919061380a565b61098e565b6040516102cd939291906138b6565b60405180910390f35b6102f060048036038101906102eb91906139f4565b610ac8565b6040516102fd9190613364565b60405180910390f35b610320600480360381019061031b9190613a77565b610b1d565b60405161032d9190613b95565b60405180910390f35b610350600480360381019061034b9190613bb7565b610c4d565b60405161035d9190613364565b60405180910390f35b610380600480360381019061037b9190613bb7565b610ca3565b005b61039c60048036038101906103979190613c26565b610e5a565b005b6103b860048036038101906103b391906133e4565b610fd2565b005b6103c26111b1565b005b6103de60048036038101906103d99190613d68565b6111c5565b6040516103eb9190613364565b60405180910390f35b61040e600480360381019061040991906133e4565b61121c565b005b61042a60048036038101906104259190613e37565b6113fb565b005b61043461148e565b6040516104419190613edb565b60405180910390f35b610464600480360381019061045f9190613f9c565b6114b7565b005b610480600480360381019061047b9190613a77565b61182d565b60405161048d919061402c565b60405180910390f35b6104b060048036038101906104ab91906133e4565b6119e1565b6040516104bd9190613364565b60405180910390f35b6104e060048036038101906104db919061380a565b611a7c565b6040516104ed919061410c565b60405180910390f35b610510600480360381019061050b9190613309565b6120f9565b005b61052c6004803603810190610527919061380a565b61213a565b604051610539919061423a565b60405180910390f35b61055c6004803603810190610557919061380a565b61256c565b6040516105699190613edb565b60405180910390f35b61058c60048036038101906105879190613a77565b612611565b005b6105a860048036038101906105a3919061380a565b612678565b6040516105b5919061402c565b60405180910390f35b6105d860048036038101906105d391906137dd565b612722565b005b6105f460048036038101906105ef919061380a565b6127a5565b6040516106019190614375565b60405180910390f35b610624600480360381019061061f9190613a77565b6129db565b6040516106319190613364565b60405180910390f35b610642612a48565b60405161064f91906143f6565b60405180910390f35b6000610697836001600681111561067257610671614411565b5b846040516020016106839190614488565b604051602081830303815290604052610c4d565b8061076857508173ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e856040518263ffffffff1660e01b815260040161070f91906136f8565b602060405180830381865afa15801561072c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075091906144b8565b73ffffffffffffffffffffffffffffffffffffffff16145b905092915050565b606060006107c28686868080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061089f565b90506000600360008981526020019081526020016000206000838152602001908152602001600020905060008467ffffffffffffffff81111561080857610807613562565b5b6040519080825280602002602001820160405280156108365781602001602082028036833780820191505090505b50905060005b8581101561088f576108578184612a6e90919063ffffffff16565b82828151811061086a576108696144e5565b5b602002602001019015159081151581525050808061088790614543565b91505061083c565b5080935050505095945050505050565b600082826040516020016108b492919061458b565b6040516020818303038152906040528051906020012060001c905092915050565b61093c846040518060600160405280600160068111156108f8576108f7614411565b5b81526020018660405160200161090e9190614488565b60405160208183030381529060405281526020016040518060200160405280600081525081525084846114b7565b50505050565b61094a612aaa565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60046020528060005260406000206000915090508060000154908060010180546109b7906145ea565b80601f01602080910402602001604051908101604052809291908181526020018280546109e3906145ea565b8015610a305780601f10610a0557610100808354040283529160200191610a30565b820191906000526020600020905b815481529060010190602001808311610a1357829003601f168201915b505050505090806002018054610a45906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054610a71906145ea565b8015610abe5780601f10610a9357610100808354040283529160200191610abe565b820191906000526020600020905b815481529060010190602001808311610aa157829003601f168201915b5050505050905083565b6000806006600087815260200190815260200160002060008681526020019081526020016000205490506000801b8103610b06576000915050610b15565b610b11848285612b28565b9150505b949350505050565b60606000610b6f8585858080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061089f565b90506000610b8e60056000848152602001908152602001600020612b3f565b905060008167ffffffffffffffff811115610bac57610bab613562565b5b604051908082528060200260200182016040528015610bda5781602001602082028036833780820191505090505b50905060005b82811015610c3f57610c0d8160056000878152602001908152602001600020612b5490919063ffffffff16565b828281518110610c2057610c1f6144e5565b5b6020026020010181815250508080610c3790614543565b915050610be0565b508093505050509392505050565b600080610c5a848461089f565b90506000610c838260026000898152602001908152602001600020612b6e90919063ffffffff16565b905080610c9557600092505050610c9c565b6001925050505b9392505050565b826000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b8152600401610d0191906136f8565b602060405180830381865afa158015610d1e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4291906144b8565b90508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610db2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610da990614678565b60405180910390fd5b6000610dbe858561089f565b90506000600260008881526020019081526020016000209050610dea8282612b8890919063ffffffff16565b506000600560008481526020019081526020016000209050610e158882612b8890919063ffffffff16565b50877f9830658acd6a41f1cb12b425ed83cb2b8ccbfa753337cd13be80be51fc3f33738488604051610e4892919061458b565b60405180910390a25050505050505050565b826000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b8152600401610eb891906136f8565b602060405180830381865afa158015610ed5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ef991906144b8565b90508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610f69576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f6090614678565b60405180910390fd5b826006600087815260200190815260200160002060008681526020019081526020016000208190555083857fd4beb656267200ccd79d73dbdfbad162c213e10ebad16508f22cb4df8d3259ad85604051610fc391906146a7565b60405180910390a35050505050565b846000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b815260040161103091906136f8565b602060405180830381865afa15801561104d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061107191906144b8565b90508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146110e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110d890614678565b60405180910390fd5b60006111318787878080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061089f565b905061116984600360008b81526020019081526020016000206000848152602001908152602001600020612ba290919063ffffffff16565b877f29eb060f266aff306ec81b612728a417406dd6298f8f7576a37b4e6830dcc60e8288888860405161119f94939291906146ef565b60405180910390a25050505050505050565b6111b9612aaa565b6111c36000612be0565b565b6000806006600088815260200190815260200160002060008781526020019081526020016000205490506000801b8103611203576000915050611213565b61120f85858386612ca4565b9150505b95945050505050565b846000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b815260040161127a91906136f8565b602060405180830381865afa158015611297573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112bb91906144b8565b90508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461132b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161132290614678565b60405180910390fd5b600061137b8787878080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061089f565b90506113b384600360008b81526020019081526020016000206000848152602001908152602001600020612cbd90919063ffffffff16565b877f49bb3a0761ed218e1db1e9c41096ed35188868994cc37a32e1f25855745b424e888888886040516113e994939291906146ef565b60405180910390a25050505050505050565b6114878560405180606001604052806002600681111561141e5761141d614411565b5b815260200187878080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505081526020016040518060200160405280600081525081525084846114b7565b5050505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b836000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b815260040161151591906136f8565b602060405180830381865afa158015611532573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061155691906144b8565b90508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146115c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115bd90614678565b60405180910390fd5b60006115da8660000151876020015161089f565b905060006004600083815260200190815260200160002060020180546115ff906145ea565b9050148061164157508560400151805190602001206004600083815260200190815260200160002060020160405161163791906147d2565b6040518091039020145b611680576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161167790614881565b60405180910390fd5b85600460008381526020019081526020016000206000820151816000015560208201518160010190816116b39190614a2e565b5060408201518160020190816116c99190614a2e565b5090505060006002600089815260200190815260200160002090506116f78282612cfc90919063ffffffff16565b5060006005600084815260200190815260200160002090506117228982612cfc90919063ffffffff16565b5060005b878790508110156117d9576000888883818110611746576117456144e5565b5b90506020020135905061178581600360008e81526020019081526020016000206000888152602001908152602001600020612ba290919063ffffffff16565b8a7f29eb060f266aff306ec81b612728a417406dd6298f8f7576a37b4e6830dcc60e868c60200151846040516117bd93929190614b00565b60405180910390a25080806117d190614543565b915050611726565b50887fd7db314a62650aaa1b15d4bb5c95c558a03cde3ee7f36e144b73126a3a8e839a89600001518a602001518b6040015160405161181a939291906138b6565b60405180910390a2505050505050505050565b6060600061187f8585858080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061089f565b9050600060046000838152602001908152602001600020604051806060016040529081600082015481526020016001820180546118bb906145ea565b80601f01602080910402602001604051908101604052809291908181526020018280546118e7906145ea565b80156119345780601f1061190957610100808354040283529160200191611934565b820191906000526020600020905b81548152906001019060200180831161191757829003601f168201915b5050505050815260200160028201805461194d906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054611979906145ea565b80156119c65780601f1061199b576101008083540402835291602001916119c6565b820191906000526020600020905b8154815290600101906020018083116119a957829003601f168201915b50505050508152505090508060400151925050509392505050565b600080611a328686868080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061089f565b90506000611a6c84600360008b81526020019081526020016000206000858152602001908152602001600020612a6e90919063ffffffff16565b9050809250505095945050505050565b60606000611a9b60026000858152602001908152602001600020612b3f565b90506000805b82811015611c64576000611ad08260026000898152602001908152602001600020612b5490919063ffffffff16565b905060006004600083815260200190815260200160002060405180606001604052908160008201548152602001600182018054611b0c906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054611b38906145ea565b8015611b855780601f10611b5a57610100808354040283529160200191611b85565b820191906000526020600020905b815481529060010190602001808311611b6857829003601f168201915b50505050508152602001600282018054611b9e906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054611bca906145ea565b8015611c175780601f10611bec57610100808354040283529160200191611c17565b820191906000526020600020905b815481529060010190602001808311611bfa57829003601f168201915b505050505081525050905060016006811115611c3657611c35614411565b5b816000015103611c4f578380611c4b90614543565b9450505b50508080611c5c90614543565b915050611aa1565b506000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634f558e79866040518263ffffffff1660e01b8152600401611cc291906136f8565b602060405180830381865afa158015611cdf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d039190614b53565b9050606060008215611e6957600184611d1c9190614b80565b67ffffffffffffffff811115611d3557611d34613562565b5b604051908082528060200260200182016040528015611d635781602001602082028036833780820191505090505b5091506000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e896040518263ffffffff1660e01b8152600401611dc391906136f8565b602060405180830381865afa158015611de0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0491906144b8565b90508083600081518110611e1b57611e1a6144e5565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508180611e6090614543565b92505050611eb5565b8367ffffffffffffffff811115611e8357611e82613562565b5b604051908082528060200260200182016040528015611eb15781602001602082028036833780820191505090505b5091505b60005b858110156120eb576000611ee782600260008c8152602001908152602001600020612b5490919063ffffffff16565b905060006004600083815260200190815260200160002060405180606001604052908160008201548152602001600182018054611f23906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054611f4f906145ea565b8015611f9c5780601f10611f7157610100808354040283529160200191611f9c565b820191906000526020600020905b815481529060010190602001808311611f7f57829003601f168201915b50505050508152602001600282018054611fb5906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054611fe1906145ea565b801561202e5780601f106120035761010080835404028352916020019161202e565b820191906000526020600020905b81548152906001019060200180831161201157829003601f168201915b50505050508152505090506001600681111561204d5761204c614411565b5b8160000151036120d657600080826020015190506c0100000000000000000000000060208201510491508187878151811061208b5761208a6144e5565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505085806120d090614543565b96505050505b505080806120e390614543565b915050611eb8565b508195505050505050919050565b612136826001600681111561211157612110614411565b5b836040516020016121229190614488565b604051602081830303815290604052610ca3565b5050565b6060600061215960026000858152602001908152602001600020612b3f565b90506000805b8281101561232257600061218e8260026000898152602001908152602001600020612b5490919063ffffffff16565b9050600060046000838152602001908152602001600020604051806060016040529081600082015481526020016001820180546121ca906145ea565b80601f01602080910402602001604051908101604052809291908181526020018280546121f6906145ea565b80156122435780601f1061221857610100808354040283529160200191612243565b820191906000526020600020905b81548152906001019060200180831161222657829003601f168201915b5050505050815260200160028201805461225c906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054612288906145ea565b80156122d55780601f106122aa576101008083540402835291602001916122d5565b820191906000526020600020905b8154815290600101906020018083116122b857829003601f168201915b5050505050815250509050600260068111156122f4576122f3614411565b5b81600001510361230d57838061230990614543565b9450505b5050808061231a90614543565b91505061215f565b5060008167ffffffffffffffff81111561233f5761233e613562565b5b60405190808252806020026020018201604052801561237257816020015b606081526020019060019003908161235d5790505b5090506000805b8481101561255f5760006123a882600260008b8152602001908152602001600020612b5490919063ffffffff16565b9050600060046000838152602001908152602001600020604051806060016040529081600082015481526020016001820180546123e4906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054612410906145ea565b801561245d5780601f106124325761010080835404028352916020019161245d565b820191906000526020600020905b81548152906001019060200180831161244057829003601f168201915b50505050508152602001600282018054612476906145ea565b80601f01602080910402602001604051908101604052809291908181526020018280546124a2906145ea565b80156124ef5780601f106124c4576101008083540402835291602001916124ef565b820191906000526020600020905b8154815290600101906020018083116124d257829003601f168201915b50505050508152505090506002600681111561250e5761250d614411565b5b81600001510361254a5780602001518585815181106125305761252f6144e5565b5b6020026020010181905250838061254690614543565b9450505b5050808061255790614543565b915050612379565b5081945050505050919050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663bd4986a0836040518263ffffffff1660e01b81526004016125c991906136f8565b602060405180830381865afa1580156125e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061260a91906144b8565b9050919050565b612673836002600681111561262957612628614411565b5b84848080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050610ca3565b505050565b6060600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ef6fd878836040518263ffffffff1660e01b81526004016126d591906136f8565b600060405180830381865afa1580156126f2573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f8201168201806040525081019061271b9190614c24565b9050919050565b61272a612aaa565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603612799576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161279090614cdf565b60405180910390fd5b6127a281612be0565b50565b606060006127c460026000858152602001908152602001600020612b3f565b905060008167ffffffffffffffff8111156127e2576127e1613562565b5b60405190808252806020026020018201604052801561281b57816020015b612808613240565b8152602001906001900390816128005790505b50905060005b828110156129d05760006128508260026000898152602001908152602001600020612b5490919063ffffffff16565b9050600460008281526020019081526020016000206040518060600160405290816000820154815260200160018201805461288a906145ea565b80601f01602080910402602001604051908101604052809291908181526020018280546128b6906145ea565b80156129035780601f106128d857610100808354040283529160200191612903565b820191906000526020600020905b8154815290600101906020018083116128e657829003601f168201915b5050505050815260200160028201805461291c906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054612948906145ea565b80156129955780601f1061296a57610100808354040283529160200191612995565b820191906000526020600020905b81548152906001019060200180831161297857829003601f168201915b5050505050815250508383815181106129b1576129b06144e5565b5b60200260200101819052505080806129c890614543565b915050612821565b508092505050919050565b6000612a3f84600260068111156129f5576129f4614411565b5b85858080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050610c4d565b90509392505050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080600883901c9050600060ff84166001901b9050600081866000016000858152602001908152602001600020541614159250505092915050565b612ab2612d16565b73ffffffffffffffffffffffffffffffffffffffff16612ad061148e565b73ffffffffffffffffffffffffffffffffffffffff1614612b26576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612b1d90614d4b565b60405180910390fd5b565b600082612b358584612d1e565b1490509392505050565b6000612b4d82600001612d74565b9050919050565b6000612b638360000183612d85565b60001c905092915050565b6000612b80836000018360001b612db0565b905092915050565b6000612b9a836000018360001b612dd3565b905092915050565b6000600882901c9050600060ff83166001901b9050808460000160008481526020019081526020016000206000828254179250508190555050505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600082612cb2868685612ee7565b149050949350505050565b6000600882901c9050600060ff83166001901b905080198460000160008481526020019081526020016000206000828254169250508190555050505050565b6000612d0e836000018360001b61318e565b905092915050565b600033905090565b60008082905060005b8451811015612d6957612d5482868381518110612d4757612d466144e5565b5b60200260200101516131fe565b91508080612d6190614543565b915050612d27565b508091505092915050565b600081600001805490509050919050565b6000826000018281548110612d9d57612d9c6144e5565b5b9060005260206000200154905092915050565b600080836001016000848152602001908152602001600020541415905092915050565b60008083600101600084815260200190815260200160002054905060008114612edb576000600182612e059190614d6b565b9050600060018660000180549050612e1d9190614d6b565b9050818114612e8c576000866000018281548110612e3e57612e3d6144e5565b5b9060005260206000200154905080876000018481548110612e6257612e616144e5565b5b90600052602060002001819055508387600101600083815260200190815260200160002081905550505b85600001805480612ea057612e9f614d9f565b5b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050612ee1565b60009150505b92915050565b60008082519050600084519050806001875184612f049190614b80565b612f0e9190614d6b565b14612f4e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612f4590614e1a565b60405180910390fd5b60008167ffffffffffffffff811115612f6a57612f69613562565b5b604051908082528060200260200182016040528015612f985781602001602082028036833780820191505090505b5090506000806000805b858110156130f2576000878510612fdf57858480612fbf90614543565b955081518110612fd257612fd16144e5565b5b6020026020010151613007565b898580612feb90614543565b965081518110612ffe57612ffd6144e5565b5b60200260200101515b905060008b838151811061301e5761301d6144e5565b5b6020026020010151613056578c848061303690614543565b955081518110613049576130486144e5565b5b60200260200101516130b2565b8886106130895786858061306990614543565b96508151811061307c5761307b6144e5565b5b60200260200101516130b1565b8a868061309590614543565b9750815181106130a8576130a76144e5565b5b60200260200101515b5b90506130be82826131fe565b8784815181106130d1576130d06144e5565b5b602002602001018181525050505080806130ea90614543565b915050612fa2565b506000851115613130578360018661310a9190614d6b565b8151811061311b5761311a6144e5565b5b60200260200101519650505050505050613187565b6000861115613162578760008151811061314d5761314c6144e5565b5b60200260200101519650505050505050613187565b89600081518110613176576131756144e5565b5b602002602001015196505050505050505b9392505050565b600061319a8383612db0565b6131f35782600001829080600181540180825580915050600190039060005260206000200160009091909190915055826000018054905083600101600084815260200190815260200160002081905550600190506131f8565b600090505b92915050565b6000818310613216576132118284613229565b613221565b6132208383613229565b5b905092915050565b600082600052816020526040600020905092915050565b60405180606001604052806000815260200160608152602001606081525090565b6000604051905090565b600080fd5b600080fd5b6000819050919050565b61328881613275565b811461329357600080fd5b50565b6000813590506132a58161327f565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006132d6826132ab565b9050919050565b6132e6816132cb565b81146132f157600080fd5b50565b600081359050613303816132dd565b92915050565b600080604083850312156133205761331f61326b565b5b600061332e85828601613296565b925050602061333f858286016132f4565b9150509250929050565b60008115159050919050565b61335e81613349565b82525050565b60006020820190506133796000830184613355565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f8401126133a4576133a361337f565b5b8235905067ffffffffffffffff8111156133c1576133c0613384565b5b6020830191508360018202830111156133dd576133dc613389565b5b9250929050565b600080600080600060808688031215613400576133ff61326b565b5b600061340e88828901613296565b955050602061341f88828901613296565b945050604086013567ffffffffffffffff8111156134405761343f613270565b5b61344c8882890161338e565b9350935050606061345f88828901613296565b9150509295509295909350565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6134a181613349565b82525050565b60006134b38383613498565b60208301905092915050565b6000602082019050919050565b60006134d78261346c565b6134e18185613477565b93506134ec83613488565b8060005b8381101561351d57815161350488826134a7565b975061350f836134bf565b9250506001810190506134f0565b5085935050505092915050565b6000602082019050818103600083015261354481846134cc565b905092915050565b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61359a82613551565b810181811067ffffffffffffffff821117156135b9576135b8613562565b5b80604052505050565b60006135cc613261565b90506135d88282613591565b919050565b600067ffffffffffffffff8211156135f8576135f7613562565b5b61360182613551565b9050602081019050919050565b82818337600083830152505050565b600061363061362b846135dd565b6135c2565b90508281526020810184848401111561364c5761364b61354c565b5b61365784828561360e565b509392505050565b600082601f8301126136745761367361337f565b5b813561368484826020860161361d565b91505092915050565b600080604083850312156136a4576136a361326b565b5b60006136b285828601613296565b925050602083013567ffffffffffffffff8111156136d3576136d2613270565b5b6136df8582860161365f565b9150509250929050565b6136f281613275565b82525050565b600060208201905061370d60008301846136e9565b92915050565b60008083601f8401126137295761372861337f565b5b8235905067ffffffffffffffff81111561374657613745613384565b5b60208301915083602082028301111561376257613761613389565b5b9250929050565b600080600080606085870312156137835761378261326b565b5b600061379187828801613296565b94505060206137a2878288016132f4565b935050604085013567ffffffffffffffff8111156137c3576137c2613270565b5b6137cf87828801613713565b925092505092959194509250565b6000602082840312156137f3576137f261326b565b5b6000613801848285016132f4565b91505092915050565b6000602082840312156138205761381f61326b565b5b600061382e84828501613296565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015613871578082015181840152602081019050613856565b60008484015250505050565b600061388882613837565b6138928185613842565b93506138a2818560208601613853565b6138ab81613551565b840191505092915050565b60006060820190506138cb60008301866136e9565b81810360208301526138dd818561387d565b905081810360408301526138f1818461387d565b9050949350505050565b600067ffffffffffffffff82111561391657613915613562565b5b602082029050602081019050919050565b6000819050919050565b61393a81613927565b811461394557600080fd5b50565b60008135905061395781613931565b92915050565b600061397061396b846138fb565b6135c2565b9050808382526020820190506020840283018581111561399357613992613389565b5b835b818110156139bc57806139a88882613948565b845260208401935050602081019050613995565b5050509392505050565b600082601f8301126139db576139da61337f565b5b81356139eb84826020860161395d565b91505092915050565b60008060008060808587031215613a0e57613a0d61326b565b5b6000613a1c87828801613296565b9450506020613a2d87828801613296565b935050604085013567ffffffffffffffff811115613a4e57613a4d613270565b5b613a5a878288016139c6565b9250506060613a6b87828801613948565b91505092959194509250565b600080600060408486031215613a9057613a8f61326b565b5b6000613a9e86828701613296565b935050602084013567ffffffffffffffff811115613abf57613abe613270565b5b613acb8682870161338e565b92509250509250925092565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b613b0c81613275565b82525050565b6000613b1e8383613b03565b60208301905092915050565b6000602082019050919050565b6000613b4282613ad7565b613b4c8185613ae2565b9350613b5783613af3565b8060005b83811015613b88578151613b6f8882613b12565b9750613b7a83613b2a565b925050600181019050613b5b565b5085935050505092915050565b60006020820190508181036000830152613baf8184613b37565b905092915050565b600080600060608486031215613bd057613bcf61326b565b5b6000613bde86828701613296565b9350506020613bef86828701613296565b925050604084013567ffffffffffffffff811115613c1057613c0f613270565b5b613c1c8682870161365f565b9150509250925092565b600080600060608486031215613c3f57613c3e61326b565b5b6000613c4d86828701613296565b9350506020613c5e86828701613296565b9250506040613c6f86828701613948565b9150509250925092565b600067ffffffffffffffff821115613c9457613c93613562565b5b602082029050602081019050919050565b613cae81613349565b8114613cb957600080fd5b50565b600081359050613ccb81613ca5565b92915050565b6000613ce4613cdf84613c79565b6135c2565b90508083825260208201905060208402830185811115613d0757613d06613389565b5b835b81811015613d305780613d1c8882613cbc565b845260208401935050602081019050613d09565b5050509392505050565b600082601f830112613d4f57613d4e61337f565b5b8135613d5f848260208601613cd1565b91505092915050565b600080600080600060a08688031215613d8457613d8361326b565b5b6000613d9288828901613296565b9550506020613da388828901613296565b945050604086013567ffffffffffffffff811115613dc457613dc3613270565b5b613dd0888289016139c6565b935050606086013567ffffffffffffffff811115613df157613df0613270565b5b613dfd88828901613d3a565b925050608086013567ffffffffffffffff811115613e1e57613e1d613270565b5b613e2a888289016139c6565b9150509295509295909350565b600080600080600060608688031215613e5357613e5261326b565b5b6000613e6188828901613296565b955050602086013567ffffffffffffffff811115613e8257613e81613270565b5b613e8e8882890161338e565b9450945050604086013567ffffffffffffffff811115613eb157613eb0613270565b5b613ebd88828901613713565b92509250509295509295909350565b613ed5816132cb565b82525050565b6000602082019050613ef06000830184613ecc565b92915050565b600080fd5b600080fd5b600060608284031215613f1657613f15613ef6565b5b613f2060606135c2565b90506000613f3084828501613296565b600083015250602082013567ffffffffffffffff811115613f5457613f53613efb565b5b613f608482850161365f565b602083015250604082013567ffffffffffffffff811115613f8457613f83613efb565b5b613f908482850161365f565b60408301525092915050565b60008060008060608587031215613fb657613fb561326b565b5b6000613fc487828801613296565b945050602085013567ffffffffffffffff811115613fe557613fe4613270565b5b613ff187828801613f00565b935050604085013567ffffffffffffffff81111561401257614011613270565b5b61401e87828801613713565b925092505092959194509250565b60006020820190508181036000830152614046818461387d565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b614083816132cb565b82525050565b6000614095838361407a565b60208301905092915050565b6000602082019050919050565b60006140b98261404e565b6140c38185614059565b93506140ce8361406a565b8060005b838110156140ff5781516140e68882614089565b97506140f1836140a1565b9250506001810190506140d2565b5085935050505092915050565b6000602082019050818103600083015261412681846140ae565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600082825260208201905092915050565b600061417682613837565b614180818561415a565b9350614190818560208601613853565b61419981613551565b840191505092915050565b60006141b0838361416b565b905092915050565b6000602082019050919050565b60006141d08261412e565b6141da8185614139565b9350836020820285016141ec8561414a565b8060005b85811015614228578484038952815161420985826141a4565b9450614214836141b8565b925060208a019950506001810190506141f0565b50829750879550505050505092915050565b6000602082019050818103600083015261425481846141c5565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b60006060830160008301516142a06000860182613b03565b50602083015184820360208601526142b8828261416b565b915050604083015184820360408601526142d2828261416b565b9150508091505092915050565b60006142eb8383614288565b905092915050565b6000602082019050919050565b600061430b8261425c565b6143158185614267565b93508360208202850161432785614278565b8060005b85811015614363578484038952815161434485826142df565b945061434f836142f3565b925060208a0199505060018101905061432b565b50829750879550505050505092915050565b6000602082019050818103600083015261438f8184614300565b905092915050565b6000819050919050565b60006143bc6143b76143b2846132ab565b614397565b6132ab565b9050919050565b60006143ce826143a1565b9050919050565b60006143e0826143c3565b9050919050565b6143f0816143d5565b82525050565b600060208201905061440b60008301846143e7565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60008160601b9050919050565b600061445882614440565b9050919050565b600061446a8261444d565b9050919050565b61448261447d826132cb565b61445f565b82525050565b60006144948284614471565b60148201915081905092915050565b6000815190506144b2816132dd565b92915050565b6000602082840312156144ce576144cd61326b565b5b60006144dc848285016144a3565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061454e82613275565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036145805761457f614514565b5b600182019050919050565b60006040820190506145a060008301856136e9565b81810360208301526145b2818461387d565b90509392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061460257607f821691505b602082108103614615576146146145bb565b5b50919050565b600082825260208201905092915050565b7f4e6f7420504b50204e4654206f776e6572000000000000000000000000000000600082015250565b600061466260118361461b565b915061466d8261462c565b602082019050919050565b6000602082019050818103600083015261469181614655565b9050919050565b6146a181613927565b82525050565b60006020820190506146bc6000830184614698565b92915050565b60006146ce8385613842565b93506146db83858461360e565b6146e483613551565b840190509392505050565b600060608201905061470460008301876136e9565b81810360208301526147178185876146c2565b905061472660408301846136e9565b95945050505050565b600081905092915050565b60008190508160005260206000209050919050565b6000815461475c816145ea565b614766818661472f565b945060018216600081146147815760018114614796576147c9565b60ff19831686528115158202860193506147c9565b61479f8561473a565b60005b838110156147c1578154818901526001820191506020810190506147a2565b838801955050505b50505092915050565b60006147de828461474f565b915081905092915050565b7f43616e6e6f7420616464206120646966666572656e74207075626b657920666f60008201527f72207468652073616d652061757468206d6574686f64207479706520616e642060208201527f6964000000000000000000000000000000000000000000000000000000000000604082015250565b600061486b60428361461b565b9150614876826147e9565b606082019050919050565b6000602082019050818103600083015261489a8161485e565b9050919050565b60006020601f8301049050919050565b600082821b905092915050565b6000600883026148ee7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826148b1565b6148f886836148b1565b95508019841693508086168417925050509392505050565b600061492b61492661492184613275565b614397565b613275565b9050919050565b6000819050919050565b61494583614910565b61495961495182614932565b8484546148be565b825550505050565b600090565b61496e614961565b61497981848461493c565b505050565b5b8181101561499d57614992600082614966565b60018101905061497f565b5050565b601f8211156149e2576149b38161473a565b6149bc846148a1565b810160208510156149cb578190505b6149df6149d7856148a1565b83018261497e565b50505b505050565b600082821c905092915050565b6000614a05600019846008026149e7565b1980831691505092915050565b6000614a1e83836149f4565b9150826002028217905092915050565b614a3782613837565b67ffffffffffffffff811115614a5057614a4f613562565b5b614a5a82546145ea565b614a658282856149a1565b600060209050601f831160018114614a985760008415614a86578287015190505b614a908582614a12565b865550614af8565b601f198416614aa68661473a565b60005b82811015614ace57848901518255600182019150602085019450602081019050614aa9565b86831015614aeb5784890151614ae7601f8916826149f4565b8355505b6001600288020188555050505b505050505050565b6000606082019050614b1560008301866136e9565b8181036020830152614b27818561387d565b9050614b3660408301846136e9565b949350505050565b600081519050614b4d81613ca5565b92915050565b600060208284031215614b6957614b6861326b565b5b6000614b7784828501614b3e565b91505092915050565b6000614b8b82613275565b9150614b9683613275565b9250828201905080821115614bae57614bad614514565b5b92915050565b6000614bc7614bc2846135dd565b6135c2565b905082815260208101848484011115614be357614be261354c565b5b614bee848285613853565b509392505050565b600082601f830112614c0b57614c0a61337f565b5b8151614c1b848260208601614bb4565b91505092915050565b600060208284031215614c3a57614c3961326b565b5b600082015167ffffffffffffffff811115614c5857614c57613270565b5b614c6484828501614bf6565b91505092915050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b6000614cc960268361461b565b9150614cd482614c6d565b604082019050919050565b60006020820190508181036000830152614cf881614cbc565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b6000614d3560208361461b565b9150614d4082614cff565b602082019050919050565b60006020820190508181036000830152614d6481614d28565b9050919050565b6000614d7682613275565b9150614d8183613275565b9250828203905081811115614d9957614d98614514565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b7f4d65726b6c6550726f6f663a20696e76616c6964206d756c746970726f6f6600600082015250565b6000614e04601f8361461b565b9150614e0f82614dce565b602082019050919050565b60006020820190508181036000830152614e3381614df7565b905091905056fea26469706673582212205c71f66a1aff859461f0950df2f0741ae79cf6881cc93a5a0e9a4f24ad393f8e64736f6c634300081100330000000000000000000000008f75a53f65e31dd0d2e40d0827becaae2299d111

Deployed ByteCode

0x608060405234801561001057600080fd5b50600436106101d75760003560e01c80638a43157811610104578063bb7a1070116100a2578063f2fde38b11610071578063f2fde38b146105be578063f34f21ba146105da578063fceb39831461060a578063ffa2e9531461063a576101d7565b8063bb7a107014610512578063bd4986a014610542578063d41a327214610572578063ef6fd8781461058e576101d7565b8063a1afdc6f116100de578063a1afdc6f14610466578063a1c805fa14610496578063abc541ae146104c6578063b997606f146104f6576101d7565b80638a431578146104105780638da5cb5b1461042c5780639dd4349b1461044a576101d7565b80635521c4521161017c5780636821c8e21161014b5780636821c8e21461039e578063715018a6146103ba57806378c49efa146103c457806382559561146103f4576101d7565b80635521c45214610306578063557b5eba1461033657806366fc6541146103665780636705c6f214610382576101d7565b80631663c121116101b85780631663c1211461026c578063176354fd146102885780632657768b146102a457806345b72bde146102d6576101d7565b80618b4f146101dc578062221c081461020c5780630a60950d1461023c575b600080fd5b6101f660048036038101906101f19190613309565b610658565b6040516102039190613364565b60405180910390f35b610226600480360381019061022191906133e4565b610770565b604051610233919061352a565b60405180910390f35b6102566004803603810190610251919061368d565b61089f565b60405161026391906136f8565b60405180910390f35b61028660048036038101906102819190613769565b6108d5565b005b6102a2600480360381019061029d91906137dd565b610942565b005b6102be60048036038101906102b9919061380a565b61098e565b6040516102cd939291906138b6565b60405180910390f35b6102f060048036038101906102eb91906139f4565b610ac8565b6040516102fd9190613364565b60405180910390f35b610320600480360381019061031b9190613a77565b610b1d565b60405161032d9190613b95565b60405180910390f35b610350600480360381019061034b9190613bb7565b610c4d565b60405161035d9190613364565b60405180910390f35b610380600480360381019061037b9190613bb7565b610ca3565b005b61039c60048036038101906103979190613c26565b610e5a565b005b6103b860048036038101906103b391906133e4565b610fd2565b005b6103c26111b1565b005b6103de60048036038101906103d99190613d68565b6111c5565b6040516103eb9190613364565b60405180910390f35b61040e600480360381019061040991906133e4565b61121c565b005b61042a60048036038101906104259190613e37565b6113fb565b005b61043461148e565b6040516104419190613edb565b60405180910390f35b610464600480360381019061045f9190613f9c565b6114b7565b005b610480600480360381019061047b9190613a77565b61182d565b60405161048d919061402c565b60405180910390f35b6104b060048036038101906104ab91906133e4565b6119e1565b6040516104bd9190613364565b60405180910390f35b6104e060048036038101906104db919061380a565b611a7c565b6040516104ed919061410c565b60405180910390f35b610510600480360381019061050b9190613309565b6120f9565b005b61052c6004803603810190610527919061380a565b61213a565b604051610539919061423a565b60405180910390f35b61055c6004803603810190610557919061380a565b61256c565b6040516105699190613edb565b60405180910390f35b61058c60048036038101906105879190613a77565b612611565b005b6105a860048036038101906105a3919061380a565b612678565b6040516105b5919061402c565b60405180910390f35b6105d860048036038101906105d391906137dd565b612722565b005b6105f460048036038101906105ef919061380a565b6127a5565b6040516106019190614375565b60405180910390f35b610624600480360381019061061f9190613a77565b6129db565b6040516106319190613364565b60405180910390f35b610642612a48565b60405161064f91906143f6565b60405180910390f35b6000610697836001600681111561067257610671614411565b5b846040516020016106839190614488565b604051602081830303815290604052610c4d565b8061076857508173ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e856040518263ffffffff1660e01b815260040161070f91906136f8565b602060405180830381865afa15801561072c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075091906144b8565b73ffffffffffffffffffffffffffffffffffffffff16145b905092915050565b606060006107c28686868080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061089f565b90506000600360008981526020019081526020016000206000838152602001908152602001600020905060008467ffffffffffffffff81111561080857610807613562565b5b6040519080825280602002602001820160405280156108365781602001602082028036833780820191505090505b50905060005b8581101561088f576108578184612a6e90919063ffffffff16565b82828151811061086a576108696144e5565b5b602002602001019015159081151581525050808061088790614543565b91505061083c565b5080935050505095945050505050565b600082826040516020016108b492919061458b565b6040516020818303038152906040528051906020012060001c905092915050565b61093c846040518060600160405280600160068111156108f8576108f7614411565b5b81526020018660405160200161090e9190614488565b60405160208183030381529060405281526020016040518060200160405280600081525081525084846114b7565b50505050565b61094a612aaa565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60046020528060005260406000206000915090508060000154908060010180546109b7906145ea565b80601f01602080910402602001604051908101604052809291908181526020018280546109e3906145ea565b8015610a305780601f10610a0557610100808354040283529160200191610a30565b820191906000526020600020905b815481529060010190602001808311610a1357829003601f168201915b505050505090806002018054610a45906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054610a71906145ea565b8015610abe5780601f10610a9357610100808354040283529160200191610abe565b820191906000526020600020905b815481529060010190602001808311610aa157829003601f168201915b5050505050905083565b6000806006600087815260200190815260200160002060008681526020019081526020016000205490506000801b8103610b06576000915050610b15565b610b11848285612b28565b9150505b949350505050565b60606000610b6f8585858080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061089f565b90506000610b8e60056000848152602001908152602001600020612b3f565b905060008167ffffffffffffffff811115610bac57610bab613562565b5b604051908082528060200260200182016040528015610bda5781602001602082028036833780820191505090505b50905060005b82811015610c3f57610c0d8160056000878152602001908152602001600020612b5490919063ffffffff16565b828281518110610c2057610c1f6144e5565b5b6020026020010181815250508080610c3790614543565b915050610be0565b508093505050509392505050565b600080610c5a848461089f565b90506000610c838260026000898152602001908152602001600020612b6e90919063ffffffff16565b905080610c9557600092505050610c9c565b6001925050505b9392505050565b826000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b8152600401610d0191906136f8565b602060405180830381865afa158015610d1e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4291906144b8565b90508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610db2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610da990614678565b60405180910390fd5b6000610dbe858561089f565b90506000600260008881526020019081526020016000209050610dea8282612b8890919063ffffffff16565b506000600560008481526020019081526020016000209050610e158882612b8890919063ffffffff16565b50877f9830658acd6a41f1cb12b425ed83cb2b8ccbfa753337cd13be80be51fc3f33738488604051610e4892919061458b565b60405180910390a25050505050505050565b826000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b8152600401610eb891906136f8565b602060405180830381865afa158015610ed5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ef991906144b8565b90508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610f69576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f6090614678565b60405180910390fd5b826006600087815260200190815260200160002060008681526020019081526020016000208190555083857fd4beb656267200ccd79d73dbdfbad162c213e10ebad16508f22cb4df8d3259ad85604051610fc391906146a7565b60405180910390a35050505050565b846000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b815260040161103091906136f8565b602060405180830381865afa15801561104d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061107191906144b8565b90508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146110e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016110d890614678565b60405180910390fd5b60006111318787878080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061089f565b905061116984600360008b81526020019081526020016000206000848152602001908152602001600020612ba290919063ffffffff16565b877f29eb060f266aff306ec81b612728a417406dd6298f8f7576a37b4e6830dcc60e8288888860405161119f94939291906146ef565b60405180910390a25050505050505050565b6111b9612aaa565b6111c36000612be0565b565b6000806006600088815260200190815260200160002060008781526020019081526020016000205490506000801b8103611203576000915050611213565b61120f85858386612ca4565b9150505b95945050505050565b846000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b815260040161127a91906136f8565b602060405180830381865afa158015611297573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112bb91906144b8565b90508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461132b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161132290614678565b60405180910390fd5b600061137b8787878080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061089f565b90506113b384600360008b81526020019081526020016000206000848152602001908152602001600020612cbd90919063ffffffff16565b877f49bb3a0761ed218e1db1e9c41096ed35188868994cc37a32e1f25855745b424e888888886040516113e994939291906146ef565b60405180910390a25050505050505050565b6114878560405180606001604052806002600681111561141e5761141d614411565b5b815260200187878080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505081526020016040518060200160405280600081525081525084846114b7565b5050505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b836000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b815260040161151591906136f8565b602060405180830381865afa158015611532573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061155691906144b8565b90508073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146115c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016115bd90614678565b60405180910390fd5b60006115da8660000151876020015161089f565b905060006004600083815260200190815260200160002060020180546115ff906145ea565b9050148061164157508560400151805190602001206004600083815260200190815260200160002060020160405161163791906147d2565b6040518091039020145b611680576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161167790614881565b60405180910390fd5b85600460008381526020019081526020016000206000820151816000015560208201518160010190816116b39190614a2e565b5060408201518160020190816116c99190614a2e565b5090505060006002600089815260200190815260200160002090506116f78282612cfc90919063ffffffff16565b5060006005600084815260200190815260200160002090506117228982612cfc90919063ffffffff16565b5060005b878790508110156117d9576000888883818110611746576117456144e5565b5b90506020020135905061178581600360008e81526020019081526020016000206000888152602001908152602001600020612ba290919063ffffffff16565b8a7f29eb060f266aff306ec81b612728a417406dd6298f8f7576a37b4e6830dcc60e868c60200151846040516117bd93929190614b00565b60405180910390a25080806117d190614543565b915050611726565b50887fd7db314a62650aaa1b15d4bb5c95c558a03cde3ee7f36e144b73126a3a8e839a89600001518a602001518b6040015160405161181a939291906138b6565b60405180910390a2505050505050505050565b6060600061187f8585858080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061089f565b9050600060046000838152602001908152602001600020604051806060016040529081600082015481526020016001820180546118bb906145ea565b80601f01602080910402602001604051908101604052809291908181526020018280546118e7906145ea565b80156119345780601f1061190957610100808354040283529160200191611934565b820191906000526020600020905b81548152906001019060200180831161191757829003601f168201915b5050505050815260200160028201805461194d906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054611979906145ea565b80156119c65780601f1061199b576101008083540402835291602001916119c6565b820191906000526020600020905b8154815290600101906020018083116119a957829003601f168201915b50505050508152505090508060400151925050509392505050565b600080611a328686868080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505061089f565b90506000611a6c84600360008b81526020019081526020016000206000858152602001908152602001600020612a6e90919063ffffffff16565b9050809250505095945050505050565b60606000611a9b60026000858152602001908152602001600020612b3f565b90506000805b82811015611c64576000611ad08260026000898152602001908152602001600020612b5490919063ffffffff16565b905060006004600083815260200190815260200160002060405180606001604052908160008201548152602001600182018054611b0c906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054611b38906145ea565b8015611b855780601f10611b5a57610100808354040283529160200191611b85565b820191906000526020600020905b815481529060010190602001808311611b6857829003601f168201915b50505050508152602001600282018054611b9e906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054611bca906145ea565b8015611c175780601f10611bec57610100808354040283529160200191611c17565b820191906000526020600020905b815481529060010190602001808311611bfa57829003601f168201915b505050505081525050905060016006811115611c3657611c35614411565b5b816000015103611c4f578380611c4b90614543565b9450505b50508080611c5c90614543565b915050611aa1565b506000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16634f558e79866040518263ffffffff1660e01b8152600401611cc291906136f8565b602060405180830381865afa158015611cdf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d039190614b53565b9050606060008215611e6957600184611d1c9190614b80565b67ffffffffffffffff811115611d3557611d34613562565b5b604051908082528060200260200182016040528015611d635781602001602082028036833780820191505090505b5091506000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e896040518263ffffffff1660e01b8152600401611dc391906136f8565b602060405180830381865afa158015611de0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0491906144b8565b90508083600081518110611e1b57611e1a6144e5565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508180611e6090614543565b92505050611eb5565b8367ffffffffffffffff811115611e8357611e82613562565b5b604051908082528060200260200182016040528015611eb15781602001602082028036833780820191505090505b5091505b60005b858110156120eb576000611ee782600260008c8152602001908152602001600020612b5490919063ffffffff16565b905060006004600083815260200190815260200160002060405180606001604052908160008201548152602001600182018054611f23906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054611f4f906145ea565b8015611f9c5780601f10611f7157610100808354040283529160200191611f9c565b820191906000526020600020905b815481529060010190602001808311611f7f57829003601f168201915b50505050508152602001600282018054611fb5906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054611fe1906145ea565b801561202e5780601f106120035761010080835404028352916020019161202e565b820191906000526020600020905b81548152906001019060200180831161201157829003601f168201915b50505050508152505090506001600681111561204d5761204c614411565b5b8160000151036120d657600080826020015190506c0100000000000000000000000060208201510491508187878151811061208b5761208a6144e5565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505085806120d090614543565b96505050505b505080806120e390614543565b915050611eb8565b508195505050505050919050565b612136826001600681111561211157612110614411565b5b836040516020016121229190614488565b604051602081830303815290604052610ca3565b5050565b6060600061215960026000858152602001908152602001600020612b3f565b90506000805b8281101561232257600061218e8260026000898152602001908152602001600020612b5490919063ffffffff16565b9050600060046000838152602001908152602001600020604051806060016040529081600082015481526020016001820180546121ca906145ea565b80601f01602080910402602001604051908101604052809291908181526020018280546121f6906145ea565b80156122435780601f1061221857610100808354040283529160200191612243565b820191906000526020600020905b81548152906001019060200180831161222657829003601f168201915b5050505050815260200160028201805461225c906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054612288906145ea565b80156122d55780601f106122aa576101008083540402835291602001916122d5565b820191906000526020600020905b8154815290600101906020018083116122b857829003601f168201915b5050505050815250509050600260068111156122f4576122f3614411565b5b81600001510361230d57838061230990614543565b9450505b5050808061231a90614543565b91505061215f565b5060008167ffffffffffffffff81111561233f5761233e613562565b5b60405190808252806020026020018201604052801561237257816020015b606081526020019060019003908161235d5790505b5090506000805b8481101561255f5760006123a882600260008b8152602001908152602001600020612b5490919063ffffffff16565b9050600060046000838152602001908152602001600020604051806060016040529081600082015481526020016001820180546123e4906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054612410906145ea565b801561245d5780601f106124325761010080835404028352916020019161245d565b820191906000526020600020905b81548152906001019060200180831161244057829003601f168201915b50505050508152602001600282018054612476906145ea565b80601f01602080910402602001604051908101604052809291908181526020018280546124a2906145ea565b80156124ef5780601f106124c4576101008083540402835291602001916124ef565b820191906000526020600020905b8154815290600101906020018083116124d257829003601f168201915b50505050508152505090506002600681111561250e5761250d614411565b5b81600001510361254a5780602001518585815181106125305761252f6144e5565b5b6020026020010181905250838061254690614543565b9450505b5050808061255790614543565b915050612379565b5081945050505050919050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663bd4986a0836040518263ffffffff1660e01b81526004016125c991906136f8565b602060405180830381865afa1580156125e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061260a91906144b8565b9050919050565b612673836002600681111561262957612628614411565b5b84848080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050610ca3565b505050565b6060600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ef6fd878836040518263ffffffff1660e01b81526004016126d591906136f8565b600060405180830381865afa1580156126f2573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f8201168201806040525081019061271b9190614c24565b9050919050565b61272a612aaa565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603612799576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161279090614cdf565b60405180910390fd5b6127a281612be0565b50565b606060006127c460026000858152602001908152602001600020612b3f565b905060008167ffffffffffffffff8111156127e2576127e1613562565b5b60405190808252806020026020018201604052801561281b57816020015b612808613240565b8152602001906001900390816128005790505b50905060005b828110156129d05760006128508260026000898152602001908152602001600020612b5490919063ffffffff16565b9050600460008281526020019081526020016000206040518060600160405290816000820154815260200160018201805461288a906145ea565b80601f01602080910402602001604051908101604052809291908181526020018280546128b6906145ea565b80156129035780601f106128d857610100808354040283529160200191612903565b820191906000526020600020905b8154815290600101906020018083116128e657829003601f168201915b5050505050815260200160028201805461291c906145ea565b80601f0160208091040260200160405190810160405280929190818152602001828054612948906145ea565b80156129955780601f1061296a57610100808354040283529160200191612995565b820191906000526020600020905b81548152906001019060200180831161297857829003601f168201915b5050505050815250508383815181106129b1576129b06144e5565b5b60200260200101819052505080806129c890614543565b915050612821565b508092505050919050565b6000612a3f84600260068111156129f5576129f4614411565b5b85858080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050610c4d565b90509392505050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080600883901c9050600060ff84166001901b9050600081866000016000858152602001908152602001600020541614159250505092915050565b612ab2612d16565b73ffffffffffffffffffffffffffffffffffffffff16612ad061148e565b73ffffffffffffffffffffffffffffffffffffffff1614612b26576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612b1d90614d4b565b60405180910390fd5b565b600082612b358584612d1e565b1490509392505050565b6000612b4d82600001612d74565b9050919050565b6000612b638360000183612d85565b60001c905092915050565b6000612b80836000018360001b612db0565b905092915050565b6000612b9a836000018360001b612dd3565b905092915050565b6000600882901c9050600060ff83166001901b9050808460000160008481526020019081526020016000206000828254179250508190555050505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600082612cb2868685612ee7565b149050949350505050565b6000600882901c9050600060ff83166001901b905080198460000160008481526020019081526020016000206000828254169250508190555050505050565b6000612d0e836000018360001b61318e565b905092915050565b600033905090565b60008082905060005b8451811015612d6957612d5482868381518110612d4757612d466144e5565b5b60200260200101516131fe565b91508080612d6190614543565b915050612d27565b508091505092915050565b600081600001805490509050919050565b6000826000018281548110612d9d57612d9c6144e5565b5b9060005260206000200154905092915050565b600080836001016000848152602001908152602001600020541415905092915050565b60008083600101600084815260200190815260200160002054905060008114612edb576000600182612e059190614d6b565b9050600060018660000180549050612e1d9190614d6b565b9050818114612e8c576000866000018281548110612e3e57612e3d6144e5565b5b9060005260206000200154905080876000018481548110612e6257612e616144e5565b5b90600052602060002001819055508387600101600083815260200190815260200160002081905550505b85600001805480612ea057612e9f614d9f565b5b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050612ee1565b60009150505b92915050565b60008082519050600084519050806001875184612f049190614b80565b612f0e9190614d6b565b14612f4e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401612f4590614e1a565b60405180910390fd5b60008167ffffffffffffffff811115612f6a57612f69613562565b5b604051908082528060200260200182016040528015612f985781602001602082028036833780820191505090505b5090506000806000805b858110156130f2576000878510612fdf57858480612fbf90614543565b955081518110612fd257612fd16144e5565b5b6020026020010151613007565b898580612feb90614543565b965081518110612ffe57612ffd6144e5565b5b60200260200101515b905060008b838151811061301e5761301d6144e5565b5b6020026020010151613056578c848061303690614543565b955081518110613049576130486144e5565b5b60200260200101516130b2565b8886106130895786858061306990614543565b96508151811061307c5761307b6144e5565b5b60200260200101516130b1565b8a868061309590614543565b9750815181106130a8576130a76144e5565b5b60200260200101515b5b90506130be82826131fe565b8784815181106130d1576130d06144e5565b5b602002602001018181525050505080806130ea90614543565b915050612fa2565b506000851115613130578360018661310a9190614d6b565b8151811061311b5761311a6144e5565b5b60200260200101519650505050505050613187565b6000861115613162578760008151811061314d5761314c6144e5565b5b60200260200101519650505050505050613187565b89600081518110613176576131756144e5565b5b602002602001015196505050505050505b9392505050565b600061319a8383612db0565b6131f35782600001829080600181540180825580915050600190039060005260206000200160009091909190915055826000018054905083600101600084815260200190815260200160002081905550600190506131f8565b600090505b92915050565b6000818310613216576132118284613229565b613221565b6132208383613229565b5b905092915050565b600082600052816020526040600020905092915050565b60405180606001604052806000815260200160608152602001606081525090565b6000604051905090565b600080fd5b600080fd5b6000819050919050565b61328881613275565b811461329357600080fd5b50565b6000813590506132a58161327f565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006132d6826132ab565b9050919050565b6132e6816132cb565b81146132f157600080fd5b50565b600081359050613303816132dd565b92915050565b600080604083850312156133205761331f61326b565b5b600061332e85828601613296565b925050602061333f858286016132f4565b9150509250929050565b60008115159050919050565b61335e81613349565b82525050565b60006020820190506133796000830184613355565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f8401126133a4576133a361337f565b5b8235905067ffffffffffffffff8111156133c1576133c0613384565b5b6020830191508360018202830111156133dd576133dc613389565b5b9250929050565b600080600080600060808688031215613400576133ff61326b565b5b600061340e88828901613296565b955050602061341f88828901613296565b945050604086013567ffffffffffffffff8111156134405761343f613270565b5b61344c8882890161338e565b9350935050606061345f88828901613296565b9150509295509295909350565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6134a181613349565b82525050565b60006134b38383613498565b60208301905092915050565b6000602082019050919050565b60006134d78261346c565b6134e18185613477565b93506134ec83613488565b8060005b8381101561351d57815161350488826134a7565b975061350f836134bf565b9250506001810190506134f0565b5085935050505092915050565b6000602082019050818103600083015261354481846134cc565b905092915050565b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61359a82613551565b810181811067ffffffffffffffff821117156135b9576135b8613562565b5b80604052505050565b60006135cc613261565b90506135d88282613591565b919050565b600067ffffffffffffffff8211156135f8576135f7613562565b5b61360182613551565b9050602081019050919050565b82818337600083830152505050565b600061363061362b846135dd565b6135c2565b90508281526020810184848401111561364c5761364b61354c565b5b61365784828561360e565b509392505050565b600082601f8301126136745761367361337f565b5b813561368484826020860161361d565b91505092915050565b600080604083850312156136a4576136a361326b565b5b60006136b285828601613296565b925050602083013567ffffffffffffffff8111156136d3576136d2613270565b5b6136df8582860161365f565b9150509250929050565b6136f281613275565b82525050565b600060208201905061370d60008301846136e9565b92915050565b60008083601f8401126137295761372861337f565b5b8235905067ffffffffffffffff81111561374657613745613384565b5b60208301915083602082028301111561376257613761613389565b5b9250929050565b600080600080606085870312156137835761378261326b565b5b600061379187828801613296565b94505060206137a2878288016132f4565b935050604085013567ffffffffffffffff8111156137c3576137c2613270565b5b6137cf87828801613713565b925092505092959194509250565b6000602082840312156137f3576137f261326b565b5b6000613801848285016132f4565b91505092915050565b6000602082840312156138205761381f61326b565b5b600061382e84828501613296565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015613871578082015181840152602081019050613856565b60008484015250505050565b600061388882613837565b6138928185613842565b93506138a2818560208601613853565b6138ab81613551565b840191505092915050565b60006060820190506138cb60008301866136e9565b81810360208301526138dd818561387d565b905081810360408301526138f1818461387d565b9050949350505050565b600067ffffffffffffffff82111561391657613915613562565b5b602082029050602081019050919050565b6000819050919050565b61393a81613927565b811461394557600080fd5b50565b60008135905061395781613931565b92915050565b600061397061396b846138fb565b6135c2565b9050808382526020820190506020840283018581111561399357613992613389565b5b835b818110156139bc57806139a88882613948565b845260208401935050602081019050613995565b5050509392505050565b600082601f8301126139db576139da61337f565b5b81356139eb84826020860161395d565b91505092915050565b60008060008060808587031215613a0e57613a0d61326b565b5b6000613a1c87828801613296565b9450506020613a2d87828801613296565b935050604085013567ffffffffffffffff811115613a4e57613a4d613270565b5b613a5a878288016139c6565b9250506060613a6b87828801613948565b91505092959194509250565b600080600060408486031215613a9057613a8f61326b565b5b6000613a9e86828701613296565b935050602084013567ffffffffffffffff811115613abf57613abe613270565b5b613acb8682870161338e565b92509250509250925092565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b613b0c81613275565b82525050565b6000613b1e8383613b03565b60208301905092915050565b6000602082019050919050565b6000613b4282613ad7565b613b4c8185613ae2565b9350613b5783613af3565b8060005b83811015613b88578151613b6f8882613b12565b9750613b7a83613b2a565b925050600181019050613b5b565b5085935050505092915050565b60006020820190508181036000830152613baf8184613b37565b905092915050565b600080600060608486031215613bd057613bcf61326b565b5b6000613bde86828701613296565b9350506020613bef86828701613296565b925050604084013567ffffffffffffffff811115613c1057613c0f613270565b5b613c1c8682870161365f565b9150509250925092565b600080600060608486031215613c3f57613c3e61326b565b5b6000613c4d86828701613296565b9350506020613c5e86828701613296565b9250506040613c6f86828701613948565b9150509250925092565b600067ffffffffffffffff821115613c9457613c93613562565b5b602082029050602081019050919050565b613cae81613349565b8114613cb957600080fd5b50565b600081359050613ccb81613ca5565b92915050565b6000613ce4613cdf84613c79565b6135c2565b90508083825260208201905060208402830185811115613d0757613d06613389565b5b835b81811015613d305780613d1c8882613cbc565b845260208401935050602081019050613d09565b5050509392505050565b600082601f830112613d4f57613d4e61337f565b5b8135613d5f848260208601613cd1565b91505092915050565b600080600080600060a08688031215613d8457613d8361326b565b5b6000613d9288828901613296565b9550506020613da388828901613296565b945050604086013567ffffffffffffffff811115613dc457613dc3613270565b5b613dd0888289016139c6565b935050606086013567ffffffffffffffff811115613df157613df0613270565b5b613dfd88828901613d3a565b925050608086013567ffffffffffffffff811115613e1e57613e1d613270565b5b613e2a888289016139c6565b9150509295509295909350565b600080600080600060608688031215613e5357613e5261326b565b5b6000613e6188828901613296565b955050602086013567ffffffffffffffff811115613e8257613e81613270565b5b613e8e8882890161338e565b9450945050604086013567ffffffffffffffff811115613eb157613eb0613270565b5b613ebd88828901613713565b92509250509295509295909350565b613ed5816132cb565b82525050565b6000602082019050613ef06000830184613ecc565b92915050565b600080fd5b600080fd5b600060608284031215613f1657613f15613ef6565b5b613f2060606135c2565b90506000613f3084828501613296565b600083015250602082013567ffffffffffffffff811115613f5457613f53613efb565b5b613f608482850161365f565b602083015250604082013567ffffffffffffffff811115613f8457613f83613efb565b5b613f908482850161365f565b60408301525092915050565b60008060008060608587031215613fb657613fb561326b565b5b6000613fc487828801613296565b945050602085013567ffffffffffffffff811115613fe557613fe4613270565b5b613ff187828801613f00565b935050604085013567ffffffffffffffff81111561401257614011613270565b5b61401e87828801613713565b925092505092959194509250565b60006020820190508181036000830152614046818461387d565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b614083816132cb565b82525050565b6000614095838361407a565b60208301905092915050565b6000602082019050919050565b60006140b98261404e565b6140c38185614059565b93506140ce8361406a565b8060005b838110156140ff5781516140e68882614089565b97506140f1836140a1565b9250506001810190506140d2565b5085935050505092915050565b6000602082019050818103600083015261412681846140ae565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600082825260208201905092915050565b600061417682613837565b614180818561415a565b9350614190818560208601613853565b61419981613551565b840191505092915050565b60006141b0838361416b565b905092915050565b6000602082019050919050565b60006141d08261412e565b6141da8185614139565b9350836020820285016141ec8561414a565b8060005b85811015614228578484038952815161420985826141a4565b9450614214836141b8565b925060208a019950506001810190506141f0565b50829750879550505050505092915050565b6000602082019050818103600083015261425481846141c5565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b60006060830160008301516142a06000860182613b03565b50602083015184820360208601526142b8828261416b565b915050604083015184820360408601526142d2828261416b565b9150508091505092915050565b60006142eb8383614288565b905092915050565b6000602082019050919050565b600061430b8261425c565b6143158185614267565b93508360208202850161432785614278565b8060005b85811015614363578484038952815161434485826142df565b945061434f836142f3565b925060208a0199505060018101905061432b565b50829750879550505050505092915050565b6000602082019050818103600083015261438f8184614300565b905092915050565b6000819050919050565b60006143bc6143b76143b2846132ab565b614397565b6132ab565b9050919050565b60006143ce826143a1565b9050919050565b60006143e0826143c3565b9050919050565b6143f0816143d5565b82525050565b600060208201905061440b60008301846143e7565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60008160601b9050919050565b600061445882614440565b9050919050565b600061446a8261444d565b9050919050565b61448261447d826132cb565b61445f565b82525050565b60006144948284614471565b60148201915081905092915050565b6000815190506144b2816132dd565b92915050565b6000602082840312156144ce576144cd61326b565b5b60006144dc848285016144a3565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061454e82613275565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036145805761457f614514565b5b600182019050919050565b60006040820190506145a060008301856136e9565b81810360208301526145b2818461387d565b90509392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061460257607f821691505b602082108103614615576146146145bb565b5b50919050565b600082825260208201905092915050565b7f4e6f7420504b50204e4654206f776e6572000000000000000000000000000000600082015250565b600061466260118361461b565b915061466d8261462c565b602082019050919050565b6000602082019050818103600083015261469181614655565b9050919050565b6146a181613927565b82525050565b60006020820190506146bc6000830184614698565b92915050565b60006146ce8385613842565b93506146db83858461360e565b6146e483613551565b840190509392505050565b600060608201905061470460008301876136e9565b81810360208301526147178185876146c2565b905061472660408301846136e9565b95945050505050565b600081905092915050565b60008190508160005260206000209050919050565b6000815461475c816145ea565b614766818661472f565b945060018216600081146147815760018114614796576147c9565b60ff19831686528115158202860193506147c9565b61479f8561473a565b60005b838110156147c1578154818901526001820191506020810190506147a2565b838801955050505b50505092915050565b60006147de828461474f565b915081905092915050565b7f43616e6e6f7420616464206120646966666572656e74207075626b657920666f60008201527f72207468652073616d652061757468206d6574686f64207479706520616e642060208201527f6964000000000000000000000000000000000000000000000000000000000000604082015250565b600061486b60428361461b565b9150614876826147e9565b606082019050919050565b6000602082019050818103600083015261489a8161485e565b9050919050565b60006020601f8301049050919050565b600082821b905092915050565b6000600883026148ee7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826148b1565b6148f886836148b1565b95508019841693508086168417925050509392505050565b600061492b61492661492184613275565b614397565b613275565b9050919050565b6000819050919050565b61494583614910565b61495961495182614932565b8484546148be565b825550505050565b600090565b61496e614961565b61497981848461493c565b505050565b5b8181101561499d57614992600082614966565b60018101905061497f565b5050565b601f8211156149e2576149b38161473a565b6149bc846148a1565b810160208510156149cb578190505b6149df6149d7856148a1565b83018261497e565b50505b505050565b600082821c905092915050565b6000614a05600019846008026149e7565b1980831691505092915050565b6000614a1e83836149f4565b9150826002028217905092915050565b614a3782613837565b67ffffffffffffffff811115614a5057614a4f613562565b5b614a5a82546145ea565b614a658282856149a1565b600060209050601f831160018114614a985760008415614a86578287015190505b614a908582614a12565b865550614af8565b601f198416614aa68661473a565b60005b82811015614ace57848901518255600182019150602085019450602081019050614aa9565b86831015614aeb5784890151614ae7601f8916826149f4565b8355505b6001600288020188555050505b505050505050565b6000606082019050614b1560008301866136e9565b8181036020830152614b27818561387d565b9050614b3660408301846136e9565b949350505050565b600081519050614b4d81613ca5565b92915050565b600060208284031215614b6957614b6861326b565b5b6000614b7784828501614b3e565b91505092915050565b6000614b8b82613275565b9150614b9683613275565b9250828201905080821115614bae57614bad614514565b5b92915050565b6000614bc7614bc2846135dd565b6135c2565b905082815260208101848484011115614be357614be261354c565b5b614bee848285613853565b509392505050565b600082601f830112614c0b57614c0a61337f565b5b8151614c1b848260208601614bb4565b91505092915050565b600060208284031215614c3a57614c3961326b565b5b600082015167ffffffffffffffff811115614c5857614c57613270565b5b614c6484828501614bf6565b91505092915050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b6000614cc960268361461b565b9150614cd482614c6d565b604082019050919050565b60006020820190508181036000830152614cf881614cbc565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b6000614d3560208361461b565b9150614d4082614cff565b602082019050919050565b60006020820190508181036000830152614d6481614d28565b9050919050565b6000614d7682613275565b9150614d8183613275565b9250828203905081811115614d9957614d98614514565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b7f4d65726b6c6550726f6f663a20696e76616c6964206d756c746970726f6f6600600082015250565b6000614e04601f8361461b565b9150614e0f82614dce565b602082019050919050565b60006020820190508181036000830152614e3381614df7565b905091905056fea26469706673582212205c71f66a1aff859461f0950df2f0741ae79cf6881cc93a5a0e9a4f24ad393f8e64736f6c63430008110033