ETH Price: $1,976.06 (-5.13%)

Contract

0xA0BfBB2119A0beeE2C6e276F394Bd2fFbA7b2Bd9
 

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Open Gift189264902024-01-03 11:18:47793 days ago1704280727IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0053094620.99980075
Open Gift189129042024-01-01 13:34:11795 days ago1704116051IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0029418411.3679825
Open Gift188790622023-12-27 19:26:35800 days ago1703705195IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0075666629.87766406
Open Gift188704012023-12-26 14:14:47801 days ago1703600087IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0063972823.79702931
Open Gift188633162023-12-25 14:24:47802 days ago1703514287IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0077497130.21353114
Open Gift188448812023-12-23 0:14:59805 days ago1703290499IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0057114223.98044553
Open Gift188394542023-12-22 5:58:35806 days ago1703224715IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0071811225.19100485
Open Gift188393702023-12-22 5:41:47806 days ago1703223707IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0066642425.98398203
Open Gift188390582023-12-22 4:38:23806 days ago1703219903IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0060147623.24482618
Open Gift188387772023-12-22 3:41:47806 days ago1703216507IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0075054226.35359603
Open Gift188387262023-12-22 3:31:35806 days ago1703215895IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.006587528.14234068
Open Gift188386602023-12-22 3:18:11806 days ago1703215091IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0079383127.66878108
Open Gift188386042023-12-22 3:06:47806 days ago1703214407IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0066926826.37460094
Open Gift188383382023-12-22 2:12:59806 days ago1703211179IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0062921525.55440425
Open Gift188383332023-12-22 2:11:59806 days ago1703211119IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0065811525.93588031
Open Gift188383002023-12-22 2:05:23806 days ago1703210723IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0077738530.65305399
Open Gift188380462023-12-22 1:14:11806 days ago1703207651IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0067153926.55911969
Open Gift188377202023-12-22 0:08:35806 days ago1703203715IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0077671731.54489221
Open Gift188376772023-12-21 23:59:59806 days ago1703203199IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0070758926.87633096
Open Gift188375752023-12-21 23:39:23806 days ago1703201963IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0077796928.02818163
Open Gift188374972023-12-21 23:23:35806 days ago1703201015IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0081556534.06734001
Open Gift188373472023-12-21 22:53:35806 days ago1703199215IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0067870730.27388259
Open Gift188373432023-12-21 22:52:47806 days ago1703199167IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0077112329.51692511
Open Gift188373222023-12-21 22:48:35806 days ago1703198915IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0094105332.65415421
Open Gift188373172023-12-21 22:47:35806 days ago1703198855IN
0xA0BfBB21...FbA7b2Bd9
0 ETH0.0087304129.13001997
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Method Block
From
To
Safe Transfer Fr...189264902024-01-03 11:18:47793 days ago1704280727
0xA0BfBB21...FbA7b2Bd9
0 ETH
Burn189264902024-01-03 11:18:47793 days ago1704280727
0xA0BfBB21...FbA7b2Bd9
0 ETH
Owner Of189264902024-01-03 11:18:47793 days ago1704280727
0xA0BfBB21...FbA7b2Bd9
0 ETH
Safe Transfer Fr...189129042024-01-01 13:34:11795 days ago1704116051
0xA0BfBB21...FbA7b2Bd9
0 ETH
Burn189129042024-01-01 13:34:11795 days ago1704116051
0xA0BfBB21...FbA7b2Bd9
0 ETH
Owner Of189129042024-01-01 13:34:11795 days ago1704116051
0xA0BfBB21...FbA7b2Bd9
0 ETH
Safe Transfer Fr...188790622023-12-27 19:26:35800 days ago1703705195
0xA0BfBB21...FbA7b2Bd9
0 ETH
Burn188790622023-12-27 19:26:35800 days ago1703705195
0xA0BfBB21...FbA7b2Bd9
0 ETH
Owner Of188790622023-12-27 19:26:35800 days ago1703705195
0xA0BfBB21...FbA7b2Bd9
0 ETH
Safe Transfer Fr...188704012023-12-26 14:14:47801 days ago1703600087
0xA0BfBB21...FbA7b2Bd9
0 ETH
Burn188704012023-12-26 14:14:47801 days ago1703600087
0xA0BfBB21...FbA7b2Bd9
0 ETH
Owner Of188704012023-12-26 14:14:47801 days ago1703600087
0xA0BfBB21...FbA7b2Bd9
0 ETH
Safe Transfer Fr...188633162023-12-25 14:24:47802 days ago1703514287
0xA0BfBB21...FbA7b2Bd9
0 ETH
Burn188633162023-12-25 14:24:47802 days ago1703514287
0xA0BfBB21...FbA7b2Bd9
0 ETH
Owner Of188633162023-12-25 14:24:47802 days ago1703514287
0xA0BfBB21...FbA7b2Bd9
0 ETH
Safe Transfer Fr...188448812023-12-23 0:14:59805 days ago1703290499
0xA0BfBB21...FbA7b2Bd9
0 ETH
Burn188448812023-12-23 0:14:59805 days ago1703290499
0xA0BfBB21...FbA7b2Bd9
0 ETH
Owner Of188448812023-12-23 0:14:59805 days ago1703290499
0xA0BfBB21...FbA7b2Bd9
0 ETH
Safe Transfer Fr...188394542023-12-22 5:58:35806 days ago1703224715
0xA0BfBB21...FbA7b2Bd9
0 ETH
Burn188394542023-12-22 5:58:35806 days ago1703224715
0xA0BfBB21...FbA7b2Bd9
0 ETH
Owner Of188394542023-12-22 5:58:35806 days ago1703224715
0xA0BfBB21...FbA7b2Bd9
0 ETH
Safe Transfer Fr...188393702023-12-22 5:41:47806 days ago1703223707
0xA0BfBB21...FbA7b2Bd9
0 ETH
Burn188393702023-12-22 5:41:47806 days ago1703223707
0xA0BfBB21...FbA7b2Bd9
0 ETH
Owner Of188393702023-12-22 5:41:47806 days ago1703223707
0xA0BfBB21...FbA7b2Bd9
0 ETH
Safe Transfer Fr...188390582023-12-22 4:38:23806 days ago1703219903
0xA0BfBB21...FbA7b2Bd9
0 ETH
View All Internal Transactions
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Validator Index Block Amount
View All Withdrawals

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

Contract Source Code Verified (Exact Match)

Contract Name:
TokenGatedSantaProtocol

Compiler Version
v0.8.23+commit.f704f362

Optimization Enabled:
Yes with 20000 runs

Other Settings:
paris EvmVersion
// SPDX-License-Identifier: LGPL-3.0-only
// Created By: Prohibition / VenturePunk,LLC
// Written By: Thomas Lipari (thom.eth)
pragma solidity ^0.8.23;

import {ECDSA} from "openzeppelin-contracts/utils/cryptography/ECDSA.sol";
import {IERC721} from "openzeppelin-contracts/token/ERC721/IERC721.sol";
import {IDelegateRegistry} from "@delegate-registry/IDelegateRegistry.sol";

import {ITokenGatedSantaProtocol} from "./ITokenGatedSantaProtocol.sol";
import {SantaProtocol} from "./SantaProtocol.sol";

/**
 * @title The TokenGatedSantaProtocol contract
 * @author Thomas Lipari (thom.eth)
 * @notice An extension of the SantaProtocol contract that adds token gating
 */
