VRFSubscriptionManagerV2Mock
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
Name | Type | Description |
---|---|---|
_governor | address | The Governor of the contract |
_vrfCoordinator | address | The address of the VRFCoordinator contract. |
changeVrfCoordinator
Changes the vrfCoordinator
storage variable.
function changeVrfCoordinator(address _vrfCoordinator) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_vrfCoordinator | address | The 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
Name | Type | Description |
---|---|---|
amount | uint96 | Amount of LINK token in wei. |
addConsumer
Add a Consumer to the subscription.
function addConsumer(address consumer) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
consumer | address | Address of the Consumer contract added to the subscription. |
removeConsumer
Removes a Consumer to the subscription
function removeConsumer(address consumer) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
consumer | address | Address 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
Name | Type | Description |
---|---|---|
balance | uint96 | LINK token balance of the current subscription. |
reqCount | uint64 | Number of requests made to the subscription. |
owner | address | Address of the current owner of the subscription. |
consumers | address[] | 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);