VRFSubscriptionManagerV2Mock

Git Source

Author: Simon Malatrait simon.malatrait@grenoble-inp.org

This contracts implements a subscription manager for using VRF v2 with the Subscription Method.

It allows to create subscriptions, manage them and consumers.

VRFCoordinatorV2 address: https://docs.chain.link/vrf/v2/subscription/supported-networks#arbitrum-mainnet

For SECURITY CONSIDERATIONS, you might also have a look to: https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/vrf/VRFCoordinatorV2.sol

State Variables

vrfCoordinator

VRFCoordinatorV2InterfaceMock public vrfCoordinator;

subscriptionId

uint64 public subscriptionId;

governor

address public governor;

Functions

onlyByGovernor

modifier onlyByGovernor();

constructor

Constructs the Chainlink VRF v2 Subscription Manager.

constructor(address _governor, address _vrfCoordinator);

Parameters

NameTypeDescription
_governoraddressThe Governor of the contract
_vrfCoordinatoraddressThe address of the VRFCoordinator contract.

changeVrfCoordinator

Changes the vrfCoordinator storage variable.

function changeVrfCoordinator(address _vrfCoordinator) external onlyByGovernor;

Parameters

NameTypeDescription
_vrfCoordinatoraddressThe new value for the vrfCoordinator storage variable.

createNewSubscription

Creates a new subscription, overriding the previous one to be manageable by the contract.

function createNewSubscription() public onlyByGovernor;

topUpSubscription

Funds the current subscription by amount LINK tokens.

function topUpSubscription(uint96 amount) external;

Parameters

NameTypeDescription
amountuint96Amount of LINK token in wei.

addConsumer

Add a Consumer to the subscription.

function addConsumer(address consumer) external onlyByGovernor;

Parameters

NameTypeDescription
consumeraddressAddress of the Consumer contract added to the subscription.

removeConsumer

Removes a Consumer to the subscription

function removeConsumer(address consumer) external onlyByGovernor;

Parameters

NameTypeDescription
consumeraddressAddress of the Consumer contract removed from the subscription.

cancelSubscriptionToGovernor

Cancel the current subscription and send the remaining LINK of the subscription to the governor.

function cancelSubscriptionToGovernor() external onlyByGovernor;

getSubscription

Returns information on the current subscription

function getSubscription()
    external
    view
    returns (uint96 balance, uint64 reqCount, address owner, address[] memory consumers);

Returns

NameTypeDescription
balanceuint96LINK token balance of the current subscription.
reqCountuint64Number of requests made to the subscription.
owneraddressAddress of the current owner of the subscription.
consumersaddress[]List of consumers subscribed to the current subscription.

Events

SubscriptionFunded

Emitted when LINK tokens are sent from this contract to the current subscription.

event SubscriptionFunded(uint64 subscriptionId, uint256 amount);