ETH Price: $2,601.68 (+1.03%)
Gas: 5 Gwei

Contract

0x453f8714935F564DE2E8aF3C00D52447A58b2c14
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Transfer Fee And...199582482024-05-27 2:33:2374 days ago1716777203IN
0x453f8714...7A58b2c14
0 ETH0.002808339.2709227
Transfer Fee And...199513032024-05-26 3:15:3575 days ago1716693335IN
0x453f8714...7A58b2c14
0 ETH0.000386093.75804369
Transfer Fee And...199513032024-05-26 3:15:3575 days ago1716693335IN
0x453f8714...7A58b2c14
0 ETH0.001166413.8497593
Transfer Fee And...199375162024-05-24 5:00:4777 days ago1716526847IN
0x453f8714...7A58b2c14
0 ETH0.002158187.12311706
Transfer Fee And...199297232024-05-23 2:52:5978 days ago1716432779IN
0x453f8714...7A58b2c14
0 ETH0.002052936.77718349
Transfer Fee And...199225742024-05-22 2:52:4779 days ago1716346367IN
0x453f8714...7A58b2c14
0 ETH0.002494338.23431803
Transfer Fee And...199159772024-05-21 4:44:4780 days ago1716266687IN
0x453f8714...7A58b2c14
0 ETH0.002384057.86860179
Transfer Fee And...199081182024-05-20 2:20:4781 days ago1716171647IN
0x453f8714...7A58b2c14
0 ETH0.00113463.74557144
Transfer Fee And...199020792024-05-19 6:04:4782 days ago1716098687IN
0x453f8714...7A58b2c14
0 ETH0.001240254.09349235
Transfer Fee And...198946942024-05-18 5:16:4783 days ago1716009407IN
0x453f8714...7A58b2c14
0 ETH0.001278334.21917107
Transfer Fee And...198870772024-05-17 3:40:4784 days ago1715917247IN
0x453f8714...7A58b2c14
0 ETH0.00110783.65632107
Transfer Fee And...198801552024-05-16 4:28:4785 days ago1715833727IN
0x453f8714...7A58b2c14
0 ETH0.001397054.61099515
Transfer Fee And...198728332024-05-15 3:56:4786 days ago1715745407IN
0x453f8714...7A58b2c14
0 ETH0.001486254.90542359
Transfer Fee And...198657102024-05-14 3:56:4787 days ago1715659007IN
0x453f8714...7A58b2c14
0 ETH0.001430314.72076338
Transfer Fee And...198580752024-05-13 2:20:3588 days ago1715566835IN
0x453f8714...7A58b2c14
0 ETH0.001426524.70925565
Transfer Fee And...198513222024-05-12 3:40:4789 days ago1715485247IN
0x453f8714...7A58b2c14
0 ETH0.001362984.49854063
Transfer Fee And...198443272024-05-11 4:12:4790 days ago1715400767IN
0x453f8714...7A58b2c14
0 ETH0.001588845.24400268
Transfer Fee And...198367782024-05-10 2:52:4791 days ago1715309567IN
0x453f8714...7A58b2c14
0 ETH0.00137054.52433928
Transfer Fee And...198294702024-05-09 2:20:4792 days ago1715221247IN
0x453f8714...7A58b2c14
0 ETH0.0015014.95513794
Transfer Fee And...198231222024-05-08 5:00:4793 days ago1715144447IN
0x453f8714...7A58b2c14
0 ETH0.001465124.83565995
Transfer Fee And...198158112024-05-07 4:28:4794 days ago1715056127IN
0x453f8714...7A58b2c14
0 ETH0.001521175.02066753
Transfer Fee And...198081852024-05-06 2:52:4795 days ago1714963967IN
0x453f8714...7A58b2c14
0 ETH0.001754565.79219222
Transfer Fee And...198008782024-05-05 2:20:4796 days ago1714875647IN
0x453f8714...7A58b2c14
0 ETH0.001817515.99999728
Transfer Fee And...197943602024-05-04 4:28:4797 days ago1714796927IN
0x453f8714...7A58b2c14
0 ETH0.001898446.26584554
Transfer Fee And...197872842024-05-03 4:44:4798 days ago1714711487IN
0x453f8714...7A58b2c14
0 ETH0.002078226.85922845
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ChainlinkVRFV2DirectRngAuctionHelper

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 21 : ChainlinkVRFV2DirectRngAuctionHelper.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { IRngAuction } from "./interfaces/IRngAuction.sol";
import { ChainlinkVRFV2Direct } from "./ChainlinkVRFV2Direct.sol";
import { IERC20 } from "openzeppelin-contracts/contracts/interfaces/IERC20.sol";
import { VRFV2Wrapper } from "chainlink/vrf/VRFV2Wrapper.sol";

/// @notice Thrown if the ChainlinkVRFV2Direct contract is set to the zero address.
error ChainlinkVRFV2DirectZeroAddress();

/// @notice Thrown if the RngAuction contract is set to the zero address.
error RngAuctionZeroAddress();

/**
 * @notice Thrown if the active RNG service of the RngAuction doesn't match the address of
 * the ChainlinkVRFV2Direct contract.
 * @param chainlinkVrfV2Direct The ChainlinkVRFV2Direct contract address
 * @param activeRngService The active RNG service of the RngAuction
 */
error RngServiceNotActive(address chainlinkVrfV2Direct, address activeRngService);

/**
 * @title PoolTogether V5 ChainlinkVRFV2DirectRngAuctionHelper
 * @author G9 Software Inc.
 * @notice This is a helper contract to provide clients a simplified interface to interact
 * with the RNGAuction if a fee needs to be transferred before starting the RNG request.
 */
contract ChainlinkVRFV2DirectRngAuctionHelper {

    /// @notice The ChainlinkVRFV2Direct contract that the fee will be transferred to.
    ChainlinkVRFV2Direct public immutable chainlinkVrfV2Direct;

    /// @notice The RngAuction that will be completed after the fee is transferred.
    IRngAuction public immutable rngAuction;

    /**
     * @notice Initializes the contract with the target ChainlinkVRFV2Direct and RngAuction
     * contracts.
     * @param _chainlinkVrfV2Direct The ChainlinkVRFV2Direct contract that the fee will be transferred to.
     * @param _rngAuction The RngAuction contract that will be completed after the fee is transferred.
     */
    constructor (ChainlinkVRFV2Direct _chainlinkVrfV2Direct, IRngAuction _rngAuction) {
        if (address(_chainlinkVrfV2Direct) == address(0)) revert ChainlinkVRFV2DirectZeroAddress();
        if (address(_rngAuction) == address(0)) revert RngAuctionZeroAddress();
        chainlinkVrfV2Direct = _chainlinkVrfV2Direct;
        rngAuction = _rngAuction;
    }

    /**
     * @notice Transfers the RNG fee from the caller to the ChainlinkVRFV2Direct contract before
     * completing the RNG auction by starting the RNG request.
     * @dev Will revert if the active RNG service of the RngAuction does not match the ChainlinkVRFV2Direct
     * contract address.
     * @dev To estimate the request fee, use the `estimateRequestFee(...)` function on this contract.
     * @dev DO NOT USE THE `getRequestFee()` FUNCTION ON THE RNG SERVICE TO PREDICT THE FEE AS IT REQUIRES A
     * TX GAS PRICE TO CALCULATE THE CORRECT VALUE!
     * @param _rewardRecipient Address that will receive the auction reward for starting the RNG request
     */
    function transferFeeAndStartRngRequest(address _rewardRecipient) external {
        if (address(rngAuction.getNextRngService()) != address(chainlinkVrfV2Direct)) {
            revert RngServiceNotActive(address(chainlinkVrfV2Direct), address(rngAuction.getNextRngService()));
        }
        (address _feeToken, uint256 _requestFee) = chainlinkVrfV2Direct.getRequestFee();
        IERC20(_feeToken).transferFrom(msg.sender, address(chainlinkVrfV2Direct), _requestFee);
        rngAuction.startRngRequest(_rewardRecipient);
    }

    /**
     * @notice Estimates the RNG request fee in LINK based on the expected gas price.
     * @dev Use this function instead of `RNGInterface.getRequestFee()` when estimating request fees offchain.
     * @param _gasPrice The gas price to calculate the request fee for
     * @return _feeToken The LINK address
     * @return _requestFee The estimated request fee based on the given gas price
     */
    function estimateRequestFee(uint256 _gasPrice) external view returns (address _feeToken, uint256 _requestFee) {
        VRFV2Wrapper wrapper = chainlinkVrfV2Direct.vrfV2Wrapper();
        _feeToken = address(wrapper.LINK());
        _requestFee = wrapper.estimateRequestPrice(chainlinkVrfV2Direct.getCallbackGasLimit(), _gasPrice);
    }

}

