// File: @chainlink/contracts/src/v0.8/ConfirmedOwner.sol



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

import "./ConfirmedOwnerWithProposal.sol";

/**
 * @title The ConfirmedOwner contract
 * @notice A contract with helpers for basic contract ownership.
 */
contract ConfirmedOwner is ConfirmedOwnerWithProposal {
  constructor(address newOwner) ConfirmedOwnerWithProposal(newOwner, address(0)) {}
}

// File: @chainlink/contracts/src/v0.8/ConfirmedOwnerWithProposal.sol



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

import "./interfaces/OwnableInterface.sol";

/**
 * @title The ConfirmedOwner contract
 * @notice A contract with helpers for basic contract ownership.
 */
contract ConfirmedOwnerWithProposal is OwnableInterface {
  address private s_owner;
  address private s_pendingOwner;

  event OwnershipTransferRequested(address indexed from, address indexed to);
  event OwnershipTransferred(address indexed from, address indexed to);

  constructor(address newOwner, address pendingOwner) {
    require(newOwner != address(0), "Cannot set owner to zero");

    s_owner = newOwner;
    if (pendingOwner != address(0)) {
      _transferOwnership(pendingOwner);
    }
  }

  /**
   * @notice Allows an owner to begin transferring ownership to a new address,
   * pending.
   */
  function transferOwnership(address to) public override onlyOwner {
    _transferOwnership(to);
  }

  /**
   * @notice Allows an ownership transfer to be completed by the recipient.
   */
  function acceptOwnership() external override {
    require(msg.sender == s_pendingOwner, "Must be proposed owner");

    address oldOwner = s_owner;
    s_owner = msg.sender;
    s_pendingOwner = address(0);

    emit OwnershipTransferred(oldOwner, msg.sender);
  }

  /**
   * @notice Get the current owner
   */
  function owner() public view override returns (address) {
    return s_owner;
  }

  /**
   * @notice validate, transfer ownership, and emit relevant events
   */
  function _transferOwnership(address to) private {
    require(to != msg.sender, "Cannot transfer to self");

    s_pendingOwner = to;

    emit OwnershipTransferRequested(s_owner, to);
  }

  /**
   * @notice validate access
   */
  function _validateOwnership() internal view {
    require(msg.sender == s_owner, "Only callable by owner");
  }

  /**
   * @notice Reverts if called by anyone other than the contract owner.
   */
  modifier onlyOwner() {
    _validateOwnership();
    _;
  }
}

// File: @chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol



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

// File: @chainlink/contracts/src/v0.8/interfaces/OwnableInterface.sol



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

interface OwnableInterface {
  function owner() external returns (address);

  function transferOwnership(address recipient) external;

  function acceptOwnership() external;
}

// File: @chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol



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

// File: contracts/INounsVisionBatchTransfer.sol



// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

/// @dev Interface for ERC721Like
interface ERC721Like {
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    function balanceOf(address owner) external view returns (uint256 balance);

    function ownerOf(uint256 tokenId) external view returns (address owner);

    function setApprovalForAll(address operator, bool approved) external;
    
    function totalSupply() external returns (uint256);

}

/// @dev Interface for NounsVisionBatchTransfer
interface INounsVisionBatchTransfer {
    function getStartId() external view returns (uint256 startId);

    function getStartIdAndBatchAmount(address receiver) external
        returns (uint256 startId, uint256 amount);

    function claimGlasses(uint256 startId, uint256 amount) external;

    function sendGlasses(uint256 startId, address recipient) external;

    function sendManyGlasses(uint256 startId, address[] calldata recipients) external;

    function allowanceFor(address receiver) external view
        returns (uint256);
}
// File: contracts/NounsVisionVRFDistributor.sol



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

import "./VRFv2Consumer.sol";
import "./INounsVisionBatchTransfer.sol";