contract TokenGatedSantaProtocol is SantaProtocol, ITokenGatedSantaProtocol {
    using ECDSA for bytes32;

    //=========//
    // Storage //
    //=========//

    /* Delegate */

    IDelegateRegistry public constant DELEGATE_REGISTRY = IDelegateRegistry(0x00000000000000447e69651d841bD8D104Bed493);

    /* Token Gating */

    // An optional ERC721 that can be used to gate access to the protocol
    IERC721 public TOKEN_GATE_CONTRACT;
    // The maximum number of times an account can participate per owned token ID
    uint32 public TOKEN_GATE_LIMIT;
    // Whether or not delegated wallets are supported
    bool public SUPPORTS_DELEGATES = true;
    // Mapping of token gate NFTs to token IDs to number of times they've been used
    mapping(address tokenGateNft => mapping(uint256 tokenId => uint32 usedCount)) public _tokenGateNftUsed;

    //=============//
    // Constructor //
    //=============//

    /**
     * @notice Constructor inherits SantaProtocol and RandomNumberConsumerV2
     * @param subscriptionId - the subscription ID that this contract uses for funding Chainlink VFR requests
     * @param vrfCoordinator - coordinator, check https://docs.chain.link/docs/vrf-contracts/#configurations
     * @param keyHash - the Chainlink gas lane to use, which specifies the maximum gas price to bump to
     * @param registrationEnd - the time that registration/adding gifts ends
     * @param redemptionStart - the time that participants can begin redeeming their gifts
     * @param signer - the address of the signer that signs the gift hashes
     * @param presentNft - the address of the NFT that represents the gifts in the pool
     * @param tokenGateNft - the address of the NFT being used to gate access to the protocol
     * @param tokenGateLimit - the maximum number of times an account can participate per owned token ID
     */
    constructor(
        uint64 subscriptionId,
        address vrfCoordinator,
        bytes32 keyHash,
        uint256 registrationEnd,
        uint256 redemptionStart,
        address signer,
        address presentNft,
        address tokenGateNft,
        uint32 tokenGateLimit
    ) SantaProtocol(subscriptionId, vrfCoordinator, keyHash, registrationEnd, redemptionStart, signer, presentNft) {
        if (tokenGateNft != address(0)) {
            TOKEN_GATE_CONTRACT = IERC721(tokenGateNft);
            TOKEN_GATE_LIMIT = tokenGateLimit;
        }
    }

    //=========================//
    // Gift Exchange Functions //
    //=========================//

    /**
     * @notice Disabled because token gate requires more values
     * @param nft - the address of the NFT being added
     * @param tokenId - the token id of the NFT being added
     * @param tokenGateNft - the address of the NFT being used to gate access to the protocol
     * @param tokenGateTokenId - the token id of the NFT being used to gate access to the protocol
     * @param sig - a message signed by the signer address verifying the NFT is eligible
     */
    function addGift(address nft, uint256 tokenId, address tokenGateNft, uint256 tokenGateTokenId, bytes calldata sig)
        public
        virtual
        isNotPaused
        returns (address giftAddress, uint256 giftTokenId)
    {
        // If the pool isn't token gated, revert
        if (address(TOKEN_GATE_CONTRACT) == address(0)) revert PoolIsNotTokenGated();
        // Run validity check
        _addGiftChecks(nft, tokenId);
        // If the NFT doesn't pass token gating
        _tokenGate(msg.sender, tokenGateNft, tokenGateTokenId);
        // If the signature isn't valid, revert
        if (!_validateTokenGateSignatureIfRequired(msg.sender, nft, tokenId, tokenGateNft, tokenGateTokenId, sig)) {
            revert InvalidSignature();
        }

        // Add the gift to the pool and mint a PresentNft to the user that added the gift
        (giftAddress, giftTokenId) = _addGiftTransfers(nft, tokenId);
    }

    /**
     * @notice Disabled because token gate requires more values
     * @param nft - the address of the NFT being added
     * @param tokenId - the token id of the NFT being added
     * @param sig - a message signed by the signer address verifying the NFT is eligible
     */
    function addGift(address nft, uint256 tokenId, bytes calldata sig)
        public
        virtual
        override(SantaProtocol)
        isNotPaused
        returns (address giftAddress, uint256 giftTokenId)
    {
        if (address(TOKEN_GATE_CONTRACT) != address(0)) revert TokenGated();
        return super.addGift(nft, tokenId, sig);
    }

    //================//
    // View Functions //
    //================//

    /**
     * @notice Get the the address of the TokenGate NFT
     */
    function getTokenGateContract() public view returns (address) {
        return address(TOKEN_GATE_CONTRACT);
    }

    /**
     * @notice Function that checks if an NFT is eligible to be used to gate access to the protocol
     * @param account - the account that is using the NFT
     * @param tokenGateNft - the address of the NFT being used to gate access to the protocol
     * @param tokenGateTokenId - the token id of the NFT being used to gate access to the protocol
     */
    function getTokenGateEligibility(address account, address tokenGateNft, uint256 tokenGateTokenId)
        public
        view
        virtual
        returns (bool eligible)
    {
        if (address(TOKEN_GATE_CONTRACT) == address(0)) return true;
        if (tokenGateNft != address(TOKEN_GATE_CONTRACT)) return false;
        if (!_validateOwnershipOrDelegation(account, tokenGateNft, tokenGateTokenId)) return false;
        if (TOKEN_GATE_LIMIT == 0) return true;
        if (_tokenGateNftUsed[tokenGateNft][tokenGateTokenId] >= TOKEN_GATE_LIMIT) return false;
        return true;
    }

    /**
     * @notice Function that checks if the token gate support delegates
     */
    function getSupportsDelegates() public view returns (bool) {
        return SUPPORTS_DELEGATES;
    }

    //=================//
    // Admin Functions //
    //=================//

    /**
     * @notice Function that allows the owners to update the address of the Token Gate NFT
     * @param newTokenGateNft - new address of the Token Gate NFT
     */
    function setTokenGateContract(address newTokenGateNft) public onlyOwner {
        TOKEN_GATE_CONTRACT = IERC721(newTokenGateNft);
    }

    /**
     * @notice Function that allows the owners to update the address of the Token Gate NFT
     * @param newTokenGateLimit - new address of the Token Gate NFT
     */
    function setTokenGateLimit(uint32 newTokenGateLimit) public onlyOwner {
        TOKEN_GATE_LIMIT = newTokenGateLimit;
    }

    /**
     * @notice Function that allows the owners to toggle whether or not delegated wallets are supported
     */
    function toggleSupportsDelegates() public onlyOwner {
        SUPPORTS_DELEGATES = !SUPPORTS_DELEGATES;
    }

    //===================//
    // Signing/Verifying //
    //===================//

    /**
     * @notice Function used to hash a gift along with tokengate information
     * @param gifter - address of the gifter
     * @param nft - the address of the NFT being gifted
     * @param tokenId - the id of the NFT being gifted
     * @param tokenGateNft - the address of the NFT being used to gate access to the protocol
     * @param tokenGateTokenId - the token id of the NFT being used to gate access to the protocol
     */
    function hashTokenGateGift(
        address gifter,
        address nft,
        uint256 tokenId,
        address tokenGateNft,
        uint256 tokenGateTokenId
    ) public view override returns (bytes32) {
        bytes32 tokenGateHash = keccak256(abi.encode(tokenGateNft, tokenGateTokenId));
        return keccak256(abi.encode(getContractHash(), hashGift(gifter, nft, tokenId), tokenGateHash));
    }

    /**
     * @notice Function that validates that the gift hash signature was signed by the designated signer authority
     * @param gifter - address of the gifter
     * @param nft - the address of the NFT being gifted
     * @param tokenId - the id of the NFT being gifted
     * @param tokenGateNft - the address of the NFT being used to gate access to the protocol
     * @param tokenGateTokenId - the token id of the NFT being used to gate access to the protocol
     * @param sig - the signature of the gift hash
     */
    function validateTokenGateSignature(
        address gifter,
        address nft,
        uint256 tokenId,
        address tokenGateNft,
        uint256 tokenGateTokenId,
        bytes calldata sig
    ) public view override returns (bool) {
        bytes32 tokenGateHash = hashTokenGateGift(gifter, nft, tokenId, tokenGateNft, tokenGateTokenId);
        bytes32 ethSignedMessageHash = tokenGateHash.toEthSignedMessageHash();
        address signer = ethSignedMessageHash.recover(sig);
        return signer == s_signer;
    }

    //==========//
    // Internal //
    //==========//

    /**
     * @notice Checks if an NFT being used by an account passes token gating.
     * @param account - the account that is using the NFT
     * @param nft - the address of the NFT being used
     * @param tokenId - the token id of the NFT being used
     * @dev Only used if token gating is enabled and updates the tally of times an NFT has been used.
     */
    function _tokenGate(address account, address nft, uint256 tokenId) internal virtual {
        // If the nft isn't the token gate nft...
        if (nft != address(TOKEN_GATE_CONTRACT)) {
            revert NotTokenGateCollection();
        }

        // If there's a limit on each token's use and the token has been used too many times...
        if (TOKEN_GATE_LIMIT != 0 && _tokenGateNftUsed[nft][tokenId] >= TOKEN_GATE_LIMIT) {
            revert TokenGateLimitReached();
        }

        // If the account doesn't own the token nor has been delegated use of it...
        if (!_validateOwnershipOrDelegation(account, nft, tokenId)) {
            revert NotTokenGatedTokenHolder();
        }

        _tokenGateNftUsed[nft][tokenId]++;
    }

    /**
     * @notice Checks if an NFT is either owned by or delegated to an account
     * @param account - the account that is using the NFT
     * @param nft - the address of the NFT being used
     * @param tokenId - the token id of the NFT being used
     */
    function _validateOwnershipOrDelegation(address account, address nft, uint256 tokenId)
        internal
        view
        virtual
        returns (bool)
    {
        if (IERC721(nft).ownerOf(tokenId) == account) return true;
        if (!SUPPORTS_DELEGATES) return false;
        return DELEGATE_REGISTRY.checkDelegateForERC721(account, IERC721(nft).ownerOf(tokenId), nft, tokenId, 0);
    }

    /**
     * @notice Function that validates that the gift hash signature was signed by the designated signer authority
     * @param gifter - address of the gifter
     * @param nft - the address of the NFT being gifted
     * @param tokenId - the id of the NFT being gifted
     * @param tokenGateNft - the address of the NFT being used to gate access to the protocol
     * @param tokenGateTokenId - the token id of the NFT being used to gate access to the protocol
     * @param sig - the signature of the gift hash
     * @dev Bypasses if signature isn't required
     */
    function _validateTokenGateSignatureIfRequired(
        address gifter,
        address nft,
        uint256 tokenId,
        address tokenGateNft,
        uint256 tokenGateTokenId,
        bytes calldata sig
    ) internal view virtual returns (bool) {
        if (!REQUIRES_SIGNATURE) return true;
        return validateTokenGateSignature(gifter, nft, tokenId, tokenGateNft, tokenGateTokenId, sig);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (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 // Deprecated in v4.8
    }

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

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: CC0-1.0
pragma solidity >=0.8.13;

/**
 * @title IDelegateRegistry
 * @custom:version 2.0
 * @custom:author foobar (0xfoobar)
 * @notice A standalone immutable registry storing delegated permissions from one address to another
 */
interface IDelegateRegistry {
    /// @notice Delegation type, NONE is used when a delegation does not exist or is revoked
    enum DelegationType {
        NONE,
        ALL,
        CONTRACT,
        ERC721,
        ERC20,
        ERC1155
    }

    /// @notice Struct for returning delegations
    struct Delegation {
        DelegationType type_;
        address to;
        address from;
        bytes32 rights;
        address contract_;
        uint256 tokenId;
        uint256 amount;
    }

    /// @notice Emitted when an address delegates or revokes rights for their entire wallet
    event DelegateAll(address indexed from, address indexed to, bytes32 rights, bool enable);

    /// @notice Emitted when an address delegates or revokes rights for a contract address
    event DelegateContract(address indexed from, address indexed to, address indexed contract_, bytes32 rights, bool enable);

    /// @notice Emitted when an address delegates or revokes rights for an ERC721 tokenId
    event DelegateERC721(address indexed from, address indexed to, address indexed contract_, uint256 tokenId, bytes32 rights, bool enable);

    /// @notice Emitted when an address delegates or revokes rights for an amount of ERC20 tokens
    event DelegateERC20(address indexed from, address indexed to, address indexed contract_, bytes32 rights, uint256 amount);

    /// @notice Emitted when an address delegates or revokes rights for an amount of an ERC1155 tokenId
    event DelegateERC1155(address indexed from, address indexed to, address indexed contract_, uint256 tokenId, bytes32 rights, uint256 amount);

    /// @notice Thrown if multicall calldata is malformed
    error MulticallFailed();

    /**
     * -----------  WRITE -----------
     */

    /**
     * @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
     * @param data The encoded function data for each of the calls to make to this contract
     * @return results The results from each of the calls passed in via data
     */
    function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);

    /**
     * @notice Allow the delegate to act on behalf of `msg.sender` for all contracts
     * @param to The address to act as delegate
     * @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights
     * @param enable Whether to enable or disable this delegation, true delegates and false revokes
     * @return delegationHash The unique identifier of the delegation
     */
    function delegateAll(address to, bytes32 rights, bool enable) external payable returns (bytes32 delegationHash);

    /**
     * @notice Allow the delegate to act on behalf of `msg.sender` for a specific contract
     * @param to The address to act as delegate
     * @param contract_ The contract whose rights are being delegated
     * @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights
     * @param enable Whether to enable or disable this delegation, true delegates and false revokes
     * @return delegationHash The unique identifier of the delegation
     */
    function delegateContract(address to, address contract_, bytes32 rights, bool enable) external payable returns (bytes32 delegationHash);

    /**
     * @notice Allow the delegate to act on behalf of `msg.sender` for a specific ERC721 token
     * @param to The address to act as delegate
     * @param contract_ The contract whose rights are being delegated
     * @param tokenId The token id to delegate
     * @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights
     * @param enable Whether to enable or disable this delegation, true delegates and false revokes
     * @return delegationHash The unique identifier of the delegation
     */
    function delegateERC721(address to, address contract_, uint256 tokenId, bytes32 rights, bool enable) external payable returns (bytes32 delegationHash);

    /**
     * @notice Allow the delegate to act on behalf of `msg.sender` for a specific amount of ERC20 tokens
     * @dev The actual amount is not encoded in the hash, just the existence of a amount (since it is an upper bound)
     * @param to The address to act as delegate
     * @param contract_ The address for the fungible token contract
     * @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights
     * @param amount The amount to delegate, > 0 delegates and 0 revokes
     * @return delegationHash The unique identifier of the delegation
     */
    function delegateERC20(address to, address contract_, bytes32 rights, uint256 amount) external payable returns (bytes32 delegationHash);

    /**
     * @notice Allow the delegate to act on behalf of `msg.sender` for a specific amount of ERC1155 tokens
     * @dev The actual amount is not encoded in the hash, just the existence of a amount (since it is an upper bound)
     * @param to The address to act as delegate
     * @param contract_ The address of the contract that holds the token
     * @param tokenId The token id to delegate
     * @param rights Specific subdelegation rights granted to the delegate, pass an empty bytestring to encompass all rights
     * @param amount The amount of that token id to delegate, > 0 delegates and 0 revokes
     * @return delegationHash The unique identifier of the delegation
     */
    function delegateERC1155(address to, address contract_, uint256 tokenId, bytes32 rights, uint256 amount) external payable returns (bytes32 delegationHash);

    /**
     * ----------- CHECKS -----------
     */

    /**
     * @notice Check if `to` is a delegate of `from` for the entire wallet
     * @param to The potential delegate address
     * @param from The potential address who delegated rights
     * @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only
     * @return valid Whether delegate is granted to act on the from's behalf
     */
    function checkDelegateForAll(address to, address from, bytes32 rights) external view returns (bool);

    /**
     * @notice Check if `to` is a delegate of `from` for the specified `contract_` or the entire wallet
     * @param to The delegated address to check
     * @param contract_ The specific contract address being checked
     * @param from The cold wallet who issued the delegation
     * @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only
     * @return valid Whether delegate is granted to act on from's behalf for entire wallet or that specific contract
     */
    function checkDelegateForContract(address to, address from, address contract_, bytes32 rights) external view returns (bool);

    /**
     * @notice Check if `to` is a delegate of `from` for the specific `contract` and `tokenId`, the entire `contract_`, or the entire wallet
     * @param to The delegated address to check
     * @param contract_ The specific contract address being checked
     * @param tokenId The token id for the token to delegating
     * @param from The wallet that issued the delegation
     * @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only
     * @return valid Whether delegate is granted to act on from's behalf for entire wallet, that contract, or that specific tokenId
     */
    function checkDelegateForERC721(address to, address from, address contract_, uint256 tokenId, bytes32 rights) external view returns (bool);

    /**
     * @notice Returns the amount of ERC20 tokens the delegate is granted rights to act on the behalf of
     * @param to The delegated address to check
     * @param contract_ The address of the token contract
     * @param from The cold wallet who issued the delegation
     * @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only
     * @return balance The delegated balance, which will be 0 if the delegation does not exist
     */
    function checkDelegateForERC20(address to, address from, address contract_, bytes32 rights) external view returns (uint256);

    /**
     * @notice Returns the amount of a ERC1155 tokens the delegate is granted rights to act on the behalf of
     * @param to The delegated address to check
     * @param contract_ The address of the token contract
     * @param tokenId The token id to check the delegated amount of
     * @param from The cold wallet who issued the delegation
     * @param rights Specific rights to check for, pass the zero value to ignore subdelegations and check full delegations only
     * @return balance The delegated balance, which will be 0 if the delegation does not exist
     */
    function checkDelegateForERC1155(address to, address from, address contract_, uint256 tokenId, bytes32 rights) external view returns (uint256);

    /**
     * ----------- ENUMERATIONS -----------
     */

    /**
     * @notice Returns all enabled delegations a given delegate has received
     * @param to The address to retrieve delegations for
     * @return delegations Array of Delegation structs
     */
    function getIncomingDelegations(address to) external view returns (Delegation[] memory delegations);

    /**
     * @notice Returns all enabled delegations an address has given out
     * @param from The address to retrieve delegations for
     * @return delegations Array of Delegation structs
     */
    function getOutgoingDelegations(address from) external view returns (Delegation[] memory delegations);

    /**
     * @notice Returns all hashes associated with enabled delegations an address has received
     * @param to The address to retrieve incoming delegation hashes for
     * @return delegationHashes Array of delegation hashes
     */
    function getIncomingDelegationHashes(address to) external view returns (bytes32[] memory delegationHashes);

    /**
     * @notice Returns all hashes associated with enabled delegations an address has given out
     * @param from The address to retrieve outgoing delegation hashes for
     * @return delegationHashes Array of delegation hashes
     */
    function getOutgoingDelegationHashes(address from) external view returns (bytes32[] memory delegationHashes);

    /**
     * @notice Returns the delegations for a given array of delegation hashes
     * @param delegationHashes is an array of hashes that correspond to delegations
     * @return delegations Array of Delegation structs, return empty structs for nonexistent or revoked delegations
     */
    function getDelegationsFromHashes(bytes32[] calldata delegationHashes) external view returns (Delegation[] memory delegations);

    /**
     * ----------- STORAGE ACCESS -----------
     */

    /**
     * @notice Allows external contracts to read arbitrary storage slots
     */
    function readSlot(bytes32 location) external view returns (bytes32);

    /**
     * @notice Allows external contracts to read an arbitrary array of storage slots
     */
    function readSlots(bytes32[] calldata locations) external view returns (bytes32[] memory);
}

// SPDX-License-Identifier: LGPL-3.0-only
// Created By: Prohibition / VenturePunk,LLC
// Written By: Thomas Lipari (thom.eth)
pragma solidity ^0.8.23;

/**
 * @title The TokenGatedSantaProtocol contract
 * @author Thomas Lipari (thom.eth)
 * @notice An extension of the SantaProtocol contract that adds token gating
 */
interface ITokenGatedSantaProtocol {
    //========//
    // Errors //
    //========//

    error NotTokenGatedCollectionHolder();
    error NotTokenGatedTokenHolder();
    error NotTokenGateCollection();
    error TokenGateLimitReached();
    error PoolIsNotTokenGated();
    error TokenGated();

    //=========================//
    // Gift Exchange Functions //
    //=========================//

    /**
     * @notice Disabled because token gate requires more values
     * @param nft - the address of the NFT being added
     * @param tokenId - the token id of the NFT being added
     * @param tokenGateNft - the address of the NFT being used to gate access to the protocol
     * @param tokenGateTokenId - the token id of the NFT being used to gate access to the protocol
     * @param sig - a message signed by the signer address verifying the NFT is eligible
     */
    function addGift(address nft, uint256 tokenId, address tokenGateNft, uint256 tokenGateTokenId, bytes calldata sig)
        external
        returns (address giftAddress, uint256 giftTokenId);

    //================//
    // View Functions //
    //================//

    /**
     * @notice Get the the address of the TokenGate NFT
     */
    function getTokenGateContract() external view returns (address);

    /**
     * @notice Function that checks if an NFT is eligible to be used to gate access to the protocol
     * @param account - the account that is using the NFT
     * @param tokenGateNft - the address of the NFT being used to gate access to the protocol
     * @param tokenGateTokenId - the token id of the NFT being used to gate access to the protocol
     */
    function getTokenGateEligibility(address account, address tokenGateNft, uint256 tokenGateTokenId)
        external
        view
        returns (bool eligible);

    /**
     * @notice Function that checks if the token gate support delegates
     */
    function getSupportsDelegates() external view returns (bool);

    //=================//
    // Admin Functions //
    //=================//

    /**
     * @notice Function that allows the owners to update the address of the Token Gate NFT
     * @param newTokenGateNft - new address of the Token Gate NFT
     */
    function setTokenGateContract(address newTokenGateNft) external;

    /**
     * @notice Function that allows the owners to update the address of the Token Gate NFT
     * @param newTokenGateLimit - new address of the Token Gate NFT
     */
    function setTokenGateLimit(uint32 newTokenGateLimit) external;

    /**
     * @notice Function that allows the owners to toggle whether or not delegated wallets are supported
     */
    function toggleSupportsDelegates() external;

    //===================//
    // Signing/Verifying //
    //===================//

    /**
     * @notice Function used to hash a gift along with tokengate information
     * @param gifter - address of the gifter
     * @param nft - the address of the NFT being gifted
     * @param tokenId - the id of the NFT being gifted
     * @param tokenGateNft - the address of the NFT being used to gate access to the protocol
     * @param tokenGateTokenId - the token id of the NFT being used to gate access to the protocol
     */
    function hashTokenGateGift(
        address gifter,
        address nft,
        uint256 tokenId,
        address tokenGateNft,
        uint256 tokenGateTokenId
    ) external view returns (bytes32);

    /**
     * @notice Function that validates that the gift hash signature was signed by the designated signer authority
     * @param gifter - address of the gifter
     * @param nft - the address of the NFT being gifted
     * @param tokenId - the id of the NFT being gifted
     * @param tokenGateNft - the address of the NFT being used to gate access to the protocol
     * @param tokenGateTokenId - the token id of the NFT being used to gate access to the protocol
     * @param sig - the signature of the gift hash
     */
    function validateTokenGateSignature(
        address gifter,
        address nft,
        uint256 tokenId,
        address tokenGateNft,
        uint256 tokenGateTokenId,
        bytes calldata sig
    ) external view returns (bool);
}

// SPDX-License-Identifier: LGPL-3.0-only
// Created By: Prohibition / VenturePunk,LLC
// Written By: Thomas Lipari (thom.eth)
pragma solidity ^0.8.23;

import {IERC721Receiver} from "openzeppelin-contracts/token/ERC721/IERC721Receiver.sol";
import {ECDSA} from "openzeppelin-contracts/utils/cryptography/ECDSA.sol";
import {IERC721} from "openzeppelin-contracts/token/ERC721/IERC721.sol";
import {SafeMath} from "openzeppelin-contracts/utils/math/SafeMath.sol";
import {SafeCast} from "openzeppelin-contracts/utils/math/SafeCast.sol";
import {IERC165} from "openzeppelin-contracts/interfaces/IERC165.sol";
import {Ownable} from "openzeppelin-contracts/access/Ownable.sol";

import {RandomNumberConsumerV2} from "src/util/RandomNumberConsumerV2.sol";
import {WrappedPresent} from "./WrappedPresent.sol";
import {ISantaProtocol} from "./ISantaProtocol.sol";

/**
 * @title The SantaProtocol contract
 * @author Thomas Lipari (thom.eth)
 * @notice A contract that lets people deposit an NFT into a pool and then later lets them randomly redeem another one using Chainlink VRF2
 */
contract SantaProtocol is Ownable, IERC721Receiver, ISantaProtocol, RandomNumberConsumerV2 {
    using ECDSA for bytes32;
    using SafeMath for uint256;
    using SafeCast for uint256;

    //=========//
    // Storage //
    //=========//

    /* Constants */

    // The Present NFT that's minted to users when they add to the pool
    WrappedPresent public immutable PRESENT_NFT;

    /* Private values */

    // Address that signs verification messages when adding gifts
    address internal s_signer;
    // Blocktime that adding gifts to the pool ends
    uint32 internal s_registrationEnd;
    // Blocktime that redemptions start
    uint32 internal s_redemptionStart;
    // The Gift Pool
    Gift[] internal s_giftPool;
    // The array to map Present Token IDs to gifts in the Gift Pool
    uint32[] internal s_giftPoolIndices;
    // Mapping of gifts chosen by each user
    mapping(address user => Gift[] unwrappedGifts) internal s_chosenGifts;

    /* Config */

    // The state that pauses the contract's functionality
    bool public PAUSED = false;
    // The state that says that the gift pool has been shuffled
    bool public SHUFFLED = false;
    // Maximum allowed gifts in the pool
    uint32 public MAX_GIFTS = 50000;
    // The state that dictates whether adding a gift requires a signature
    bool public REQUIRES_SIGNATURE = true;

    /* Chainlink VRF */

    // The random word returned by VRF used as a seed for the randomness
    uint256 public SEED;
    // The request ID for the SEED
    uint256 public SEED_REQUEST_ID;

    //=============//
    // Constructor //
    //=============//

    /**
     * @notice Constructor inherits RandomNumberConsumerV2
     * @param subscriptionId - the subscription ID that this contract uses for funding Chainlink VFR requests
     * @param vrfCoordinator - coordinator, check https://docs.chain.link/docs/vrf-contracts/#configurations
     * @param keyHash - the Chainlink gas lane to use, which specifies the maximum gas price to bump to
     * @param registrationEnd - the time that registration/adding gifts ends
     * @param redemptionStart - the time that participants can begin redeeming their gifts
     */
    constructor(
        uint64 subscriptionId,
        address vrfCoordinator,
        bytes32 keyHash,
        uint256 registrationEnd,
        uint256 redemptionStart,
        address signer,
        address presentNft
    ) RandomNumberConsumerV2(subscriptionId, vrfCoordinator, keyHash) {
        s_registrationEnd = registrationEnd.toUint32();
        s_redemptionStart = redemptionStart.toUint32();
        s_signer = signer;
        PRESENT_NFT = WrappedPresent(presentNft);
    }

    //=========================//
    // Gift Exchange Functions //
    //=========================//

    /**
     * @notice Function used to add an NFT to the pool.
     * @param nft - the address of the NFT being added
     * @param tokenId - the token id of the NFT being added
     * @param sig - a message signed by the signer address verifying the NFT is eligible
     */
    function addGift(address nft, uint256 tokenId, bytes calldata sig)
        public
        virtual
        isNotPaused
        returns (address giftAddress, uint256 giftTokenId)
    {
        // Run validity check
        _addGiftChecks(nft, tokenId);
        // If the signature isn't valid
        if (!_validateGiftHashSignatureIfRequired(msg.sender, nft, tokenId, sig)) revert InvalidSignature();
        // Add the gift to the pool and mint a PresentNft to the user that added the gift
        (giftAddress, giftTokenId) = _addGiftTransfers(nft, tokenId);
    }

    /**
     * @notice Function used to burn a Present NFT and redeem the gift in the pool it's been tied to
     * @param tokenId - the token id of the Present NFT being burned
     */
    function openGift(uint256 tokenId)
        public
        virtual
        isNotPaused
        returns (address chosenGiftAddress, uint256 chosenGiftTokenId)
    {
        // Run validity check
        _openGiftChecks(tokenId);
        // Open the gift and transfer it to the user
        (chosenGiftAddress, chosenGiftTokenId) = _openGiftTransfers(tokenId);
    }

    //================//
    // View Functions //
    //================//

    /**
     * @notice Get the number of NFTs in the gift pool
     */
    function getSigner() public view returns (address) {
        return s_signer;
    }

    /**
     * @notice Get the end of the deposit window
     */
    function getRegistrationEnd() public view returns (uint256) {
        return uint256(s_registrationEnd);
    }

    /**
     * @notice Get start of the redemption window
     */
    function getRedemptionStart() public view returns (uint256) {
        return uint256(s_redemptionStart);
    }

    /**
     * @notice Get the number of NFTs in the gift pool
     */
    function getGiftPoolSize() public view returns (uint256) {
        return s_giftPool.length;
    }

    /**
     * @notice Get the whole gift pool
     * @dev intended for offchain use only
     */
    function getGiftPool() public view returns (Gift[] memory) {
        return s_giftPool;
    }

    /**
     * @notice Get the number of gifts that a user has randomly chosen
     * @param account - the wallet address of the user
     */
    function getNumberOfChosenGifts(address account) public view returns (uint256) {
        return s_chosenGifts[account].length;
    }

    /**
     * @notice Get the array of gifts that a user has randomly chosen
     * @param account - the wallet address of the user
     * @dev intended for offchain use only
     */
    function getChosenGifts(address account) public view returns (Gift[] memory) {
        return s_chosenGifts[account];
    }

    //=================//
    // Admin Functions //
    //=================//

    /**
     * @notice Set signer to new account
     * @param newSigner - the addres of the new owner
     */
    function setSigner(address newSigner) public onlyOwner {
        s_signer = newSigner;
    }

    /**
     * @notice Toggle whether adding a gift requires a signature
     */
    function toggleSignatureRequired() public onlyOwner {
        REQUIRES_SIGNATURE = !REQUIRES_SIGNATURE;
    }

    /**
     * @notice Set the time that adding gifts ends
     * @param newRegistrationEnd - the new s_registerationEnd time
     */
    function setRegistrationEnd(uint256 newRegistrationEnd) public onlyOwner {
        if (s_redemptionStart != 0 && newRegistrationEnd >= s_redemptionStart) {
            revert RedemptionMustHappenAfterRegistration();
        }
        s_registrationEnd = newRegistrationEnd.toUint32();
    }

    /**
     * @notice Set the time that claiming a random gift starts
     * @param newRedemptionStart - the new s_redemptionStart time
     */
    function setRedemptionStart(uint256 newRedemptionStart) public onlyOwner {
        if (newRedemptionStart <= s_registrationEnd) revert RedemptionMustHappenAfterRegistration();
        s_redemptionStart = newRedemptionStart.toUint32();
    }

    /**
     * @notice Function used to update the subscription ID
     * @param newSubscriptionId - the chainlink vrf subscription id
     */
    function setSubscriptionId(uint64 newSubscriptionId) public onlyOwner {
        s_subscriptionId = newSubscriptionId;
    }

    /**
     * @notice Function used to update the gas lane used by VRF
     * @param newKeyHash - the keyhash of the gaslane that VRF uses
     */
    function setKeyHash(bytes32 newKeyHash) public onlyOwner {
        s_keyHash = newKeyHash;
    }

    /**
     * @notice Function used to update the callback gas limit
     * @param newCallbackGasLimit - the gas limit of the fulfillRandomWords callback
     */
    function setCallbackGasLimit(uint32 newCallbackGasLimit) public onlyOwner {
        CALLBACK_GAS_LIMIT = newCallbackGasLimit;
    }

    /**
     * @notice Function that pauses the contract
     * @param isPaused - now what're we turning the pause to!?
     */
    function setPaused(bool isPaused) public onlyOwner {
        PAUSED = isPaused;
    }

    /**
     * @notice Function that allows the owner to update the max size of the pool
     * @param newMaxGifts - new max number of gifts in the pool
     */
    function setMaxGifts(uint32 newMaxGifts) public onlyOwner {
        if (s_giftPool.length > newMaxGifts) revert PoolSizeExceedsAmount();
        MAX_GIFTS = newMaxGifts;
    }

    //================//
    // Pool Shuffling //
    //================//

    /**
     * @notice Function that requests a random seed from VRF
     */
    function requestSeed() public onlyOwner {
        require(block.timestamp > s_registrationEnd, "Registration has not ended yet");
        SEED_REQUEST_ID = requestRandomWords(1);
        SHUFFLED = false;
    }

    /**
     * @notice Callback function used by VRF Coordinator
     * @param requestId - id of the request
     * @param randomWords - array of random results from VRF Coordinator
     */
    function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal override {
        if (SEED_REQUEST_ID == requestId) {
            SEED = randomWords[0];
            emit ReturnedRandomness(requestId, randomWords);
        }
    }

    /**
     * @notice Function that uses the SEED to shuffle the index array.
     * Just in case this ends up being a large array (Ho Ho Ho!), we will make it possible
     * to break this operation up into multiple calls
     * @param startPosition - the starting index we're shuffling
     * @param endPosition - the ending index we're shuffling
     */
    function shuffleRandomGiftIndices(uint32 startPosition, uint32 endPosition) public onlyOwner {
        require(SEED != 0, "SEED does not exist");
        require(endPosition >= startPosition, "End position must be after start position");

        // Make sure that we're not going to go out of bounds
        uint32 lastPosition = endPosition > s_giftPool.length - 1 ? uint32(s_giftPool.length - 1) : endPosition;

        // Shuffle the indices in the array
        for (uint32 i = startPosition; i <= lastPosition;) {
            uint32 j = uint32((uint256(keccak256(abi.encode(SEED, i))) % (s_giftPool.length)));
            (s_giftPoolIndices[i], s_giftPoolIndices[j]) = (s_giftPoolIndices[j], s_giftPoolIndices[i]);
            unchecked {
                i++;
            }
        }

        // Once we've shuffled the entire array, set the state to shuffled
        if (lastPosition == s_giftPool.length - 1) {
            SHUFFLED = true;
        }
    }

    //===================//
    // Signing/Verifying //
    //===================//

    /**
     * @notice returns an identifying contract hash to verify this contract
     */
    function getContractHash() public view virtual returns (bytes32) {
        return keccak256(abi.encode(block.chainid, address(this)));
    }

    /**
     * @notice Function used to hash a gift
     *
     * @param gifter - address of the gifter
     * @param nft - the address of the NFT being gifted
     * @param tokenId - the id of the NFT being gifted
     */
    function hashGift(address gifter, address nft, uint256 tokenId) public view virtual returns (bytes32) {
        bytes32 giftHash = keccak256(abi.encode(Gift(gifter, nft, tokenId)));
        return keccak256(abi.encode(getContractHash(), giftHash));
    }

    /**
     * @notice Function that validates that the gift hash signature was signed by the designated signer authority
     * @param gifter - address of the gifter
     * @param nft - the address of the NFT being gifted
     * @param tokenId - the id of the NFT being gifted
     * @param sig - the signature of the gift hash
     */
    function validateGiftHashSignature(address gifter, address nft, uint256 tokenId, bytes calldata sig)
        public
        view
        virtual
        returns (bool)
    {
        bytes32 giftHash = hashGift(gifter, nft, tokenId);
        bytes32 ethSignedMessageHash = giftHash.toEthSignedMessageHash();
        address signer = ethSignedMessageHash.recover(sig);
        return signer == s_signer;
    }

    //==========//
    // Internal //
    //==========//

    /**
     * @notice Checks that the gift is eligible to be added
     * @param nft - the address of the NFT being added
     * @param tokenId - the token id of the NFT being added
     * @dev This function leaves out the signature check so that inherited contracts can use custom logic
     */
    function _addGiftChecks(address nft, uint256 tokenId) internal view {
        // If the registration/adding gift end time has passed
        if (block.timestamp > s_registrationEnd) revert RegistrationEnded();
        // If the pool size has already reached its limit
        if (s_giftPool.length >= MAX_GIFTS) revert MaxGiftsReached();
        // If the gift is already a present, ya do-do!
        if (nft == address(PRESENT_NFT)) revert CannotGiftPresent();
        // If the gift doesn't support the ERC721 interface
        if (!giftSupports721(nft)) revert GiftMustSupportERC721Interface();
        // If the user doesn't own the nft they're adding
        if (IERC721(nft).ownerOf(tokenId) != msg.sender) revert MustOwnTokenId();
        // If the user hasn't individually approved this contract
        if (IERC721(nft).getApproved(tokenId) != address(this)) revert MustApproveContract();
    }

    /**
     * @notice Transfers the gift and present NFTs
     * @param nft - the address of the NFT being added
     * @param tokenId - the token id of the NFT being added
     */
    function _addGiftTransfers(address nft, uint256 tokenId)
        internal
        returns (address giftAddress, uint256 giftTokenId)
    {
        // Transfer the NFT from the caller to this contract
        IERC721(nft).safeTransferFrom(msg.sender, address(this), tokenId);
        // Mint a present NFT to the caller
        PRESENT_NFT.simpleMint(msg.sender);

        // Add the gift to the pool
        s_giftPool.push(Gift({gifter: msg.sender, nft: nft, tokenId: tokenId}));
        s_giftPoolIndices.push(uint32(s_giftPool.length - 1));

        emit GiftAdded(msg.sender, nft, tokenId);

        giftAddress = address(PRESENT_NFT);
        giftTokenId = s_giftPool.length;
    }

    /**
     * @notice Checks that the present is eligible to be opened
     * @param tokenId - the token id of the Present NFT
     */
    function _openGiftChecks(uint256 tokenId) internal view {
        // If redemptions haven't started yet
        if (block.timestamp < s_redemptionStart) revert RedemptionHasNotStarted();
        // If the pool has not been shuffled
        if (!SHUFFLED) revert HasNotBeenShuffled();
        // Make sure the caller owns the tokenId
        if (PRESENT_NFT.ownerOf(tokenId) != msg.sender) revert DoesNotOwnPresent();
    }

    /**
     * @notice Burns the present and sends the chosen gift to the user
     * @param tokenId - the token id of the Present NFT
     */
    function _openGiftTransfers(uint256 tokenId)
        internal
        returns (address chosenGiftAddress, uint256 chosenGiftTokenId)
    {
        // Select the randomized gift associated with the tokenId
        uint32 index = s_giftPoolIndices[tokenId - 1];
        Gift memory chosenGift = s_giftPool[index];

        // Trade the present for a random number
        PRESENT_NFT.burn(tokenId, msg.sender);
        s_chosenGifts[msg.sender].push(chosenGift);
        IERC721(chosenGift.nft).safeTransferFrom(address(this), msg.sender, chosenGift.tokenId);

        emit GiftChosen(msg.sender, tokenId, chosenGift.nft, chosenGift.tokenId);

        return (chosenGift.nft, chosenGift.tokenId);
    }

    /**
     * @notice Function that validates that the gift hash signature was signed by the designated signer authority
     * @param gifter - address of the gifter
     * @param nft - the address of the NFT being gifted
     * @param tokenId - the id of the NFT being gifted
     * @param sig - the signature of the gift hash
     * @dev Bypasses if signature isn't required
     */
    function _validateGiftHashSignatureIfRequired(address gifter, address nft, uint256 tokenId, bytes calldata sig)
        internal
        view
        virtual
        returns (bool)
    {
        if (!REQUIRES_SIGNATURE) return true;
        return validateGiftHashSignature(gifter, nft, tokenId, sig);
    }

    //======//
    // Misc //
    //======//

    /**
     * @notice OpenZeppelin requires ERC721Received implementation.
     */
    function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data)
        public
        override
        returns (bytes4)
    {
        emit ERC721Received(operator, from, tokenId, data);
        return this.onERC721Received.selector;
    }

    /**
     * @notice Function used to determine if a contract supports 721 interface
     * @param nft - the address of an NFT
     */
    function giftSupports721(address nft) public view returns (bool) {
        try IERC165(nft).supportsInterface(type(IERC721).interfaceId) returns (bool result) {
            return result;
        } catch {
            return false;
        }
    }

    //===========//
    // Modifiers //
    //===========//

    modifier isNotPaused() {
        require(!PAUSED, "The NFT Exchange is currently paused.");
        _;
    }
}

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