File 2 of 21 : IRngAuction.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { RNGInterface } from "rng-contracts/RNGInterface.sol";

interface IRngAuction {
    function startRngRequest(address _rewardRecipient) external;
    function getNextRngService() external view returns (RNGInterface);
}

File 3 of 21 : ChainlinkVRFV2Direct.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import { VRFV2WrapperConsumerBase } from "chainlink/vrf/VRFV2WrapperConsumerBase.sol";
import { Ownable } from "owner-manager/Ownable.sol";

import { VRFV2Wrapper } from "chainlink/vrf/VRFV2Wrapper.sol";
import { LinkTokenInterface } from "chainlink/interfaces/LinkTokenInterface.sol";
import { RNGInterface } from "rng-contracts/RNGInterface.sol";

/**
 * @title PoolTogether V5 ChainlinkVRFV2Direct
 * @author G9 Software Inc.
 * @notice This is an RNG service contract that interfaces with the Chainlink VRF V2
 * service to trigger direct-funded RNG requests.
 */
contract ChainlinkVRFV2Direct is VRFV2WrapperConsumerBase, Ownable, RNGInterface {

  /* ============ Global Variables ============ */

  /// @notice A counter for the number of requests made used for request ids
  uint32 internal _requestCounter;

  /// @notice The callback gas limit
  uint32 internal _callbackGasLimit;

  /// @notice The number of confirmations to wait before fulfilling the request
  uint16 internal _requestConfirmations;

  /// @notice A list of random numbers from past requests mapped by request id
  mapping(uint32 => uint256) internal _randomNumbers;

  /// @notice A list of random number completion timestamps mapped by request id
  mapping(uint32 => uint64) internal _requestCompletedAt;

  /// @notice A mapping from Chainlink request ids to internal request ids
  mapping(uint256 => uint32) internal _chainlinkRequestIds;

  /* ============ Custom Errors ============ */

  /// @notice Thrown when the LINK token contract address is set to the zero address.
  error LinkTokenZeroAddress();

  /// @notice Thrown when the VRFV2Wrapper address is set to the zero address.
  error VRFV2WrapperZeroAddress();

  /// @notice Thrown when the callback gas limit is set to zero.
  error CallbackGasLimitZero();

  /// @notice Thrown when the number of request confirmations is set to zero.
  error RequestConfirmationsZero();

  /// @notice Thrown when the chainlink VRF request ID does not match any stored request IDs.
  /// @param vrfRequestId The chainlink ID for the VRF Request
  error InvalidVrfRequestId(uint256 vrfRequestId);

  /* ============ Custom Events ============ */

  /// @notice Emitted when the callback gas limit is set
  /// @param callbackGasLimit The new callback gas limit
  event SetCallbackGasLimit(uint32 callbackGasLimit);

  /// @notice Emitted when the number of request confirmations is set.
  /// @param requestConfirmations The new request confirmations
  event SetRequestConfirmations(uint16 requestConfirmations);

  /* ============ Constructor ============ */

  /**
   * @notice Constructor of the contract
   * @param _owner Address of the contract owner
   * @param _vrfV2Wrapper Address of the VRF V2 Wrapper
   * @param callbackGasLimit_ Gas limit for the fulfillRandomWords callback
   * @param requestConfirmations_ The number of confirmations to wait before fulfilling the request
   */
  constructor(
    address _owner,
    VRFV2Wrapper _vrfV2Wrapper,
    uint32 callbackGasLimit_,
    uint16 requestConfirmations_
  ) VRFV2WrapperConsumerBase(address(_vrfV2Wrapper.LINK()), address(_vrfV2Wrapper)) Ownable(_owner) {
    if (address(_vrfV2Wrapper) == address(0)) revert VRFV2WrapperZeroAddress();
    _setCallbackGasLimit(callbackGasLimit_);
    _setRequestConfirmations(requestConfirmations_);
  }

  /* ============ External Functions ============ */

  /// @inheritdoc RNGInterface
  function requestRandomNumber()
    external
    returns (uint32 requestId, uint32 lockBlock)
  {
    uint256 _vrfRequestId = requestRandomness(
      _callbackGasLimit,
      _requestConfirmations,
      1 // num words
    );

    requestId = _requestCounter + 1;
    _requestCounter = requestId;

    _chainlinkRequestIds[_vrfRequestId] = requestId;

    lockBlock = uint32(block.number);

    emit RandomNumberRequested(requestId, msg.sender);
  }

  /// @inheritdoc RNGInterface
  function isRequestComplete(uint32 _internalRequestId)
    external
    view
    override
    returns (bool isCompleted)
  {
    return _randomNumbers[_internalRequestId] != 0;
  }

  /// @inheritdoc RNGInterface
  function randomNumber(uint32 _internalRequestId)
    external
    view
    override
    returns (uint256 randomNum)
  {
    return _randomNumbers[_internalRequestId];
  }

  /**
   * @notice Returns the timestamp at which the passed `requestId` was completed.
   * @dev Returns zero if not completed or if the request doesn't exist
   * @param requestId The ID of the request
   */
  function completedAt(uint32 requestId) external view returns (uint64 completedAtTimestamp) {
    return _requestCompletedAt[requestId];
  }

  /// @inheritdoc RNGInterface
  function getLastRequestId() external view override returns (uint32 requestId) {
    return _requestCounter;
  }

  /// @inheritdoc RNGInterface
  function getRequestFee() external view override returns (address feeToken, uint256 requestFee) {
    return (address(LINK), VRF_V2_WRAPPER.calculateRequestPrice(_callbackGasLimit));
  }

  /// @notice Returns the current callback gas limit.
  /// @return The current callback gas limit
  function getCallbackGasLimit() external view returns (uint32) {
    return _callbackGasLimit;
  }

  /// @notice Returns the current request confirmation count.
  /// @return The current request confirmation count
  function getRequestConfirmations() external view returns (uint16) {
    return _requestConfirmations;
  }

  /// @notice Returns the VRF V2 Wrapper contract that this contract uses.
  /// @return The VRFV2Wrapper contract
  function vrfV2Wrapper() external view returns (VRFV2Wrapper) {
    return VRFV2Wrapper(address(VRF_V2_WRAPPER));
  }

  /* ============ External Setters ============ */

  /// @notice Sets a new callback gat limit.
  /// @param callbackGasLimit_ The new callback gat limit
  function setCallbackGasLimit(uint32 callbackGasLimit_) external onlyOwner {
    _setCallbackGasLimit(callbackGasLimit_);
  }

  /// @notice Sets a new request confirmation count.
  /// @param requestConfirmations_ The new request confirmation count
  function setRequestConfirmations(uint16 requestConfirmations_) external onlyOwner {
    _setRequestConfirmations(requestConfirmations_);
  }

  /* ============ Internal Functions ============ */

  /**
   * @notice Callback function called by VRF Wrapper
   * @dev The VRF Wrapper will only call it once it has verified the proof associated with the randomness.
   * @param _vrfRequestId Chainlink VRF request id
   * @param _randomWords Chainlink VRF array of random words
   */
  function fulfillRandomWords(uint256 _vrfRequestId, uint256[] memory _randomWords)
    internal
    override
  {
    uint32 _internalRequestId = _chainlinkRequestIds[_vrfRequestId];
    if (_internalRequestId == 0) revert InvalidVrfRequestId(_vrfRequestId);

    uint256 _randomNumber = _randomWords[0];
    _randomNumbers[_internalRequestId] = _randomNumber;
    _requestCompletedAt[_internalRequestId] = uint64(block.timestamp);

    emit RandomNumberCompleted(_internalRequestId, _randomNumber);
  }

  /* ============ Internal Setters ============ */

  /// @notice Sets a new callback gat limit.
  /// @param callbackGasLimit_ The new callback gat limit
  function _setCallbackGasLimit(uint32 callbackGasLimit_) internal {
    if (callbackGasLimit_ == 0) revert CallbackGasLimitZero();
    _callbackGasLimit = callbackGasLimit_;
    emit SetCallbackGasLimit(_callbackGasLimit);
  }

  /// @notice Sets a new request confirmation count.
  /// @param requestConfirmations_ The new request confirmation count
  function _setRequestConfirmations(uint16 requestConfirmations_) internal {
    if (requestConfirmations_ == 0) revert RequestConfirmationsZero();
    _requestConfirmations = requestConfirmations_;
    emit SetRequestConfirmations(_requestConfirmations);
  }

}

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

pragma solidity ^0.8.0;

import "../token/ERC20/IERC20.sol";

File 5 of 21 : VRFV2Wrapper.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;

