You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: pyth-sdk-solana/README.md
+15-5
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Applications can obtain the content of these accounts in two different ways:
26
26
* On-chain programs should pass these accounts to the instructions that require price feeds.
27
27
* Off-chain programs can access these accounts using the Solana RPC client (as in the [eth price example program](examples/eth_price.rs)).
28
28
29
-
The pyth.network website can be used to identify the public keys of the various Pyth Network accounts (e.g., [Crypto.BTC/USD accounts](https://pyth.network/markets/#Crypto.BTC/USD)).
29
+
The [pyth.network](https://pyth.network/developers/price-feed-ids#solana-mainnet-beta) website can be used to identify the public keys of each price feed's price account (e.g.Crypto.BTC/USD).
30
30
31
31
### On-chain
32
32
@@ -37,15 +37,19 @@ The `load_price_feed_from_account_info` function will construct a `PriceFeed` st
msg!("price: ({} +- {}) x 10^{}", current_price.price, current_price.conf, current_price.expo);
44
46
```
45
47
46
48
The `PriceFeed` object returned by `load_price_feed_from_account_info` contains all currently-available pricing information about the product.
47
49
This struct also has some useful functions for manipulating and combining prices; see the [common SDK documentation](../pyth-sdk) for more details.
48
50
51
+
The function `get_price_no_older_than` takes in an `age` in seconds. If the current on-chain aggregate is older than `current_timestamp - age`, `get_price_no_older_than` will return `None`.
52
+
49
53
Note that your application should also validate the address of the passed-in price account before using it.
50
54
Otherwise, an attacker could pass in a different account and set the price to an arbitrary value.
51
55
@@ -58,10 +62,16 @@ The `load_price_feed_from_account` function will construct a `PriceFeed` struct
Copy file name to clipboardexpand all lines: pyth-sdk/README.md
+7-3
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# Pyth Network Common Rust SDK
2
2
3
3
This crate contains Pyth Network data structures that are shared across all Rust-based consumers of Pyth Network data.
4
-
This crate is typically used in combination with a platform-specific crate such as [pyth-sdk-solana](../pyth-sdk-solana) or [pyth-sdk-cw](../pyth-sdk-cw).
4
+
This crate is typically used in combination with a platform-specific crate such as [pyth-sdk-solana](../pyth-sdk-solana).
5
5
6
6
## Usage
7
7
@@ -19,7 +19,9 @@ Once you have a `PriceFeed`, you can call one of the methods below to get the pr
19
19
Get the current price of the product from its `PriceFeed`:
20
20
21
21
```rust
22
-
letcurrent_price:Price=price_feed.get_current_price().ok_or(StdError::not_found("Current price is not available"))?;
22
+
constSTALENESS_THRESHOLD:u64=60; // staleness threshold in seconds
23
+
letcurrent_timestamp=...;
24
+
letcurrent_price:Price=price_feed.get_price_no_older_than(current_timestamp, STALENESS_THRESHOLD).ok_or(StdError::not_found("Current price is not available"))?;
23
25
println!("price: ({} +- {}) x 10^{}", current_price.price, current_price.conf, current_price.expo);
24
26
```
25
27
@@ -35,7 +37,9 @@ Please see the [consumer best practices guide](https://docs.pyth.network/consume
35
37
The EMA price can be retrieved as follows:
36
38
37
39
```rust
38
-
letema_price:Price=price_feed.get_ema_price().ok_or(StdError::not_found("EMA price is not available"))?;
40
+
constSTALENESS_THRESHOLD:u64=60; // staleness threshold in seconds
41
+
letcurrent_timestamp=...;
42
+
letema_price:Price=price_feed.get_ema_price_no_older_than(current_timestamp, STALENESS_THRESHOLD).ok_or(StdError::not_found("EMA price is not available"))?;
39
43
println!("price: ({} +- {}) x 10^{}", ema_price.price, ema_price.conf, ema_price.expo);
0 commit comments