Skip to content
Lattice

API3QRNGAdapter

Git Source

Inherits: IAPI3QRNGAdapter

Title: API3QRNGAdapter

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from API3 (https://github.com/api3dao/airnode)

Diamond facet for API3 QRNG (quantum randomness) over the Airnode Request-Response Protocol (self-sponsoring).

Stateless delegator — all logic and storage live in API3QRNGAdapterLib.

This facet handles the request/track layer only. Consumer facets that inherit this contract should override fulfillRandomNumber to act on delivered randomness after calling super.fulfillRandomNumber.

Notes:

  • lattice-version: 0.1.0
  • lattice-source: API3

Functions

getConfig

Returns the current QRNG configuration.

function getConfig() external view virtual override returns (QRNGConfig memory);

Returns

NameTypeDescription
<none>QRNGConfig

getUserKey

Returns the user key associated with a pending request.

function getUserKey(bytes32 requestId) external view virtual override returns (bytes32);

Parameters

NameTypeDescription
requestIdbytes32The RRP-assigned request ID.

Returns

NameTypeDescription
<none>bytes32The user-supplied key, or bytes32(0) if not found.

setConfig

Sets or replaces the QRNG configuration.

Caller must hold DEFAULT_ADMIN_ROLE. Reverts QRNGInvalidConfig on any zero field.

function setConfig(QRNGConfig calldata config) external virtual override;

Parameters

NameTypeDescription
configQRNGConfigThe new configuration.

setSelfSponsorship

Registers (or revokes) this contract as its own sponsor with the Airnode RRP.

Caller must hold DEFAULT_ADMIN_ROLE. A full request only succeeds while self-sponsored.

function setSelfSponsorship(bool status) external virtual override;

Parameters

NameTypeDescription
statusboolTrue to self-sponsor, false to revoke.

requestRandomNumber

Requests a quantum random number via the Airnode RRP.

Caller must hold DEFAULT_ADMIN_ROLE.

function requestRandomNumber(bytes32 userKey) external virtual override returns (bytes32 requestId);

Parameters

NameTypeDescription
userKeybytes32Arbitrary key the caller wants associated with this request.

Returns

NameTypeDescription
requestIdbytes32The RRP-assigned request ID.

fulfillRandomNumber

Called by the Airnode RRP to deliver the random number.

Verifies the caller is the configured Airnode RRP, looks up the user key, clears the pending entry, decodes the random number, and emits RandomNumberFulfilled. Consumer facets should override this to consume the randomness.

function fulfillRandomNumber(bytes32 requestId, bytes calldata data) external virtual override;

Parameters

NameTypeDescription
requestIdbytes32The RRP-assigned request ID.
databytesThe ABI-encoded random number (abi.encode(uint256)).

exportSelectors

ERC-8153 selector export: this facet's cuttable selectors, tightly packed (4 bytes each).

Excludes exportSelectors() itself (0x0ef22643) - it is never cut into a diamond. Order matches forge inspect API3QRNGAdapter methodIdentifiers (alphabetical by signature); kept in exact parity by ExportSelectorsParityTest. Chunks: fulfillRandomNumber(bytes32,bytes) 0xf43a72e3 getConfig() 0xc3f909d4 getUserKey(bytes32) 0xa1cfedf0 requestRandomNumber(bytes32) 0xbd313d78 setConfig((address,address,bytes32,address)) 0xa601dfb6 setSelfSponsorship(bool) 0x230bc58e

function exportSelectors() external pure virtual returns (bytes memory selectors);

Returns

NameTypeDescription
selectorsbytes