import "../ConfirmedOwner.sol";
import "../interfaces/TypeAndVersionInterface.sol";
import "./VRFConsumerBaseV2.sol";
import "../interfaces/LinkTokenInterface.sol";
import "../interfaces/AggregatorV3Interface.sol";
import "../interfaces/VRFCoordinatorV2Interface.sol";
import "../interfaces/VRFV2WrapperInterface.sol";
import "./VRFV2WrapperConsumerBase.sol";
import "../ChainSpecificUtil.sol";

/**
 * @notice A wrapper for VRFCoordinatorV2 that provides an interface better suited to one-off
 * @notice requests for randomness.
 */
contract VRFV2Wrapper is ConfirmedOwner, TypeAndVersionInterface, VRFConsumerBaseV2, VRFV2WrapperInterface {
  event WrapperFulfillmentFailed(uint256 indexed requestId, address indexed consumer);

  LinkTokenInterface public immutable LINK;
  AggregatorV3Interface public immutable LINK_ETH_FEED;
  ExtendedVRFCoordinatorV2Interface public immutable COORDINATOR;
  uint64 public immutable SUBSCRIPTION_ID;
  /// @dev this is the size of a VRF v2 fulfillment's calldata abi-encoded in bytes.
  /// @dev proofSize = 13 words = 13 * 256 = 3328 bits
  /// @dev commitmentSize = 5 words = 5 * 256 = 1280 bits
  /// @dev dataSize = proofSize + commitmentSize = 4608 bits
  /// @dev selector = 32 bits
  /// @dev total data size = 4608 bits + 32 bits = 4640 bits = 580 bytes
  uint32 public s_fulfillmentTxSizeBytes = 580;

  // 5k is plenty for an EXTCODESIZE call (2600) + warm CALL (100)
  // and some arithmetic operations.
  uint256 private constant GAS_FOR_CALL_EXACT_CHECK = 5_000;

  // lastRequestId is the request ID of the most recent VRF V2 request made by this wrapper. This
  // should only be relied on within the same transaction the request was made.
  uint256 public override lastRequestId;

  // Configuration fetched from VRFCoordinatorV2

  // s_configured tracks whether this contract has been configured. If not configured, randomness
  // requests cannot be made.
  bool public s_configured;

  // s_disabled disables the contract when true. When disabled, new VRF requests cannot be made
  // but existing ones can still be fulfilled.
  bool public s_disabled;

  // s_fallbackWeiPerUnitLink is the backup LINK exchange rate used when the LINK/NATIVE feed is
  // stale.
  int256 private s_fallbackWeiPerUnitLink;

  // s_stalenessSeconds is the number of seconds before we consider the feed price to be stale and
  // fallback to fallbackWeiPerUnitLink.
  uint32 private s_stalenessSeconds;

  // s_fulfillmentFlatFeeLinkPPM is the flat fee in millionths of LINK that VRFCoordinatorV2
  // charges.
  uint32 private s_fulfillmentFlatFeeLinkPPM;

  // Other configuration

  // s_wrapperGasOverhead reflects the gas overhead of the wrapper's fulfillRandomWords
  // function. The cost for this gas is passed to the user.
  uint32 private s_wrapperGasOverhead;

  // s_coordinatorGasOverhead reflects the gas overhead of the coordinator's fulfillRandomWords
  // function. The cost for this gas is billed to the subscription, and must therefor be included
  // in the pricing for wrapped requests. This includes the gas costs of proof verification and
  // payment calculation in the coordinator.
  uint32 private s_coordinatorGasOverhead;

  // s_wrapperPremiumPercentage is the premium ratio in percentage. For example, a value of 0
  // indicates no premium. A value of 15 indicates a 15 percent premium.
  uint8 private s_wrapperPremiumPercentage;

  // s_keyHash is the key hash to use when requesting randomness. Fees are paid based on current gas
  // fees, so this should be set to the highest gas lane on the network.
  bytes32 s_keyHash;

  // s_maxNumWords is the max number of words that can be requested in a single wrapped VRF request.
  uint8 s_maxNumWords;

  struct Callback {
    address callbackAddress;
    uint32 callbackGasLimit;
    uint256 requestGasPrice;
    int256 requestWeiPerUnitLink;
    uint256 juelsPaid;
  }
  mapping(uint256 => Callback) /* requestID */ /* callback */ public s_callbacks;

  constructor(
    address _link,
    address _linkEthFeed,
    address _coordinator
  ) ConfirmedOwner(msg.sender) VRFConsumerBaseV2(_coordinator) {
    LINK = LinkTokenInterface(_link);
    LINK_ETH_FEED = AggregatorV3Interface(_linkEthFeed);
    COORDINATOR = ExtendedVRFCoordinatorV2Interface(_coordinator);

    // Create this wrapper's subscription and add itself as a consumer.
    uint64 subId = ExtendedVRFCoordinatorV2Interface(_coordinator).createSubscription();
    SUBSCRIPTION_ID = subId;
    ExtendedVRFCoordinatorV2Interface(_coordinator).addConsumer(subId, address(this));
  }

  /**
   * @notice setFulfillmentTxSize sets the size of the fulfillment transaction in bytes.
   * @param size is the size of the fulfillment transaction in bytes.
   */
  function setFulfillmentTxSize(uint32 size) external onlyOwner {
    s_fulfillmentTxSizeBytes = size;
  }

  /**
   * @notice setConfig configures VRFV2Wrapper.
   *
   * @dev Sets wrapper-specific configuration based on the given parameters, and fetches any needed
   * @dev VRFCoordinatorV2 configuration from the coordinator.
   *
   * @param _wrapperGasOverhead reflects the gas overhead of the wrapper's fulfillRandomWords
   *        function.
   *
   * @param _coordinatorGasOverhead reflects the gas overhead of the coordinator's
   *        fulfillRandomWords function.
   *
   * @param _wrapperPremiumPercentage is the premium ratio in percentage for wrapper requests.
   *
   * @param _keyHash to use for requesting randomness.
   */
  function setConfig(
    uint32 _wrapperGasOverhead,
    uint32 _coordinatorGasOverhead,
    uint8 _wrapperPremiumPercentage,
    bytes32 _keyHash,
    uint8 _maxNumWords
  ) external onlyOwner {
    s_wrapperGasOverhead = _wrapperGasOverhead;
    s_coordinatorGasOverhead = _coordinatorGasOverhead;
    s_wrapperPremiumPercentage = _wrapperPremiumPercentage;
    s_keyHash = _keyHash;
    s_maxNumWords = _maxNumWords;
    s_configured = true;

    // Get other configuration from coordinator
    (, , s_stalenessSeconds, ) = COORDINATOR.getConfig();
    s_fallbackWeiPerUnitLink = COORDINATOR.getFallbackWeiPerUnitLink();
    (s_fulfillmentFlatFeeLinkPPM, , , , , , , , ) = COORDINATOR.getFeeConfig();
  }

  /**
   * @notice getConfig returns the current VRFV2Wrapper configuration.
   *
   * @return fallbackWeiPerUnitLink is the backup LINK exchange rate used when the LINK/NATIVE feed
   *         is stale.
   *
   * @return stalenessSeconds is the number of seconds before we consider the feed price to be stale
   *         and fallback to fallbackWeiPerUnitLink.
   *
   * @return fulfillmentFlatFeeLinkPPM is the flat fee in millionths of LINK that VRFCoordinatorV2
   *         charges.
   *
   * @return wrapperGasOverhead reflects the gas overhead of the wrapper's fulfillRandomWords
   *         function. The cost for this gas is passed to the user.
   *
   * @return coordinatorGasOverhead reflects the gas overhead of the coordinator's
   *         fulfillRandomWords function.
   *
   * @return wrapperPremiumPercentage is the premium ratio in percentage. For example, a value of 0
   *         indicates no premium. A value of 15 indicates a 15 percent premium.
   *
   * @return keyHash is the key hash to use when requesting randomness. Fees are paid based on
   *         current gas fees, so this should be set to the highest gas lane on the network.
   *
   * @return maxNumWords is the max number of words that can be requested in a single wrapped VRF
   *         request.
   */
  function getConfig()
    external
    view
    returns (
      int256 fallbackWeiPerUnitLink,
      uint32 stalenessSeconds,
      uint32 fulfillmentFlatFeeLinkPPM,
      uint32 wrapperGasOverhead,
      uint32 coordinatorGasOverhead,
      uint8 wrapperPremiumPercentage,
      bytes32 keyHash,
      uint8 maxNumWords
    )
  {
    return (
      s_fallbackWeiPerUnitLink,
      s_stalenessSeconds,
      s_fulfillmentFlatFeeLinkPPM,
      s_wrapperGasOverhead,
      s_coordinatorGasOverhead,
      s_wrapperPremiumPercentage,
      s_keyHash,
      s_maxNumWords
    );
  }

  /**
   * @notice Calculates the price of a VRF request with the given callbackGasLimit at the current
   * @notice block.
   *
   * @dev This function relies on the transaction gas price which is not automatically set during
   * @dev simulation. To estimate the price at a specific gas price, use the estimatePrice function.
   *
   * @param _callbackGasLimit is the gas limit used to estimate the price.
   */
  function calculateRequestPrice(
    uint32 _callbackGasLimit
  ) external view override onlyConfiguredNotDisabled returns (uint256) {
    int256 weiPerUnitLink = getFeedData();
    return calculateRequestPriceInternal(_callbackGasLimit, tx.gasprice, weiPerUnitLink);
  }

  /**
   * @notice Estimates the price of a VRF request with a specific gas limit and gas price.
   *
   * @dev This is a convenience function that can be called in simulation to better understand
   * @dev pricing.
   *
   * @param _callbackGasLimit is the gas limit used to estimate the price.
   * @param _requestGasPriceWei is the gas price in wei used for the estimation.
   */
  function estimateRequestPrice(
    uint32 _callbackGasLimit,
    uint256 _requestGasPriceWei
  ) external view override onlyConfiguredNotDisabled returns (uint256) {
    int256 weiPerUnitLink = getFeedData();
    return calculateRequestPriceInternal(_callbackGasLimit, _requestGasPriceWei, weiPerUnitLink);
  }

  function calculateRequestPriceInternal(
    uint256 _gas,
    uint256 _requestGasPrice,
    int256 _weiPerUnitLink
  ) internal view returns (uint256) {
    // costWei is the base fee denominated in wei (native)
    // costWei takes into account the L1 posting costs of the VRF fulfillment
    // transaction, if we are on an L2.
    uint256 costWei = (_requestGasPrice *
      (_gas + s_wrapperGasOverhead + s_coordinatorGasOverhead) +
      ChainSpecificUtil.getL1CalldataGasCost(s_fulfillmentTxSizeBytes));
    // (1e18 juels/link) * ((wei/gas * (gas)) + l1wei) / (wei/link) == 1e18 juels * wei/link / (wei/link) == 1e18 juels * wei/link * link/wei == juels
    // baseFee is the base fee denominated in juels (link)
    uint256 baseFee = (1e18 * costWei) / uint256(_weiPerUnitLink);
    // feeWithPremium is the fee after the percentage premium is applied
    uint256 feeWithPremium = (baseFee * (s_wrapperPremiumPercentage + 100)) / 100;
    // feeWithFlatFee is the fee after the flat fee is applied on top of the premium
    uint256 feeWithFlatFee = feeWithPremium + (1e12 * uint256(s_fulfillmentFlatFeeLinkPPM));

    return feeWithFlatFee;
  }

  /**
   * @notice onTokenTransfer is called by LinkToken upon payment for a VRF request.
   *
   * @dev Reverts if payment is too low.
   *
   * @param _sender is the sender of the payment, and the address that will receive a VRF callback
   *        upon fulfillment.
   *
   * @param _amount is the amount of LINK paid in Juels.
   *
   * @param _data is the abi-encoded VRF request parameters: uint32 callbackGasLimit,
   *        uint16 requestConfirmations, and uint32 numWords.
   */
  function onTokenTransfer(address _sender, uint256 _amount, bytes calldata _data) external onlyConfiguredNotDisabled {
    require(msg.sender == address(LINK), "only callable from LINK");

    (uint32 callbackGasLimit, uint16 requestConfirmations, uint32 numWords) = abi.decode(
      _data,
      (uint32, uint16, uint32)
    );
    uint32 eip150Overhead = getEIP150Overhead(callbackGasLimit);
    int256 weiPerUnitLink = getFeedData();
    uint256 price = calculateRequestPriceInternal(callbackGasLimit, tx.gasprice, weiPerUnitLink);
    require(_amount >= price, "fee too low");
    require(numWords <= s_maxNumWords, "numWords too high");

    uint256 requestId = COORDINATOR.requestRandomWords(
      s_keyHash,
      SUBSCRIPTION_ID,
      requestConfirmations,
      callbackGasLimit + eip150Overhead + s_wrapperGasOverhead,
      numWords
    );
    s_callbacks[requestId] = Callback({
      callbackAddress: _sender,
      callbackGasLimit: callbackGasLimit,
      requestGasPrice: tx.gasprice,
      requestWeiPerUnitLink: weiPerUnitLink,
      juelsPaid: _amount
    });
    lastRequestId = requestId;
  }

  /**
   * @notice withdraw is used by the VRFV2Wrapper's owner to withdraw LINK revenue.
   *
   * @param _recipient is the address that should receive the LINK funds.
   *
   * @param _amount is the amount of LINK in Juels that should be withdrawn.
   */
  function withdraw(address _recipient, uint256 _amount) external onlyOwner {
    LINK.transfer(_recipient, _amount);
  }

  /**
   * @notice enable this contract so that new requests can be accepted.
   */
  function enable() external onlyOwner {
    s_disabled = false;
  }

  /**
   * @notice disable this contract so that new requests will be rejected. When disabled, new requests
   * @notice will revert but existing requests can still be fulfilled.
   */
  function disable() external onlyOwner {
    s_disabled = true;
  }

  function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal override {
    Callback memory callback = s_callbacks[_requestId];
    delete s_callbacks[_requestId];
    require(callback.callbackAddress != address(0), "request not found"); // This should never happen

    VRFV2WrapperConsumerBase c;
    bytes memory resp = abi.encodeWithSelector(c.rawFulfillRandomWords.selector, _requestId, _randomWords);

    bool success = callWithExactGas(callback.callbackGasLimit, callback.callbackAddress, resp);
    if (!success) {
      emit WrapperFulfillmentFailed(_requestId, callback.callbackAddress);
    }
  }

  function getFeedData() private view returns (int256) {
    bool staleFallback = s_stalenessSeconds > 0;
    uint256 timestamp;
    int256 weiPerUnitLink;
    (, weiPerUnitLink, , timestamp, ) = LINK_ETH_FEED.latestRoundData();
    // solhint-disable-next-line not-rely-on-time
    if (staleFallback && s_stalenessSeconds < block.timestamp - timestamp) {
      weiPerUnitLink = s_fallbackWeiPerUnitLink;
    }
    require(weiPerUnitLink >= 0, "Invalid LINK wei price");
    return weiPerUnitLink;
  }

  /**
   * @dev Calculates extra amount of gas required for running an assembly call() post-EIP150.
   */
  function getEIP150Overhead(uint32 gas) private pure returns (uint32) {
    return gas / 63 + 1;
  }

  /**
   * @dev calls target address with exactly gasAmount gas and data as calldata
   * or reverts if at least gasAmount gas is not available.
   */
  function callWithExactGas(uint256 gasAmount, address target, bytes memory data) private returns (bool success) {
    // solhint-disable-next-line no-inline-assembly
    assembly {
      let g := gas()
      // Compute g -= GAS_FOR_CALL_EXACT_CHECK and check for underflow
      // The gas actually passed to the callee is min(gasAmount, 63//64*gas available).
      // We want to ensure that we revert if gasAmount >  63//64*gas available
      // as we do not want to provide them with less, however that check itself costs
      // gas.  GAS_FOR_CALL_EXACT_CHECK ensures we have at least enough gas to be able
      // to revert if gasAmount >  63//64*gas available.
      if lt(g, GAS_FOR_CALL_EXACT_CHECK) {
        revert(0, 0)
      }
      g := sub(g, GAS_FOR_CALL_EXACT_CHECK)
      // if g - g//64 <= gasAmount, revert
      // (we subtract g//64 because of EIP-150)
      if iszero(gt(sub(g, div(g, 64)), gasAmount)) {
        revert(0, 0)
      }
      // solidity calls check that a contract actually exists at the destination, so we do the same
      if iszero(extcodesize(target)) {
        revert(0, 0)
      }
      // call and return whether we succeeded. ignore return data
      // call(gas,addr,value,argsOffset,argsLength,retOffset,retLength)
      success := call(gasAmount, target, 0, add(data, 0x20), mload(data), 0, 0)
    }
    return success;
  }

  function typeAndVersion() external pure virtual override returns (string memory) {
    return "VRFV2Wrapper 1.0.0";
  }

  modifier onlyConfiguredNotDisabled() {
    require(s_configured, "wrapper is not configured");
    require(!s_disabled, "wrapper is disabled");
    _;
  }
}

