Skip to content
Lattice

PythEntropyAdapter

Git Source

Inherits: IPythEntropyAdapter

Title: PythEntropyAdapter

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Pyth (https://github.com/pyth-network/pyth-crosschain)

Diamond facet for Pyth Entropy on-demand (commit/reveal) randomness.

Stateless delegator — all logic and storage live in PythEntropyAdapterLib.

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

Notes:

  • lattice-version: 0.1.0
  • lattice-source: Pyth

Functions

getConfig

Returns the current Entropy configuration.

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

Returns

NameTypeDescription
<none>EntropyConfig

getFee

Returns the fee (in wei) required for one request under the current config.

function getFee() external view virtual override returns (uint256);

Returns

NameTypeDescription
<none>uint256

getUserKey

Returns the user key associated with a pending request.

function getUserKey(uint64 sequenceNumber) external view virtual override returns (bytes32);

Parameters

NameTypeDescription
sequenceNumberuint64The Entropy-assigned sequence number.

Returns

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

setConfig

Sets or replaces the Entropy configuration.

Caller must hold DEFAULT_ADMIN_ROLE. Reverts EntropyInvalidConfig if entropy is zero.

function setConfig(EntropyConfig calldata config) external virtual override;

Parameters

NameTypeDescription
configEntropyConfigThe new configuration.

requestRandomNumber

Requests a random number, caller-funded with excess refunded.

Caller must hold DEFAULT_ADMIN_ROLE and send msg.value >= getFee().

function requestRandomNumber(bytes32 userKey, bytes32 userRandomNumber)
        external
        payable
        virtual
        override
        returns (uint64 sequenceNumber);

Parameters

NameTypeDescription
userKeybytes32Arbitrary key the caller wants associated with this request.
userRandomNumberbytes32The caller's commitment to its half of the randomness.

Returns

NameTypeDescription
sequenceNumberuint64The Entropy-assigned sequence number.

entropyCallback

Called by the Entropy contract to deliver a random number.

Verifies the caller is the configured Entropy contract, looks up the user key, clears the pending entry, and emits RandomNumberFulfilled. Consumer facets should override this to consume the randomness.

function entropyCallback(uint64 sequence, address provider, bytes32 randomNumber) external virtual override;

Parameters

NameTypeDescription
sequenceuint64The Entropy-assigned sequence number.
provideraddressThe provider that fulfilled the request.
randomNumberbytes32The delivered random number.

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 PythEntropyAdapter methodIdentifiers (alphabetical by signature); kept in exact parity by ExportSelectorsParityTest. Chunks: entropyCallback(uint64,address,bytes32) 0x24185135 getConfig() 0xc3f909d4 getFee() 0xced72f87 getUserKey(uint64) 0x65b56cd4 requestRandomNumber(bytes32,bytes32) 0x8738559f setConfig((address,address)) 0x861fb568

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

Returns

NameTypeDescription
selectorsbytes