pragma solidity ^0.8.0;

import "./math/Math.sol";

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.2._
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v2.5._
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.2._
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v2.5._
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v2.5._
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v2.5._
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v2.5._
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     *
     * _Available since v3.0._
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.7._
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.7._
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     *
     * _Available since v3.0._
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

File 12 of 25 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC165.sol)

pragma solidity ^0.8.0;

import "../utils/introspection/IERC165.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);
    }
}

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

import {VRFCoordinatorV2Interface} from "chainlink/v0.8/vrf/interfaces/VRFCoordinatorV2Interface.sol";
import {VRFConsumerBaseV2} from "chainlink/v0.8/vrf/VRFConsumerBaseV2.sol";

/**
 * @title The RandomNumberConsumerV2 contract
 * @notice A contract that gets random values from Chainlink VRF V2
 */
contract RandomNumberConsumerV2 is VRFConsumerBaseV2 {
    VRFCoordinatorV2Interface immutable COORDINATOR;

    // VRF subscription ID.
    uint64 internal s_subscriptionId;

    // The gas lane to use, which specifies the maximum gas price to bump to.
    // For a list of available gas lanes on each network,
    // see https://docs.chain.link/docs/vrf-contracts/#configurations
    bytes32 internal s_keyHash;

    // Depends on the number of requested values that you want sent to the
    // fulfillRandomWords() function. Storing each word costs about 20,000 gas.
    uint32 internal CALLBACK_GAS_LIMIT = 100000;

    // The default is 3, but you can set this higher.
    uint16 constant REQUEST_CONFIRMATIONS = 3;

    // For this example, retrieve 2 random values in one request.
    // Cannot exceed VRFCoordinatorV2.MAX_NUM_WORDS.
    uint32 constant NUM_WORDS = 1;

    uint256[] public s_randomWords;
    uint256 public s_requestId;

    mapping(uint256 => address) public s_requestIdMapping;
    mapping(address => uint256[]) s_randomWordMapping;

    event ReturnedRandomness(uint256 requestId, uint256[] randomWords);
    event NewRandomNumberConsumerOwner(address newOwner);

    /**
     * @notice Constructor inherits VRFConsumerBaseV2
     *
     * @param subscriptionId - the subscription ID that this contract uses for funding requests
     * @param vrfCoordinator - coordinator, check https://docs.chain.link/docs/vrf-contracts/#configurations
     * @param keyHash - the gas lane to use, which specifies the maximum gas price to bump to
     */
    constructor(uint64 subscriptionId, address vrfCoordinator, bytes32 keyHash) VRFConsumerBaseV2(vrfCoordinator) {
        COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator);
        s_keyHash = keyHash;
        s_subscriptionId = subscriptionId;
    }

    /**
     * @notice Requests randomness
     * Assumes the subscription is funded sufficiently; "Words" refers to unit of data in Computer Science
     */
    function requestRandomWords(uint32 numberOfWords) internal returns (uint256 requestId) {
        // Will revert if subscription is not set and funded.
        requestId = COORDINATOR.requestRandomWords(
            s_keyHash, s_subscriptionId, REQUEST_CONFIRMATIONS, CALLBACK_GAS_LIMIT, numberOfWords
        );
        s_requestIdMapping[requestId] = msg.sender;
    }

    /**
     * @notice Callback function used by VRF Coordinator
     *
     * @param requestId - id of the request
     * @param randomWords - array of random results from VRF Coordinator
     */
    function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual override {
        s_randomWordMapping[s_requestIdMapping[requestId]] = randomWords;
        emit ReturnedRandomness(requestId, randomWords);
    }
}