interface ExtendedVRFCoordinatorV2Interface is VRFCoordinatorV2Interface {
  function getConfig()
    external
    view
    returns (
      uint16 minimumRequestConfirmations,
      uint32 maxGasLimit,
      uint32 stalenessSeconds,
      uint32 gasAfterPaymentCalculation
    );

  function getFallbackWeiPerUnitLink() external view returns (int256);

  function getFeeConfig()
    external
    view
    returns (
      uint32 fulfillmentFlatFeeLinkPPMTier1,
      uint32 fulfillmentFlatFeeLinkPPMTier2,
      uint32 fulfillmentFlatFeeLinkPPMTier3,
      uint32 fulfillmentFlatFeeLinkPPMTier4,
      uint32 fulfillmentFlatFeeLinkPPMTier5,
      uint24 reqsForTier2,
      uint24 reqsForTier3,
      uint24 reqsForTier4,
      uint24 reqsForTier5
    );
}

File 6 of 21 : RNGInterface.sol
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.6;

/**
 * @title Random Number Generator Interface
 * @notice Provides an interface for requesting random numbers from 3rd-party RNG services (Chainlink VRF, Starkware VDF, etc..)
 */
interface RNGInterface {
  /**
   * @notice Emitted when a new request for a random number has been submitted
   * @param requestId The indexed ID of the request used to get the results of the RNG service
   * @param sender The indexed address of the sender of the request
   */
  event RandomNumberRequested(uint32 indexed requestId, address indexed sender);