// crafted by @0xDigitalOil with ❤️ for Nouns DAO ⌐◨-◨
contract NounsVisionVRFDistributor is VRFv2Consumer {
    
    /**
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
      EVENTS
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
    **/

    /// @dev Event log for when Nouns Vision Glasses are won
    /// @param roundId the round number
    /// @param randomResult random number generated by Chainlink VRF
    /// @param winners list of winning wallets (can include repeat wins)
    event Winners(
        uint256 roundId,
        uint256 randomResult,
        address[] winners
    );

    /// @dev Event log for when a Nouns holder claims GLASSES
    /// @param holder address of GLASSES claimer
    /// @param glassesClaimed number of GLASSES claimed
    event GlassesClaimed(
        address holder,
        uint256 glassesClaimed
    );


    /**
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
      CONSTANTS
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
    **/

    ERC721Like public constant NOUNS_VISION =
        ERC721Like(0xd8e6b954f7d3F42570D3B0adB516f2868729eC4D);

    ERC721Like public constant NOUNS_TOKEN =
        ERC721Like(0x9C8fF314C9Bc7F6e59A9d9225Fb22946427eDC03);       

    INounsVisionBatchTransfer public constant NOUNS_VISION_BATCH_TRANSFER =
        INounsVisionBatchTransfer(0x6ff4FF4Fe59D7EC571f36e36961B032027e68ceE);

    uint256 public constant CLAIM_WINDOW = 108_000; // 15 days in blocks


    /**
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
      STORAGE VARIABLES
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
    **/

    struct ClaimRound {
      uint256 id;
      uint256 startBlock; 
      uint256 endBlock; // last block to claim
      mapping (address => uint256) winners; /* winnerAddress --> numberGlasses */
      uint256 numberWon;
      uint256 numberClaimed;
    }

    ClaimRound[] public claimRounds;
    uint256 public currentRound;

    /**
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
      ERRORS
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
    **/

    error AvailGlassesZero();   
    error ClaimPeriodNotFinished(); 
    error NoClaimRoundsOpen();
    error NoClaimsForYou();

    /**
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
      CONSTRUCTOR
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
    **/

    constructor(uint64 subscriptionId) VRFv2Consumer(subscriptionId) {}    

    /**
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
      INTERNAL FUNCTIONS
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
    **/

    /// @notice Receives randomness; determines which wallets and quantities will have claimable GLASSES. The more tokens are in the wallet, the more likely it is that it will get each individual GLASSES awarded.
    /// @param _requestId Id of the VRF request
    /// @param _randomWords array of random numbers returned from VRF
    function fulfillRandomWords(
        uint256 _requestId,
        uint256[] memory _randomWords
    ) internal override {

        super.fulfillRandomWords(_requestId, _randomWords);

        if ((claimRounds.length > 0) && (block.number <= claimRounds[currentRound].endBlock)) {
          revert ClaimPeriodNotFinished();
        }

        uint256 availGlasses = remainingAllowance();

        if (availGlasses == 0) {
          revert AvailGlassesZero(); 
        }

        // Take first random word as source of randomness
        uint256 salt = _randomWords[0];

        uint256 nounsSupply = NOUNS_TOKEN.totalSupply();
        address[] memory winners = new address[](availGlasses);

        if (claimRounds.length > 0) {
          currentRound++;
        }
        claimRounds.push();
        ClaimRound storage round = claimRounds[currentRound];
        round.id = currentRound;
        round.startBlock = block.number;
        round.endBlock = block.number + CLAIM_WINDOW;
        round.numberWon = availGlasses;
        
        uint256 winnerId;
        address winner;
        for (uint256 i = 0; i < availGlasses; i++) {
            winnerId = uint256(keccak256(abi.encode(salt, i))) % nounsSupply;
            winner = NOUNS_TOKEN.ownerOf(winnerId);
            winners[i] = winner;
            round.winners[winner]++;
        }

        emit Winners(currentRound, salt, winners);

    }

    /**
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
      PUBLIC & EXTERNAL VIEW FUNCTIONS
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
    **/

    /// @notice Get number of claimed GLASSES per round
    /// @param round round number
    function numberClaimedGlasses(uint256 round) external view returns (uint256) {
      return (claimRounds.length > 0) ? claimRounds[round].numberClaimed : 0;
    }

    /// @notice Get remaining GLASSES allowance for this contract
    function remainingAllowance() public view returns (uint256) {    
      return NOUNS_VISION_BATCH_TRANSFER.allowanceFor(address(this));
    }

    /// @notice Get remaining claimable number of GLASSES this round. First check if this contract's allowance was taken away and in this case, return 0.
    function remainingClaimableCurrentRound() external view returns (uint256) { 
      if (remainingAllowance() == 0) {
        return 0;
      }   
      else if ((claimRounds.length > 0) && block.number <= claimRounds[currentRound].endBlock) {
        return claimRounds[currentRound].numberWon - claimRounds[currentRound].numberClaimed;
      }
      else {
        return 0;
      }
    }

    /// @notice Expired GLASSES that were not claimed in the last expired round. 
    function expiredGlassesLastRound() public view returns (uint256) {     
      if ((claimRounds.length > 0) && block.number > claimRounds[currentRound].endBlock) {
        return claimRounds[currentRound].numberWon - claimRounds[currentRound].numberClaimed;
      }
      else if ((claimRounds.length > 1) && block.number <= claimRounds[currentRound].endBlock) { // Current round still alive but previous round exists
        return claimRounds[currentRound-1].numberWon - claimRounds[currentRound-1].numberClaimed;
      }
      else {
        return 0;
      }
    }   

    /// @notice Returns number of GLASSES that should be allocated for new round taking into account current allowance and number of GLASSES desired to distributed in new round. If there is a round currently open, will return 0.
    /// @param numberToDistribute the number of GLASSES looking to distribute
    function additionalAllowanceRequiredFor(uint256 numberToDistribute) external view returns (uint256) {        
      if ((claimRounds.length == 0) || (block.number > claimRounds[currentRound].endBlock)) {
        return (numberToDistribute >= remainingAllowance()) ? (numberToDistribute - remainingAllowance()) : 0;
      }
      else {
        return 0;
      }
    }

    /// @notice Returns number of GLASSES that are claimable by an address
    /// @param receiver address that would claim GLASSES
    function claimableGlasses(address receiver) external view returns (uint256) {    
      // First check if there is a current claim round open
      if ((claimRounds.length == 0) || (block.number > claimRounds[currentRound].endBlock)) {
        return 0;
      }

      // Check if sender has claims 
      return claimRounds[currentRound].winners[receiver];
    }      

    /// @notice Returns remaining number of blocks until current claim period expires
    function blocksUntilClaimExpires() external view returns (uint256) 
    {        
      if ((claimRounds.length == 0) || (block.number > claimRounds[currentRound].endBlock)) {
        return 0;
      }

      return claimRounds[currentRound].endBlock + 1 - block.number; // adding one because expiry will be the block after endBlock
    }

    /**
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
      EXTERNAL FUNCTIONS
    ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
    **/

    /// @notice Claim GLASSES available to this wallet in this Claim Round
    function claimGlasses() external {

      // Check if there is a current claim round open
      if ((claimRounds.length == 0) || (block.number > claimRounds[currentRound].endBlock)) {
        revert NoClaimRoundsOpen();
      }

      // Check if sender has claims and send them
      uint256 numberClaims = claimRounds[currentRound].winners[msg.sender];
      if (numberClaims > 0) {
        claimRounds[currentRound].numberClaimed += numberClaims;
      }
      else {
        revert NoClaimsForYou();
      }

      claimRounds[currentRound].winners[msg.sender] = 0;
      uint256 startId = NOUNS_VISION_BATCH_TRANSFER.getStartId();
      address[] memory twins = new address[](numberClaims);
      for (uint256 i; i < numberClaims; i++) {
        twins[i] = msg.sender;
      }
      NOUNS_VISION_BATCH_TRANSFER.sendManyGlasses(startId, twins);      
      emit GlassesClaimed(msg.sender, numberClaims);

    }
   
}
// File: contracts/VRFv2Consumer.sol



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

