PythAdapter
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
| Name | Type | Description |
|---|---|---|
| <none> | address |
getFeed
Returns a feed's configuration.
function getFeed(bytes32 key)
external
view
virtual
override
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 virtual override 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
virtual
override
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 virtual override returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| updateData | bytes[] | The signed Pyth price-update blobs. |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| 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 virtual override;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
virtual
override;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 virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The 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
| Name | Type | Description |
|---|---|---|
| selectors | bytes |