// SPDX-License-Identifier: LGPL-3.0-only
// Created By: Prohibition / VenturePunk,LLC
// Written By: Thomas Lipari (thom.eth)
pragma solidity ^0.8.0;

import {ERC721} from "openzeppelin-contracts/token/ERC721/ERC721.sol";
import {Ownable} from "openzeppelin-contracts/access/Ownable.sol";
import {Strings} from "openzeppelin-contracts/utils/Strings.sol";
import {Base64} from "openzeppelin-contracts/utils/Base64.sol";

/**
 * @title The WrappedPresent contract
 * @author Thomas Lipari (thom.eth)
 * @notice A contract that represents a random gift in the Santa.fm Gift Exchange
 */
contract WrappedPresent is Ownable, ERC721 {
    using Strings for uint256;

    // Designated Minter Role
    address public minter;
    // URL for the image returned in the token's metadata
    string internal tokenImage;
    // Counter for tokens minted
    uint256 public totalTokensMinted;
    // Counter for tokens burned
    uint256 public totalTokensBurned;
    // Year of the gift exchange
    uint256 public year;
    // URL of the gift exchange dapp ui
    string public url;

    // Mapping of burned tokens by address
    mapping(address burnerAccount => uint256[] burnedTokenIds) public burnedBy;
    // Mapping of of whether or not a token has been burned
    mapping(uint256 tokenId => bool hasBeenBurned) public burned;

    // Error for when an account doesn't own a token when burning
    error OnlyOwnerCanBurnThroughMinter();

    // Event for burning tokens
    event Burn(uint256 tokenId, address account);

    constructor(
        string memory _name,
        string memory _symbol,
        string memory _tokenImage,
        string memory _url,
        uint256 _year
    ) Ownable() ERC721(_name, _symbol) {
        tokenImage = _tokenImage;
        url = _url;
        year = _year;
    }

    /*
     * Owner Functions
     */

    /**
     * @notice Function that sets the image to be returned in Token URI
     * @param _tokenImage - The tokenId we're checking
     */
    function setTokenImage(string memory _tokenImage) public onlyOwner {
        tokenImage = _tokenImage;
    }

    /**
     * @notice Function that updates the designated minter
     * @param _minter - The address of the new minter
     */
    function setMinter(address _minter) public onlyOwner {
        minter = _minter;
    }

    /**
     * @notice Function that transfers a tokenId
     * @param from - The sender of the transfer
     * @param to - The receiver of the transfer
     * @param tokenId - TokenID of the token being transferred
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) public override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /*
     * Minter Functions
     */

    /**
     * @notice Function that mints an NFT. Can only be called by `minter`
     * @param to - The address that receives the minted NFT
     */
    function simpleMint(address to) public onlyMinter {
        // increment number of tokens minted
        totalTokensMinted += 1;

        // mint the token to the address
        _mint(to, totalTokensMinted);
    }

    /**
     * @notice Function that burns a present
     * @param tokenId - The tokenId to burn
     * @param account - The account that owns the token
     *
     * @dev [WARNING!] Be sure that when using this function, the `account` actually owns `tokenId`
     */
    function burn(uint256 tokenId, address account) public onlyMinter {
        // Since _burn does not check approval for burning, we have to make sure that the
        // designated Minter only passes the correct owner of the token as `account`
        if (ownerOf(tokenId) != account) revert OnlyOwnerCanBurnThroughMinter();

        // burn the token.
        _burn(tokenId);

        // keep track of burnings
        totalTokensBurned += 1;
        burnedBy[account].push(tokenId);
        burned[tokenId] = true;

        // emit our event
        emit Burn(tokenId, account);
    }

    /*
     * URI Functions
     */

    /**
     * @notice Function that returns the Contract URI
     */
    function contractURI() public view returns (string memory) {
        return string(
            abi.encodePacked(
                "data:application/json;base64,",
                Base64.encode(
                    bytes(
                        string(
                            abi.encodePacked(
                                '{"name": "Santa.FM NFT Gift Exchange", ',
                                '"description": "Santa.fm Presents are NFTs from the NFT Gift Exchange pool. Add a NFT gift to the pool and receive a NFT Present in return that you open on Christmas morning.", ',
                                '"external_link": "',
                                url,
                                '" }'
                            )
                        )
                    )
                )
            )
        );
    }

    /**
     * @notice Function that returns the URI for a token
     * @param id - Token ID we're referencing
     */
    function tokenURI(uint256 id) public view override returns (string memory) {
        // Fail if token hasn't been minted
        require(id <= totalTokensMinted);

        // Fail if token has been burned
        require(!burned[id]);

        return string(
            abi.encodePacked(
                "data:application/json;base64,",
                Base64.encode(
                    bytes(
                        string(
                            abi.encodePacked(
                                '{"name": "Wrapped Present #',
                                id.toString(),
                                '", ',
                                '"description": "Wrapped Presents are given to you when you add an NFT to the Gift Dexchange. Use this present to redeem a random gift on Christmas Day!", ',
                                '"image": "',
                                tokenImage,
                                '", "attributes": [{"trait_type": "Gift", "value": "Wrapped Present"}, {"trait_type": "Year", "value": "',
                                year.toString(),
                                '" }]}'
                            )
                        )
                    )
                )
            )
        );
    }

    /*
     * Modifiers
     */

    modifier onlyMinter() {
        require(msg.sender == minter);
        _;
    }
}

// SPDX-License-Identifier: LGPL-3.0-only
// Created By: Prohibition / VenturePunk,LLC
// Written By: Thomas Lipari (thom.eth)
pragma solidity ^0.8.23;

/**
 * @title The SantaProtocol contract
 * @author Thomas Lipari (thom.eth)
 * @notice A contract that lets people deposit an NFT into a pool and then later lets them randomly redeem another one using Chainlink VRF2
 */
interface ISantaProtocol {
    //=========//
    // Structs //
    //=========//

    // Struct to store gifts in the pool
    struct Gift {
        address gifter;
        address nft;
        uint256 tokenId;
    }

    //========//
    // Errors //
    //========//

    error RedemptionMustHappenAfterRegistration();
    error GiftMustSupportERC721Interface();
    error InvalidSenderMustNotBeContract();
    error RedemptionHasNotStarted();
    error PoolSizeExceedsAmount();
    error MustApproveContract();
    error HasNotBeenShuffled();
    error DoesNotOwnPresent();
    error RegistrationEnded();
    error CannotGiftPresent();
    error InvalidSignature();
    error MaxGiftsReached();
    error MustOwnTokenId();

    //========//
    // Events //
    //========//

    event ERC721Received(address operator, address from, uint256 tokenId, bytes data);
    event GiftAdded(address gifter, address nft, uint256 tokenId);
    event GiftChosen(address account, uint256 presentTokenId, address nft, uint256 tokenId);

    //=========================//
    // Gift Exchange Functions //
    //=========================//

    /**
     * @notice Function used to add an NFT to the pool.
     * @param nft - the address of the NFT being added
     * @param tokenId - the token id of the NFT being added
     * @param sig - a message signed by the signer address verifying the NFT is eligible
     */
    function addGift(address nft, uint256 tokenId, bytes calldata sig)
        external
        returns (address giftAddress, uint256 giftTokenId);

    /**
     * @notice Function used to burn a Present NFT and redeem the gift in the pool it's been tied to
     * @param tokenId - the token id of the Present NFT being burned
     */
    function openGift(uint256 tokenId) external returns (address chosenGiftAddress, uint256 chosenGiftTokenId);

    //================//
    // View Functions //
    //================//

    /**
     * @notice Get the number of NFTs in the gift pool
     */
    function getSigner() external view returns (address);

    /**
     * @notice Get the number of NFTs in the gift pool
     */
    function getRegistrationEnd() external view returns (uint256);

    /**
     * @notice Get the number of NFTs in the gift pool
     */
    function getRedemptionStart() external view returns (uint256);

    /**
     * @notice Get the number of NFTs in the gift pool
     */
    function getGiftPoolSize() external view returns (uint256);

    /**
     * @notice Get the whole gift pool
     * @dev intended for offchain use only
     */
    function getGiftPool() external view returns (Gift[] memory);

    /**
     * @notice Get the number of gifts that a user has randomly chosen
     * @param account - the wallet address of the user
     */
    function getNumberOfChosenGifts(address account) external view returns (uint256);

    /**
     * @notice Get the array of gifts that a user has randomly chosen
     * @param account - the wallet address of the user
     * @dev intended for offchain use only
     */
    function getChosenGifts(address account) external view returns (Gift[] memory);

    //=================//
    // Admin Functions //
    //=================//

    /**
     * @notice Set signer to new account
     * @param newSigner - the addres of the new owner
     */
    function setSigner(address newSigner) external;

    /**
     * @notice Set the time that adding gifts ends
     * @param newRegistrationEnd - the new s_registerationEnd time
     */
    function setRegistrationEnd(uint256 newRegistrationEnd) external;

    /**
     * @notice Set the time that claiming a random gift starts
     * @param newRedemptionStart - the new s_redemptionStart time
     */
    function setRedemptionStart(uint256 newRedemptionStart) external;

    /**
     * @notice Function used to update the subscription ID
     * @param newSubscriptionId - the chainlink vrf subscription id
     */
    function setSubscriptionId(uint64 newSubscriptionId) external;

    /**
     * @notice Function used to update the gas lane used by VRF
     * @param newKeyHash - the keyhash of the gaslane that VRF uses
     */
    function setKeyHash(bytes32 newKeyHash) external;

    /**
     * @notice Function used to update the callback gas limit
     * @param newCallbackGasLimit - the gas limit of the fulfillRandomWords callback
     */
    function setCallbackGasLimit(uint32 newCallbackGasLimit) external;

    /**
     * @notice Function that pauses the contract
     * @param isPaused - now what're we turning the pause to!?
     */
    function setPaused(bool isPaused) external;

    /**
     * @notice Function that allows the owner to update the max size of the pool
     * @param newMaxGifts - new max number of gifts in the pool
     */
    function setMaxGifts(uint32 newMaxGifts) external;

    //================//
    // Pool Shuffling //
    //================//

    /**
     * @notice Function that requests a random seed from VRF
     */
    function requestSeed() external;

    /**
     * @notice Function that uses the SEED to shuffle the index array.
     * Just in case this ends up being a large array (Ho Ho Ho!), we will make it possible
     * to break this operation up into multiple calls
     * @param startPosition - the starting index we're shuffling
     * @param endPosition - the ending index we're shuffling
     */
    function shuffleRandomGiftIndices(uint32 startPosition, uint32 endPosition) external;

    //===================//
    // Signing/Verifying //
    //===================//

    /**
     * @notice Function used to hash a gift
     * @param gifter - address of the gifter
     * @param nft - the address of the NFT being gifted
     * @param tokenId - the id of the NFT being gifted
     */
    function hashGift(address gifter, address nft, uint256 tokenId) external view returns (bytes32);

    /**
     * @notice Function that valifates that the gift hash signature was signed by the designated signer authority
     * @param gifter - address of the gifter
     * @param nft - the address of the NFT being gifted
     * @param tokenId - the id of the NFT being gifted
     * @param sig - the signature of the gift hash
     */
    function validateGiftHashSignature(address gifter, address nft, uint256 tokenId, bytes calldata sig)
        external
        view
        returns (bool);

    //======//
    // Misc //
    //======//

    /**
     * @notice Function used to determine if a contract supports 721 interface
     * @param nft - the address of an NFT
     */
    function giftSupports721(address nft) external view returns (bool);
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

interface VRFCoordinatorV2Interface {
  /**
   * @notice Get configuration relevant for making requests
   * @return minimumRequestConfirmations global min for request confirmations
   * @return maxGasLimit global max for request gas limit
   * @return s_provingKeyHashes list of registered key hashes
   */
  function getRequestConfig() external view returns (uint16, uint32, bytes32[] memory);

  /**
   * @notice Request a set of random words.
   * @param keyHash - Corresponds to a particular oracle job which uses
   * that key for generating the VRF proof. Different keyHash's have different gas price
   * ceilings, so you can select a specific one to bound your maximum per request cost.
   * @param subId  - The ID of the VRF subscription. Must be funded
   * with the minimum subscription balance required for the selected keyHash.
   * @param minimumRequestConfirmations - How many blocks you'd like the
   * oracle to wait before responding to the request. See SECURITY CONSIDERATIONS
   * for why you may want to request more. The acceptable range is
   * [minimumRequestBlockConfirmations, 200].
   * @param callbackGasLimit - How much gas you'd like to receive in your
   * fulfillRandomWords callback. Note that gasleft() inside fulfillRandomWords
   * may be slightly less than this amount because of gas used calling the function
   * (argument decoding etc.), so you may need to request slightly more than you expect
   * to have inside fulfillRandomWords. The acceptable range is
   * [0, maxGasLimit]
   * @param numWords - The number of uint256 random values you'd like to receive
   * in your fulfillRandomWords callback. Note these numbers are expanded in a
   * secure way by the VRFCoordinator from a single random value supplied by the oracle.
   * @return requestId - A unique identifier of the request. Can be used to match
   * a request to a response in fulfillRandomWords.
   */
  function requestRandomWords(
    bytes32 keyHash,
    uint64 subId,
    uint16 minimumRequestConfirmations,
    uint32 callbackGasLimit,
    uint32 numWords
  ) external returns (uint256 requestId);

  /**
   * @notice Create a VRF subscription.
   * @return subId - A unique subscription id.
   * @dev You can manage the consumer set dynamically with addConsumer/removeConsumer.
   * @dev Note to fund the subscription, use transferAndCall. For example
   * @dev  LINKTOKEN.transferAndCall(
   * @dev    address(COORDINATOR),
   * @dev    amount,
   * @dev    abi.encode(subId));
   */
  function createSubscription() external returns (uint64 subId);

  /**
   * @notice Get a VRF subscription.
   * @param subId - ID of the subscription
   * @return balance - LINK balance of the subscription in juels.
   * @return reqCount - number of requests for this subscription, determines fee tier.
   * @return owner - owner of the subscription.
   * @return consumers - list of consumer address which are able to use this subscription.
   */
  function getSubscription(
    uint64 subId
  ) external view returns (uint96 balance, uint64 reqCount, address owner, address[] memory consumers);

  /**
   * @notice Request subscription owner transfer.
   * @param subId - ID of the subscription
   * @param newOwner - proposed new owner of the subscription
   */
  function requestSubscriptionOwnerTransfer(uint64 subId, address newOwner) external;

  /**
   * @notice Request subscription owner transfer.
   * @param subId - ID of the subscription
   * @dev will revert if original owner of subId has
   * not requested that msg.sender become the new owner.
   */
  function acceptSubscriptionOwnerTransfer(uint64 subId) external;

