Skip to content

Commit 2c599bd

Browse files
authored
feat(target_chains/ethereum): remove getPrice from IPyth (#1811)
* feat: remove getPrice from IPyth and mentions of it * fix: address feedback
1 parent 627d499 commit 2c599bd

File tree

16 files changed

+41
-153
lines changed

16 files changed

+41
-153
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/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

0 commit comments

Comments
 (0)