Skip to content
Lattice

IGelatoVRFAdapter

Git Source

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

NameTypeDescription
<none>address

getUserKey

Returns the user key associated with a pending request.

function getUserKey(uint256 requestId) external view returns (bytes32);

Parameters

NameTypeDescription
requestIduint256The adapter-assigned request ID.

Returns

NameTypeDescription
<none>bytes32The 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

NameTypeDescription
operatoraddressThe 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

NameTypeDescription
userKeybytes32Arbitrary key the caller wants associated with this request.

Returns

NameTypeDescription
requestIduint256The 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

NameTypeDescription
randomnessuint256The drand-derived randomness for the requested round.
dataWithRoundbytesThe opaque payload originally emitted in RequestedRandomness.

Events

GelatoVRFOperatorSet

Emitted when the dedicated operator is updated.

event GelatoVRFOperatorSet(address operator);

Parameters

NameTypeDescription
operatoraddressThe 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

NameTypeDescription
requestIduint256The adapter-assigned request ID.
userKeybytes32The caller-supplied key associated with this request.
rounduint256The 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

NameTypeDescription
requestIduint256The adapter-assigned request ID.
userKeybytes32The caller-supplied key originally associated with this request.
randomnessuint256The 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

NameTypeDescription
calleraddressThe unauthorised caller.

GelatoVRFRequestNotFound

The given request ID has no pending entry (already fulfilled or never requested).

error GelatoVRFRequestNotFound(uint256 requestId);

Parameters

NameTypeDescription
requestIduint256The unknown request ID.