import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
import "@chainlink/contracts/src/v0.8/ConfirmedOwner.sol";

contract VRFv2Consumer is VRFConsumerBaseV2, ConfirmedOwner {
    event RequestSent(uint256 requestId, uint32 numWords);
    event RequestFulfilled(uint256 requestId, uint256[] randomWords);

    struct RequestStatus {
        bool fulfilled; // whether the request has been successfully fulfilled
        bool exists; // whether a requestId exists
        uint256[] randomWords;
    }
    mapping(uint256 => RequestStatus)
        public s_requests; /* requestId --> requestStatus */
    VRFCoordinatorV2Interface COORDINATOR;

    // Your subscription ID.
    uint64 s_subscriptionId;

    // past requests Id.
    uint256[] public requestIds;
    uint256 public lastRequestId;

    // The gas lane to use, which specifies the maximum gas price to bump to.
    bytes32 keyHash =
        0x8af398995b04c28e9951adb9721ef74c74f93e6a478f39e7e0777be13527e7ef;

    uint32 callbackGasLimit = 2_500_000;

    // The default is 3
    uint16 requestConfirmations = 3;

    // Cannot exceed VRFCoordinatorV2.MAX_NUM_WORDS.
    uint32 numWords = 1;

    /**
     * HARDCODED FOR MAINNET
     * COORDINATOR: 0x271682DEB8C4E0901D1a1550aD2e64D568E69909
     */
    constructor(
        uint64 subscriptionId
    )
        VRFConsumerBaseV2(0x271682DEB8C4E0901D1a1550aD2e64D568E69909)
        ConfirmedOwner(0x0BC3807Ec262cB779b38D65b38158acC3bfedE10) // Nouns DAO Executor address
    {
        COORDINATOR = VRFCoordinatorV2Interface(
            0x271682DEB8C4E0901D1a1550aD2e64D568E69909
        );
        s_subscriptionId = subscriptionId;
    }

    // Assumes the subscription is funded sufficiently.
    function requestRandomWords()
        external
        onlyOwner
        returns (uint256 requestId)
    {
        // Will revert if subscription is not set and funded.
        requestId = COORDINATOR.requestRandomWords(
            keyHash,
            s_subscriptionId,
            requestConfirmations,
            callbackGasLimit,
            numWords
        );
        s_requests[requestId] = RequestStatus({
            randomWords: new uint256[](0),
            exists: true,
            fulfilled: false
        });
        requestIds.push(requestId);
        lastRequestId = requestId;
        emit RequestSent(requestId, numWords);
        return requestId;
    }

    function fulfillRandomWords(
        uint256 _requestId,
        uint256[] memory _randomWords
    ) virtual internal override {
        require(s_requests[_requestId].exists, "request not found");
        s_requests[_requestId].fulfilled = true;
        s_requests[_requestId].randomWords = _randomWords;
        emit RequestFulfilled(_requestId, _randomWords);
    }

    function getRequestStatus(
        uint256 _requestId
    ) external view returns (bool fulfilled, uint256[] memory randomWords) {
        require(s_requests[_requestId].exists, "request not found");
        RequestStatus memory request = s_requests[_requestId];
        return (request.fulfilled, request.randomWords);
    }
}