diff --git a/pages/price-feeds/api-reference/evm.mdx b/pages/price-feeds/api-reference/evm.mdx index 0e5fd2d2..97feeab9 100644 --- a/pages/price-feeds/api-reference/evm.mdx +++ b/pages/price-feeds/api-reference/evm.mdx @@ -11,5 +11,5 @@ Users of the Pyth contract will typically need to perform two operations: for verification. This operation makes the price available for on-chain use. You will typically call [updatePriceFeeds](evm/update-price-feeds) to do this. - Read the on-chain price -- After updating the price, your on-chain contract can call one of the - many getter functions on the contract to get the price. See [getPrice](evm/get-price) and its variants + many getter functions on the contract to get the price. See [getPriceNoOlderThan](evm/get-price-no-older-than) and its variants for more information. diff --git a/pages/price-feeds/api-reference/evm/_meta.json b/pages/price-feeds/api-reference/evm/_meta.json index f86e20f0..35aaba09 100644 --- a/pages/price-feeds/api-reference/evm/_meta.json +++ b/pages/price-feeds/api-reference/evm/_meta.json @@ -10,14 +10,14 @@ "type": "separator" }, - "get-price": "getPrice", + "get-price": "getPrice (deprecated)", "get-price-unsafe": "getPriceUnsafe", "get-price-no-older-than": "getPriceNoOlderThan", "get-ema-price": "getEmaPrice", "get-ema-price-unsafe": "getEmaPriceUnsafe", "get-ema-price-no-older-than": "getEmaPriceNoOlderThan", "get-update-fee": "getUpdateFee", - "get-valid-time-period": "getValidTimePeriod", + "get-valid-time-period": "getValidTimePeriod (deprecated)", "parse-price-feed-updates": "parsePriceFeedUpdates", "parse-price-feed-updates-unique": "parsePriceFeedUpdatesUnique", "update-price-feeds": "updatePriceFeeds", diff --git a/pages/price-feeds/api-reference/evm/get-price.mdx b/pages/price-feeds/api-reference/evm/get-price.mdx index cc2e1796..4b1a9dc0 100644 --- a/pages/price-feeds/api-reference/evm/get-price.mdx +++ b/pages/price-feeds/api-reference/evm/get-price.mdx @@ -7,7 +7,9 @@ import DynamicCode from "../../../../components/DynamicCode"; import EvmCall from "../../../../components/EvmCall"; import { Tab, Tabs } from "nextra-theme-docs"; -# Get Price +# Get Price (Deprecated) + +**This function is deprecated, please consider using `getPriceNoOlderThan` or `getPriceUnsafe` instead.** Get the latest price and confidence interval for the requested price feed id. The price feed id is a 32-byte id written as a hexadecimal string; see the [price feed ids](https://pyth.network/developers/price-feed-ids) page to look up the id for a given symbol. diff --git a/pages/price-feeds/api-reference/evm/get-valid-time-period.mdx b/pages/price-feeds/api-reference/evm/get-valid-time-period.mdx index 1e573a4e..2dc06f20 100644 --- a/pages/price-feeds/api-reference/evm/get-valid-time-period.mdx +++ b/pages/price-feeds/api-reference/evm/get-valid-time-period.mdx @@ -2,7 +2,9 @@ import DynamicCode from "../../../../components/DynamicCode"; import EvmCall from "../../../../components/EvmCall"; import { Tab, Tabs } from "nextra-theme-docs"; -# Get Valid Time Period +# Get Valid Time Period (deprecated) + +**This function is deprecated. Please consider using `getPriceNoOlderThan` with your own acceptable staleness time period.** Get the default valid time period in seconds. This quantity is the maximum age of price updates returned by functions like [getPrice](get-price) and [getEmaPrice](get-ema-price); diff --git a/pages/price-feeds/api-reference/evm/parse-price-feed-updates.mdx b/pages/price-feeds/api-reference/evm/parse-price-feed-updates.mdx index 30e2483b..2fc87195 100644 --- a/pages/price-feeds/api-reference/evm/parse-price-feed-updates.mdx +++ b/pages/price-feeds/api-reference/evm/parse-price-feed-updates.mdx @@ -11,7 +11,7 @@ import { Tab, Tabs } from "nextra-theme-docs"; Parse `updateData` and return the price feeds for the given `priceIds` within, if they are all published between `minPublishTime` and `maxPublishTime` (`minPublishTime <= publishTime <= maxPublishTime`). Use this function if you want to use a Pyth price for a fixed time and not the most recent price; -otherwise, consider using [updatePriceFeeds](update-price-feeds) followed by [getPrice](get-price) or one of its variants. +otherwise, consider using [updatePriceFeeds](update-price-feeds) followed by [getPriceNoOlderThan](get-price-no-older-than) or one of its variants. Unlike `updatePriceFeeds`, calling this function will not update the on-chain price. If you need to make sure the price update is the earliest update after the `minPublishTime` consider using [parsePriceFeedUpdatesUnique](parse-price-feed-updates-unique). diff --git a/pages/price-feeds/create-your-first-pyth-app/evm/part-1.mdx b/pages/price-feeds/create-your-first-pyth-app/evm/part-1.mdx index 52d4c321..c3e3df96 100644 --- a/pages/price-feeds/create-your-first-pyth-app/evm/part-1.mdx +++ b/pages/price-feeds/create-your-first-pyth-app/evm/part-1.mdx @@ -121,7 +121,10 @@ contract MyFirstPythContract { // ... other functions omitted function mint() public payable { - PythStructs.Price memory price = pyth.getPrice(ethUsdPriceId); + PythStructs.Price memory price = pyth.getPriceNoOlderThan( + ethUsdPriceId, + 60 + ); uint ethPrice18Decimals = (uint(uint64(price.price)) * (10 ** 18)) / (10 ** uint8(uint32(-1 * price.expo))); @@ -144,7 +147,7 @@ contract MyFirstPythContract { ``` -This function first reads a `Price` from the pyth contract. +This function first reads a `Price` from the pyth contract if it is updated within the last 60 seconds. It then performs some arithmetic on the price in order to calculate how much the caller needs to pay. This conversion assumes that 10^18 wei is equal to the native token (ETH in this example); in some networks (like Hedera) the decimal places are different and you need to change the math. @@ -292,8 +295,8 @@ Now run `forge test -vvv` ``` Oh no, the test fails with a `StalePrice` error! -When our contract calls `getPrice`, it checks the timestamp on the blockchain and compares it to the timestamp for the Pyth price. -If the Pyth price's timestamp is too far in the past, then a `StalePrice` error occurs. +When our contract calls `getPriceNoOlderThan(.., 60)`, it checks the timestamp on the blockchain and compares it to the timestamp for the Pyth price. +If the Pyth price's timestamp is more than 60 seconds in the past, then a `StalePrice` error occurs. `skip` moves the timestamp on the blockchain forward, which triggers the error. We can fix this problem, but first, let's fix the test case. @@ -413,7 +416,10 @@ contract MyFirstPythContract { } function mint() public payable { - PythStructs.Price memory price = pyth.getPrice(ethUsdPriceId); + PythStructs.Price memory price = pyth.getPriceNoOlderThan( + ethUsdPriceId, + 60 + ); console2.log("price of ETH in USD"); console2.log(price.price); diff --git a/pages/price-feeds/use-real-time-data/evm.mdx b/pages/price-feeds/use-real-time-data/evm.mdx index 5c75516e..8668d43c 100644 --- a/pages/price-feeds/use-real-time-data/evm.mdx +++ b/pages/price-feeds/use-real-time-data/evm.mdx @@ -68,15 +68,15 @@ contract SomeContract { function exampleMethod(bytes[] calldata priceUpdate) public payable { // Submit a priceUpdate to the Pyth contract to update the on-chain price. // Updating the price requires paying the fee returned by getUpdateFee. - // WARNING: These lines are required to ensure the getPrice call below succeeds. If you remove them, transactions may fail with "0x19abf40e" error. + // WARNING: These lines are required to ensure the getPriceNoOlderThan call below succeeds. If you remove them, transactions may fail with "0x19abf40e" error. uint fee = pyth.getUpdateFee(priceUpdate); pyth.updatePriceFeeds{ value: fee }(priceUpdate); - // Read the current price from a price feed. + // Read the current price from a price feed if it is less than 60 seconds old. // Each price feed (e.g., ETH/USD) is identified by a price feed ID. // The complete list of feed IDs is available at https://pyth.network/developers/price-feed-ids bytes32 priceFeedId = 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace; // ETH/USD - PythStructs.Price memory price = pyth.getPrice(priceFeedId); + PythStructs.Price memory price = pyth.getPriceNoOlderThan(priceFeedId, 60); } } @@ -85,10 +85,11 @@ contract SomeContract { The code snippet above does the following things: 1. Instantiate the `IPyth` interface from the Solidity SDK using the price feeds [contract address](../contract-addresses/evm). -1. Select the [Price Feed IDs](https://pyth.network/developers/price-feed-ids) for the assets you want to fetch prices for. Price feeds come in two varieties, Stable and Beta. You should select Stable feed ids -1. Call `IPyth.getUpdateFee` to calculate the fee charged by Pyth to update the price. -1. Call `IPyth.updatePriceFeeds` to update the price, paying the fee calculated in the previous step. -1. Call `IPyth.getPrice` to read the current price, providing the [price feed ID](https://pyth.network/developers/price-feed-ids) that you wish to read. +2. Select the [Price Feed IDs](https://pyth.network/developers/price-feed-ids) for the assets you want to fetch prices for. Price feeds come in two varieties, Stable and Beta. You should select Stable feed ids +3. Call `IPyth.getUpdateFee` to calculate the fee charged by Pyth to update the price. +4. Call `IPyth.updatePriceFeeds` to update the price, paying the fee calculated in the previous step. +5. Call `IPyth.getPriceNoOlderThan` to read the current price, providing the [price feed ID](https://pyth.network/developers/price-feed-ids) that you wish to read and your acceptable staleness threshold for + the price. ## Additional Resources