PythOracle
Inherits: IPythOracle
This contract is used to get the price of the asset that corresponds to the stored feed ID.
Is implemented by the CommonOracleMiddleware contract.
State Variables
_pythFeedId
The ID of the Pyth price feed.
bytes32 internal immutable _pythFeedId;
_pyth
The address of the Pyth contract.
IPyth internal immutable _pyth;
_pythRecentPriceDelay
The maximum age of a recent price to be considered valid.
uint64 internal _pythRecentPriceDelay = 45 seconds;
Functions
constructor
constructor(address pythAddress, bytes32 pythFeedId);
Parameters
Name | Type | Description |
---|---|---|
pythAddress | address | The address of the Pyth contract. |
pythFeedId | bytes32 | The ID of the Pyth price feed. |
getPyth
Gets the Pyth contract address.
function getPyth() external view returns (IPyth);
Returns
Name | Type | Description |
---|---|---|
<none> | IPyth | pyth_ The Pyth contract address. |
getPythFeedId
Gets the ID of the price feed queried by this contract.
function getPythFeedId() external view returns (bytes32);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | feedId_ The Pyth price feed ID. |
getPythRecentPriceDelay
Gets the recent price delay.
function getPythRecentPriceDelay() external view returns (uint64);
Returns
Name | Type | Description |
---|---|---|
<none> | uint64 | recentPriceDelay_ The maximum age of a recent price to be considered valid. |
_getPythPrice
Gets the price of the asset from the stored Pyth price feed.
function _getPythPrice(bytes calldata priceUpdateData, uint128 targetTimestamp, uint128 targetLimit)
internal
returns (PythStructs.Price memory);
Parameters
Name | Type | Description |
---|---|---|
priceUpdateData | bytes | The data required to update the price feed. |
targetTimestamp | uint128 | The timestamp of the price in the given priceUpdateData . If zero, then we accept all recent prices. |
targetLimit | uint128 | The most recent timestamp a price can have. Can be zero if targetTimestamp is zero. |
Returns
Name | Type | Description |
---|---|---|
<none> | PythStructs.Price | price_ The raw price of the asset returned by Pyth. |
_getFormattedPythPrice
Gets the price of the asset from Pyth, formatted to the specified number of decimals.
function _getFormattedPythPrice(
bytes calldata priceUpdateData,
uint128 targetTimestamp,
uint256 middlewareDecimals,
uint128 targetLimit
) internal returns (FormattedPythPrice memory price_);
Parameters
Name | Type | Description |
---|---|---|
priceUpdateData | bytes | The data required to update the price feed. |
targetTimestamp | uint128 | The timestamp of the price in the given priceUpdateData . If zero, then we accept all recent prices. |
middlewareDecimals | uint256 | The number of decimals to format the price to. |
targetLimit | uint128 | The most recent timestamp a price can have. Can be zero if targetTimestamp is zero. |
Returns
Name | Type | Description |
---|---|---|
price_ | FormattedPythPrice | The Pyth price formatted with middlewareDecimals . |
_formatPythPrice
Formats a Pyth price object to normalize to the specified number of decimals.
function _formatPythPrice(PythStructs.Price memory pythPrice, uint256 middlewareDecimals)
internal
pure
returns (FormattedPythPrice memory price_);
Parameters
Name | Type | Description |
---|---|---|
pythPrice | PythStructs.Price | A Pyth price object. |
middlewareDecimals | uint256 | The number of decimals to format the price to. |
Returns
Name | Type | Description |
---|---|---|
price_ | FormattedPythPrice | The Pyth price formatted with middlewareDecimals . |
_getPythUpdateFee
Gets the fee required to update the price feed.
function _getPythUpdateFee(bytes calldata priceUpdateData) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
priceUpdateData | bytes | The data required to update the price feed. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | updateFee_ The fee required to update the price feed. |
_getLatestStoredPythPrice
Gets the latest seen (cached) price from the Pyth contract.
function _getLatestStoredPythPrice(uint256 middlewareDecimals)
internal
view
returns (FormattedPythPrice memory price_);
Parameters
Name | Type | Description |
---|---|---|
middlewareDecimals | uint256 | The number of decimals for the returned price. |
Returns
Name | Type | Description |
---|---|---|
price_ | FormattedPythPrice | The formatted cached Pyth price, or all-zero values if there was no valid Pyth price on-chain. |