  /**
   * @notice Emitted when an existing request for a random number has been completed
   * @param requestId The indexed ID of the request used to get the results of the RNG service
   * @param randomNumber The random number produced by the 3rd-party service
   */
  event RandomNumberCompleted(uint32 indexed requestId, uint256 randomNumber);

  /**
   * @notice Gets the last request id used by the RNG service
   * @return requestId The last request id used in the last request
   */
  function getLastRequestId() external view returns (uint32 requestId);

  /**
   * @notice Gets the Fee for making a Request against an RNG service
   * @return feeToken The address of the token that is used to pay fees
   * @return requestFee The fee required to be paid to make a request
   */
  function getRequestFee() external view returns (address feeToken, uint256 requestFee);

  /**
   * @notice Sends a request for a random number to the 3rd-party service
   * @dev Some services will complete the request immediately, others may have a time-delay
   * @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF
   * @return requestId The ID of the request used to get the results of the RNG service
   * @return lockBlock The block number at which the RNG service will start generating time-delayed randomness.
   * The calling contract should "lock" all activity until the result is available via the `requestId`
   */
  function requestRandomNumber() external returns (uint32 requestId, uint32 lockBlock);

  /**
   * @notice Checks if the request for randomness from the 3rd-party service has completed
   * @dev For time-delayed requests, this function is used to check/confirm completion
   * @param requestId The ID of the request used to get the results of the RNG service
   * @return isCompleted True if the request has completed and a random number is available, false otherwise
   */
  function isRequestComplete(uint32 requestId) external view returns (bool isCompleted);

  /**
   * @notice Gets the random number produced by the 3rd-party service
   * @param requestId The ID of the request used to get the results of the RNG service
   * @return randomNum The random number
   */
  function randomNumber(uint32 requestId) external returns (uint256 randomNum);

  /**
   * @notice Returns the timestamps at which the request was completed
   * @param requestId The ID of the request used to get the results of the RNG service
   * @return completedAtTimestamp The timestamp at which the request was completed
   */
  function completedAt(uint32 requestId) external view returns (uint64 completedAtTimestamp);
}

File 7 of 21 : VRFV2WrapperConsumerBase.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../interfaces/LinkTokenInterface.sol";
import "../interfaces/VRFV2WrapperInterface.sol";

/** *******************************************************************************
 * @notice Interface for contracts using VRF randomness through the VRF V2 wrapper
 * ********************************************************************************
 * @dev PURPOSE
 *
 * @dev Create VRF V2 requests without the need for subscription management. Rather than creating
 * @dev and funding a VRF V2 subscription, a user can use this wrapper to create one off requests,
 * @dev paying up front rather than at fulfillment.
 *
 * @dev Since the price is determined using the gas price of the request transaction rather than
 * @dev the fulfillment transaction, the wrapper charges an additional premium on callback gas
 * @dev usage, in addition to some extra overhead costs associated with the VRFV2Wrapper contract.
 * *****************************************************************************
 * @dev USAGE
 *
 * @dev Calling contracts must inherit from VRFV2WrapperConsumerBase. The consumer must be funded
 * @dev with enough LINK to make the request, otherwise requests will revert. To request randomness,
 * @dev call the 'requestRandomness' function with the desired VRF parameters. This function handles
 * @dev paying for the request based on the current pricing.
 *
 * @dev Consumers must implement the fullfillRandomWords function, which will be called during
 * @dev fulfillment with the randomness result.
 */
abstract contract VRFV2WrapperConsumerBase {
  LinkTokenInterface internal immutable LINK;
  VRFV2WrapperInterface internal immutable VRF_V2_WRAPPER;

  /**
   * @param _link is the address of LinkToken
   * @param _vrfV2Wrapper is the address of the VRFV2Wrapper contract
   */
  constructor(address _link, address _vrfV2Wrapper) {
    LINK = LinkTokenInterface(_link);
    VRF_V2_WRAPPER = VRFV2WrapperInterface(_vrfV2Wrapper);
  }

  /**
   * @dev Requests randomness from the VRF V2 wrapper.
   *
   * @param _callbackGasLimit is the gas limit that should be used when calling the consumer's
   *        fulfillRandomWords function.
   * @param _requestConfirmations is the number of confirmations to wait before fulfilling the
   *        request. A higher number of confirmations increases security by reducing the likelihood
   *        that a chain re-org changes a published randomness outcome.
   * @param _numWords is the number of random words to request.
   *
   * @return requestId is the VRF V2 request ID of the newly created randomness request.
   */
  function requestRandomness(
    uint32 _callbackGasLimit,
    uint16 _requestConfirmations,
    uint32 _numWords
  ) internal returns (uint256 requestId) {
    LINK.transferAndCall(
      address(VRF_V2_WRAPPER),
      VRF_V2_WRAPPER.calculateRequestPrice(_callbackGasLimit),
      abi.encode(_callbackGasLimit, _requestConfirmations, _numWords)
    );
    return VRF_V2_WRAPPER.lastRequestId();
  }

  /**
   * @notice fulfillRandomWords handles the VRF V2 wrapper response. The consuming contract must
   * @notice implement it.
   *
   * @param _requestId is the VRF V2 request ID.
   * @param _randomWords is the randomness result.
   */
  function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal virtual;

  function rawFulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) external {
    require(msg.sender == address(VRF_V2_WRAPPER), "only VRF V2 wrapper can fulfill");
    fulfillRandomWords(_requestId, _randomWords);
  }
}

File 8 of 21 : Ownable.sol
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.0;

/**
 * @title Abstract ownable contract that can be inherited by other contracts
 * @notice Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The `owner` is first set by passing the address of the `initialOwner` to the Ownable constructor.
 *
 * The owner account can be transferred through a two steps process:
 *      1. The current `owner` calls {transferOwnership} to set a `pendingOwner`
 *      2. The `pendingOwner` calls {claimOwnership} to accept the ownership transfer
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to the owner.
 */
abstract contract Ownable {
    address private _owner;
    address private _pendingOwner;

    /**
     * @dev Emitted when `_pendingOwner` has been changed.
     * @param pendingOwner new `_pendingOwner` address.
     */
    event OwnershipOffered(address indexed pendingOwner);

    /**
     * @dev Emitted when `_owner` has been changed.
     * @param previousOwner previous `_owner` address.
     * @param newOwner new `_owner` address.
     */
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /* ============ Deploy ============ */

    /**
     * @notice Initializes the contract setting `_initialOwner` as the initial owner.
     * @param _initialOwner Initial owner of the contract.
     */
    constructor(address _initialOwner) {
        _setOwner(_initialOwner);
    }

    /* ============ External Functions ============ */

    /**
     * @notice Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @notice Gets current `_pendingOwner`.
     * @return Current `_pendingOwner` address.
     */
    function pendingOwner() external view virtual returns (address) {
        return _pendingOwner;
    }

    /**
     * @notice Renounce ownership of the contract.
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() external virtual onlyOwner {
        _setOwner(address(0));
    }

    /**
    * @notice Allows current owner to set the `_pendingOwner` address.
    * @param _newOwner Address to transfer ownership to.
    */
    function transferOwnership(address _newOwner) external onlyOwner {
        require(_newOwner != address(0), "Ownable/pendingOwner-not-zero-address");

        _pendingOwner = _newOwner;

        emit OwnershipOffered(_newOwner);
    }

    /**
    * @notice Allows the `_pendingOwner` address to finalize the transfer.
    * @dev This function is only callable by the `_pendingOwner`.
    */
    function claimOwnership() external onlyPendingOwner {
        _setOwner(_pendingOwner);
        _pendingOwner = address(0);
    }

    /* ============ Internal Functions ============ */

    /**
     * @notice Internal function to set the `_owner` of the contract.
     * @param _newOwner New `_owner` address.
     */
    function _setOwner(address _newOwner) private {
        address _oldOwner = _owner;
        _owner = _newOwner;
        emit OwnershipTransferred(_oldOwner, _newOwner);
    }

    /* ============ Modifier Functions ============ */

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == msg.sender, "Ownable/caller-not-owner");
        _;
    }

    /**
    * @dev Throws if called by any account other than the `pendingOwner`.
    */
    modifier onlyPendingOwner() {
        require(msg.sender == _pendingOwner, "Ownable/caller-not-pendingOwner");
        _;
    }
}