  /**
   * @notice Add a consumer to a VRF subscription.
   * @param subId - ID of the subscription
   * @param consumer - New consumer which can use the subscription
   */
  function addConsumer(uint64 subId, address consumer) external;

  /**
   * @notice Remove a consumer from a VRF subscription.
   * @param subId - ID of the subscription
   * @param consumer - Consumer to remove from the subscription
   */
  function removeConsumer(uint64 subId, address consumer) external;

  /**
   * @notice Cancel a subscription
   * @param subId - ID of the subscription
   * @param to - Where to send the remaining LINK to
   */
  function cancelSubscription(uint64 subId, address to) external;

  /*
   * @notice Check to see if there exists a request commitment consumers
   * for all consumers and keyhashes for a given sub.
   * @param subId - ID of the subscription
   * @return true if there exists at least one unfulfilled request for the subscription, false
   * otherwise.
   */
  function pendingRequestExists(uint64 subId) external view returns (bool);
}

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

/** ****************************************************************************
 * @notice Interface for contracts using VRF randomness
 * *****************************************************************************
 * @dev PURPOSE
 *
 * @dev Reggie the Random Oracle (not his real job) wants to provide randomness
 * @dev to Vera the verifier in such a way that Vera can be sure he's not
 * @dev making his output up to suit himself. Reggie provides Vera a public key
 * @dev to which he knows the secret key. Each time Vera provides a seed to
 * @dev Reggie, he gives back a value which is computed completely
 * @dev deterministically from the seed and the secret key.
 *
 * @dev Reggie provides a proof by which Vera can verify that the output was
 * @dev correctly computed once Reggie tells it to her, but without that proof,
 * @dev the output is indistinguishable to her from a uniform random sample
 * @dev from the output space.
 *
 * @dev The purpose of this contract is to make it easy for unrelated contracts
 * @dev to talk to Vera the verifier about the work Reggie is doing, to provide
 * @dev simple access to a verifiable source of randomness. It ensures 2 things:
 * @dev 1. The fulfillment came from the VRFCoordinator
 * @dev 2. The consumer contract implements fulfillRandomWords.
 * *****************************************************************************
 * @dev USAGE
 *
 * @dev Calling contracts must inherit from VRFConsumerBase, and can
 * @dev initialize VRFConsumerBase's attributes in their constructor as
 * @dev shown:
 *
 * @dev   contract VRFConsumer {
 * @dev     constructor(<other arguments>, address _vrfCoordinator, address _link)
 * @dev       VRFConsumerBase(_vrfCoordinator) public {
 * @dev         <initialization with other arguments goes here>
 * @dev       }
 * @dev   }
 *
 * @dev The oracle will have given you an ID for the VRF keypair they have
 * @dev committed to (let's call it keyHash). Create subscription, fund it
 * @dev and your consumer contract as a consumer of it (see VRFCoordinatorInterface
 * @dev subscription management functions).
 * @dev Call requestRandomWords(keyHash, subId, minimumRequestConfirmations,
 * @dev callbackGasLimit, numWords),
 * @dev see (VRFCoordinatorInterface for a description of the arguments).
 *
 * @dev Once the VRFCoordinator has received and validated the oracle's response
 * @dev to your request, it will call your contract's fulfillRandomWords method.
 *
 * @dev The randomness argument to fulfillRandomWords is a set of random words
 * @dev generated from your requestId and the blockHash of the request.
 *
 * @dev If your contract could have concurrent requests open, you can use the
 * @dev requestId returned from requestRandomWords to track which response is associated
 * @dev with which randomness request.
 * @dev See "SECURITY CONSIDERATIONS" for principles to keep in mind,
 * @dev if your contract could have multiple requests in flight simultaneously.
 *
 * @dev Colliding `requestId`s are cryptographically impossible as long as seeds
 * @dev differ.
 *
 * *****************************************************************************
 * @dev SECURITY CONSIDERATIONS
 *
 * @dev A method with the ability to call your fulfillRandomness method directly
 * @dev could spoof a VRF response with any random value, so it's critical that
 * @dev it cannot be directly called by anything other than this base contract
 * @dev (specifically, by the VRFConsumerBase.rawFulfillRandomness method).
 *
 * @dev For your users to trust that your contract's random behavior is free
 * @dev from malicious interference, it's best if you can write it so that all
 * @dev behaviors implied by a VRF response are executed *during* your
 * @dev fulfillRandomness method. If your contract must store the response (or
 * @dev anything derived from it) and use it later, you must ensure that any
 * @dev user-significant behavior which depends on that stored value cannot be
 * @dev manipulated by a subsequent VRF request.
 *
 * @dev Similarly, both miners and the VRF oracle itself have some influence
 * @dev over the order in which VRF responses appear on the blockchain, so if
 * @dev your contract could have multiple VRF requests in flight simultaneously,
 * @dev you must ensure that the order in which the VRF responses arrive cannot
 * @dev be used to manipulate your contract's user-significant behavior.
 *
 * @dev Since the block hash of the block which contains the requestRandomness
 * @dev call is mixed into the input to the VRF *last*, a sufficiently powerful
 * @dev miner could, in principle, fork the blockchain to evict the block
 * @dev containing the request, forcing the request to be included in a
 * @dev different block with a different hash, and therefore a different input
 * @dev to the VRF. However, such an attack would incur a substantial economic
 * @dev cost. This cost scales with the number of blocks the VRF oracle waits
 * @dev until it calls responds to a request. It is for this reason that
 * @dev that you can signal to an oracle you'd like them to wait longer before
 * @dev responding to the request (however this is not enforced in the contract
 * @dev and so remains effective only in the case of unmodified oracle software).
 */
abstract contract VRFConsumerBaseV2 {
  error OnlyCoordinatorCanFulfill(address have, address want);
  // solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i
  address private immutable vrfCoordinator;

  /**
   * @param _vrfCoordinator address of VRFCoordinator contract
   */
  constructor(address _vrfCoordinator) {
    vrfCoordinator = _vrfCoordinator;
  }

  /**
   * @notice fulfillRandomness handles the VRF response. Your contract must
   * @notice implement it. See "SECURITY CONSIDERATIONS" above for important
   * @notice principles to keep in mind when implementing your fulfillRandomness
   * @notice method.
   *
   * @dev VRFConsumerBaseV2 expects its subcontracts to have a method with this
   * @dev signature, and will call it once it has verified the proof
   * @dev associated with the randomness. (It is triggered via a call to
   * @dev rawFulfillRandomness, below.)
   *
   * @param requestId The Id initially returned by requestRandomness
   * @param randomWords the VRF output expanded to the requested number of words
   */
  // solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore
  function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual;

  // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF
  // proof. rawFulfillRandomness then calls fulfillRandomness, after validating
  // the origin of the call
  function rawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external {
    if (msg.sender != vrfCoordinator) {
      revert OnlyCoordinatorCanFulfill(msg.sender, vrfCoordinator);
    }
    fulfillRandomWords(requestId, randomWords);
  }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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 = _ownerOf(tokenId);
        require(owner != address(0), "ERC721: invalid token ID");
        return owner;
    }

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

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

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

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

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

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

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

