GelatoVRFAdapterLib
Title: GelatoVRFAdapterLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Gelato (https://github.com/gelatodigital/vrf-contracts)
Library that wraps Gelato VRF (drand-backed, quicknet beacon) random
requests. This is the request/track layer only — fulfillment
bookkeeping is handled here, but consumer facets inheriting
GelatoVRFAdapter should override fulfillRandomness (calling
super.fulfillRandomness first) to actually consume the randomness.
Constants
_GENESIS
Genesis timestamp of the drand quicknet beacon used by Gelato VRF.
uint256 internal constant _GENESIS = 1_692_803_367;_PERIOD
Period (in seconds) between drand quicknet beacon rounds.
uint256 internal constant _PERIOD = 3;Functions
gelatoVRFAdapterStorage
Returns the ERC-7201 storage struct for GelatoVRFAdapter.
function gelatoVRFAdapterStorage() internal pure returns (GelatoVRFAdapterStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | GelatoVRFAdapterStorage |
__GelatoVRFAdapter_init
Registers the IGelatoVRFAdapter ERC-165 interface.
Must be called between preInitializer / postInitializer.
function __GelatoVRFAdapter_init() internal;registerInterface
Writes true to the ERC-165 map slot for IGelatoVRFAdapter.
function registerInterface() internal;_requireOperator
Returns the configured operator, reverting if unset.
function _requireOperator() internal view returns (address op);Returns
| Name | Type | Description |
|---|---|---|
| op | address | The configured dedicated operator. |
_round
Returns the current drand round for the quicknet beacon.
Underflow-guarded so it is safe at low test timestamps.
function _round() internal view returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
getOperator
Returns the configured dedicated operator.
function getOperator() internal view returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
getUserKey
Returns the user key associated with a pending request.
function getUserKey(uint256 requestId) internal view returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| requestId | uint256 | The adapter-assigned request ID. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
setOperator
Sets or replaces the dedicated operator.
Caller must hold DEFAULT_ADMIN_ROLE.
Reverts GelatoVRFInvalidOperator if operator is zero.
function setOperator(address operator) internal;Parameters
| Name | Type | Description |
|---|---|---|
| operator | address | The new dedicated operator. |
requestRandomness
Requests randomness from Gelato VRF.
Caller must hold DEFAULT_ADMIN_ROLE.
Stores the userKey against the returned requestId so the
fulfillment callback can look it up, then emits both the adapter
RandomnessRequested event and the Gelato RequestedRandomness
event the dedicated operator listens for.
Reverts GelatoVRFInvalidUserKey if userKey is the zero sentinel
and GelatoVRFNotConfigured if no operator has been set.
function requestRandomness(bytes32 userKey) internal 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 (msg.sender),
decodes the request, looks up the user key, clears the pending
entry, domain-separates the randomness per request, and emits
RandomnessFulfilled.
NOTE: This function only manages bookkeeping. Consumer facets that
inherit GelatoVRFAdapter should override fulfillRandomness (or
provide a follow-up hook) to act on the delivered randomness.
function fulfillRandomness(uint256 randomness, bytes calldata dataWithRound) internal;Parameters
| Name | Type | Description |
|---|---|---|
| randomness | uint256 | The drand-derived randomness for the requested round. |
| dataWithRound | bytes | The opaque payload originally emitted in RequestedRandomness. |