File 9 of 21 : LinkTokenInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface LinkTokenInterface {
  function allowance(address owner, address spender) external view returns (uint256 remaining);

  function approve(address spender, uint256 value) external returns (bool success);

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

  function decimals() external view returns (uint8 decimalPlaces);

  function decreaseApproval(address spender, uint256 addedValue) external returns (bool success);

  function increaseApproval(address spender, uint256 subtractedValue) external;

  function name() external view returns (string memory tokenName);

  function symbol() external view returns (string memory tokenSymbol);

  function totalSupply() external view returns (uint256 totalTokensIssued);

  function transfer(address to, uint256 value) external returns (bool success);

  function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool success);

  function transferFrom(address from, address to, uint256 value) external returns (bool success);
}

File 10 of 21 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

File 11 of 21 : 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 12 of 21 : TypeAndVersionInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

abstract contract TypeAndVersionInterface {
  function typeAndVersion() external pure virtual returns (string memory);
}

File 13 of 21 : 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 14 of 21 : AggregatorV3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface AggregatorV3Interface {
  function decimals() external view returns (uint8);

  function description() external view returns (string memory);

  function version() external view returns (uint256);

  function getRoundData(
    uint80 _roundId
  ) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

  function latestRoundData()
    external
    view
    returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}

File 15 of 21 : 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 16 of 21 : VRFV2WrapperInterface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface VRFV2WrapperInterface {
  /**
   * @return the request ID of the most recent VRF V2 request made by this wrapper. This should only
   * be relied option within the same transaction that the request was made.
   */
  function lastRequestId() external view returns (uint256);

  /**
   * @notice Calculates the price of a VRF request with the given callbackGasLimit at the current
   * @notice block.
   *
   * @dev This function relies on the transaction gas price which is not automatically set during
   * @dev simulation. To estimate the price at a specific gas price, use the estimatePrice function.
   *
   * @param _callbackGasLimit is the gas limit used to estimate the price.
   */
  function calculateRequestPrice(uint32 _callbackGasLimit) external view returns (uint256);

  /**
   * @notice Estimates the price of a VRF request with a specific gas limit and gas price.
   *
   * @dev This is a convenience function that can be called in simulation to better understand
   * @dev pricing.
   *
   * @param _callbackGasLimit is the gas limit used to estimate the price.
   * @param _requestGasPriceWei is the gas price in wei used for the estimation.
   */
  function estimateRequestPrice(uint32 _callbackGasLimit, uint256 _requestGasPriceWei) external view returns (uint256);
}

File 17 of 21 : ChainSpecificUtil.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {ArbSys} from "./vendor/@arbitrum/nitro-contracts/src/precompiles/ArbSys.sol";
import {ArbGasInfo} from "./vendor/@arbitrum/nitro-contracts/src/precompiles/ArbGasInfo.sol";

//@dev A library that abstracts out opcodes that behave differently across chains.
//@dev The methods below return values that are pertinent to the given chain.
//@dev For instance, ChainSpecificUtil.getBlockNumber() returns L2 block number in L2 chains
library ChainSpecificUtil {
  address private constant ARBSYS_ADDR = address(0x0000000000000000000000000000000000000064);
  ArbSys private constant ARBSYS = ArbSys(ARBSYS_ADDR);
  address private constant ARBGAS_ADDR = address(0x000000000000000000000000000000000000006C);
  ArbGasInfo private constant ARBGAS = ArbGasInfo(ARBGAS_ADDR);
  uint256 private constant ARB_MAINNET_CHAIN_ID = 42161;
  uint256 private constant ARB_GOERLI_TESTNET_CHAIN_ID = 421613;

  function getBlockhash(uint64 blockNumber) internal view returns (bytes32) {
    uint256 chainid = block.chainid;
    if (chainid == ARB_MAINNET_CHAIN_ID || chainid == ARB_GOERLI_TESTNET_CHAIN_ID) {
      if ((getBlockNumber() - blockNumber) > 256 || blockNumber >= getBlockNumber()) {
        return "";
      }
      return ARBSYS.arbBlockHash(blockNumber);
    }
    return blockhash(blockNumber);
  }

  function getBlockNumber() internal view returns (uint256) {
    uint256 chainid = block.chainid;
    if (chainid == ARB_MAINNET_CHAIN_ID || chainid == ARB_GOERLI_TESTNET_CHAIN_ID) {
      return ARBSYS.arbBlockNumber();
    }
    return block.number;
  }

  function getCurrentTxL1GasFees() internal view returns (uint256) {
    uint256 chainid = block.chainid;
    if (chainid == ARB_MAINNET_CHAIN_ID || chainid == ARB_GOERLI_TESTNET_CHAIN_ID) {
      return ARBGAS.getCurrentTxL1GasFees();
    }
    return 0;
  }

  /**
   * @notice Returns the gas cost in wei of calldataSizeBytes of calldata being posted
   * @notice to L1.
   */
  function getL1CalldataGasCost(uint256 calldataSizeBytes) internal view returns (uint256) {
    uint256 chainid = block.chainid;
    if (chainid == ARB_MAINNET_CHAIN_ID || chainid == ARB_GOERLI_TESTNET_CHAIN_ID) {
      (, uint256 l1PricePerByte, , , , ) = ARBGAS.getPricesInWei();
      // see https://developer.arbitrum.io/devs-how-tos/how-to-estimate-gas#where-do-we-get-all-this-information-from
      // for the justification behind the 140 number.
      return l1PricePerByte * (calldataSizeBytes + 140);
    }
    return 0;
  }
}

File 18 of 21 : 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 19 of 21 : ArbSys.sol
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE
// SPDX-License-Identifier: BUSL-1.1

pragma solidity >=0.4.21 <0.9.0;

/**
 * @title System level functionality
 * @notice For use by contracts to interact with core L2-specific functionality.
 * Precompiled contract that exists in every Arbitrum chain at address(100), 0x0000000000000000000000000000000000000064.
 */
interface ArbSys {
    /**
     * @notice Get Arbitrum block number (distinct from L1 block number; Arbitrum genesis block has block number 0)
     * @return block number as int
     */
    function arbBlockNumber() external view returns (uint256);

    /**
     * @notice Get Arbitrum block hash (reverts unless currentBlockNum-256 <= arbBlockNum < currentBlockNum)
     * @return block hash
     */
    function arbBlockHash(uint256 arbBlockNum) external view returns (bytes32);

    /**
     * @notice Gets the rollup's unique chain identifier
     * @return Chain identifier as int
     */
    function arbChainID() external view returns (uint256);

    /**
     * @notice Get internal version number identifying an ArbOS build
     * @return version number as int
     */
    function arbOSVersion() external view returns (uint256);

    /**
     * @notice Returns 0 since Nitro has no concept of storage gas
     * @return uint 0
     */
    function getStorageGasAvailable() external view returns (uint256);

    /**
     * @notice (deprecated) check if current call is top level (meaning it was triggered by an EoA or a L1 contract)
     * @dev this call has been deprecated and may be removed in a future release
     * @return true if current execution frame is not a call by another L2 contract
     */
    function isTopLevelCall() external view returns (bool);

    /**
     * @notice map L1 sender contract address to its L2 alias
     * @param sender sender address
     * @param unused argument no longer used
     * @return aliased sender address
     */
    function mapL1SenderContractAddressToL2Alias(address sender, address unused)
        external
        pure
        returns (address);

    /**
     * @notice check if the caller (of this caller of this) is an aliased L1 contract address
     * @return true iff the caller's address is an alias for an L1 contract address
     */
    function wasMyCallersAddressAliased() external view returns (bool);

    /**
     * @notice return the address of the caller (of this caller of this), without applying L1 contract address aliasing
     * @return address of the caller's caller, without applying L1 contract address aliasing
     */
    function myCallersAddressWithoutAliasing() external view returns (address);

