IPythAdapter
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
| Name | Type | Description |
|---|---|---|
| <none> | address |
getFeed
Returns a feed's configuration.
function getFeed(bytes32 key) external view returns (bytes32 priceId, uint48 maxStaleness, uint64 maxConfBps);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| priceId | bytes32 | The Pyth price-feed id. |
| maxStaleness | uint48 | Maximum age (seconds) before a price is stale. |
| maxConfBps | uint64 | Maximum 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
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| answerWad | int256 | The 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
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The feed identifier. |
Returns
| Name | Type | Description |
|---|---|---|
| price | int64 | The Pyth price (scale 10^expo). |
| expo | int32 | The price exponent. |
| conf | uint64 | The confidence interval. |
| publishTime | uint256 | The publish timestamp. |
getUpdateFee
Returns the fee (wei) required to submit updateData.
function getUpdateFee(bytes[] calldata updateData) external view returns (uint256 feeAmount);Parameters
| Name | Type | Description |
|---|---|---|
| updateData | bytes[] | The signed Pyth price-update blobs. |
Returns
| Name | Type | Description |
|---|---|---|
| feeAmount | 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;Parameters
| Name | Type | Description |
|---|---|---|
| updateData | bytes[] | The signed Pyth price-update blobs. |
setPyth
Sets the Pyth contract. Caller must hold DEFAULT_ADMIN_ROLE.
function setPyth(address pyth_) external;Parameters
| Name | Type | Description |
|---|---|---|
| pyth_ | address | The 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
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The arbitrary feed identifier. |
| priceId | bytes32 | The Pyth price-feed id (non-zero). |
| maxStaleness | uint48 | Maximum age (seconds); must be non-zero. |
| maxConfBps | uint64 | Maximum confidence ratio in basis points (0 = disabled). |
unregisterFeed
Removes a registered feed. Caller must hold DEFAULT_ADMIN_ROLE.
function unregisterFeed(bytes32 key) external;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The 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
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The arbitrary feed identifier. |
| priceId | bytes32 | The Pyth price-feed id. |
| maxStaleness | uint48 | Maximum age (seconds) before a price is stale. |
| maxConfBps | uint64 | Maximum confidence ratio in basis points (conf/price); 0 disables the check. |
FeedUnregistered
Emitted when a feed is removed.
event FeedUnregistered(bytes32 indexed key);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The removed feed identifier. |
PythContractSet
Emitted when the Pyth contract address is set.
event PythContractSet(address indexed pyth);Parameters
| Name | Type | Description |
|---|---|---|
| pyth | address | The Pyth contract. |
Errors
PythFeedNotRegistered
The requested feed key has not been registered.
error PythFeedNotRegistered(bytes32 key);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
PythStaleData
The price is older than the feed's maxStaleness.
error PythStaleData(bytes32 key, uint256 publishTime, uint256 maxStaleness);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| publishTime | uint256 | |
| maxStaleness | uint256 |
PythFuturePrice
The price has a future publish time.
error PythFuturePrice(bytes32 key, uint256 publishTime);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| publishTime | uint256 |
PythInvalidAnswer
The feed returned a non-positive price.
error PythInvalidAnswer(bytes32 key, int64 price);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| price | int64 |
PythConfidenceTooWide
The confidence ratio conf/price exceeds the feed's maxConfBps.
error PythConfidenceTooWide(bytes32 key, uint64 conf, int64 price, uint64 maxConfBps);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| conf | uint64 | |
| price | int64 | |
| maxConfBps | uint64 |
PythExpoOutOfRange
The price exponent is outside the supported normalization range.
error PythExpoOutOfRange(int32 expo);Parameters
| Name | Type | Description |
|---|---|---|
| expo | int32 |
PythNormalizedAnswerZero
A positive price truncated to zero when normalized to 18 decimals (expo < -18 and
price < 10^(-18 - expo)).
error PythNormalizedAnswerZero(bytes32 key, int64 price, int32 expo);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| price | int64 | |
| expo | int32 |
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
| Name | Type | Description |
|---|---|---|
| provided | uint256 | |
| required | uint256 |
PythRefundFailed
The excess-fee refund to the caller failed.
error PythRefundFailed();