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
This repo contains multiple crates for using Pyth Oracle.
4
-
1. Pyth SDK: This crate contains general Pyth structures and interfaces which are consistent across different blockchains.
5
-
2. Pyth SDK Solana: This crate contains methods for reading and parsing Pyth structures from Pyth Solana accounts.
3
+
The Pyth Network Rust SDK provides utilities for reading price feeds from the [pyth.network](https://pyth.network/) oracle in on- and off-chain applications.
4
+
5
+
Key features of this SDK include:
6
+
7
+
* Get the current price of over [50 products](https://pyth.network/markets/), including cryptocurrencies,
8
+
US equities, forex and more.
9
+
* Combine listed products to create new price feeds, e.g., for baskets of tokens or non-USD quote currencies.
10
+
* Consume prices in Solana programs, Terra smart contracts, or off-chain applications.
11
+
12
+
Please see the [pyth.network documentation](https://docs.pyth.network/) for more information about pyth.network.
13
+
14
+
## Usage
15
+
16
+
This repository is divided into several crates focused on specific use cases:
17
+
18
+
1.[Pyth SDK](pyth-sdk) provides common data types and interfaces for that are shared across different blockchains.
19
+
2.[Pyth SDK Solana](pyth-sdk-solana) provides an interface for reading Pyth price feeds in Solana programs.
20
+
This crate may also be used in off-chain applications that read prices from the Solana blockchain.
21
+
3.[Pyth SDK Terra](pyth-sdk-terra) provides an interface for reading Pyth price feeds in on-chain Terra contracts.
22
+
23
+
Please see the documentation for the relevant crate to get started using Pyth Network.
6
24
7
25
## Development
8
26
9
-
These crates can be built for either your native platform or other platforms for specific blockchains.
10
-
-Use `cargo build` / `cargo test` to build and test natively.
27
+
All crates in this repository can be built for either your native platform or blockchain-specific platforms.
28
+
Use `cargo build` / `cargo test` to build and test natively.
11
29
12
-
### Releases
30
+
### Creating a Release
13
31
14
-
To release new versions of these packages, perform the following steps within the crate being released:
32
+
To release a new version of any of these crates, perform the following steps within the crate being released:
15
33
16
34
1. Increment the version number in `Cargo.toml`.
17
35
You may use a version number with a `-beta.x` suffix such as `0.0.1-beta.0` to create opt-in test versions.
18
36
2. Merge your change into `main` on github.
19
37
3. Create and publish a new github release.
38
+
We currently don't have a Github Action to automatically push releases to [crates.io](https://crates.io), but should set one up.
Copy file name to clipboardExpand all lines: pyth-sdk-solana/README.md
+26-79Lines changed: 26 additions & 79 deletions
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,7 @@
1
-
# Pyth SDK Solana
1
+
# Pyth Network Solana SDK
2
2
3
3
This crate provides utilities for reading price feeds from the [pyth.network](https://pyth.network/) oracle on the Solana network.
4
-
The crate includes a library for reading and using Pyth data feeds in Solana both on-chain (Solana programs) and off-chain (clients interacting with Solana blockchain). It also includes multiple off-chain example programs.
5
-
6
-
Key features of this library include:
7
-
8
-
* Get the current price of over [50 products](https://pyth.network/markets/), including cryptocurrencies,
9
-
US equities, forex and more.
10
-
* Combine listed products to create new price feeds, e.g., for baskets of tokens or non-USD quote currencies.
11
-
* Consume prices in on-chain Solana programs or off-chain applications.
12
-
13
-
Please see the [pyth.network documentation](https://docs.pyth.network/) for more information about pyth.network.
4
+
It also includes several [off-chain example programs](examples/).
14
5
15
6
## Installation
16
7
@@ -30,96 +21,51 @@ Pyth Network stores its price feeds in a collection of Solana accounts of variou
30
21
* Product accounts store metadata about a product, such as its symbol (e.g., "BTC/USD").
31
22
* Mapping accounts store a listing of all Pyth accounts
32
23
33
-
> :warning: This structure is designed for Pyth Oracle internal program. In most of the use cases only Price account is needed.
34
-
35
-
For more information on the different types of Pyth accounts, see the [account structure documentation](https://docs.pyth.network/how-pyth-works/account-structure).
36
-
The pyth.network website also lists the public keys of the accounts (e.g., [Crypto.BTC/USD accounts](https://pyth.network/markets/#Crypto.BTC/USD)).
37
-
38
-
This crate provides utilities for interpreting and manipulating the content of these accounts.
24
+
Most users of this SDK only need to access the content of price accounts; the other two account types are implementation details of the oracle.
39
25
Applications can obtain the content of these accounts in two different ways:
40
26
* On-chain programs should pass these accounts to the instructions that require price feeds.
41
27
* Off-chain programs can access these accounts using the Solana RPC client (as in the [eth price example program](examples/eth_price.rs)).
42
28
43
-
In both cases, the content of the account will be provided to the application as a binary blob (`Vec<u8>`).
44
-
The examples below assume that the user has already obtained this account data.
45
-
46
-
### Parse price data
47
-
Each price feed (e.g: `Crypto.BTC/USD`) is stored in a Solana price account.
48
-
You can find price accounts in the pyth.network website (e.g.: [Crypto.BTC/USD accounts](https://pyth.network/markets/#Crypto.BTC/USD)).
49
-
50
-
The `Price` struct contains several useful functions for working with the price.
51
-
Some of these functions are described below.
52
-
For more detailed information, please see the crate documentation.
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)).
53
30
54
-
####On-chain
31
+
### On-chain
55
32
56
-
To read the price from a price account on-chain, this library provides a `load_price_from_account_info` method that constructs `Price` struct from AccountInfo:
33
+
On-chain applications should pass the relevant Pyth Network price account to the Solana instruction that consumes it.
34
+
This price account will be represented as an `AccountInfo` in the code for the Solana instruction.
35
+
The `load_price_feed_from_account_info` function will construct a `PriceFeed` struct from `AccountInfo`:
println!("price: ({} +- {}) x 10^{}", current_price.price, current_price.conf, current_price.expo);
63
44
```
64
45
65
-
#### Off-chain
66
-
To read the price from a price account off-chain in clients, this library provides a `load_price_from_account` method that constructs `Price` struct from Account:
46
+
The `PriceFeed` object returned by `load_price_feed_from_account_info` contains all currently-available pricing information about the product.
47
+
This struct also has some useful functions for manipulating and combining prices; see the [common SDK documentation](../pyth-sdk) for more details.
48
+
49
+
Note that your application should also validate the address of the passed-in price account before using it.
50
+
Otherwise, an attacker could pass in a different account and set the price to an arbitrary value.
51
+
52
+
### Off-chain
53
+
54
+
Off-chain applications can read the current value of a Pyth Network price account using the Solana RPC client.
55
+
This client will return the content of the account as an `Account` struct.
56
+
The `load_price_feed_from_account` function will construct a `PriceFeed` struct from `Account`:
For more information on the different types of Pyth accounts, see the [account structure documentation](https://docs.pyth.network/how-pyth-works/account-structure).
142
89
143
-
###Off-chain example program
90
+
## Off-chain Example Programs
144
91
145
92
The example [eth_price](examples/eth_price.rs) program prints the product reference data and current price information for Pyth on Solana devnet.
146
93
Run the following commands to try this example program:
This function additionally propagates any uncertainty in the price into uncertainty in the value of the basket.
32
+
`query_price_feed` makes a query to the Pyth Network Terra contract
33
+
This query requires a price feed id that indicates the product whose price should be returned.
34
+
Each product listed on Pyth Network (e.g., BTC/USD) has its own price feed id; see the [Contracts and Price Feeds](#contracts-and-price-feeds) section below for the possible products and their price feed ids.
35
+
The result of the query is a `PriceFeed` struct which contains the current price of the product along with additional metadata.
36
+
This struct also has some useful functions for manipulating and combining prices; see the [common SDK documentation](../pyth-sdk) for more details.
75
37
76
-
## Client-side Usage
38
+
## Off-Chain Queries
77
39
78
-
You can use the provided schemas in the `schema` directory to query the terra contract client side.
79
-
80
-
The query should look like:
40
+
You can use the provided schemas in the `schema` directory to directly query the terra contract from off-chain applications.
41
+
A typical query will look like:
81
42
82
43
```
83
44
{
@@ -91,7 +52,7 @@ By going to the contract address in [Terra Finder](https://finder.terra.money/)
91
52
92
53
## Contracts and Price Feeds
93
54
94
-
Currently Pyth is only available in testnet network.
55
+
Pyth is currently only available in Terra testnet.
95
56
96
57
### Testnet
97
58
@@ -107,5 +68,7 @@ List of available Price Feeds and their ids:
0 commit comments