Skip to content
Lattice

PythAdapter

Git Source

Inherits: IPythAdapter

Title: PythAdapter

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

Diamond facet exposing pull-based Pyth price feeds with per-feed staleness + confidence configuration and WAD-normalized answers. Shares the IPriceOracleReader read surface with the other Lattice oracle adapters.

Stateless delegator — all logic and storage live in PythAdapterLib. Consumers inherit this contract and add AccessControl + an initializer. Prices are refreshed via the payable updatePriceFeeds, then read via latestAnswer.

Notes:

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

Functions

pyth

Returns the Pyth contract address.

function pyth() external view virtual override returns (address);

Returns

NameTypeDescription
<none>address

getFeed

Returns a feed's configuration.

function getFeed(bytes32 key)
        external
        view
        virtual
        override
        returns (bytes32 priceId, uint48 maxStaleness, uint64 maxConfBps);

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
priceIdbytes32The Pyth price-feed id.
maxStalenessuint48Maximum age (seconds) before a price is stale.
maxConfBpsuint64Maximum confidence ratio in basis points (0 = disabled).

latestAnswer

Returns the latest price for key, normalized to 18 decimals (WAD). Selector matches IPriceOracleReader.latestAnswer. Reverts on stale / future / non-positive / wide-confidence, or when the normalized answer truncates to zero.

function latestAnswer(bytes32 key) external view virtual override returns (int256 answerWad);

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
answerWadint256The latest price scaled to 1e18.

latestAnswerRaw

Returns the validated raw price for key.

function latestAnswerRaw(bytes32 key)
        external
        view
        virtual
        override
        returns (int64 price, int32 expo, uint64 conf, uint256 publishTime);

Parameters

NameTypeDescription
keybytes32The feed identifier.

Returns

NameTypeDescription
priceint64The Pyth price (scale 10^expo).
expoint32The price exponent.
confuint64The confidence interval.
publishTimeuint256The publish timestamp.

getUpdateFee

Returns the fee (wei) required to submit updateData.

function getUpdateFee(bytes[] calldata updateData) external view virtual override returns (uint256);

Parameters

NameTypeDescription
updateDatabytes[]The signed Pyth price-update blobs.

Returns

NameTypeDescription
<none>uint256

updatePriceFeeds

Refreshes on-chain Pyth prices from updateData. Permissionless and caller-funded: msg.value must be >= getUpdateFee(updateData); any excess is refunded to the caller.

function updatePriceFeeds(bytes[] calldata updateData) external payable virtual override;

Parameters

NameTypeDescription
updateDatabytes[]The signed Pyth price-update blobs.

setPyth

Sets the Pyth contract. Caller must hold DEFAULT_ADMIN_ROLE.

function setPyth(address pyth_) external virtual override;

Parameters

NameTypeDescription
pyth_addressThe Pyth contract (non-zero).

registerFeed

Registers a Pyth feed under key. Caller must hold DEFAULT_ADMIN_ROLE.

function registerFeed(bytes32 key, bytes32 priceId, uint48 maxStaleness, uint64 maxConfBps)
        external
        virtual
        override;

Parameters

NameTypeDescription
keybytes32The arbitrary feed identifier.
priceIdbytes32The Pyth price-feed id (non-zero).
maxStalenessuint48Maximum age (seconds); must be non-zero.
maxConfBpsuint64Maximum confidence ratio in basis points (0 = disabled).

unregisterFeed

Removes a registered feed. Caller must hold DEFAULT_ADMIN_ROLE.

function unregisterFeed(bytes32 key) external virtual override;

Parameters

NameTypeDescription
keybytes32The feed identifier to remove.

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 PythAdapter methodIdentifiers (alphabetical by signature); kept in exact parity by ExportSelectorsParityTest. Chunks: getFeed(bytes32) 0x280aebcf getUpdateFee(bytes[]) 0xd47eed45 latestAnswer(bytes32) 0x084d4783 latestAnswerRaw(bytes32) 0xad0ddbee pyth() 0xf98d06f0 registerFeed(bytes32,bytes32,uint48,uint64) 0xb364e0d4 setPyth(address) 0xee22fd6f unregisterFeed(bytes32) 0x2a589908 updatePriceFeeds(bytes[]) 0xef9e5e28

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

Returns

NameTypeDescription
selectorsbytes