Skip to content
Lattice

IPythAdapter

Git Source

Title: IPythAdapter

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

Interface for the PythAdapter Diamond facet — Pyth price feeds with per-feed staleness + confidence configuration and WAD-normalized answers.

Pyth is PULL-based: prices are refreshed by submitting signed updateData (paying a fee) via the payable updatePriceFeeds, then read via latestAnswer/latestAnswerRaw (which validate staleness, future timestamps, sign, and confidence). Feeds are keyed by an arbitrary bytes32 mapped to a Pyth price-feed id. latestAnswer(bytes32)->int256 is declared with the same selector as IPriceOracleReader, so consumers can read this adapter through that provider-agnostic interface. (Declared directly, not by inheriting IPriceOracleReader, because Solidity excludes inherited functions from type(I).interfaceId, which would shift the ERC-165 id.)

The adapter does NOT check an L2 sequencer-uptime feed and does NOT bound the answer to a sane range. Integrators that need either check read through the opt-in IOracleGuard (OracleGuard facet) instead of calling latestAnswer directly.

Functions

pyth

Returns the Pyth contract address.

function pyth() external view returns (address);

Returns

NameTypeDescription
<none>address

getFeed

Returns a feed's configuration.

function getFeed(bytes32 key) external view 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 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
        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 returns (uint256 feeAmount);

Parameters

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

Returns

NameTypeDescription
feeAmountuint256

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;

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;

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;

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;

Parameters

NameTypeDescription
keybytes32The feed identifier to remove.

Events

FeedRegistered

Emitted when a feed is registered or updated.

event FeedRegistered(bytes32 indexed key, bytes32 indexed priceId, uint48 maxStaleness, uint64 maxConfBps);

Parameters

NameTypeDescription
keybytes32The arbitrary feed identifier.
priceIdbytes32The Pyth price-feed id.
maxStalenessuint48Maximum age (seconds) before a price is stale.
maxConfBpsuint64Maximum confidence ratio in basis points (conf/price); 0 disables the check.

FeedUnregistered

Emitted when a feed is removed.

event FeedUnregistered(bytes32 indexed key);

Parameters

NameTypeDescription
keybytes32The removed feed identifier.

PythContractSet

Emitted when the Pyth contract address is set.

event PythContractSet(address indexed pyth);

Parameters

NameTypeDescription
pythaddressThe Pyth contract.

Errors

PythFeedNotRegistered

The requested feed key has not been registered.

error PythFeedNotRegistered(bytes32 key);

Parameters

NameTypeDescription
keybytes32

PythStaleData

The price is older than the feed's maxStaleness.

error PythStaleData(bytes32 key, uint256 publishTime, uint256 maxStaleness);

Parameters

NameTypeDescription
keybytes32
publishTimeuint256
maxStalenessuint256

PythFuturePrice

The price has a future publish time.

error PythFuturePrice(bytes32 key, uint256 publishTime);

Parameters

NameTypeDescription
keybytes32
publishTimeuint256

PythInvalidAnswer

The feed returned a non-positive price.

error PythInvalidAnswer(bytes32 key, int64 price);

Parameters

NameTypeDescription
keybytes32
priceint64

PythConfidenceTooWide

The confidence ratio conf/price exceeds the feed's maxConfBps.

error PythConfidenceTooWide(bytes32 key, uint64 conf, int64 price, uint64 maxConfBps);

Parameters

NameTypeDescription
keybytes32
confuint64
priceint64
maxConfBpsuint64

PythExpoOutOfRange

The price exponent is outside the supported normalization range.

error PythExpoOutOfRange(int32 expo);

Parameters

NameTypeDescription
expoint32

PythNormalizedAnswerZero

A positive price truncated to zero when normalized to 18 decimals (expo &lt; -18 and price &lt; 10^(-18 - expo)).

error PythNormalizedAnswerZero(bytes32 key, int64 price, int32 expo);

Parameters

NameTypeDescription
keybytes32
priceint64
expoint32

PythInvalidConfig

registerFeed was called with a zero price id or zero maxStaleness.

error PythInvalidConfig();

PythContractNotSet

The Pyth contract address has not been set.

error PythContractNotSet();

PythContractIsZero

Setting the Pyth contract to the zero address.

error PythContractIsZero();

PythInsufficientFee

msg.value is less than the required Pyth update fee.

error PythInsufficientFee(uint256 provided, uint256 required);

Parameters

NameTypeDescription
provideduint256
requireduint256

PythRefundFailed

The excess-fee refund to the caller failed.

error PythRefundFailed();