VRFSubscriptionManagerV2
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.
LINK Token Arbitrum: https://docs.chain.link/resources/link-token-contracts?parent=vrf#arbitrum
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
VRFCoordinatorV2Interface public vrfCoordinator;
linkToken
LinkTokenInterface public linkToken;
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, address _linkToken);
Parameters
Name | Type | Description |
---|---|---|
_governor | address | The Governor of the contract |
_vrfCoordinator | address | The address of the VRFCoordinator contract. |
_linkToken | address | The address of the LINK token. |
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. |
requestSubscriptionOwnerTransfer
Request the ownership transfer of the current subscription to newOwner
The current owner of the subscription is the Subscription Manager contract
function requestSubscriptionOwnerTransfer(address newOwner) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
newOwner | address | Address of the proposed new owner of the current subscription Note: Transferring the ownership should be used when migrating a subscription from one Subscription Manager to another without removing the consumers nor cancelling the subscription |
acceptSubscriptionOwnerTransfer
Accept the subscription transfer of ownership.
function acceptSubscriptionOwnerTransfer(uint64 _subscriptionId) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
_subscriptionId | uint64 | ID of the subscription to be accepted. It will override the current subscription if any. |
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(uint256 amount) external;
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | 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;
withdrawLinkToGovernor
Transfers amount
LINK tokens of the Subscription Manager (this contract) to the governor.
function withdrawLinkToGovernor(uint256 amount) external onlyByGovernor;
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | Amount of LINK token in wei. |
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);
LinkWithdrawn
Emitted when the governor withdraws amount
LINK from the subscription manager.
event LinkWithdrawn(address indexed receiver, uint256 indexed amount);