PythAdapterLib
Title: PythAdapterLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Pyth Network (https://github.com/pyth-network/pyth-crosschain)
Library wrapping the pull-based Pyth oracle with per-feed staleness + confidence configuration and WAD normalization, exposing the shared IPriceOracleReader read surface.
Three-layer pattern: this library holds the logic + namespaced storage; the stateless
PythAdapter facet forwards to it. Reads use Pyth's getPriceUnsafe and validate staleness,
future timestamp, sign, and confidence on-chain.
Functions
pythAdapterStorage
function pythAdapterStorage() internal pure returns (PythAdapterStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | PythAdapterStorage |
__PythAdapter_init
Initializes PythAdapter with the Pyth contract and registers the ERC-165 interface.
Must be called between preInitializer / postInitializer.
function __PythAdapter_init(address pyth_) internal;Parameters
| Name | Type | Description |
|---|---|---|
| pyth_ | address |
registerInterface
Writes true to the ERC-165 map slot for IPythAdapter.
function registerInterface() internal;pyth
function pyth() internal view returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
getFeed
function getFeed(bytes32 key) internal view returns (bytes32 priceId, uint48 maxStaleness, uint64 maxConfBps);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| priceId | bytes32 | |
| maxStaleness | uint48 | |
| maxConfBps | uint64 |
getUpdateFee
function getUpdateFee(bytes[] calldata updateData) internal view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| updateData | bytes[] |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
latestAnswerRaw
Returns the validated raw Pyth price for key.
Validates: registration, sign (price > 0), future-timestamp, staleness, and confidence.
function latestAnswerRaw(bytes32 key)
internal
view
returns (int64 price, int32 expo, uint64 conf, uint256 publishTime);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| price | int64 | |
| expo | int32 | |
| conf | uint64 | |
| publishTime | uint256 |
latestAnswer
Returns the latest price normalized to 18 decimals (WAD): price * 10^(18 + expo).
Reverts IPythAdapter.PythNormalizedAnswerZero rather than return 0 when the scaling truncates.
function latestAnswer(bytes32 key) internal view returns (int256 answerWad);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| answerWad | int256 |
updatePriceFeeds
Refreshes Pyth prices from updateData; caller-funded with excess refunded.
Permissionless. Effects are external (in the Pyth contract); the refund is the final step.
function updatePriceFeeds(bytes[] calldata updateData) internal;Parameters
| Name | Type | Description |
|---|---|---|
| updateData | bytes[] |
setPyth
function setPyth(address pyth_) internal;Parameters
| Name | Type | Description |
|---|---|---|
| pyth_ | address |
registerFeed
function registerFeed(bytes32 key, bytes32 priceId, uint48 maxStaleness, uint64 maxConfBps) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | |
| priceId | bytes32 | |
| maxStaleness | uint48 | |
| maxConfBps | uint64 |
unregisterFeed
function unregisterFeed(bytes32 key) internal;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 |
_requirePyth
function _requirePyth() private view returns (address p);Returns
| Name | Type | Description |
|---|---|---|
| p | address |