IGelatoVRFAdapter
Title: IGelatoVRFAdapter
Author: Modified from Gelato (https://github.com/gelatodigital/vrf-contracts)
Interface for the GelatoVRFAdapter Diamond facet — drand-backed randomness (no on-chain fee).
Request/track layer over Gelato VRF. A request emits RequestedRandomness (the Gelato
IGelatoVRFConsumer event) for the dedicated operator to pick up; the operator fulfils via
fulfillRandomness, which is gated so only the configured operator may call it. The delivered
randomness is domain-separated per request before being surfaced. Consumer facets that inherit
GelatoVRFAdapter should override fulfillRandomness (calling super.fulfillRandomness
first) to act on the randomness.
Functions
getOperator
Returns the configured dedicated operator.
function getOperator() external view returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
getUserKey
Returns the user key associated with a pending request.
function getUserKey(uint256 requestId) external view returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| requestId | uint256 | The adapter-assigned request ID. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 | The user-supplied key, or bytes32(0) if not found. |
setOperator
Sets or replaces the dedicated operator.
Caller must hold DEFAULT_ADMIN_ROLE. Reverts GelatoVRFInvalidOperator if zero.
function setOperator(address operator) external;Parameters
| Name | Type | Description |
|---|---|---|
| operator | address | The new dedicated operator. |
requestRandomness
Requests randomness from Gelato VRF.
Caller must hold DEFAULT_ADMIN_ROLE. Emits RequestedRandomness for the operator.
function requestRandomness(bytes32 userKey) external returns (uint256 requestId);Parameters
| Name | Type | Description |
|---|---|---|
| userKey | bytes32 | Arbitrary key the caller wants associated with this request. |
Returns
| Name | Type | Description |
|---|---|---|
| requestId | uint256 | The adapter-assigned request ID. |
fulfillRandomness
Called by the dedicated operator to deliver randomness.
Verifies the caller is the configured operator, decodes the request, domain-separates the
randomness, clears the pending entry, and emits RandomnessFulfilled. Consumer facets
should override this to consume the randomness.
function fulfillRandomness(uint256 randomness, bytes calldata dataWithRound) external;Parameters
| Name | Type | Description |
|---|---|---|
| randomness | uint256 | The drand-derived randomness for the requested round. |
| dataWithRound | bytes | The opaque payload originally emitted in RequestedRandomness. |
Events
GelatoVRFOperatorSet
Emitted when the dedicated operator is updated.
event GelatoVRFOperatorSet(address operator);Parameters
| Name | Type | Description |
|---|---|---|
| operator | address | The Gelato dedicated operator allowed to fulfil requests. |
RandomnessRequested
Emitted (in addition to the Gelato RequestedRandomness event) when randomness is requested.
event RandomnessRequested(uint256 indexed requestId, bytes32 indexed userKey, uint256 round);Parameters
| Name | Type | Description |
|---|---|---|
| requestId | uint256 | The adapter-assigned request ID. |
| userKey | bytes32 | The caller-supplied key associated with this request. |
| round | uint256 | The drand round whose beacon will seed the randomness. |
RandomnessFulfilled
Emitted when the operator fulfils a request.
event RandomnessFulfilled(uint256 indexed requestId, bytes32 indexed userKey, uint256 randomness);Parameters
| Name | Type | Description |
|---|---|---|
| requestId | uint256 | The adapter-assigned request ID. |
| userKey | bytes32 | The caller-supplied key originally associated with this request. |
| randomness | uint256 | The domain-separated randomness delivered for this request. |
Errors
GelatoVRFNotConfigured
The dedicated operator has not been configured (operator address is zero).
error GelatoVRFNotConfigured();GelatoVRFInvalidOperator
setOperator was called with a zero operator address.
error GelatoVRFInvalidOperator();GelatoVRFInvalidUserKey
requestRandomness was called with a zero userKey.
bytes32(0) is the sentinel used to detect a missing pending request.
error GelatoVRFInvalidUserKey();GelatoVRFOnlyOperator
fulfillRandomness was called by an address other than the dedicated operator.
error GelatoVRFOnlyOperator(address caller);Parameters
| Name | Type | Description |
|---|---|---|
| caller | address | The unauthorised caller. |
GelatoVRFRequestNotFound
The given request ID has no pending entry (already fulfilled or never requested).
error GelatoVRFRequestNotFound(uint256 requestId);Parameters
| Name | Type | Description |
|---|---|---|
| requestId | uint256 | The unknown request ID. |