File size: 72,308 Bytes
f998fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{
  "language": "Solidity",
  "sources": {
    "contracts/Raffle.sol": {
      "content": "// SPDX-License-Identifier: MIT\r\npragma solidity ^0.8.9;\r\n\r\nimport \"contracts/ICryptoPunk.sol\";\r\nimport \"contracts/TicketStorage.sol\";\r\n\r\nimport \"@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol\";\r\nimport \"@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol\";\r\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\r\nimport \"@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol\";\r\nimport \"@openzeppelin/contracts/token/ERC1155/IERC1155.sol\";\r\nimport \"@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol\";\r\nimport \"@openzeppelin/contracts/token/ERC721/IERC721.sol\";\r\nimport \"@openzeppelin/contracts/security/PullPayment.sol\";\r\n\r\n/**\r\n * @dev This contract is used to represent BoredLucky raffle. It supports CryptoPunks, ERC721 and ERC1155 NFTs.\r\n *\r\n * Raffle relies on Chainlink VRF to draw the winner.\r\n *\r\n * Raffle ensures that buyers will get a fair chance of winning (proportional to the number of purchased tickets), or\r\n * a way to get ETH back if raffle gets cancelled.\r\n *\r\n * Raffle can start only after the correct NFT is transferred to the account.\r\n *\r\n * Each raffle has an `owner`, the admin account that has the following abilities:\r\n * - gets ETH after the raffle is completed\r\n * - gets back the NFT if raffle is cancelled\r\n * - able to giveaway tickets\r\n * - able to cancel raffle before it has started (e.g. created with wrong parameters)\r\n *\r\n * Raffle gets cancelled if:\r\n * - not all tickets are sold before `endTimestamp`\r\n * - `owner` cancels it before start\r\n * - for some reason we do not have response from Chainlink VRF for one day after we request random number\r\n *\r\n * In any scenario, raffle cannot get stuck and users have a fair chance to win or get ETH back.\r\n *\r\n * `PullPayments` are used where possible to increase security.\r\n *\r\n * The lifecycle of raffle consist of following states:\r\n * - WaitingForNFT: after raffle is created, it waits for\r\n * - WaitingForStart: correct NFT is transferred and we wait for `startTimestamp`\r\n * - SellingTickets: it possible to purchase tickets\r\n * - WaitingForRNG: all tickets are sold, we wait for Chainlink VRF to send random number\r\n * - Completed (terminal) -- we know the winner, it can get NFT, raffle owner can get ETH\r\n * - Cancelled (terminal) -- raffle cancelled, buyers can get back their ETH, owner can get NFT\r\n */\r\ncontract Raffle is Ownable, TicketStorage, ERC1155Holder, ERC721Holder, PullPayment, VRFConsumerBaseV2 {\r\n    event WinnerDrawn(uint16 ticketNumber, address owner);\r\n\r\n    enum State {\r\n        WaitingForNFT,\r\n        WaitingForStart,\r\n        SellingTickets,\r\n        WaitingForRNG,\r\n        Completed,\r\n        Cancelled\r\n    }\r\n    State private _state;\r\n\r\n    address public immutable nftContract;\r\n    uint256 public immutable nftTokenId;\r\n    enum NFTStandard {\r\n        CryptoPunks,\r\n        ERC721,\r\n        ERC1155\r\n    }\r\n    NFTStandard public immutable nftStandard;\r\n\r\n    uint256 public immutable ticketPrice;\r\n    uint256 public immutable startTimestamp;\r\n    uint256 public immutable endTimestamp;\r\n\r\n    uint16 private _soldTickets;\r\n    uint16 private _giveawayTickets;\r\n    mapping(address => uint16) private _addressToPurchasedCountMap;\r\n\r\n    uint256 private _cancelTimestamp;\r\n    uint256 private _transferNFTToWinnerTimestamp;\r\n\r\n    uint256 private _winnerDrawTimestamp;\r\n    uint16 private _winnerTicketNumber;\r\n    address private _winnerAddress;\r\n\r\n    VRFCoordinatorV2Interface immutable VRF_COORDINATOR;\r\n    uint64 immutable vrfSubscriptionId;\r\n    bytes32 immutable vrfKeyHash;\r\n    uint256[] public vrfRandomWords;\r\n    uint256 public vrfRequestId;\r\n\r\n    uint32 constant VRF_CALLBACK_GAS_LIMIT = 300_000;\r\n    uint16 constant VRF_REQUEST_CONFIRMATIONS = 20;\r\n    uint16 constant VRF_NUM_WORDS = 1;\r\n\r\n    constructor(\r\n        address _nftContract,\r\n        uint256 _nftTokenId,\r\n        uint256 _nftStandardId,\r\n        uint16 _tickets,\r\n        uint256 _ticketPrice,\r\n        uint256 _startTimestamp,\r\n        uint256 _endTimestamp,\r\n        uint64 _vrfSubscriptionId,\r\n        address _vrfCoordinator,\r\n        bytes32 _vrfKeyHash\r\n    ) TicketStorage(_tickets) VRFConsumerBaseV2(_vrfCoordinator) {\r\n        require(block.timestamp < _startTimestamp, \"Start timestamp cannot be in the past\");\r\n        require(_endTimestamp > _startTimestamp, \"End timestamp must be after start timestamp\");\r\n        require(_nftContract != address(0), \"NFT contract cannot be 0x0\");\r\n        nftStandard = NFTStandard(_nftStandardId);\r\n        require(\r\n            nftStandard == NFTStandard.CryptoPunks || nftStandard == NFTStandard.ERC721 || nftStandard == NFTStandard.ERC1155,\r\n            \"Not supported NFT standard\"\r\n        );\r\n\r\n        nftContract = _nftContract;\r\n        nftTokenId = _nftTokenId;\r\n        ticketPrice = _ticketPrice;\r\n        startTimestamp = _startTimestamp;\r\n        endTimestamp = _endTimestamp;\r\n        VRF_COORDINATOR = VRFCoordinatorV2Interface(_vrfCoordinator);\r\n        vrfKeyHash = _vrfKeyHash;\r\n        vrfSubscriptionId = _vrfSubscriptionId;\r\n\r\n        _state = State.WaitingForNFT;\r\n    }\r\n\r\n    /**\r\n     * @dev Purchases raffle tickets.\r\n     *\r\n     * If last ticket is sold, triggers {_requestRandomWords} to request random number from Chainlink VRF.\r\n     *\r\n     * Requirements:\r\n     * - must be in SellingTickets state\r\n     * - cannot purchase after `endTimestamp`\r\n     * - cannot purchase 0 tickets\r\n     * - must have correct `value` of ETH\r\n     */\r\n    function purchaseTicket(uint16 count) external payable {\r\n        if (_state == State.WaitingForStart) {\r\n            if (block.timestamp > startTimestamp && block.timestamp < endTimestamp) {\r\n                _state = State.SellingTickets;\r\n            }\r\n        }\r\n        require(_state == State.SellingTickets, \"Must be in SellingTickets\");\r\n        require(block.timestamp < endTimestamp, \"End timestamp must be in the future\");\r\n        require(count > 0, \"Ticket count must be more than 0\");\r\n        require(msg.value == ticketPrice * count, \"Incorrect purchase amount (must be ticketPrice * count)\");\r\n\r\n        _assignTickets(msg.sender, count);\r\n        _soldTickets += count;\r\n        assert(_tickets == _ticketsLeft + _soldTickets + _giveawayTickets);\r\n\r\n        _addressToPurchasedCountMap[msg.sender] += count;\r\n\r\n        if (_ticketsLeft == 0) {\r\n            _state = State.WaitingForRNG;\r\n            _requestRandomWords();\r\n        }\r\n    }\r\n\r\n    struct AddressAndCount {\r\n        address receiverAddress;\r\n        uint16 count;\r\n    }\r\n\r\n    /**\r\n     * @dev Giveaway tickets. `owner` of raffle can giveaway free tickets, used for promotion.\r\n     *\r\n     * It is possible to giveaway tickets before start, ensuring that promised tickets for promotions can be assigned,\r\n     * otherwise if raffle is quickly sold out, we may not able to do it in time.\r\n     *\r\n     * If last ticket is given out, triggers {_requestRandomWords} to request random number from Chainlink VRF.\r\n     *\r\n     * Requirements:\r\n     * - must be in WaitingForStart or SellingTickets state\r\n     * - cannot giveaway after `endTimestamp`\r\n     */\r\n    function giveawayTicket(AddressAndCount[] memory receivers) external onlyOwner {\r\n        require(\r\n            _state == State.WaitingForStart || _state == State.SellingTickets,\r\n            \"Must be in WaitingForStart or SellingTickets\"\r\n        );\r\n\r\n        if (_state == State.WaitingForStart) {\r\n            if (block.timestamp > startTimestamp && block.timestamp < endTimestamp) {\r\n                _state = State.SellingTickets;\r\n            }\r\n        }\r\n        require(block.timestamp < endTimestamp, \"End timestamp must be in the future\");\r\n\r\n        for (uint256 i = 0; i < receivers.length; i++) {\r\n            AddressAndCount memory item = receivers[i];\r\n\r\n            _assignTickets(item.receiverAddress, item.count);\r\n            _giveawayTickets += item.count;\r\n            assert(_tickets == _ticketsLeft + _soldTickets + _giveawayTickets);\r\n        }\r\n\r\n        if (_ticketsLeft == 0) {\r\n            _state = State.WaitingForRNG;\r\n            _requestRandomWords();\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev After the correct NFT (specified in raffle constructor) is transferred to raffle contract,\r\n     * this method must be invoked to verify it and move raffle into WaitingForStart state.\r\n     *\r\n     * Requirements:\r\n     * - must be in WaitingForNFT state\r\n     */\r\n    function verifyNFTPresenceBeforeStart() external {\r\n        require(_state == State.WaitingForNFT, \"Must be in WaitingForNFT\");\r\n\r\n        if (nftStandard == NFTStandard.CryptoPunks) {\r\n            if (ICryptoPunk(nftContract).punkIndexToAddress(nftTokenId) == address(this)) {\r\n                _state = State.WaitingForStart;\r\n            }\r\n        }\r\n        else if (nftStandard == NFTStandard.ERC721) {\r\n            if (IERC721(nftContract).ownerOf(nftTokenId) == address(this)) {\r\n                _state = State.WaitingForStart;\r\n            }\r\n        }\r\n        else if (nftStandard == NFTStandard.ERC1155) {\r\n            if (IERC1155(nftContract).balanceOf(address(this), nftTokenId) == 1) {\r\n                _state = State.WaitingForStart;\r\n            }\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Cancels raffle before it has started.\r\n     *\r\n     * Only raffle `owner` can do it and it is needed in case raffle was created incorrectly.\r\n     *\r\n     * Requirements:\r\n     * - must be in WaitingForNFT or WaitingForStart state\r\n     */\r\n    function cancelBeforeStart() external onlyOwner {\r\n        require(\r\n            _state == State.WaitingForNFT || _state == State.WaitingForStart,\r\n            \"Must be in WaitingForNFT or WaitingForStart\"\r\n        );\r\n\r\n        _state = State.Cancelled;\r\n        _cancelTimestamp = block.timestamp;\r\n    }\r\n\r\n    /**\r\n     * @dev Cancels raffle if not all tickets were sold.\r\n     *\r\n     * Anyone can call this method after `endTimestamp`.\r\n     *\r\n     * Requirements:\r\n     * - must be in SellingTickets state\r\n     */\r\n    function cancelIfUnsold() external {\r\n        require(\r\n            _state == State.WaitingForStart || _state == State.SellingTickets,\r\n            \"Must be in WaitingForStart or SellingTickets\"\r\n        );\r\n        require(block.timestamp > endTimestamp, \"End timestamp must be in the past\");\r\n\r\n        _state = State.Cancelled;\r\n        _cancelTimestamp = block.timestamp;\r\n    }\r\n\r\n    /**\r\n     * @dev Cancels raffle if there is no response from Chainlink VRF.\r\n     *\r\n     * Anyone can call this method after `endTimestamp` + 1 day.\r\n     *\r\n     * Requirements:\r\n     * - must be in WaitingForRNG state\r\n     */\r\n    function cancelIfNoRNG() external {\r\n        require(_state == State.WaitingForRNG, \"Must be in WaitingForRNG\");\r\n        require(block.timestamp > endTimestamp + 1 days, \"End timestamp + 1 day must be in the past\");\r\n\r\n        _state = State.Cancelled;\r\n        _cancelTimestamp = block.timestamp;\r\n    }\r\n\r\n    /**\r\n     * @dev Transfers purchased ticket refund into internal escrow, after that user can claim ETH\r\n     * using {PullPayment-withdrawPayments}.\r\n     *\r\n     * Requirements:\r\n     * - must be in Cancelled state\r\n     */\r\n    function transferTicketRefundIfCancelled() external {\r\n        require(_state == State.Cancelled, \"Must be in Cancelled\");\r\n\r\n        uint256 refundAmount = _addressToPurchasedCountMap[msg.sender] * ticketPrice;\r\n        if (refundAmount > 0) {\r\n            _addressToPurchasedCountMap[msg.sender] = 0;\r\n            _asyncTransfer(msg.sender, refundAmount);\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Transfers specified NFT to raffle `owner`. This method is used to recover NFT (including other NFTs,\r\n     * that could have been transferred to raffle by mistake) if raffle gets cancelled.\r\n     *\r\n     * Requirements:\r\n     * - must be in Cancelled state\r\n     */\r\n    function transferNFTToOwnerIfCancelled(NFTStandard nftStandard, address contractAddress, uint256 tokenId) external {\r\n        require(_state == State.Cancelled, \"Must be in Cancelled\");\r\n\r\n        if (nftStandard == NFTStandard.CryptoPunks) {\r\n            ICryptoPunk(contractAddress).transferPunk(address(owner()), tokenId);\r\n        }\r\n        else if (nftStandard == NFTStandard.ERC721) {\r\n            IERC721(contractAddress).safeTransferFrom(address(this), owner(), tokenId);\r\n        }\r\n        else if (nftStandard == NFTStandard.ERC1155) {\r\n            IERC1155(contractAddress).safeTransferFrom(address(this), owner(), tokenId, 1, \"\");\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Transfers raffle NFT to `_winnerAddress` after the raffle has completed.\r\n     *\r\n     * Requirements:\r\n     * - must be in Completed state\r\n     */\r\n    function transferNFTToWinnerIfCompleted() external {\r\n        require(_state == State.Completed, \"Must be in Completed\");\r\n        assert(_winnerAddress != address(0));\r\n\r\n        _transferNFTToWinnerTimestamp = block.timestamp;\r\n        if (nftStandard == NFTStandard.CryptoPunks) {\r\n            ICryptoPunk(nftContract).transferPunk(_winnerAddress, nftTokenId);\r\n        }\r\n        else if (nftStandard == NFTStandard.ERC721) {\r\n            IERC721(nftContract).safeTransferFrom(address(this), _winnerAddress, nftTokenId);\r\n        }\r\n        else if (nftStandard == NFTStandard.ERC1155) {\r\n            IERC1155(nftContract).safeTransferFrom(address(this), _winnerAddress, nftTokenId, 1, \"\");\r\n        }\r\n    }\r\n\r\n    /**\r\n     * @dev Transfers raffle ETHinto internal escrow, after that raffle `owner` can claim it\r\n     * using {PullPayment-withdrawPayments}.\r\n     *\r\n     * Requirements:\r\n     * - must be in Completed state\r\n     */\r\n    function transferETHToOwnerIfCompleted() external {\r\n        require(_state == State.Completed, \"Must be in Completed\");\r\n\r\n        _asyncTransfer(owner(), address(this).balance);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the number of purchased tickets for given `owner`.\r\n     */\r\n    function getPurchasedTicketCount(address owner) public view returns (uint16) {\r\n        return _addressToPurchasedCountMap[owner];\r\n    }\r\n\r\n    /**\r\n    * @dev Returns raffle state.\r\n     *\r\n     * If `Completed`, it is possible to use {getWinnerAddress}, {getWinnerDrawTimestamp} and {getWinnerTicketNumber}.\r\n     */\r\n    function getState() public view returns (State) {\r\n        return _state;\r\n    }\r\n\r\n    function getCancelTimestamp() public view returns (uint256) {\r\n        return _cancelTimestamp;\r\n    }\r\n\r\n    function getTransferNFTToWinnerTimestamp() public view returns (uint256) {\r\n        return _transferNFTToWinnerTimestamp;\r\n    }\r\n\r\n    function getWinnerAddress() public view returns (address) {\r\n        return _winnerAddress;\r\n    }\r\n\r\n    function getWinnerDrawTimestamp() public view returns (uint256) {\r\n        return _winnerDrawTimestamp;\r\n    }\r\n\r\n    function getWinnerTicketNumber() public view returns (uint16) {\r\n        return _winnerTicketNumber;\r\n    }\r\n\r\n    /**\r\n     * @dev Chainlink VRF callback function.\r\n     *\r\n     * Returned `randomWords` are stored in `vrfRandomWords`, we determine winner and store all relevant information in\r\n     * `_winnerTicketNumber`, `_winnerDrawTimestamp` and `_winnerAddress`.\r\n     *\r\n     * Requirements:\r\n     * - must have correct `requestId`\r\n     * - must be in WaitingForRNG state\r\n     *\r\n     * Emits a {WinnerDrawn} event.\r\n     */\r\n    function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal override {\r\n        require(vrfRequestId == requestId, \"Unexpected VRF request id\");\r\n        require(_state == State.WaitingForRNG, \"Must be in WaitingForRNG\");\r\n\r\n        vrfRandomWords = randomWords;\r\n        _winnerTicketNumber = uint16(randomWords[0] % _tickets);\r\n        _winnerDrawTimestamp = block.timestamp;\r\n        _winnerAddress = findOwnerOfTicketNumber(_winnerTicketNumber);\r\n        _state = State.Completed;\r\n        emit WinnerDrawn(_winnerTicketNumber, _winnerAddress);\r\n    }\r\n\r\n    /**\r\n     * @dev Requests random number from Chainlink VRF. Called when last ticked is sold or given out.\r\n     *\r\n     * Requirements:\r\n     * - must be in WaitingForRNG state\r\n     */\r\n    function _requestRandomWords() private {\r\n        require(_state == State.WaitingForRNG, \"Must be in WaitingForRNG\");\r\n\r\n        vrfRequestId = VRF_COORDINATOR.requestRandomWords(\r\n            vrfKeyHash,\r\n            vrfSubscriptionId,\r\n            VRF_REQUEST_CONFIRMATIONS,\r\n            VRF_CALLBACK_GAS_LIMIT,\r\n            VRF_NUM_WORDS\r\n        );\r\n    }\r\n}\r\n"
    },
    "contracts/ICryptoPunk.sol": {
      "content": "// SPDX-License-Identifier: MIT\r\npragma solidity ^0.8.9;\r\n\r\n/**\r\n * @dev This contract is used to represent `CryptoPunksMarket` and interact with CryptoPunk NFTs.\r\n */\r\ninterface ICryptoPunk {\r\n    function punkIndexToAddress(uint256 punkIndex) external view returns (address);\r\n\r\n    function transferPunk(address to, uint256 punkIndex) external;\r\n}\r\n"
    },
    "contracts/TicketStorage.sol": {
      "content": "// SPDX-License-Identifier: MIT\r\npragma solidity ^0.8.9;\r\n\r\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\r\n\r\n/**\r\n * @dev This contract is used to store numbered ticket ranges and their owners.\r\n *\r\n * Ticket range is represented using {TicketNumberRange}, a struct of `owner, `from` and `to`. If account `0x1` buys\r\n * first ticket, then we store it as `(0x1, 0, 0)`, if then account `0x2` buys ten tickets, then we store next record as\r\n * `(0x2, 1, 10)`. If after that third account `0x3` buys ten tickets, we store it as `(0x3, 11, 20)`. And so on.\r\n *\r\n * Storing ticket numbers in such way allows compact representation of accounts who buy a lot of tickets at once.\r\n *\r\n * We set 25000 as limit of how many tickets we can support.\r\n */\r\nabstract contract TicketStorage {\r\n    event TicketsAssigned(TicketNumberRange ticketNumberRange, uint16 ticketsLeft);\r\n\r\n    struct TicketNumberRange {\r\n        address owner;\r\n        uint16 from;\r\n        uint16 to;\r\n    }\r\n\r\n    uint16 internal immutable _tickets;\r\n    uint16 internal _ticketsLeft;\r\n\r\n    TicketNumberRange[] private _ticketNumberRanges;\r\n    mapping(address => uint16) private _addressToAssignedCountMap;\r\n    mapping(address => uint16[]) private _addressToAssignedTicketNumberRangesMap;\r\n\r\n    constructor(uint16 tickets) {\r\n        require(tickets > 0, \"Number of tickets must be greater than 0\");\r\n        require(tickets <= 25_000, \"Number of tickets cannot exceed 25_000\");\r\n\r\n        _tickets = tickets;\r\n        _ticketsLeft = tickets;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns total amount of tickets.\r\n     */\r\n    function getTickets() public view returns (uint16) {\r\n        return _tickets;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns amount of unassigned tickets.\r\n     */\r\n    function getTicketsLeft() public view returns (uint16) {\r\n        return _ticketsLeft;\r\n    }\r\n\r\n    /**\r\n     * @dev Returns {TicketNumberRange} for given `index`.\r\n     */\r\n    function getTicketNumberRange(uint16 index) public view returns (TicketNumberRange memory) {\r\n        return _ticketNumberRanges[index];\r\n    }\r\n\r\n    /**\r\n     * @dev Returns how many tickets are assigned to given `owner`.\r\n     */\r\n    function getAssignedTicketCount(address owner) public view returns (uint16) {\r\n        return _addressToAssignedCountMap[owner];\r\n    }\r\n\r\n    /**\r\n     * @dev Returns the index of {TicketNumberRange} in `_ticketNumberRanges` that is assigned to `owner`.\r\n     *\r\n     * For example, if `owner` purchased tickets three times ({getAssignedTicketNumberRanges} will return `3`),\r\n     * we can use this method with `index` of 0, 1 and 2, to get indexes of {TicketNumberRange} in `_ticketNumberRanges`.\r\n     */\r\n    function getAssignedTicketNumberRange(address owner, uint16 index) public view returns (uint16) {\r\n        return _addressToAssignedTicketNumberRangesMap[owner][index];\r\n    }\r\n\r\n    /**\r\n     * @dev Returns how many {TicketNumberRange} are assigned for given `owner`.\r\n     *\r\n     * Can be used in combination with {getAssignedTicketNumberRange} and {getTicketNumberRange} to show\r\n     * all actual ticket numbers that are assigned to the `owner`.\r\n     */\r\n    function getAssignedTicketNumberRanges(address owner) public view returns (uint16) {\r\n        return uint16(_addressToAssignedTicketNumberRangesMap[owner].length);\r\n    }\r\n\r\n    /**\r\n     * @dev Assigns `count` amount of tickets to `owner` address.\r\n     *\r\n     * Requirements:\r\n     * - there must be enough tickets left\r\n     *\r\n     * Emits a {TicketsAssigned} event.\r\n     */\r\n    function _assignTickets(address owner, uint16 count) internal {\r\n        require(_ticketsLeft > 0, \"All tickets are assigned\");\r\n        require(_ticketsLeft >= count, \"Assigning too many tickets at once\");\r\n\r\n        uint16 from = _tickets - _ticketsLeft;\r\n        _ticketsLeft -= count;\r\n        TicketNumberRange memory ticketNumberRange = TicketNumberRange({\r\n            owner: owner,\r\n            from: from,\r\n            to: from + count - 1\r\n        });\r\n        _ticketNumberRanges.push(ticketNumberRange);\r\n        _addressToAssignedCountMap[owner] += count;\r\n        _addressToAssignedTicketNumberRangesMap[owner].push(uint16(_ticketNumberRanges.length - 1));\r\n\r\n        assert(_ticketNumberRanges[_ticketNumberRanges.length - 1].to == _tickets - _ticketsLeft - 1);\r\n\r\n        emit TicketsAssigned(ticketNumberRange, _ticketsLeft);\r\n    }\r\n\r\n    /**\r\n     * @dev Returns address of the `owner` of given ticket number.\r\n     *\r\n     * Uses binary search on `_ticketNumberRanges` to find it.\r\n     *\r\n     * Requirements:\r\n     * - all tickets must be assigned\r\n     */\r\n    function findOwnerOfTicketNumber(uint16 ticketNumber) public view returns (address) {\r\n        require(ticketNumber < _tickets, \"Ticket number does not exist\");\r\n        require(_ticketsLeft == 0, \"Not all tickets are assigned\");\r\n\r\n        uint16 ticketNumberRangesLength = uint16(_ticketNumberRanges.length);\r\n        assert(_ticketNumberRanges[0].from == 0);\r\n        assert(_ticketNumberRanges[ticketNumberRangesLength - 1].to == _tickets - 1);\r\n\r\n        uint16 left = 0;\r\n        uint16 right = ticketNumberRangesLength - 1;\r\n        uint16 pivot = (left + right) / 2;\r\n        address ownerAddress = address(0);\r\n        while (ownerAddress == address(0)) {\r\n            pivot = (left + right) / 2;\r\n            TicketNumberRange memory ticketNumberRange = _ticketNumberRanges[pivot];\r\n            if (ticketNumberRange.to < ticketNumber) {\r\n                left = pivot + 1;\r\n            } else if (ticketNumberRange.from > ticketNumber) {\r\n                right = pivot - 1;\r\n            } else {\r\n                ownerAddress = ticketNumberRange.owner;\r\n            }\r\n        }\r\n\r\n        return ownerAddress;\r\n    }\r\n}\r\n"
    },
    "@openzeppelin/contracts/access/Ownable.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor() {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
    },
    "@openzeppelin/contracts/security/PullPayment.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/PullPayment.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/escrow/Escrow.sol\";\n\n/**\n * @dev Simple implementation of a\n * https://consensys.github.io/smart-contract-best-practices/recommendations/#favor-pull-over-push-for-external-calls[pull-payment]\n * strategy, where the paying contract doesn't interact directly with the\n * receiver account, which must withdraw its payments itself.\n *\n * Pull-payments are often considered the best practice when it comes to sending\n * Ether, security-wise. It prevents recipients from blocking execution, and\n * eliminates reentrancy concerns.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n *\n * To use, derive from the `PullPayment` contract, and use {_asyncTransfer}\n * instead of Solidity's `transfer` function. Payees can query their due\n * payments with {payments}, and retrieve them with {withdrawPayments}.\n */\nabstract contract PullPayment {\n    Escrow private immutable _escrow;\n\n    constructor() {\n        _escrow = new Escrow();\n    }\n\n    /**\n     * @dev Withdraw accumulated payments, forwarding all gas to the recipient.\n     *\n     * Note that _any_ account can call this function, not just the `payee`.\n     * This means that contracts unaware of the `PullPayment` protocol can still\n     * receive funds this way, by having a separate account call\n     * {withdrawPayments}.\n     *\n     * WARNING: Forwarding all gas opens the door to reentrancy vulnerabilities.\n     * Make sure you trust the recipient, or are either following the\n     * checks-effects-interactions pattern or using {ReentrancyGuard}.\n     *\n     * @param payee Whose payments will be withdrawn.\n     *\n     * Causes the `escrow` to emit a {Withdrawn} event.\n     */\n    function withdrawPayments(address payable payee) public virtual {\n        _escrow.withdraw(payee);\n    }\n\n    /**\n     * @dev Returns the payments owed to an address.\n     * @param dest The creditor's address.\n     */\n    function payments(address dest) public view returns (uint256) {\n        return _escrow.depositsOf(dest);\n    }\n\n    /**\n     * @dev Called by the payer to store the sent amount as credit to be pulled.\n     * Funds sent in this way are stored in an intermediate {Escrow} contract, so\n     * there is no danger of them being spent before withdrawal.\n     *\n     * @param dest The destination address of the funds.\n     * @param amount The amount to transfer.\n     *\n     * Causes the `escrow` to emit a {Deposited} event.\n     */\n    function _asyncTransfer(address dest, uint256 amount) internal virtual {\n        _escrow.deposit{value: amount}(dest);\n    }\n}\n"
    },
    "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/** ****************************************************************************\n * @notice Interface for contracts using VRF randomness\n * *****************************************************************************\n * @dev PURPOSE\n *\n * @dev Reggie the Random Oracle (not his real job) wants to provide randomness\n * @dev to Vera the verifier in such a way that Vera can be sure he's not\n * @dev making his output up to suit himself. Reggie provides Vera a public key\n * @dev to which he knows the secret key. Each time Vera provides a seed to\n * @dev Reggie, he gives back a value which is computed completely\n * @dev deterministically from the seed and the secret key.\n *\n * @dev Reggie provides a proof by which Vera can verify that the output was\n * @dev correctly computed once Reggie tells it to her, but without that proof,\n * @dev the output is indistinguishable to her from a uniform random sample\n * @dev from the output space.\n *\n * @dev The purpose of this contract is to make it easy for unrelated contracts\n * @dev to talk to Vera the verifier about the work Reggie is doing, to provide\n * @dev simple access to a verifiable source of randomness. It ensures 2 things:\n * @dev 1. The fulfillment came from the VRFCoordinator\n * @dev 2. The consumer contract implements fulfillRandomWords.\n * *****************************************************************************\n * @dev USAGE\n *\n * @dev Calling contracts must inherit from VRFConsumerBase, and can\n * @dev initialize VRFConsumerBase's attributes in their constructor as\n * @dev shown:\n *\n * @dev   contract VRFConsumer {\n * @dev     constructor(<other arguments>, address _vrfCoordinator, address _link)\n * @dev       VRFConsumerBase(_vrfCoordinator) public {\n * @dev         <initialization with other arguments goes here>\n * @dev       }\n * @dev   }\n *\n * @dev The oracle will have given you an ID for the VRF keypair they have\n * @dev committed to (let's call it keyHash). Create subscription, fund it\n * @dev and your consumer contract as a consumer of it (see VRFCoordinatorInterface\n * @dev subscription management functions).\n * @dev Call requestRandomWords(keyHash, subId, minimumRequestConfirmations,\n * @dev callbackGasLimit, numWords),\n * @dev see (VRFCoordinatorInterface for a description of the arguments).\n *\n * @dev Once the VRFCoordinator has received and validated the oracle's response\n * @dev to your request, it will call your contract's fulfillRandomWords method.\n *\n * @dev The randomness argument to fulfillRandomWords is a set of random words\n * @dev generated from your requestId and the blockHash of the request.\n *\n * @dev If your contract could have concurrent requests open, you can use the\n * @dev requestId returned from requestRandomWords to track which response is associated\n * @dev with which randomness request.\n * @dev See \"SECURITY CONSIDERATIONS\" for principles to keep in mind,\n * @dev if your contract could have multiple requests in flight simultaneously.\n *\n * @dev Colliding `requestId`s are cryptographically impossible as long as seeds\n * @dev differ.\n *\n * *****************************************************************************\n * @dev SECURITY CONSIDERATIONS\n *\n * @dev A method with the ability to call your fulfillRandomness method directly\n * @dev could spoof a VRF response with any random value, so it's critical that\n * @dev it cannot be directly called by anything other than this base contract\n * @dev (specifically, by the VRFConsumerBase.rawFulfillRandomness method).\n *\n * @dev For your users to trust that your contract's random behavior is free\n * @dev from malicious interference, it's best if you can write it so that all\n * @dev behaviors implied by a VRF response are executed *during* your\n * @dev fulfillRandomness method. If your contract must store the response (or\n * @dev anything derived from it) and use it later, you must ensure that any\n * @dev user-significant behavior which depends on that stored value cannot be\n * @dev manipulated by a subsequent VRF request.\n *\n * @dev Similarly, both miners and the VRF oracle itself have some influence\n * @dev over the order in which VRF responses appear on the blockchain, so if\n * @dev your contract could have multiple VRF requests in flight simultaneously,\n * @dev you must ensure that the order in which the VRF responses arrive cannot\n * @dev be used to manipulate your contract's user-significant behavior.\n *\n * @dev Since the block hash of the block which contains the requestRandomness\n * @dev call is mixed into the input to the VRF *last*, a sufficiently powerful\n * @dev miner could, in principle, fork the blockchain to evict the block\n * @dev containing the request, forcing the request to be included in a\n * @dev different block with a different hash, and therefore a different input\n * @dev to the VRF. However, such an attack would incur a substantial economic\n * @dev cost. This cost scales with the number of blocks the VRF oracle waits\n * @dev until it calls responds to a request. It is for this reason that\n * @dev that you can signal to an oracle you'd like them to wait longer before\n * @dev responding to the request (however this is not enforced in the contract\n * @dev and so remains effective only in the case of unmodified oracle software).\n */\nabstract contract VRFConsumerBaseV2 {\n  error OnlyCoordinatorCanFulfill(address have, address want);\n  address private immutable vrfCoordinator;\n\n  /**\n   * @param _vrfCoordinator address of VRFCoordinator contract\n   */\n  constructor(address _vrfCoordinator) {\n    vrfCoordinator = _vrfCoordinator;\n  }\n\n  /**\n   * @notice fulfillRandomness handles the VRF response. Your contract must\n   * @notice implement it. See \"SECURITY CONSIDERATIONS\" above for important\n   * @notice principles to keep in mind when implementing your fulfillRandomness\n   * @notice method.\n   *\n   * @dev VRFConsumerBaseV2 expects its subcontracts to have a method with this\n   * @dev signature, and will call it once it has verified the proof\n   * @dev associated with the randomness. (It is triggered via a call to\n   * @dev rawFulfillRandomness, below.)\n   *\n   * @param requestId The Id initially returned by requestRandomness\n   * @param randomWords the VRF output expanded to the requested number of words\n   */\n  function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual;\n\n  // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF\n  // proof. rawFulfillRandomness then calls fulfillRandomness, after validating\n  // the origin of the call\n  function rawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external {\n    if (msg.sender != vrfCoordinator) {\n      revert OnlyCoordinatorCanFulfill(msg.sender, vrfCoordinator);\n    }\n    fulfillRandomWords(requestId, randomWords);\n  }\n}\n"
    },
    "@openzeppelin/contracts/token/ERC721/IERC721.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n    /**\n     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n    /**\n     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n     */\n    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n    /**\n     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n     */\n    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n    /**\n     * @dev Returns the number of tokens in ``owner``'s account.\n     */\n    function balanceOf(address owner) external view returns (uint256 balance);\n\n    /**\n     * @dev Returns the owner of the `tokenId` token.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function ownerOf(uint256 tokenId) external view returns (address owner);\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 tokenId,\n        bytes calldata data\n    ) external;\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n     * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 tokenId\n    ) external;\n\n    /**\n     * @dev Transfers `tokenId` token from `from` to `to`.\n     *\n     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must be owned by `from`.\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(\n        address from,\n        address to,\n        uint256 tokenId\n    ) external;\n\n    /**\n     * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n     * The approval is cleared when the token is transferred.\n     *\n     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n     *\n     * Requirements:\n     *\n     * - The caller must own the token or be an approved operator.\n     * - `tokenId` must exist.\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address to, uint256 tokenId) external;\n\n    /**\n     * @dev Approve or remove `operator` as an operator for the caller.\n     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n     *\n     * Requirements:\n     *\n     * - The `operator` cannot be the caller.\n     *\n     * Emits an {ApprovalForAll} event.\n     */\n    function setApprovalForAll(address operator, bool _approved) external;\n\n    /**\n     * @dev Returns the account approved for `tokenId` token.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function getApproved(uint256 tokenId) external view returns (address operator);\n\n    /**\n     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n     *\n     * See {setApprovalForAll}\n     */\n    function isApprovedForAll(address owner, address operator) external view returns (bool);\n}\n"
    },
    "@openzeppelin/contracts/token/ERC1155/IERC1155.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC1155 compliant contract, as defined in the\n * https://eips.ethereum.org/EIPS/eip-1155[EIP].\n *\n * _Available since v3.1._\n */\ninterface IERC1155 is IERC165 {\n    /**\n     * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.\n     */\n    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);\n\n    /**\n     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all\n     * transfers.\n     */\n    event TransferBatch(\n        address indexed operator,\n        address indexed from,\n        address indexed to,\n        uint256[] ids,\n        uint256[] values\n    );\n\n    /**\n     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to\n     * `approved`.\n     */\n    event ApprovalForAll(address indexed account, address indexed operator, bool approved);\n\n    /**\n     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.\n     *\n     * If an {URI} event was emitted for `id`, the standard\n     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value\n     * returned by {IERC1155MetadataURI-uri}.\n     */\n    event URI(string value, uint256 indexed id);\n\n    /**\n     * @dev Returns the amount of tokens of token type `id` owned by `account`.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     */\n    function balanceOf(address account, uint256 id) external view returns (uint256);\n\n    /**\n     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.\n     *\n     * Requirements:\n     *\n     * - `accounts` and `ids` must have the same length.\n     */\n    function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)\n        external\n        view\n        returns (uint256[] memory);\n\n    /**\n     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,\n     *\n     * Emits an {ApprovalForAll} event.\n     *\n     * Requirements:\n     *\n     * - `operator` cannot be the caller.\n     */\n    function setApprovalForAll(address operator, bool approved) external;\n\n    /**\n     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.\n     *\n     * See {setApprovalForAll}.\n     */\n    function isApprovedForAll(address account, address operator) external view returns (bool);\n\n    /**\n     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.\n     *\n     * Emits a {TransferSingle} event.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.\n     * - `from` must have a balance of tokens of type `id` of at least `amount`.\n     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the\n     * acceptance magic value.\n     */\n    function safeTransferFrom(\n        address from,\n        address to,\n        uint256 id,\n        uint256 amount,\n        bytes calldata data\n    ) external;\n\n    /**\n     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.\n     *\n     * Emits a {TransferBatch} event.\n     *\n     * Requirements:\n     *\n     * - `ids` and `amounts` must have the same length.\n     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the\n     * acceptance magic value.\n     */\n    function safeBatchTransferFrom(\n        address from,\n        address to,\n        uint256[] calldata ids,\n        uint256[] calldata amounts,\n        bytes calldata data\n    ) external;\n}\n"
    },
    "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface VRFCoordinatorV2Interface {\n  /**\n   * @notice Get configuration relevant for making requests\n   * @return minimumRequestConfirmations global min for request confirmations\n   * @return maxGasLimit global max for request gas limit\n   * @return s_provingKeyHashes list of registered key hashes\n   */\n  function getRequestConfig()\n    external\n    view\n    returns (\n      uint16,\n      uint32,\n      bytes32[] memory\n    );\n\n  /**\n   * @notice Request a set of random words.\n   * @param keyHash - Corresponds to a particular oracle job which uses\n   * that key for generating the VRF proof. Different keyHash's have different gas price\n   * ceilings, so you can select a specific one to bound your maximum per request cost.\n   * @param subId  - The ID of the VRF subscription. Must be funded\n   * with the minimum subscription balance required for the selected keyHash.\n   * @param minimumRequestConfirmations - How many blocks you'd like the\n   * oracle to wait before responding to the request. See SECURITY CONSIDERATIONS\n   * for why you may want to request more. The acceptable range is\n   * [minimumRequestBlockConfirmations, 200].\n   * @param callbackGasLimit - How much gas you'd like to receive in your\n   * fulfillRandomWords callback. Note that gasleft() inside fulfillRandomWords\n   * may be slightly less than this amount because of gas used calling the function\n   * (argument decoding etc.), so you may need to request slightly more than you expect\n   * to have inside fulfillRandomWords. The acceptable range is\n   * [0, maxGasLimit]\n   * @param numWords - The number of uint256 random values you'd like to receive\n   * in your fulfillRandomWords callback. Note these numbers are expanded in a\n   * secure way by the VRFCoordinator from a single random value supplied by the oracle.\n   * @return requestId - A unique identifier of the request. Can be used to match\n   * a request to a response in fulfillRandomWords.\n   */\n  function requestRandomWords(\n    bytes32 keyHash,\n    uint64 subId,\n    uint16 minimumRequestConfirmations,\n    uint32 callbackGasLimit,\n    uint32 numWords\n  ) external returns (uint256 requestId);\n\n  /**\n   * @notice Create a VRF subscription.\n   * @return subId - A unique subscription id.\n   * @dev You can manage the consumer set dynamically with addConsumer/removeConsumer.\n   * @dev Note to fund the subscription, use transferAndCall. For example\n   * @dev  LINKTOKEN.transferAndCall(\n   * @dev    address(COORDINATOR),\n   * @dev    amount,\n   * @dev    abi.encode(subId));\n   */\n  function createSubscription() external returns (uint64 subId);\n\n  /**\n   * @notice Get a VRF subscription.\n   * @param subId - ID of the subscription\n   * @return balance - LINK balance of the subscription in juels.\n   * @return reqCount - number of requests for this subscription, determines fee tier.\n   * @return owner - owner of the subscription.\n   * @return consumers - list of consumer address which are able to use this subscription.\n   */\n  function getSubscription(uint64 subId)\n    external\n    view\n    returns (\n      uint96 balance,\n      uint64 reqCount,\n      address owner,\n      address[] memory consumers\n    );\n\n  /**\n   * @notice Request subscription owner transfer.\n   * @param subId - ID of the subscription\n   * @param newOwner - proposed new owner of the subscription\n   */\n  function requestSubscriptionOwnerTransfer(uint64 subId, address newOwner) external;\n\n  /**\n   * @notice Request subscription owner transfer.\n   * @param subId - ID of the subscription\n   * @dev will revert if original owner of subId has\n   * not requested that msg.sender become the new owner.\n   */\n  function acceptSubscriptionOwnerTransfer(uint64 subId) external;\n\n  /**\n   * @notice Add a consumer to a VRF subscription.\n   * @param subId - ID of the subscription\n   * @param consumer - New consumer which can use the subscription\n   */\n  function addConsumer(uint64 subId, address consumer) external;\n\n  /**\n   * @notice Remove a consumer from a VRF subscription.\n   * @param subId - ID of the subscription\n   * @param consumer - Consumer to remove from the subscription\n   */\n  function removeConsumer(uint64 subId, address consumer) external;\n\n  /**\n   * @notice Cancel a subscription\n   * @param subId - ID of the subscription\n   * @param to - Where to send the remaining LINK to\n   */\n  function cancelSubscription(uint64 subId, address to) external;\n\n  /*\n   * @notice Check to see if there exists a request commitment consumers\n   * for all consumers and keyhashes for a given sub.\n   * @param subId - ID of the subscription\n   * @return true if there exists at least one unfulfilled request for the subscription, false\n   * otherwise.\n   */\n  function pendingRequestExists(uint64 subId) external view returns (bool);\n}\n"
    },
    "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/utils/ERC1155Holder.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./ERC1155Receiver.sol\";\n\n/**\n * Simple implementation of `ERC1155Receiver` that will allow a contract to hold ERC1155 tokens.\n *\n * IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be\n * stuck.\n *\n * @dev _Available since v3.1._\n */\ncontract ERC1155Holder is ERC1155Receiver {\n    function onERC1155Received(\n        address,\n        address,\n        uint256,\n        uint256,\n        bytes memory\n    ) public virtual override returns (bytes4) {\n        return this.onERC1155Received.selector;\n    }\n\n    function onERC1155BatchReceived(\n        address,\n        address,\n        uint256[] memory,\n        uint256[] memory,\n        bytes memory\n    ) public virtual override returns (bytes4) {\n        return this.onERC1155BatchReceived.selector;\n    }\n}\n"
    },
    "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC721Receiver.sol\";\n\n/**\n * @dev Implementation of the {IERC721Receiver} interface.\n *\n * Accepts all token transfers.\n * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}.\n */\ncontract ERC721Holder is IERC721Receiver {\n    /**\n     * @dev See {IERC721Receiver-onERC721Received}.\n     *\n     * Always returns `IERC721Receiver.onERC721Received.selector`.\n     */\n    function onERC721Received(\n        address,\n        address,\n        uint256,\n        bytes memory\n    ) public virtual override returns (bytes4) {\n        return this.onERC721Received.selector;\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/Context.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/escrow/Escrow.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/escrow/Escrow.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../access/Ownable.sol\";\nimport \"../Address.sol\";\n\n/**\n * @title Escrow\n * @dev Base escrow contract, holds funds designated for a payee until they\n * withdraw them.\n *\n * Intended usage: This contract (and derived escrow contracts) should be a\n * standalone contract, that only interacts with the contract that instantiated\n * it. That way, it is guaranteed that all Ether will be handled according to\n * the `Escrow` rules, and there is no need to check for payable functions or\n * transfers in the inheritance tree. The contract that uses the escrow as its\n * payment method should be its owner, and provide public methods redirecting\n * to the escrow's deposit and withdraw.\n */\ncontract Escrow is Ownable {\n    using Address for address payable;\n\n    event Deposited(address indexed payee, uint256 weiAmount);\n    event Withdrawn(address indexed payee, uint256 weiAmount);\n\n    mapping(address => uint256) private _deposits;\n\n    function depositsOf(address payee) public view returns (uint256) {\n        return _deposits[payee];\n    }\n\n    /**\n     * @dev Stores the sent amount as credit to be withdrawn.\n     * @param payee The destination address of the funds.\n     *\n     * Emits a {Deposited} event.\n     */\n    function deposit(address payee) public payable virtual onlyOwner {\n        uint256 amount = msg.value;\n        _deposits[payee] += amount;\n        emit Deposited(payee, amount);\n    }\n\n    /**\n     * @dev Withdraw accumulated balance for a payee, forwarding all gas to the\n     * recipient.\n     *\n     * WARNING: Forwarding all gas opens the door to reentrancy vulnerabilities.\n     * Make sure you trust the recipient, or are either following the\n     * checks-effects-interactions pattern or using {ReentrancyGuard}.\n     *\n     * @param payee The address whose funds will be withdrawn and transferred to.\n     *\n     * Emits a {Withdrawn} event.\n     */\n    function withdraw(address payable payee) public virtual onlyOwner {\n        uint256 payment = _deposits[payee];\n\n        _deposits[payee] = 0;\n\n        payee.sendValue(payment);\n\n        emit Withdrawn(payee, payment);\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/Address.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length > 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCall(target, data, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        require(isContract(target), \"Address: call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        require(isContract(target), \"Address: static call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(isContract(target), \"Address: delegate call to non-contract\");\n\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResult(success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            // Look for revert reason and bubble it up if present\n            if (returndata.length > 0) {\n                // The easiest way to bubble the revert reason is using memory via assembly\n                /// @solidity memory-safe-assembly\n                assembly {\n                    let returndata_size := mload(returndata)\n                    revert(add(32, returndata), returndata_size)\n                }\n            } else {\n                revert(errorMessage);\n            }\n        }\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/introspection/IERC165.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
    },
    "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Receiver.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC1155Receiver.sol\";\nimport \"../../../utils/introspection/ERC165.sol\";\n\n/**\n * @dev _Available since v3.1._\n */\nabstract contract ERC1155Receiver is ERC165, IERC1155Receiver {\n    /**\n     * @dev See {IERC165-supportsInterface}.\n     */\n    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {\n        return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);\n    }\n}\n"
    },
    "@openzeppelin/contracts/utils/introspection/ERC165.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n    /**\n     * @dev See {IERC165-supportsInterface}.\n     */\n    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n        return interfaceId == type(IERC165).interfaceId;\n    }\n}\n"
    },
    "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev _Available since v3.1._\n */\ninterface IERC1155Receiver is IERC165 {\n    /**\n     * @dev Handles the receipt of a single ERC1155 token type. This function is\n     * called at the end of a `safeTransferFrom` after the balance has been updated.\n     *\n     * NOTE: To accept the transfer, this must return\n     * `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))`\n     * (i.e. 0xf23a6e61, or its own function selector).\n     *\n     * @param operator The address which initiated the transfer (i.e. msg.sender)\n     * @param from The address which previously owned the token\n     * @param id The ID of the token being transferred\n     * @param value The amount of tokens being transferred\n     * @param data Additional data with no specified format\n     * @return `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))` if transfer is allowed\n     */\n    function onERC1155Received(\n        address operator,\n        address from,\n        uint256 id,\n        uint256 value,\n        bytes calldata data\n    ) external returns (bytes4);\n\n    /**\n     * @dev Handles the receipt of a multiple ERC1155 token types. This function\n     * is called at the end of a `safeBatchTransferFrom` after the balances have\n     * been updated.\n     *\n     * NOTE: To accept the transfer(s), this must return\n     * `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`\n     * (i.e. 0xbc197c81, or its own function selector).\n     *\n     * @param operator The address which initiated the batch transfer (i.e. msg.sender)\n     * @param from The address which previously owned the token\n     * @param ids An array containing ids of each token being transferred (order and length must match values array)\n     * @param values An array containing amounts of each token being transferred (order and length must match ids array)\n     * @param data Additional data with no specified format\n     * @return `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))` if transfer is allowed\n     */\n    function onERC1155BatchReceived(\n        address operator,\n        address from,\n        uint256[] calldata ids,\n        uint256[] calldata values,\n        bytes calldata data\n    ) external returns (bytes4);\n}\n"
    },
    "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol": {
      "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC721 asset contracts.\n */\ninterface IERC721Receiver {\n    /**\n     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n     * by `operator` from `from`, this function is called.\n     *\n     * It must return its Solidity selector to confirm the token transfer.\n     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\n     *\n     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.\n     */\n    function onERC721Received(\n        address operator,\n        address from,\n        uint256 tokenId,\n        bytes calldata data\n    ) external returns (bytes4);\n}\n"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "libraries": {}
  }
}