    /**
     * @notice Send given amount of Eth to dest from sender.
     * This is a convenience function, which is equivalent to calling sendTxToL1 with empty data.
     * @param destination recipient address on L1
     * @return unique identifier for this L2-to-L1 transaction.
     */
    function withdrawEth(address destination)
        external
        payable
        returns (uint256);

    /**
     * @notice Send a transaction to L1
     * @dev it is not possible to execute on the L1 any L2-to-L1 transaction which contains data
     * to a contract address without any code (as enforced by the Bridge contract).
     * @param destination recipient address on L1
     * @param data (optional) calldata for L1 contract call
     * @return a unique identifier for this L2-to-L1 transaction.
     */
    function sendTxToL1(address destination, bytes calldata data)
        external
        payable
        returns (uint256);

    /**
     * @notice Get send Merkle tree state
     * @return size number of sends in the history
     * @return root root hash of the send history
     * @return partials hashes of partial subtrees in the send history tree
     */
    function sendMerkleTreeState()
        external
        view
        returns (
            uint256 size,
            bytes32 root,
            bytes32[] memory partials
        );

    /**
     * @notice creates a send txn from L2 to L1
     * @param position = (level << 192) + leaf = (0 << 192) + leaf = leaf
     */
    event L2ToL1Tx(
        address caller,
        address indexed destination,
        uint256 indexed hash,
        uint256 indexed position,
        uint256 arbBlockNum,
        uint256 ethBlockNum,
        uint256 timestamp,
        uint256 callvalue,
        bytes data
    );

    /// @dev DEPRECATED in favour of the new L2ToL1Tx event above after the nitro upgrade
    event L2ToL1Transaction(
        address caller,
        address indexed destination,
        uint256 indexed uniqueId,
        uint256 indexed batchNumber,
        uint256 indexInBatch,
        uint256 arbBlockNum,
        uint256 ethBlockNum,
        uint256 timestamp,
        uint256 callvalue,
        bytes data
    );

    /**
     * @notice logs a merkle branch for proof synthesis
     * @param reserved an index meant only to align the 4th index with L2ToL1Transaction's 4th event
     * @param hash the merkle hash
     * @param position = (level << 192) + leaf
     */
    event SendMerkleUpdate(
        uint256 indexed reserved,
        bytes32 indexed hash,
        uint256 indexed position
    );
}

File 20 of 21 : ArbGasInfo.sol
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE
// SPDX-License-Identifier: BUSL-1.1

pragma solidity >=0.4.21 <0.9.0;

interface ArbGasInfo {
    // return gas prices in wei, assuming the specified aggregator is used
    //        (
    //            per L2 tx,
    //            per L1 calldata unit, (zero byte = 4 units, nonzero byte = 16 units)
    //            per storage allocation,
    //            per ArbGas base,
    //            per ArbGas congestion,
    //            per ArbGas total
    //        )
    function getPricesInWeiWithAggregator(address aggregator) external view returns (uint, uint, uint, uint, uint, uint);

    // return gas prices in wei, as described above, assuming the caller's preferred aggregator is used
    //     if the caller hasn't specified a preferred aggregator, the default aggregator is assumed
    function getPricesInWei() external view returns (uint, uint, uint, uint, uint, uint);

    // return prices in ArbGas (per L2 tx, per L1 calldata unit, per storage allocation),
    //       assuming the specified aggregator is used
    function getPricesInArbGasWithAggregator(address aggregator) external view returns (uint, uint, uint);

    // return gas prices in ArbGas, as described above, assuming the caller's preferred aggregator is used
    //     if the caller hasn't specified a preferred aggregator, the default aggregator is assumed
    function getPricesInArbGas() external view returns (uint, uint, uint);

    // return gas accounting parameters (speedLimitPerSecond, gasPoolMax, maxTxGasLimit)
    function getGasAccountingParams() external view returns (uint, uint, uint);

    // get ArbOS's estimate of the L1 gas price in wei
    function getL1GasPriceEstimate() external view returns(uint);

    // set ArbOS's estimate of the L1 gas price in wei
    // reverts unless called by chain owner or designated gas oracle (if any)
    function setL1GasPriceEstimate(uint priceInWei) external;

    // get L1 gas fees paid by the current transaction (txBaseFeeWei, calldataFeeWei)
    function getCurrentTxL1GasFees() external view returns(uint);
}

File 21 of 21 : 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;
}