        _approve(to, tokenId);
    }

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

        return _tokenApprovals[tokenId];
    }

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

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

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

        _transfer(from, to, tokenId);
    }

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

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

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

    /**
     * @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
     */
    function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
        return _owners[tokenId];
    }

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

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
        address owner = 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, 1);

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

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

        _owners[tokenId] = to;

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

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

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

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

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

        // Clear approvals
        delete _tokenApprovals[tokenId];

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

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

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

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

        _beforeTokenTransfer(from, to, tokenId, 1);

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

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

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

        emit Transfer(from, to, tokenId);

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

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits an {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(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. If {ERC721Consecutive} is
     * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`.
     * - When `from` is zero, the tokens will be minted for `to`.
     * - When `to` is zero, ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     * - `batchSize` is non-zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256, /* firstTokenId */
        uint256 batchSize
    ) internal virtual {
        if (batchSize > 1) {
            if (from != address(0)) {
                _balances[from] -= batchSize;
            }
            if (to != address(0)) {
                _balances[to] += batchSize;
            }
        }
    }

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

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

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

pragma solidity ^0.8.0;

import "../IERC721.sol";

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

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

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

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

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "./IERC165.sol";

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

Settings
{
  "remappings": [
    "@delegate-registry/=lib/delegate-registry/src/",
    "ERC721A-Upgradeable/=lib/ERC721A-Upgradeable/contracts/",
    "ERC721A/=lib/ERC721A/contracts/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/operator-filter-registry/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/",
    "operator-filter-registry/=lib/operator-filter-registry/src/",
    "diamond/=lib/diamond-2-hardhat/contracts/",
    "nouns-monorepo/=lib/nouns-monorepo/packages/nouns-contracts/contracts/",
    "chainlink/=lib/chainlink/contracts/src/",
    "src/=src/",
    "@eth-optimism/=lib/chainlink/contracts/node_modules/@eth-optimism/contracts/",
    "@openzeppelin/=lib/chainlink/contracts/node_modules/@openzeppelin/",
    "delegate-registry/=lib/delegate-registry/",
    "diamond-2-hardhat/=lib/diamond-2-hardhat/contracts/",
    "hardhat/=lib/chainlink/contracts/node_modules/hardhat/",
    "murky/=lib/delegate-registry/lib/murky/",
    "openzeppelin/=lib/delegate-registry/lib/openzeppelin-contracts/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 20000
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"uint64","name":"subscriptionId","type":"uint64"},{"internalType":"address","name":"vrfCoordinator","type":"address"},{"internalType":"bytes32","name":"keyHash","type":"bytes32"},{"internalType":"uint256","name":"registrationEnd","type":"uint256"},{"internalType":"uint256","name":"redemptionStart","type":"uint256"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"presentNft","type":"address"},{"internalType":"address","name":"tokenGateNft","type":"address"},{"internalType":"uint32","name":"tokenGateLimit","type":"uint32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"CannotGiftPresent","type":"error"},{"inputs":[],"name":"DoesNotOwnPresent","type":"error"},{"inputs":[],"name":"GiftMustSupportERC721Interface","type":"error"},{"inputs":[],"name":"HasNotBeenShuffled","type":"error"},{"inputs":[],"name":"InvalidSenderMustNotBeContract","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"MaxGiftsReached","type":"error"},{"inputs":[],"name":"MustApproveContract","type":"error"},{"inputs":[],"name":"MustOwnTokenId","type":"error"},{"inputs":[],"name":"NotTokenGateCollection","type":"error"},{"inputs":[],"name":"NotTokenGatedCollectionHolder","type":"error"},{"inputs":[],"name":"NotTokenGatedTokenHolder","type":"error"},{"inputs":[{"internalType":"address","name":"have","type":"address"},{"internalType":"address","name":"want","type":"address"}],"name":"OnlyCoordinatorCanFulfill","type":"error"},{"inputs":[],"name":"PoolIsNotTokenGated","type":"error"},{"inputs":[],"name":"PoolSizeExceedsAmount","type":"error"},{"inputs":[],"name":"RedemptionHasNotStarted","type":"error"},{"inputs":[],"name":"RedemptionMustHappenAfterRegistration","type":"error"},{"inputs":[],"name":"RegistrationEnded","type":"error"},{"inputs":[],"name":"TokenGateLimitReached","type":"error"},{"inputs":[],"name":"TokenGated","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"ERC721Received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"gifter","type":"address"},{"indexed":false,"internalType":"address","name":"nft","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"GiftAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"presentTokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"nft","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"GiftChosen","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"NewRandomNumberConsumerOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"randomWords","type":"uint256[]"}],"name":"ReturnedRandomness","type":"event"},{"inputs":[],"name":"DELEGATE_REGISTRY","outputs":[{"internalType":"contract IDelegateRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_GIFTS","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSED","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRESENT_NFT","outputs":[{"internalType":"contract WrappedPresent","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REQUIRES_SIGNATURE","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SEED","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SEED_REQUEST_ID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SHUFFLED","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SUPPORTS_DELEGATES","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN_GATE_CONTRACT","outputs":[{"internalType":"contract IERC721","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TOKEN_GATE_LIMIT","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenGateNft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"_tokenGateNftUsed","outputs":[{"internalType":"uint32","name":"usedCount","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"tokenGateNft","type":"address"},{"internalType":"uint256","name":"tokenGateTokenId","type":"uint256"},{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"addGift","outputs":[{"internalType":"address","name":"giftAddress","type":"address"},{"internalType":"uint256","name":"giftTokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"addGift","outputs":[{"internalType":"address","name":"giftAddress","type":"address"},{"internalType":"uint256","name":"giftTokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getChosenGifts","outputs":[{"components":[{"internalType":"address","name":"gifter","type":"address"},{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"internalType":"struct ISantaProtocol.Gift[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getContractHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getGiftPool","outputs":[{"components":[{"internalType":"address","name":"gifter","type":"address"},{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"internalType":"struct ISantaProtocol.Gift[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getGiftPoolSize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getNumberOfChosenGifts","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRedemptionStart","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRegistrationEnd","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSupportsDelegates","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTokenGateContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"tokenGateNft","type":"address"},{"internalType":"uint256","name":"tokenGateTokenId","type":"uint256"}],"name":"getTokenGateEligibility","outputs":[{"internalType":"bool","name":"eligible","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"nft","type":"address"}],"name":"giftSupports721","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"gifter","type":"address"},{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"hashGift","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"gifter","type":"address"},{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"tokenGateNft","type":"address"},{"internalType":"uint256","name":"tokenGateTokenId","type":"uint256"}],"name":"hashTokenGateGift","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"openGift","outputs":[{"internalType":"address","name":"chosenGiftAddress","type":"address"},{"internalType":"uint256","name":"chosenGiftTokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"uint256[]","name":"randomWords","type":"uint256[]"}],"name":"rawFulfillRandomWords","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"requestSeed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"s_randomWords","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"s_requestId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"s_requestIdMapping","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"newCallbackGasLimit","type":"uint32"}],"name":"setCallbackGasLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"newKeyHash","type":"bytes32"}],"name":"setKeyHash","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"newMaxGifts","type":"uint32"}],"name":"setMaxGifts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"isPaused","type":"bool"}],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newRedemptionStart","type":"uint256"}],"name":"setRedemptionStart","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newRegistrationEnd","type":"uint256"}],"name":"setRegistrationEnd","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newSigner","type":"address"}],"name":"setSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"newSubscriptionId","type":"uint64"}],"name":"setSubscriptionId","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newTokenGateNft","type":"address"}],"name":"setTokenGateContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"newTokenGateLimit","type":"uint32"}],"name":"setTokenGateLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"startPosition","type":"uint32"},{"internalType":"uint32","name":"endPosition","type":"uint32"}],"name":"shuffleRandomGiftIndices","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"toggleSignatureRequired","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"toggleSupportsDelegates","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"gifter","type":"address"},{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"validateGiftHashSignature","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"gifter","type":"address"},{"internalType":"address","name":"nft","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"tokenGateNft","type":"address"},{"internalType":"uint256","name":"tokenGateTokenId","type":"uint256"},{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"validateTokenGateSignature","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]

60e06040526002805463ffffffff1916620186a0179055600b805466010000c350000066ffffffffffffff19909116179055600e805460ff60c01b1916600160c01b1790553480156200005157600080fd5b5060405162003e7838038062003e78833981016040819052620000749162000285565b88888888888888868686816200008a33620001aa565b6001600160a01b039081166080529190911660a052600155600080546001600160401b03909216600160a01b02600160a01b600160e01b0319909216919091179055620000d784620001fa565b6007805463ffffffff92909216600160a01b0263ffffffff60a01b199092169190911790556200010783620001fa565b600780547fffffffff00000000ffffffff000000000000000000000000000000000000000016600160c01b63ffffffff93909316929092026001600160a01b031916919091176001600160a01b03938416179055811660c05287161594506200019b935050505057600e805463ffffffff8316600160a01b026001600160c01b03199091166001600160a01b038516171790555b5050505050505050506200033e565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600063ffffffff821115620002645760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201526532206269747360d01b606482015260840160405180910390fd5b5090565b80516001600160a01b03811681146200028057600080fd5b919050565b60008060008060008060008060006101208a8c031215620002a557600080fd5b89516001600160401b0381168114620002bd57600080fd5b9850620002cd60208b0162000268565b975060408a0151965060608a0151955060808a01519450620002f260a08b0162000268565b93506200030260c08b0162000268565b92506200031260e08b0162000268565b91506101008a015163ffffffff811681146200032d57600080fd5b809150509295985092959850929598565b60805160a05160c051613ae062000398600039600081816108a60152818161208b015281816125b5015281816127c6015281816129f20152612b9401526000611db1015260008181610b440152610bac0152613ae06000f3fe608060405234801561001057600080fd5b50600436106103575760003560e01c8063964da0db116101c8578063e067510c11610104578063f2fde38b116100a2578063f6eaffc81161007c578063f6eaffc81461087b578063f76117c51461088e578063fbcfbad4146108a1578063ff512615146108c857600080fd5b8063f2fde38b1461084d578063f3fecc0b14610860578063f4e3ae6f1461087357600080fd5b8063e89e106a116100de578063e89e106a1461080b578063ea7b4f7714610814578063f1bead9b14610827578063f27010e91461083a57600080fd5b8063e067510c146107c3578063e43db9af146107d6578063e81c2340146107ed57600080fd5b8063a9aad58c11610171578063bf7852001161014b578063bf78520014610734578063c48de91f14610773578063cb111cf814610786578063cf51fb9d1461079957600080fd5b8063a9aad58c146106ff578063af25c1e71461070c578063bab556a71461071457600080fd5b8063998dc690116101a2578063998dc690146106ce578063a0c70d69146106d6578063a4eb718c146106ec57600080fd5b8063964da0db1461069657806397e8db30146106a957806398544710146106bb57600080fd5b80636c19e783116102975780637af9f01011610240578063889dae131161021a578063889dae131461062b5780638d17e3ac1461063e5780638da5cb5b1461065157806395de3cef1461066f57600080fd5b80637af9f010146105ef5780638286eee21461060257806385dfc7e41461061657600080fd5b8063798713871161027157806379871387146105885780637a33d5ae1461059b5780637ac3c02f146105d157600080fd5b80636c19e78314610534578063715018a61461054757806375dac0c91461054f57600080fd5b806316c38b3c116103045780635183d62f116102de5780635183d62f14610445578063521a179e1461048b5780636081051f146104e65780636b22d54a1461050c57600080fd5b806316c38b3c146104165780631fe543e31461042957806347c76ef11461043c57600080fd5b80630edc4737116103355780630edc4737146103c1578063114bf2e3146103ca578063150b7a02146103d257600080fd5b80630770e2381461035c57806309b98ce8146103995780630a367704146103ae575b600080fd5b60408051466020808301919091523082840152825180830384018152606090920190925280519101205b6040519081526020015b60405180910390f35b6103ac6103a73660046132d9565b6108db565b005b6103ac6103bc3660046132d9565b610962565b610386600c5481565b6103ac6109b9565b6103e56103e0366004613358565b610a86565b6040517fffffffff000000000000000000000000000000000000000000000000000000009091168152602001610390565b6103ac6104243660046133d9565b610af3565b6103ac610437366004613425565b610b2c565b610386600d5481565b61047661045336600461350d565b600f60209081526000928352604080842090915290825290205463ffffffff1681565b60405163ffffffff9091168152602001610390565b6104c1610499366004613539565b60056020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610390565b60075474010000000000000000000000000000000000000000900463ffffffff16610386565b600e546104769074010000000000000000000000000000000000000000900463ffffffff1681565b6103ac610542366004613552565b610be7565b6103ac610c36565b600e54610578907801000000000000000000000000000000000000000000000000900460ff1681565b6040519015158152602001610390565b61038661059636600461356f565b610c4a565b6103866105a9366004613552565b73ffffffffffffffffffffffffffffffffffffffff166000908152600a602052604090205490565b60075473ffffffffffffffffffffffffffffffffffffffff166104c1565b6103ac6105fd366004613539565b610cfa565b6104c16c447e69651d841bd8d104bed49381565b61061e610d87565b60405161039091906135ca565b610386610639366004613649565b610e1b565b6103ac61064c366004613539565b610efa565b60005473ffffffffffffffffffffffffffffffffffffffff166104c1565b600e547801000000000000000000000000000000000000000000000000900460ff16610578565b6105786106a4366004613552565b610fbc565b600b5461057890610100900460ff1681565b6103ac6106c9366004613539565b61109a565b600854610386565b600b546104769062010000900463ffffffff1681565b6103ac6106fa3660046132d9565b6110a7565b600b546105789060ff1681565b6103ac6110e6565b600e546104c19073ffffffffffffffffffffffffffffffffffffffff1681565b61074761074236600461368a565b61112d565b6040805173ffffffffffffffffffffffffffffffffffffffff9093168352602083019190915201610390565b610578610781366004613358565b611287565b61061e610794366004613552565b611361565b6007547801000000000000000000000000000000000000000000000000900463ffffffff16610386565b6107476107d1366004613706565b611418565b600b54610578906601000000000000900460ff1681565b600e5473ffffffffffffffffffffffffffffffffffffffff166104c1565b61038660045481565b6103ac610822366004613762565b61151a565b6103ac610835366004613552565b611575565b6103ac61084836600461378c565b6115c4565b6103ac61085b366004613552565b6118e7565b61074761086e366004613539565b61199e565b6103ac611a52565b610386610889366004613539565b611aab565b61057861089c366004613649565b611acc565b6104c17f000000000000000000000000000000000000000000000000000000000000000081565b6105786108d63660046137bf565b611bd2565b6108e3611cb2565b60085463ffffffff82161015610925576040517f2cfbb4f800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600b805463ffffffff90921662010000027fffffffffffffffffffffffffffffffffffffffffffffffffffff00000000ffff909216919091179055565b61096a611cb2565b600e805463ffffffff90921674010000000000000000000000000000000000000000027fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff909216919091179055565b6109c1611cb2565b60075474010000000000000000000000000000000000000000900463ffffffff164211610a4f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f526567697374726174696f6e20686173206e6f7420656e64656420796574000060448201526064015b60405180910390fd5b610a596001611d33565b600d55600b80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff169055565b60007fa05d90f300156ad1b545bc5d8197024456f21d22a708f5af04dd293e3d6052518686868686604051610abf95949392919061384e565b60405180910390a1507f150b7a02000000000000000000000000000000000000000000000000000000005b95945050505050565b610afb611cb2565b600b80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610bd9576040517f1cf993f400000000000000000000000000000000000000000000000000000000815233600482015273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000166024820152604401610a46565b610be38282611e6f565b5050565b610bef611cb2565b600780547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b610c3e611cb2565b610c486000611ed6565b565b6040805173ffffffffffffffffffffffffffffffffffffffff84166020808301919091528183018490528251808303840181526060830184528051908201204660808401523060a0808501919091528451808503909101815260c0909301909352815191012060009190610cbf888888610e1b565b604080516020810193909352820152606081018290526080016040516020818303038152906040528051906020012091505095945050505050565b610d02611cb2565b60075474010000000000000000000000000000000000000000900463ffffffff168111610d5b576040517f5b22800900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610d6481611f4b565b600760186101000a81548163ffffffff021916908363ffffffff16021790555050565b60606008805480602002602001604051908101604052809291908181526020016000905b82821015610e125760008481526020908190206040805160608101825260038602909201805473ffffffffffffffffffffffffffffffffffffffff908116845260018083015490911684860152600290910154918301919091529083529092019101610dab565b50505050905090565b60008060405180606001604052808673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff16815260200184815250604051602001610e7591906138cd565b604080518083037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0018152828252805160209182012046828501523084840152825180850384018152606085018452805190830120608085015260a0808501919091528251808503909101815260c090930190915281519101209150505b9392505050565b610f02611cb2565b6007547801000000000000000000000000000000000000000000000000900463ffffffff1615801590610f5957506007547801000000000000000000000000000000000000000000000000900463ffffffff168110155b15610f90576040517f5b22800900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610f9981611f4b565b600760146101000a81548163ffffffff021916908363ffffffff16021790555050565b6040517f01ffc9a70000000000000000000000000000000000000000000000000000000081527f80ac58cd00000000000000000000000000000000000000000000000000000000600482015260009073ffffffffffffffffffffffffffffffffffffffff8316906301ffc9a790602401602060405180830381865afa925050508015611083575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820190925261108091810190613909565b60015b61108f57506000919050565b92915050565b919050565b6110a2611cb2565b600155565b6110af611cb2565b600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff92909216919091179055565b6110ee611cb2565b600b80547fffffffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffff811666010000000000009182900460ff1615909102179055565b600b54600090819060ff16156111c5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f546865204e46542045786368616e67652069732063757272656e746c7920706160448201527f757365642e0000000000000000000000000000000000000000000000000000006064820152608401610a46565b600e5473ffffffffffffffffffffffffffffffffffffffff16611214576040517f5b07d65600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61121e8888611fe5565b611229338787612309565b611238338989898989896124be565b61126e576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61127888886124f8565b90999098509650505050505050565b600080611295878787610e1b565b905060006112f0826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050600061133686868080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525086939250506127ed9050565b60075473ffffffffffffffffffffffffffffffffffffffff9081169116149998505050505050505050565b73ffffffffffffffffffffffffffffffffffffffff81166000908152600a60209081526040808320805482518185028101850190935280835260609492939192909184015b8282101561140d5760008481526020908190206040805160608101825260038602909201805473ffffffffffffffffffffffffffffffffffffffff9081168452600180830154909116848601526002909101549183019190915290835290920191016113a6565b505050509050919050565b600b54600090819060ff16156114b0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f546865204e46542045786368616e67652069732063757272656e746c7920706160448201527f757365642e0000000000000000000000000000000000000000000000000000006064820152608401610a46565b600e5473ffffffffffffffffffffffffffffffffffffffff1615611500576040517f2da3634800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61150c86868686612811565b915091505b94509492505050565b611522611cb2565b6000805467ffffffffffffffff90921674010000000000000000000000000000000000000000027fffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffff909216919091179055565b61157d611cb2565b600e80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6115cc611cb2565b600c54600003611638576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f5345454420646f6573206e6f74206578697374000000000000000000000000006044820152606401610a46565b8163ffffffff168163ffffffff1610156116d4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602960248201527f456e6420706f736974696f6e206d75737420626520616674657220737461727460448201527f20706f736974696f6e00000000000000000000000000000000000000000000006064820152608401610a46565b6008546000906116e690600190613955565b8263ffffffff16116116f85781611707565b60085461170790600190613955565b9050825b8163ffffffff168163ffffffff161161189957600854600c546040516000929161174891859060200191825263ffffffff16602082015260400190565b6040516020818303038152906040528051906020012060001c61176b9190613968565b905060098163ffffffff1681548110611786576117866139a3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1660098363ffffffff16815481106117c5576117c56139a3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1660098463ffffffff1681548110611804576118046139a3565b906000526020600020906008918282040191900660040260098563ffffffff1681548110611834576118346139a3565b90600052602060002090600891828204019190066004028491906101000a81548163ffffffff021916908363ffffffff1602179055508391906101000a81548163ffffffff021916908363ffffffff160217905550505081806001019250505061170b565b506008546118a990600190613955565b8163ffffffff16036118e257600b80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b505050565b6118ef611cb2565b73ffffffffffffffffffffffffffffffffffffffff8116611992576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610a46565b61199b81611ed6565b50565b600b54600090819060ff1615611a36576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f546865204e46542045786368616e67652069732063757272656e746c7920706160448201527f757365642e0000000000000000000000000000000000000000000000000000006064820152608401610a46565b611a3f8361290d565b611a4883612aaa565b9094909350915050565b611a5a611cb2565b600e80547fffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffff811678010000000000000000000000000000000000000000000000009182900460ff1615909102179055565b60038181548110611abb57600080fd5b600091825260209091200154905081565b600e5460009073ffffffffffffffffffffffffffffffffffffffff16611af457506001610ef3565b600e5473ffffffffffffffffffffffffffffffffffffffff848116911614611b1e57506000610ef3565b611b29848484612d6c565b611b3557506000610ef3565b600e5474010000000000000000000000000000000000000000900463ffffffff16600003611b6557506001610ef3565b600e5473ffffffffffffffffffffffffffffffffffffffff84166000908152600f6020908152604080832086845290915290205463ffffffff740100000000000000000000000000000000000000009092048216911610611bc857506000610ef3565b5060019392505050565b600080611be28989898989610c4a565b90506000611c3d826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b90506000611c8386868080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525086939250506127ed9050565b60075473ffffffffffffffffffffffffffffffffffffffff91821691161493505050505b979650505050505050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610c48576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a46565b600154600080546002546040517f5d3b1d3000000000000000000000000000000000000000000000000000000000815260048101949094527401000000000000000000000000000000000000000090910467ffffffffffffffff1660248401526003604484015263ffffffff908116606484015283166084830152907f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1690635d3b1d309060a4016020604051808303816000875af1158015611e0f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e3391906139d2565b600081815260056020526040902080547fffffffffffffffffffffffff0000000000000000000000000000000000000000163317905592915050565b81600d5403610be35780600081518110611e8b57611e8b6139a3565b6020026020010151600c819055507f68f6adf8851f96fb54bce56dbb5ff1bc6b368aeaf5d3d1aedc38fb1548d354678282604051611eca9291906139eb565b60405180910390a15050565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600063ffffffff821115611fe1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201527f32206269747300000000000000000000000000000000000000000000000000006064820152608401610a46565b5090565b60075474010000000000000000000000000000000000000000900463ffffffff1642111561203f576040517f2ee88f5000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600b546008546201000090910463ffffffff1611612089576040517f909f7c4800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160361210e576040517ff52aae4300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61211782610fbc565b61214d576040517f0c4086e200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f6352211e00000000000000000000000000000000000000000000000000000000815260048101829052339073ffffffffffffffffffffffffffffffffffffffff841690636352211e90602401602060405180830381865afa1580156121ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121de9190613a3b565b73ffffffffffffffffffffffffffffffffffffffff161461222b576040517fefc0363400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f081812fc00000000000000000000000000000000000000000000000000000000815260048101829052309073ffffffffffffffffffffffffffffffffffffffff84169063081812fc90602401602060405180830381865afa158015612298573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122bc9190613a3b565b73ffffffffffffffffffffffffffffffffffffffff1614610be3576040517fd6e7fef200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600e5473ffffffffffffffffffffffffffffffffffffffff83811691161461235d576040517fa4f7bc8300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600e5474010000000000000000000000000000000000000000900463ffffffff16158015906123e05750600e5473ffffffffffffffffffffffffffffffffffffffff83166000908152600f6020908152604080832085845290915290205463ffffffff740100000000000000000000000000000000000000009092048216911610155b15612417576040517f6ff3e8e800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612422838383612d6c565b612458576040517fef9dfc5a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff82166000908152600f602090815260408083208484529091528120805463ffffffff169161249a83613a58565b91906101000a81548163ffffffff021916908363ffffffff16021790555050505050565b600b546000906601000000000000900460ff166124dd57506001611ca7565b6124ec88888888888888611bd2565b98975050505050505050565b6040517f42842e0e00000000000000000000000000000000000000000000000000000000815233600482015230602482015260448101829052600090819073ffffffffffffffffffffffffffffffffffffffff8516906342842e0e90606401600060405180830381600087803b15801561257157600080fd5b505af1158015612585573d6000803e3d6000fd5b50506040517f58dd27180000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1692506358dd27189150602401600060405180830381600087803b15801561261057600080fd5b505af1158015612624573d6000803e3d6000fd5b50506040805160608101825233815273ffffffffffffffffffffffffffffffffffffffff8881166020830190815292820188815260088054600181810183556000839052945160039091027ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee3810180549286167fffffffffffffffffffffffff000000000000000000000000000000000000000093841617905595517ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee48701805491909516911617909255517ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee5909301929092559054600993506127289250613955565b815460018101835560009283526020928390206008820401805460079092166004026101000a63ffffffff8181021990931693909216919091029190911790556040805133815273ffffffffffffffffffffffffffffffffffffffff87169281019290925281018490527faf5427fde32e98c3ccd610fa453b4b72f665627361c9edd4325e96916cbbbb879060600160405180910390a150506008547f0000000000000000000000000000000000000000000000000000000000000000939092509050565b60008060006127fc8585612fab565b9150915061280981612ff0565b509392505050565b600b54600090819060ff16156128a9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f546865204e46542045786368616e67652069732063757272656e746c7920706160448201527f757365642e0000000000000000000000000000000000000000000000000000006064820152608401610a46565b6128b38686611fe5565b6128c033878787876131a3565b6128f6576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61290086866124f8565b9097909650945050505050565b6007547801000000000000000000000000000000000000000000000000900463ffffffff1642101561296b576040517f67fb58e400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600b54610100900460ff166129ac576040517ff34818c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f6352211e00000000000000000000000000000000000000000000000000000000815260048101829052339073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001690636352211e90602401602060405180830381865afa158015612a39573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a5d9190613a3b565b73ffffffffffffffffffffffffffffffffffffffff161461199b576040517f31a4290b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080806009612abb600186613955565b81548110612acb57612acb6139a3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff169050600060088263ffffffff1681548110612b0e57612b0e6139a3565b600091825260209182902060408051606081018252600393909302909101805473ffffffffffffffffffffffffffffffffffffffff908116845260018201548116948401949094526002015482820152517ffcd3533c000000000000000000000000000000000000000000000000000000008152600481018890523360248201529092507f00000000000000000000000000000000000000000000000000000000000000009091169063fcd3533c90604401600060405180830381600087803b158015612bda57600080fd5b505af1158015612bee573d6000803e3d6000fd5b5050336000818152600a60209081526040808320805460018082018355918552938390208851600390950201805473ffffffffffffffffffffffffffffffffffffffff9586167fffffffffffffffffffffffff000000000000000000000000000000000000000091821617825593890151918101805492909516919093168117909355868101516002909201829055517f42842e0e0000000000000000000000000000000000000000000000000000000081523060048201526024810193909352604483015292506342842e0e9150606401600060405180830381600087803b158015612cda57600080fd5b505af1158015612cee573d6000803e3d6000fd5b50505060208083015160408085015181513381529384018a905273ffffffffffffffffffffffffffffffffffffffff9092169083015260608201527f0e660191854ca48492f5d6d0ae52c3c534561146f368eff1c3324cef2d1837b5915060800160405180910390a180602001518160400151935093505050915091565b60008373ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16636352211e846040518263ffffffff1660e01b8152600401612dc091815260200190565b602060405180830381865afa158015612ddd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e019190613a3b565b73ffffffffffffffffffffffffffffffffffffffff1603612e2457506001610ef3565b600e547801000000000000000000000000000000000000000000000000900460ff16612e5257506000610ef3565b6040517f6352211e000000000000000000000000000000000000000000000000000000008152600481018390526c447e69651d841bd8d104bed4939063b9f3687490869073ffffffffffffffffffffffffffffffffffffffff871690636352211e90602401602060405180830381865afa158015612ed4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ef89190613a3b565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff928316600482015290821660248201529086166044820152606481018590526000608482015260a401602060405180830381865afa158015612f7f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fa39190613909565b949350505050565b6000808251604103612fe15760208301516040840151606085015160001a612fd5878285856131d9565b94509450505050612fe9565b506000905060025b9250929050565b600081600481111561300457613004613a7b565b0361300c5750565b600181600481111561302057613020613a7b565b03613087576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610a46565b600281600481111561309b5761309b613a7b565b03613102576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610a46565b600381600481111561311657613116613a7b565b0361199b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f75650000000000000000000000000000000000000000000000000000000000006064820152608401610a46565b600b546000906601000000000000900460ff166131c257506001610aea565b6131cf8686868686611287565b9695505050505050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156132105750600090506003611511565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015613264573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff81166132b857600060019250925050611511565b9660009650945050505050565b803563ffffffff8116811461109557600080fd5b6000602082840312156132eb57600080fd5b610ef3826132c5565b73ffffffffffffffffffffffffffffffffffffffff8116811461199b57600080fd5b60008083601f84011261332857600080fd5b50813567ffffffffffffffff81111561334057600080fd5b602083019150836020828501011115612fe957600080fd5b60008060008060006080868803121561337057600080fd5b853561337b816132f4565b9450602086013561338b816132f4565b935060408601359250606086013567ffffffffffffffff8111156133ae57600080fd5b6133ba88828901613316565b969995985093965092949392505050565b801515811461199b57600080fd5b6000602082840312156133eb57600080fd5b8135610ef3816133cb565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000806040838503121561343857600080fd5b8235915060208084013567ffffffffffffffff8082111561345857600080fd5b818601915086601f83011261346c57600080fd5b81358181111561347e5761347e6133f6565b8060051b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f830116810181811085821117156134c1576134c16133f6565b6040529182528482019250838101850191898311156134df57600080fd5b938501935b828510156134fd578435845293850193928501926134e4565b8096505050505050509250929050565b6000806040838503121561352057600080fd5b823561352b816132f4565b946020939093013593505050565b60006020828403121561354b57600080fd5b5035919050565b60006020828403121561356457600080fd5b8135610ef3816132f4565b600080600080600060a0868803121561358757600080fd5b8535613592816132f4565b945060208601356135a2816132f4565b93506040860135925060608601356135b9816132f4565b949793965091946080013592915050565b6020808252825182820181905260009190848201906040850190845b8181101561363d5761362a83855173ffffffffffffffffffffffffffffffffffffffff80825116835280602083015116602084015250604081015160408301525050565b92840192606092909201916001016135e6565b50909695505050505050565b60008060006060848603121561365e57600080fd5b8335613669816132f4565b92506020840135613679816132f4565b929592945050506040919091013590565b60008060008060008060a087890312156136a357600080fd5b86356136ae816132f4565b95506020870135945060408701356136c5816132f4565b935060608701359250608087013567ffffffffffffffff8111156136e857600080fd5b6136f489828a01613316565b979a9699509497509295939492505050565b6000806000806060858703121561371c57600080fd5b8435613727816132f4565b935060208501359250604085013567ffffffffffffffff81111561374a57600080fd5b61375687828801613316565b95989497509550505050565b60006020828403121561377457600080fd5b813567ffffffffffffffff81168114610ef357600080fd5b6000806040838503121561379f57600080fd5b6137a8836132c5565b91506137b6602084016132c5565b90509250929050565b600080600080600080600060c0888a0312156137da57600080fd5b87356137e5816132f4565b965060208801356137f5816132f4565b955060408801359450606088013561380c816132f4565b93506080880135925060a088013567ffffffffffffffff81111561382f57600080fd5b61383b8a828b01613316565b989b979a50959850939692959293505050565b600073ffffffffffffffffffffffffffffffffffffffff808816835280871660208401525084604083015260806060830152826080830152828460a0840137600060a0848401015260a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f85011683010190509695505050505050565b815173ffffffffffffffffffffffffffffffffffffffff908116825260208084015190911690820152604080830151908201526060810161108f565b60006020828403121561391b57600080fd5b8151610ef3816133cb565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181038181111561108f5761108f613926565b60008261399e577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500690565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082840312156139e457600080fd5b5051919050565b60006040820184835260206040602085015281855180845260608601915060208701935060005b81811015613a2e57845183529383019391830191600101613a12565b5090979650505050505050565b600060208284031215613a4d57600080fd5b8151610ef3816132f4565b600063ffffffff808316818103613a7157613a71613926565b6001019392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fdfea2646970667358221220fa3f34915e61bab4c73248448a0b716d4710aea10ea20438265c7ff0820ba65664736f6c63430008170033000000000000000000000000000000000000000000000000000000000000037c000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e699098af398995b04c28e9951adb9721ef74c74f93e6a478f39e7e0777be13527e7ef000000000000000000000000000000000000000000000000000000006583f0800000000000000000000000000000000000000000000000000000000065846f10000000000000000000000000bf6b2273bbb4489e2eff99ae43ff148f04849b6e000000000000000000000000ec0080d33cd791e5f8b1dffd7784e7c6946f9b7a00000000000000000000000008d7c0242953446436f34b4c78fe9da38c73668d0000000000000000000000000000000000000000000000000000000000000001

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106103575760003560e01c8063964da0db116101c8578063e067510c11610104578063f2fde38b116100a2578063f6eaffc81161007c578063f6eaffc81461087b578063f76117c51461088e578063fbcfbad4146108a1578063ff512615146108c857600080fd5b8063f2fde38b1461084d578063f3fecc0b14610860578063f4e3ae6f1461087357600080fd5b8063e89e106a116100de578063e89e106a1461080b578063ea7b4f7714610814578063f1bead9b14610827578063f27010e91461083a57600080fd5b8063e067510c146107c3578063e43db9af146107d6578063e81c2340146107ed57600080fd5b8063a9aad58c11610171578063bf7852001161014b578063bf78520014610734578063c48de91f14610773578063cb111cf814610786578063cf51fb9d1461079957600080fd5b8063a9aad58c146106ff578063af25c1e71461070c578063bab556a71461071457600080fd5b8063998dc690116101a2578063998dc690146106ce578063a0c70d69146106d6578063a4eb718c146106ec57600080fd5b8063964da0db1461069657806397e8db30146106a957806398544710146106bb57600080fd5b80636c19e783116102975780637af9f01011610240578063889dae131161021a578063889dae131461062b5780638d17e3ac1461063e5780638da5cb5b1461065157806395de3cef1461066f57600080fd5b80637af9f010146105ef5780638286eee21461060257806385dfc7e41461061657600080fd5b8063798713871161027157806379871387146105885780637a33d5ae1461059b5780637ac3c02f146105d157600080fd5b80636c19e78314610534578063715018a61461054757806375dac0c91461054f57600080fd5b806316c38b3c116103045780635183d62f116102de5780635183d62f14610445578063521a179e1461048b5780636081051f146104e65780636b22d54a1461050c57600080fd5b806316c38b3c146104165780631fe543e31461042957806347c76ef11461043c57600080fd5b80630edc4737116103355780630edc4737146103c1578063114bf2e3146103ca578063150b7a02146103d257600080fd5b80630770e2381461035c57806309b98ce8146103995780630a367704146103ae575b600080fd5b60408051466020808301919091523082840152825180830384018152606090920190925280519101205b6040519081526020015b60405180910390f35b6103ac6103a73660046132d9565b6108db565b005b6103ac6103bc3660046132d9565b610962565b610386600c5481565b6103ac6109b9565b6103e56103e0366004613358565b610a86565b6040517fffffffff000000000000000000000000000000000000000000000000000000009091168152602001610390565b6103ac6104243660046133d9565b610af3565b6103ac610437366004613425565b610b2c565b610386600d5481565b61047661045336600461350d565b600f60209081526000928352604080842090915290825290205463ffffffff1681565b60405163ffffffff9091168152602001610390565b6104c1610499366004613539565b60056020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610390565b60075474010000000000000000000000000000000000000000900463ffffffff16610386565b600e546104769074010000000000000000000000000000000000000000900463ffffffff1681565b6103ac610542366004613552565b610be7565b6103ac610c36565b600e54610578907801000000000000000000000000000000000000000000000000900460ff1681565b6040519015158152602001610390565b61038661059636600461356f565b610c4a565b6103866105a9366004613552565b73ffffffffffffffffffffffffffffffffffffffff166000908152600a602052604090205490565b60075473ffffffffffffffffffffffffffffffffffffffff166104c1565b6103ac6105fd366004613539565b610cfa565b6104c16c447e69651d841bd8d104bed49381565b61061e610d87565b60405161039091906135ca565b610386610639366004613649565b610e1b565b6103ac61064c366004613539565b610efa565b60005473ffffffffffffffffffffffffffffffffffffffff166104c1565b600e547801000000000000000000000000000000000000000000000000900460ff16610578565b6105786106a4366004613552565b610fbc565b600b5461057890610100900460ff1681565b6103ac6106c9366004613539565b61109a565b600854610386565b600b546104769062010000900463ffffffff1681565b6103ac6106fa3660046132d9565b6110a7565b600b546105789060ff1681565b6103ac6110e6565b600e546104c19073ffffffffffffffffffffffffffffffffffffffff1681565b61074761074236600461368a565b61112d565b6040805173ffffffffffffffffffffffffffffffffffffffff9093168352602083019190915201610390565b610578610781366004613358565b611287565b61061e610794366004613552565b611361565b6007547801000000000000000000000000000000000000000000000000900463ffffffff16610386565b6107476107d1366004613706565b611418565b600b54610578906601000000000000900460ff1681565b600e5473ffffffffffffffffffffffffffffffffffffffff166104c1565b61038660045481565b6103ac610822366004613762565b61151a565b6103ac610835366004613552565b611575565b6103ac61084836600461378c565b6115c4565b6103ac61085b366004613552565b6118e7565b61074761086e366004613539565b61199e565b6103ac611a52565b610386610889366004613539565b611aab565b61057861089c366004613649565b611acc565b6104c17f000000000000000000000000ec0080d33cd791e5f8b1dffd7784e7c6946f9b7a81565b6105786108d63660046137bf565b611bd2565b6108e3611cb2565b60085463ffffffff82161015610925576040517f2cfbb4f800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600b805463ffffffff90921662010000027fffffffffffffffffffffffffffffffffffffffffffffffffffff00000000ffff909216919091179055565b61096a611cb2565b600e805463ffffffff90921674010000000000000000000000000000000000000000027fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff909216919091179055565b6109c1611cb2565b60075474010000000000000000000000000000000000000000900463ffffffff164211610a4f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f526567697374726174696f6e20686173206e6f7420656e64656420796574000060448201526064015b60405180910390fd5b610a596001611d33565b600d55600b80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff169055565b60007fa05d90f300156ad1b545bc5d8197024456f21d22a708f5af04dd293e3d6052518686868686604051610abf95949392919061384e565b60405180910390a1507f150b7a02000000000000000000000000000000000000000000000000000000005b95945050505050565b610afb611cb2565b600b80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055565b3373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e699091614610bd9576040517f1cf993f400000000000000000000000000000000000000000000000000000000815233600482015273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e69909166024820152604401610a46565b610be38282611e6f565b5050565b610bef611cb2565b600780547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b610c3e611cb2565b610c486000611ed6565b565b6040805173ffffffffffffffffffffffffffffffffffffffff84166020808301919091528183018490528251808303840181526060830184528051908201204660808401523060a0808501919091528451808503909101815260c0909301909352815191012060009190610cbf888888610e1b565b604080516020810193909352820152606081018290526080016040516020818303038152906040528051906020012091505095945050505050565b610d02611cb2565b60075474010000000000000000000000000000000000000000900463ffffffff168111610d5b576040517f5b22800900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610d6481611f4b565b600760186101000a81548163ffffffff021916908363ffffffff16021790555050565b60606008805480602002602001604051908101604052809291908181526020016000905b82821015610e125760008481526020908190206040805160608101825260038602909201805473ffffffffffffffffffffffffffffffffffffffff908116845260018083015490911684860152600290910154918301919091529083529092019101610dab565b50505050905090565b60008060405180606001604052808673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff16815260200184815250604051602001610e7591906138cd565b604080518083037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0018152828252805160209182012046828501523084840152825180850384018152606085018452805190830120608085015260a0808501919091528251808503909101815260c090930190915281519101209150505b9392505050565b610f02611cb2565b6007547801000000000000000000000000000000000000000000000000900463ffffffff1615801590610f5957506007547801000000000000000000000000000000000000000000000000900463ffffffff168110155b15610f90576040517f5b22800900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610f9981611f4b565b600760146101000a81548163ffffffff021916908363ffffffff16021790555050565b6040517f01ffc9a70000000000000000000000000000000000000000000000000000000081527f80ac58cd00000000000000000000000000000000000000000000000000000000600482015260009073ffffffffffffffffffffffffffffffffffffffff8316906301ffc9a790602401602060405180830381865afa925050508015611083575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820190925261108091810190613909565b60015b61108f57506000919050565b92915050565b919050565b6110a2611cb2565b600155565b6110af611cb2565b600280547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff92909216919091179055565b6110ee611cb2565b600b80547fffffffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffff811666010000000000009182900460ff1615909102179055565b600b54600090819060ff16156111c5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f546865204e46542045786368616e67652069732063757272656e746c7920706160448201527f757365642e0000000000000000000000000000000000000000000000000000006064820152608401610a46565b600e5473ffffffffffffffffffffffffffffffffffffffff16611214576040517f5b07d65600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61121e8888611fe5565b611229338787612309565b611238338989898989896124be565b61126e576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61127888886124f8565b90999098509650505050505050565b600080611295878787610e1b565b905060006112f0826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b9050600061133686868080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525086939250506127ed9050565b60075473ffffffffffffffffffffffffffffffffffffffff9081169116149998505050505050505050565b73ffffffffffffffffffffffffffffffffffffffff81166000908152600a60209081526040808320805482518185028101850190935280835260609492939192909184015b8282101561140d5760008481526020908190206040805160608101825260038602909201805473ffffffffffffffffffffffffffffffffffffffff9081168452600180830154909116848601526002909101549183019190915290835290920191016113a6565b505050509050919050565b600b54600090819060ff16156114b0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f546865204e46542045786368616e67652069732063757272656e746c7920706160448201527f757365642e0000000000000000000000000000000000000000000000000000006064820152608401610a46565b600e5473ffffffffffffffffffffffffffffffffffffffff1615611500576040517f2da3634800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61150c86868686612811565b915091505b94509492505050565b611522611cb2565b6000805467ffffffffffffffff90921674010000000000000000000000000000000000000000027fffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffff909216919091179055565b61157d611cb2565b600e80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6115cc611cb2565b600c54600003611638576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f5345454420646f6573206e6f74206578697374000000000000000000000000006044820152606401610a46565b8163ffffffff168163ffffffff1610156116d4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602960248201527f456e6420706f736974696f6e206d75737420626520616674657220737461727460448201527f20706f736974696f6e00000000000000000000000000000000000000000000006064820152608401610a46565b6008546000906116e690600190613955565b8263ffffffff16116116f85781611707565b60085461170790600190613955565b9050825b8163ffffffff168163ffffffff161161189957600854600c546040516000929161174891859060200191825263ffffffff16602082015260400190565b6040516020818303038152906040528051906020012060001c61176b9190613968565b905060098163ffffffff1681548110611786576117866139a3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1660098363ffffffff16815481106117c5576117c56139a3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1660098463ffffffff1681548110611804576118046139a3565b906000526020600020906008918282040191900660040260098563ffffffff1681548110611834576118346139a3565b90600052602060002090600891828204019190066004028491906101000a81548163ffffffff021916908363ffffffff1602179055508391906101000a81548163ffffffff021916908363ffffffff160217905550505081806001019250505061170b565b506008546118a990600190613955565b8163ffffffff16036118e257600b80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ff166101001790555b505050565b6118ef611cb2565b73ffffffffffffffffffffffffffffffffffffffff8116611992576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608401610a46565b61199b81611ed6565b50565b600b54600090819060ff1615611a36576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f546865204e46542045786368616e67652069732063757272656e746c7920706160448201527f757365642e0000000000000000000000000000000000000000000000000000006064820152608401610a46565b611a3f8361290d565b611a4883612aaa565b9094909350915050565b611a5a611cb2565b600e80547fffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffff811678010000000000000000000000000000000000000000000000009182900460ff1615909102179055565b60038181548110611abb57600080fd5b600091825260209091200154905081565b600e5460009073ffffffffffffffffffffffffffffffffffffffff16611af457506001610ef3565b600e5473ffffffffffffffffffffffffffffffffffffffff848116911614611b1e57506000610ef3565b611b29848484612d6c565b611b3557506000610ef3565b600e5474010000000000000000000000000000000000000000900463ffffffff16600003611b6557506001610ef3565b600e5473ffffffffffffffffffffffffffffffffffffffff84166000908152600f6020908152604080832086845290915290205463ffffffff740100000000000000000000000000000000000000009092048216911610611bc857506000610ef3565b5060019392505050565b600080611be28989898989610c4a565b90506000611c3d826040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b90506000611c8386868080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525086939250506127ed9050565b60075473ffffffffffffffffffffffffffffffffffffffff91821691161493505050505b979650505050505050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610c48576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a46565b600154600080546002546040517f5d3b1d3000000000000000000000000000000000000000000000000000000000815260048101949094527401000000000000000000000000000000000000000090910467ffffffffffffffff1660248401526003604484015263ffffffff908116606484015283166084830152907f000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e6990973ffffffffffffffffffffffffffffffffffffffff1690635d3b1d309060a4016020604051808303816000875af1158015611e0f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e3391906139d2565b600081815260056020526040902080547fffffffffffffffffffffffff0000000000000000000000000000000000000000163317905592915050565b81600d5403610be35780600081518110611e8b57611e8b6139a3565b6020026020010151600c819055507f68f6adf8851f96fb54bce56dbb5ff1bc6b368aeaf5d3d1aedc38fb1548d354678282604051611eca9291906139eb565b60405180910390a15050565b6000805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600063ffffffff821115611fe1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201527f32206269747300000000000000000000000000000000000000000000000000006064820152608401610a46565b5090565b60075474010000000000000000000000000000000000000000900463ffffffff1642111561203f576040517f2ee88f5000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600b546008546201000090910463ffffffff1611612089576040517f909f7c4800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f000000000000000000000000ec0080d33cd791e5f8b1dffd7784e7c6946f9b7a73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160361210e576040517ff52aae4300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61211782610fbc565b61214d576040517f0c4086e200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f6352211e00000000000000000000000000000000000000000000000000000000815260048101829052339073ffffffffffffffffffffffffffffffffffffffff841690636352211e90602401602060405180830381865afa1580156121ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121de9190613a3b565b73ffffffffffffffffffffffffffffffffffffffff161461222b576040517fefc0363400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f081812fc00000000000000000000000000000000000000000000000000000000815260048101829052309073ffffffffffffffffffffffffffffffffffffffff84169063081812fc90602401602060405180830381865afa158015612298573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122bc9190613a3b565b73ffffffffffffffffffffffffffffffffffffffff1614610be3576040517fd6e7fef200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600e5473ffffffffffffffffffffffffffffffffffffffff83811691161461235d576040517fa4f7bc8300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600e5474010000000000000000000000000000000000000000900463ffffffff16158015906123e05750600e5473ffffffffffffffffffffffffffffffffffffffff83166000908152600f6020908152604080832085845290915290205463ffffffff740100000000000000000000000000000000000000009092048216911610155b15612417576040517f6ff3e8e800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612422838383612d6c565b612458576040517fef9dfc5a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff82166000908152600f602090815260408083208484529091528120805463ffffffff169161249a83613a58565b91906101000a81548163ffffffff021916908363ffffffff16021790555050505050565b600b546000906601000000000000900460ff166124dd57506001611ca7565b6124ec88888888888888611bd2565b98975050505050505050565b6040517f42842e0e00000000000000000000000000000000000000000000000000000000815233600482015230602482015260448101829052600090819073ffffffffffffffffffffffffffffffffffffffff8516906342842e0e90606401600060405180830381600087803b15801561257157600080fd5b505af1158015612585573d6000803e3d6000fd5b50506040517f58dd27180000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000ec0080d33cd791e5f8b1dffd7784e7c6946f9b7a73ffffffffffffffffffffffffffffffffffffffff1692506358dd27189150602401600060405180830381600087803b15801561261057600080fd5b505af1158015612624573d6000803e3d6000fd5b50506040805160608101825233815273ffffffffffffffffffffffffffffffffffffffff8881166020830190815292820188815260088054600181810183556000839052945160039091027ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee3810180549286167fffffffffffffffffffffffff000000000000000000000000000000000000000093841617905595517ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee48701805491909516911617909255517ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee5909301929092559054600993506127289250613955565b815460018101835560009283526020928390206008820401805460079092166004026101000a63ffffffff8181021990931693909216919091029190911790556040805133815273ffffffffffffffffffffffffffffffffffffffff87169281019290925281018490527faf5427fde32e98c3ccd610fa453b4b72f665627361c9edd4325e96916cbbbb879060600160405180910390a150506008547f000000000000000000000000ec0080d33cd791e5f8b1dffd7784e7c6946f9b7a939092509050565b60008060006127fc8585612fab565b9150915061280981612ff0565b509392505050565b600b54600090819060ff16156128a9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f546865204e46542045786368616e67652069732063757272656e746c7920706160448201527f757365642e0000000000000000000000000000000000000000000000000000006064820152608401610a46565b6128b38686611fe5565b6128c033878787876131a3565b6128f6576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61290086866124f8565b9097909650945050505050565b6007547801000000000000000000000000000000000000000000000000900463ffffffff1642101561296b576040517f67fb58e400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600b54610100900460ff166129ac576040517ff34818c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f6352211e00000000000000000000000000000000000000000000000000000000815260048101829052339073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000ec0080d33cd791e5f8b1dffd7784e7c6946f9b7a1690636352211e90602401602060405180830381865afa158015612a39573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a5d9190613a3b565b73ffffffffffffffffffffffffffffffffffffffff161461199b576040517f31a4290b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600080806009612abb600186613955565b81548110612acb57612acb6139a3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff169050600060088263ffffffff1681548110612b0e57612b0e6139a3565b600091825260209182902060408051606081018252600393909302909101805473ffffffffffffffffffffffffffffffffffffffff908116845260018201548116948401949094526002015482820152517ffcd3533c000000000000000000000000000000000000000000000000000000008152600481018890523360248201529092507f000000000000000000000000ec0080d33cd791e5f8b1dffd7784e7c6946f9b7a9091169063fcd3533c90604401600060405180830381600087803b158015612bda57600080fd5b505af1158015612bee573d6000803e3d6000fd5b5050336000818152600a60209081526040808320805460018082018355918552938390208851600390950201805473ffffffffffffffffffffffffffffffffffffffff9586167fffffffffffffffffffffffff000000000000000000000000000000000000000091821617825593890151918101805492909516919093168117909355868101516002909201829055517f42842e0e0000000000000000000000000000000000000000000000000000000081523060048201526024810193909352604483015292506342842e0e9150606401600060405180830381600087803b158015612cda57600080fd5b505af1158015612cee573d6000803e3d6000fd5b50505060208083015160408085015181513381529384018a905273ffffffffffffffffffffffffffffffffffffffff9092169083015260608201527f0e660191854ca48492f5d6d0ae52c3c534561146f368eff1c3324cef2d1837b5915060800160405180910390a180602001518160400151935093505050915091565b60008373ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16636352211e846040518263ffffffff1660e01b8152600401612dc091815260200190565b602060405180830381865afa158015612ddd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e019190613a3b565b73ffffffffffffffffffffffffffffffffffffffff1603612e2457506001610ef3565b600e547801000000000000000000000000000000000000000000000000900460ff16612e5257506000610ef3565b6040517f6352211e000000000000000000000000000000000000000000000000000000008152600481018390526c447e69651d841bd8d104bed4939063b9f3687490869073ffffffffffffffffffffffffffffffffffffffff871690636352211e90602401602060405180830381865afa158015612ed4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ef89190613a3b565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff928316600482015290821660248201529086166044820152606481018590526000608482015260a401602060405180830381865afa158015612f7f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fa39190613909565b949350505050565b6000808251604103612fe15760208301516040840151606085015160001a612fd5878285856131d9565b94509450505050612fe9565b506000905060025b9250929050565b600081600481111561300457613004613a7b565b0361300c5750565b600181600481111561302057613020613a7b565b03613087576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610a46565b600281600481111561309b5761309b613a7b565b03613102576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610a46565b600381600481111561311657613116613a7b565b0361199b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f75650000000000000000000000000000000000000000000000000000000000006064820152608401610a46565b600b546000906601000000000000900460ff166131c257506001610aea565b6131cf8686868686611287565b9695505050505050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156132105750600090506003611511565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015613264573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff81166132b857600060019250925050611511565b9660009650945050505050565b803563ffffffff8116811461109557600080fd5b6000602082840312156132eb57600080fd5b610ef3826132c5565b73ffffffffffffffffffffffffffffffffffffffff8116811461199b57600080fd5b60008083601f84011261332857600080fd5b50813567ffffffffffffffff81111561334057600080fd5b602083019150836020828501011115612fe957600080fd5b60008060008060006080868803121561337057600080fd5b853561337b816132f4565b9450602086013561338b816132f4565b935060408601359250606086013567ffffffffffffffff8111156133ae57600080fd5b6133ba88828901613316565b969995985093965092949392505050565b801515811461199b57600080fd5b6000602082840312156133eb57600080fd5b8135610ef3816133cb565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000806040838503121561343857600080fd5b8235915060208084013567ffffffffffffffff8082111561345857600080fd5b818601915086601f83011261346c57600080fd5b81358181111561347e5761347e6133f6565b8060051b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f830116810181811085821117156134c1576134c16133f6565b6040529182528482019250838101850191898311156134df57600080fd5b938501935b828510156134fd578435845293850193928501926134e4565b8096505050505050509250929050565b6000806040838503121561352057600080fd5b823561352b816132f4565b946020939093013593505050565b60006020828403121561354b57600080fd5b5035919050565b60006020828403121561356457600080fd5b8135610ef3816132f4565b600080600080600060a0868803121561358757600080fd5b8535613592816132f4565b945060208601356135a2816132f4565b93506040860135925060608601356135b9816132f4565b949793965091946080013592915050565b6020808252825182820181905260009190848201906040850190845b8181101561363d5761362a83855173ffffffffffffffffffffffffffffffffffffffff80825116835280602083015116602084015250604081015160408301525050565b92840192606092909201916001016135e6565b50909695505050505050565b60008060006060848603121561365e57600080fd5b8335613669816132f4565b92506020840135613679816132f4565b929592945050506040919091013590565b60008060008060008060a087890312156136a357600080fd5b86356136ae816132f4565b95506020870135945060408701356136c5816132f4565b935060608701359250608087013567ffffffffffffffff8111156136e857600080fd5b6136f489828a01613316565b979a9699509497509295939492505050565b6000806000806060858703121561371c57600080fd5b8435613727816132f4565b935060208501359250604085013567ffffffffffffffff81111561374a57600080fd5b61375687828801613316565b95989497509550505050565b60006020828403121561377457600080fd5b813567ffffffffffffffff81168114610ef357600080fd5b6000806040838503121561379f57600080fd5b6137a8836132c5565b91506137b6602084016132c5565b90509250929050565b600080600080600080600060c0888a0312156137da57600080fd5b87356137e5816132f4565b965060208801356137f5816132f4565b955060408801359450606088013561380c816132f4565b93506080880135925060a088013567ffffffffffffffff81111561382f57600080fd5b61383b8a828b01613316565b989b979a50959850939692959293505050565b600073ffffffffffffffffffffffffffffffffffffffff808816835280871660208401525084604083015260806060830152826080830152828460a0840137600060a0848401015260a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f85011683010190509695505050505050565b815173ffffffffffffffffffffffffffffffffffffffff908116825260208084015190911690820152604080830151908201526060810161108f565b60006020828403121561391b57600080fd5b8151610ef3816133cb565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181038181111561108f5761108f613926565b60008261399e577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500690565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082840312156139e457600080fd5b5051919050565b60006040820184835260206040602085015281855180845260608601915060208701935060005b81811015613a2e57845183529383019391830191600101613a12565b5090979650505050505050565b600060208284031215613a4d57600080fd5b8151610ef3816132f4565b600063ffffffff808316818103613a7157613a71613926565b6001019392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fdfea2646970667358221220fa3f34915e61bab4c73248448a0b716d4710aea10ea20438265c7ff0820ba65664736f6c63430008170033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000000000000000000000000000000000000000037c000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e699098af398995b04c28e9951adb9721ef74c74f93e6a478f39e7e0777be13527e7ef000000000000000000000000000000000000000000000000000000006583f0800000000000000000000000000000000000000000000000000000000065846f10000000000000000000000000bf6b2273bbb4489e2eff99ae43ff148f04849b6e000000000000000000000000ec0080d33cd791e5f8b1dffd7784e7c6946f9b7a00000000000000000000000008d7c0242953446436f34b4c78fe9da38c73668d0000000000000000000000000000000000000000000000000000000000000001

-----Decoded View---------------
Arg [0] : subscriptionId (uint64): 892
Arg [1] : vrfCoordinator (address): 0x271682DEB8C4E0901D1a1550aD2e64D568E69909
Arg [2] : keyHash (bytes32): 0x8af398995b04c28e9951adb9721ef74c74f93e6a478f39e7e0777be13527e7ef
Arg [3] : registrationEnd (uint256): 1703145600
Arg [4] : redemptionStart (uint256): 1703178000
Arg [5] : signer (address): 0xBf6B2273bBb4489e2EFF99AE43fF148F04849b6E
Arg [6] : presentNft (address): 0xEC0080d33CD791e5f8B1dffD7784E7c6946F9b7a
Arg [7] : tokenGateNft (address): 0x08D7C0242953446436F34b4C78Fe9da38c73668d
Arg [8] : tokenGateLimit (uint32): 1

-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 000000000000000000000000000000000000000000000000000000000000037c
Arg [1] : 000000000000000000000000271682deb8c4e0901d1a1550ad2e64d568e69909
Arg [2] : 8af398995b04c28e9951adb9721ef74c74f93e6a478f39e7e0777be13527e7ef
Arg [3] : 000000000000000000000000000000000000000000000000000000006583f080
Arg [4] : 0000000000000000000000000000000000000000000000000000000065846f10
Arg [5] : 000000000000000000000000bf6b2273bbb4489e2eff99ae43ff148f04849b6e
Arg [6] : 000000000000000000000000ec0080d33cd791e5f8b1dffd7784e7c6946f9b7a
Arg [7] : 00000000000000000000000008d7c0242953446436f34b4c78fe9da38c73668d
Arg [8] : 0000000000000000000000000000000000000000000000000000000000000001


Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export  ]

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