Skip to content

Commit f42c44d

Browse files
committed
feat: remove getPrice from IPyth and mentions of it
1 parent e73fff2 commit f42c44d

File tree

17 files changed

+39
-154
lines changed

17 files changed

+39
-154
lines changed

apps/api-reference/src/apis/evm/get-price.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { readApi, solidity, ethersJS } from "./common";
22
import { ParameterType } from "../../components/EvmApi";
33

44
export const getPrice = readApi<"id">({
5-
name: "getPrice",
5+
name: "getPrice (deprecated)",
66
summary: "Get the **latest** price object for the requested price feed ID.",
77
description: `
88
This method returns the latest price object for the requested price feed ID.

apps/api-reference/src/apis/evm/get-valid-time-period.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readApi, solidity, ethersJS } from "./common";
22

33
export const getValidTimePeriod = readApi<never>({
4-
name: "getValidTimePeriod",
4+
name: "getValidTimePeriod (deprecated)",
55
summary: "Get the default valid time period of price freshness in seconds.",
66
description: `
77
This method returns the default valid time period of price freshness in **seconds**.

apps/api-reference/src/apis/evm/parse-price-feed-updates-unique.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const parsePriceFeedUpdatesUnique = writeApi<
3333
3434
Use this function if you want to use a Pyth price for a fixed time and not the most
3535
recent price; otherwise, consider using [updatePriceFeeds](update-price-feeds)
36-
followed by [getPrice](get-price) or one of its variants.
36+
followed by [getPriceNoOlderThan](get-price-no-older-than) or one of its variants.
3737
3838
Unlike [updatePriceFeeds](updatePriceFeeds), calling this function will **not** update the on-chain price.
3939

apps/api-reference/src/components/Home/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const Home = () => (
2121
<li className="contents">
2222
<ProductLink
2323
icon={PriceFeeds}
24-
href="/price-feeds/evm/getPrice"
24+
href="/price-feeds/evm/getPriceNoOlderThan"
2525
name="Price Feeds"
2626
>
2727
Fetch real-time low-latency market data, on 50+ chains or off

express_relay/examples/easy_lend/contracts/EasyLend.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ contract EasyLend is IExpressRelayFeeReceiver {
8585
*/
8686
function _getPrice(bytes32 id) internal view returns (uint256) {
8787
IPyth oracle = IPyth(payable(_oracle));
88-
return convertToUint(oracle.getPrice(id), 18);
88+
return convertToUint(oracle.getPriceNoOlderThan(id, 60), 18);
8989
}
9090

9191
function getAllowUndercollateralized() public view returns (bool) {

pnpm-lock.yaml

Lines changed: 8 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

target_chains/ethereum/contracts/contracts/pyth/Pyth.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ abstract contract Pyth is
387387
return (latestPriceInfoPublishTime(id) != 0);
388388
}
389389

390-
function getValidTimePeriod() public view override returns (uint) {
390+
function getValidTimePeriod() public view returns (uint) {
391391
return validTimePeriodSeconds();
392392
}
393393

target_chains/ethereum/contracts/forge-test/GasBenchmark.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,18 +389,18 @@ contract GasBenchmark is Test, WormholeTestUtils, PythTestUtils {
389389

390390
function testBenchmarkGetPrice() public {
391391
// Set the block timestamp to 0. As prices have < 10 timestamp and staleness
392-
// is set to 60 seconds, the getPrice should work as expected.
392+
// below is set to 60 seconds, the getPriceNoOlderThan should work as expected.
393393
vm.warp(0);
394394

395-
pyth.getPrice(priceIds[0]);
395+
pyth.getPriceNoOlderThan(priceIds[0], 60);
396396
}
397397

398398
function testBenchmarkGetEmaPrice() public {
399399
// Set the block timestamp to 0. As prices have < 10 timestamp and staleness
400-
// is set to 60 seconds, the getPrice should work as expected.
400+
// below is set to 60 seconds, the getEmaPriceNoOlderThan should work as expected.
401401
vm.warp(0);
402402

403-
pyth.getEmaPrice(priceIds[0]);
403+
pyth.getEmaPriceNoOlderThan(priceIds[0], 60);
404404
}
405405

406406
function testBenchmarkGetUpdateFee1() public view {

target_chains/ethereum/contracts/forge-test/Pyth.Aave.t.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ contract PythAaveTest is PythWormholeMerkleAccumulatorTest {
138138
uint256 aavePrice = assetPrice / BASE_CURRENCY_UNIT;
139139

140140
bytes32 priceId = priceIds[i];
141-
PythStructs.Price memory price = pyth.getPrice(priceId);
141+
PythStructs.Price memory price = pyth.getPriceNoOlderThan(
142+
priceId,
143+
60
144+
);
142145
int64 pythRawPrice = price.price;
143146
uint pythNormalizer;
144147
uint pythPrice;

target_chains/ethereum/contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@openzeppelin/contracts": "=4.8.1",
3535
"@openzeppelin/contracts-upgradeable": "=4.8.1",
3636
"@openzeppelin/hardhat-upgrades": "^1.22.1",
37-
"@pythnetwork/pyth-sdk-solidity": "^3.0.0",
37+
"@pythnetwork/pyth-sdk-solidity": "workspace:*",
3838
"@pythnetwork/entropy-sdk-solidity": "workspace:*",
3939
"@pythnetwork/contract-manager": "workspace:*",
4040
"dotenv": "^10.0.0",

target_chains/ethereum/sdk/js/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ contract SomeContract {
8484
8585
// Doing other things that uses prices
8686
bytes32 priceId = 0xf9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b;
87-
PythStructs.Price price = pyth.getPrice(priceId);
87+
// Get the price if it is not older than 10 seconds from the current time.
88+
PythStructs.Price price = pyth.getPriceNoOlderThan(priceId, 10);
8889
}
8990
}
9091

target_chains/ethereum/sdk/js/src/examples/EvmRelay.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ async function run() {
102102
receipt = await web3.eth.getTransactionReceipt(txHash);
103103
}
104104

105-
// For on-chain use, you will typically perform the getPrice call within the same transaction as updatePriceFeeds.
106-
// The call to getPrice below simply demonstrates that the on-chain price was in fact updated.
105+
// For on-chain use, you will typically perform the getPriceNoOlderThan call within the same transaction as updatePriceFeeds.
106+
// The call to getPriceNoOlderThan below simply demonstrates that the on-chain price was in fact updated.
107107
// Note that the code above for waiting for tx confirmation is a little flaky -- if so, you may see an old price printed here.
108108
for (const priceId of priceIds) {
109109
const [price, conf, expo, publishTime] = await pythContract.methods
110-
.getPrice(priceId)
110+
.getPriceNoOlderThan(priceId, 60) // 60 seconds staleness tolerance
111111
.call();
112112
console.log(
113113
`Updated ${priceId} to (${price} +- ${conf}) * 10^${expo} at unix timestamp ${publishTime}`

target_chains/ethereum/sdk/solidity/AbstractPyth.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,17 @@ abstract contract AbstractPyth is IPyth {
2323
public
2424
view
2525
virtual
26-
override
2726
returns (uint validTimePeriod);
2827

2928
function getPrice(
3029
bytes32 id
31-
) external view virtual override returns (PythStructs.Price memory price) {
30+
) external view virtual returns (PythStructs.Price memory price) {
3231
return getPriceNoOlderThan(id, getValidTimePeriod());
3332
}
3433

3534
function getEmaPrice(
3635
bytes32 id
37-
) external view virtual override returns (PythStructs.Price memory price) {
36+
) external view virtual returns (PythStructs.Price memory price) {
3837
return getEmaPriceNoOlderThan(id, getValidTimePeriod());
3938
}
4039

target_chains/ethereum/sdk/solidity/IPyth.sol

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,13 @@ import "./IPythEvents.sol";
88
/// @dev Please refer to the guidance at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for how to consume prices safely.
99
/// @author Pyth Data Association
1010
interface IPyth is IPythEvents {
11-
/// @notice Returns the period (in seconds) that a price feed is considered valid since its publish time
12-
function getValidTimePeriod() external view returns (uint validTimePeriod);
13-
14-
/// @notice Returns the price and confidence interval.
15-
/// @dev Reverts if the price has not been updated within the last `getValidTimePeriod()` seconds.
16-
/// @param id The Pyth Price Feed ID of which to fetch the price and confidence interval.
17-
/// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
18-
function getPrice(
19-
bytes32 id
20-
) external view returns (PythStructs.Price memory price);
21-
22-
/// @notice Returns the exponentially-weighted moving average price and confidence interval.
23-
/// @dev Reverts if the EMA price is not available.
24-
/// @param id The Pyth Price Feed ID of which to fetch the EMA price and confidence interval.
25-
/// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
26-
function getEmaPrice(
27-
bytes32 id
28-
) external view returns (PythStructs.Price memory price);
29-
3011
/// @notice Returns the price of a price feed without any sanity checks.
3112
/// @dev This function returns the most recent price update in this contract without any recency checks.
3213
/// This function is unsafe as the returned price update may be arbitrarily far in the past.
3314
///
3415
/// Users of this function should check the `publishTime` in the price to ensure that the returned price is
3516
/// sufficiently recent for their application. If you are considering using this function, it may be
36-
/// safer / easier to use either `getPrice` or `getPriceNoOlderThan`.
17+
/// safer / easier to use `getPriceNoOlderThan`.
3718
/// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
3819
function getPriceUnsafe(
3920
bytes32 id

target_chains/ethereum/sdk/solidity/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ Then add the following line to your `remappings.txt` file:
3333

3434
## Example Usage
3535

36-
To consume prices you should use the [`IPyth`](IPyth.sol) interface. Please make sure to read the documentation of this interface in order to use the prices safely.
36+
To consume prices you should use the [`IPyth`](IPyth.sol) interface. Please make sure to read the documentation of this
37+
interface in order to use the prices safely.
3738

38-
For example, to read the latest price, call [`getPrice`](IPyth.sol) with the Price ID of the price feed you're interested in. The price feeds available on each chain are listed [below](#target-chains).
39+
For example, to read the latest price, call [`getPriceNoOlderThan`](IPyth.sol) with the Price ID of the price feed
40+
you're interested in. The price feeds available on each chain are listed [below](#target-chains).
3941

4042
```solidity
4143
// SPDX-License-Identifier: MIT
@@ -61,10 +63,9 @@ contract ExampleContract {
6163
pyth.updatePriceFeeds{ value: fee }(priceUpdateData);
6264
6365
bytes32 priceID = 0xf9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b;
64-
// Read the current value of priceID, aborting the transaction if the price has not been updated recently.
65-
// Every chain has a default recency threshold which can be retrieved by calling the getValidTimePeriod() function on the contract.
66-
// Please see IPyth.sol for variants of this function that support configurable recency thresholds and other useful features.
67-
return pyth.getPrice(priceID);
66+
// Read the current value of priceID, aborting the transaction if the price has not been updated in the last 10
67+
// seconds.
68+
return pyth.getPriceNoOlderThan(priceID, 10);
6869
}
6970
}
7071

0 commit comments

Comments
 (0)