Settings
{
  "remappings": [
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "forge-std/=lib/forge-std/src/",
    "aave-address-book/=lib/aave-address-book/src/",
    "chainlink/=lib/pt-v5-chainlink-vrf-v2-direct/lib/chainlink/contracts/src/v0.8/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "prb-math/=lib/pt-v5-cgda-liquidator/lib/prb-math/src/",
    "solidity-stringutils/=lib/solidity-stringutils/src/",
    "yield-daddy/=lib/yield-daddy/src/",
    "pt-v5-chainlink-vrf-v2-direct/=lib/pt-v5-chainlink-vrf-v2-direct/src/",
    "pt-v5-draw-auction/=lib/pt-v5-draw-auction/src/",
    "pt-v5-cgda-liquidator/=lib/pt-v5-cgda-liquidator/src/",
    "pt-v5-liquidator-interfaces/=lib/pt-v5-cgda-liquidator/lib/pt-v5-liquidator-interfaces/src/interfaces/",
    "pt-v5-prize-pool/=lib/pt-v5-prize-pool/src/",
    "pt-v5-twab-controller/=lib/pt-v5-twab-controller/src/",
    "pt-v5-vault/=lib/pt-v5-vault/src/",
    "pt-v5-vault-boost/=lib/pt-v5-vault-boost/src/",
    "pt-v5-vault-mock/=lib/pt-v5-vault/test/contracts/mock/",
    "pt-v5-claimer/=lib/pt-v5-claimer/src/",
    "rng/=lib/pt-v5-draw-auction/lib/pt-v5-rng-contracts/contracts/",
    "rng-contracts/=lib/pt-v5-draw-auction/lib/pt-v5-rng-contracts/contracts/",
    "remote-owner/=lib/pt-v5-draw-auction/lib/remote-owner/src/",
    "@aave/core-v3/=lib/aave-address-book/lib/aave-v3-core/",
    "@aave/periphery-v3/=lib/aave-address-book/lib/aave-v3-periphery/",
    "@openzeppelin/=lib/pt-v5-draw-auction/lib/openzeppelin-contracts/",
    "@prb/test/=lib/pt-v5-vault-boost/lib/prb-math/lib/prb-test/src/",
    "aave-v3-core/=lib/aave-address-book/lib/aave-v3-core/",
    "aave-v3-periphery/=lib/aave-address-book/lib/aave-v3-periphery/",
    "brokentoken/=lib/pt-v5-vault/lib/brokentoken/src/",
    "create3-factory/=lib/yield-daddy/lib/create3-factory/",
    "erc4626-tests/=lib/pt-v5-vault/lib/erc4626-tests/",
    "erc5164-interfaces/=lib/pt-v5-draw-auction/lib/erc5164-interfaces/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "owner-manager-contracts/=lib/pt-v5-chainlink-vrf-v2-direct/lib/owner-manager-contracts/contracts/",
    "owner-manager/=lib/pt-v5-chainlink-vrf-v2-direct/lib/owner-manager-contracts/contracts/",
    "prb-test/=lib/pt-v5-vault-boost/lib/prb-math/lib/prb-test/src/",
    "pt-v5-claimable-interface/=lib/pt-v5-vault/lib/pt-v5-claimable-interface/src/",
    "pt-v5-rng-contracts/=lib/pt-v5-rng-contracts/contracts/",
    "pt-v5-twab-delegator/=lib/pt-v5-twab-delegator/src/",
    "ring-buffer-lib/=lib/pt-v5-twab-controller/lib/ring-buffer-lib/src/",
    "rng/=lib/pt-v5-draw-auction/lib/pt-v5-rng-contracts/contracts/",
    "solmate/=lib/yield-daddy/lib/solmate/src/",
    "uniform-random-number/=lib/pt-v5-prize-pool/lib/uniform-random-number/src/",
    "weird-erc20/=lib/pt-v5-vault/lib/brokentoken/lib/weird-erc20/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200,
    "details": {
      "peephole": true,
      "inliner": true,
      "deduplicate": true,
      "cse": true,
      "yul": true
    }
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "viaIR": true,
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract ChainlinkVRFV2Direct","name":"_chainlinkVrfV2Direct","type":"address"},{"internalType":"contract IRngAuction","name":"_rngAuction","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ChainlinkVRFV2DirectZeroAddress","type":"error"},{"inputs":[],"name":"RngAuctionZeroAddress","type":"error"},{"inputs":[{"internalType":"address","name":"chainlinkVrfV2Direct","type":"address"},{"internalType":"address","name":"activeRngService","type":"address"}],"name":"RngServiceNotActive","type":"error"},{"inputs":[],"name":"chainlinkVrfV2Direct","outputs":[{"internalType":"contract ChainlinkVRFV2Direct","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_gasPrice","type":"uint256"}],"name":"estimateRequestFee","outputs":[{"internalType":"address","name":"_feeToken","type":"address"},{"internalType":"uint256","name":"_requestFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rngAuction","outputs":[{"internalType":"contract IRngAuction","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_rewardRecipient","type":"address"}],"name":"transferFeeAndStartRngRequest","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60c0346100ca57601f6106ea38819003918201601f19168301916001600160401b038311848410176100cf5780849260409485528339810103126100ca5780516001600160a01b0391828216908183036100ca5760200151928316908184036100ca57156100b857156100a65760805260a05260405161060490816100e6823960805181818160c901528181610302015261035f015260a051818181608901526105430152f35b604051639a3b8ead60e01b8152600490fd5b60405163235c3aab60e11b8152600490fd5b600080fd5b634e487b7160e01b600052604160045260246000fdfe608060408181526004908136101561001657600080fd5b600092833560e01c9081630291e4b81461052f575080630b985910146103355780639a422b28146102ed57639c0f72001461005057600080fd5b8291346102e9576020806003193601126102e45781356001600160a01b0381811692918390036101e757845163122c897360e11b8082527f00000000000000000000000000000000000000000000000000000000000000008316939182818881885afa90811561024857908492918a916102c7575b50827f000000000000000000000000000000000000000000000000000000000000000016948591160361025257508651630d37b53760e01b81529287848881845afa918215610248578990819582946101fc575b50916064918594938b5197889586946323b872dd60e01b86528d339087015260248601526044850152165af180156101f2576101bb575b5050803b156101b757602485928551968793849263dab4055160e01b8452878401525af180156101ad57610182578380f35b67ffffffffffffffff831161019a5750523880808380f35b634e487b7160e01b845260419052602483fd5b82513d86823e3d90fd5b8480fd5b81813d83116101eb575b6101cf8183610572565b810103126101e75751801515036101b7573880610150565b8580fd5b503d6101c5565b86513d89823e3d90fd5b9550919250508784813d8311610241575b6102178183610572565b8101031261023d57835193818516850361023957830151919089906064610119565b8980fd5b8880fd5b503d61020d565b88513d8b823e3d90fd5b9188938886838a968784518094819382525afa9384156102bd576044979461028e575b505051639df6f24160e01b815293840152166024820152fd5b6102ae929450803d106102b6575b6102a68183610572565b8101906105aa565b918680610275565b503d61029c565b82513d89823e3d90fd5b6102de9150843d86116102b6576102a68183610572565b386100c5565b505050fd5b5050fd5b838234610331578160031936011261033157517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b5080fd5b509134610456576020806003193601126103315783516337c385a560e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811694909183818381895afa9081156105255790839186916104eb575b5016865195631b6b6d2360e01b875284878481855afa9687156104a95786976104b3575b509084839289519384809263de8be8e760e01b82525afa9182156104a95790859291879261046b575b5063ffffffff916044918a519586948593637fb5d19d60e01b855216818401523560248301525afa93841561046057809461042b575b5050845193168352820152f35b909193508282813d8311610459575b6104448183610572565b8101031261045657505191388061041e565b80fd5b503d61043a565b8651903d90823e3d90fd5b8092508391933d83116104a2575b6104838183610572565b810103126101e7575163ffffffff811681036101e757849160446103e8565b503d610479565b88513d88823e3d90fd5b9096508481813d83116104e4575b6104cb8183610572565b810103126101e7575183811681036101e75795846103bf565b503d6104c1565b809250858092503d831161051e575b6105048183610572565b810103126101b7575182811681036101b75782903861039b565b503d6104fa565b87513d87823e3d90fd5b8490346103315781600319360112610331577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b90601f8019910116810190811067ffffffffffffffff82111761059457604052565b634e487b7160e01b600052604160045260246000fd5b908160209103126105c957516001600160a01b03811681036105c95790565b600080fdfea264697066735822122018f2e431708414ad303465a0559c37ac31ec78abcbf5b584fd29c9c42ce8517864736f6c63430008130033000000000000000000000000e3df5b001575a4ce800f6f3770b7f22cbe95d8f9000000000000000000000000539a76507f18505ca696d618f8a684814c867f41

Deployed Bytecode

0x608060408181526004908136101561001657600080fd5b600092833560e01c9081630291e4b81461052f575080630b985910146103355780639a422b28146102ed57639c0f72001461005057600080fd5b8291346102e9576020806003193601126102e45781356001600160a01b0381811692918390036101e757845163122c897360e11b8082527f000000000000000000000000539a76507f18505ca696d618f8a684814c867f418316939182818881885afa90811561024857908492918a916102c7575b50827f000000000000000000000000e3df5b001575a4ce800f6f3770b7f22cbe95d8f916948591160361025257508651630d37b53760e01b81529287848881845afa918215610248578990819582946101fc575b50916064918594938b5197889586946323b872dd60e01b86528d339087015260248601526044850152165af180156101f2576101bb575b5050803b156101b757602485928551968793849263dab4055160e01b8452878401525af180156101ad57610182578380f35b67ffffffffffffffff831161019a5750523880808380f35b634e487b7160e01b845260419052602483fd5b82513d86823e3d90fd5b8480fd5b81813d83116101eb575b6101cf8183610572565b810103126101e75751801515036101b7573880610150565b8580fd5b503d6101c5565b86513d89823e3d90fd5b9550919250508784813d8311610241575b6102178183610572565b8101031261023d57835193818516850361023957830151919089906064610119565b8980fd5b8880fd5b503d61020d565b88513d8b823e3d90fd5b9188938886838a968784518094819382525afa9384156102bd576044979461028e575b505051639df6f24160e01b815293840152166024820152fd5b6102ae929450803d106102b6575b6102a68183610572565b8101906105aa565b918680610275565b503d61029c565b82513d89823e3d90fd5b6102de9150843d86116102b6576102a68183610572565b386100c5565b505050fd5b5050fd5b838234610331578160031936011261033157517f000000000000000000000000e3df5b001575a4ce800f6f3770b7f22cbe95d8f96001600160a01b03168152602090f35b5080fd5b509134610456576020806003193601126103315783516337c385a560e01b81526001600160a01b037f000000000000000000000000e3df5b001575a4ce800f6f3770b7f22cbe95d8f9811694909183818381895afa9081156105255790839186916104eb575b5016865195631b6b6d2360e01b875284878481855afa9687156104a95786976104b3575b509084839289519384809263de8be8e760e01b82525afa9182156104a95790859291879261046b575b5063ffffffff916044918a519586948593637fb5d19d60e01b855216818401523560248301525afa93841561046057809461042b575b5050845193168352820152f35b909193508282813d8311610459575b6104448183610572565b8101031261045657505191388061041e565b80fd5b503d61043a565b8651903d90823e3d90fd5b8092508391933d83116104a2575b6104838183610572565b810103126101e7575163ffffffff811681036101e757849160446103e8565b503d610479565b88513d88823e3d90fd5b9096508481813d83116104e4575b6104cb8183610572565b810103126101e7575183811681036101e75795846103bf565b503d6104c1565b809250858092503d831161051e575b6105048183610572565b810103126101b7575182811681036101b75782903861039b565b503d6104fa565b87513d87823e3d90fd5b8490346103315781600319360112610331577f000000000000000000000000539a76507f18505ca696d618f8a684814c867f416001600160a01b03168152602090f35b90601f8019910116810190811067ffffffffffffffff82111761059457604052565b634e487b7160e01b600052604160045260246000fd5b908160209103126105c957516001600160a01b03811681036105c95790565b600080fdfea264697066735822122018f2e431708414ad303465a0559c37ac31ec78abcbf5b584fd29c9c42ce8517864736f6c63430008130033

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

000000000000000000000000e3df5b001575a4ce800f6f3770b7f22cbe95d8f9000000000000000000000000539a76507f18505ca696d618f8a684814c867f41

-----Decoded View---------------
Arg [0] : _chainlinkVrfV2Direct (address): 0xE3DF5b001575a4ce800f6f3770B7f22cBe95d8F9
Arg [1] : _rngAuction (address): 0x539A76507F18505cA696d618F8A684814c867F41

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000e3df5b001575a4ce800f6f3770b7f22cbe95d8f9
Arg [1] : 000000000000000000000000539a76507f18505ca696d618f8a684814c867f41


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

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