Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Solana SDK README #48

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 5 additions & 58 deletions pyth-sdk-solana/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ See [pyth-sdk-solana on crates.io](https://crates.io/crates/pyth-sdk-solana/) to

## Usage

Pyth Network stores its price feeds in a collection of Solana accounts of various types:
* Price accounts store the current price for a product
* Product accounts store metadata about a product, such as its symbol (e.g., "BTC/USD").
* Mapping accounts store a listing of all Pyth accounts
### Price Feeds

Pyth Network stores the data for it's price feeds in Solana accounts, called "price accounts".

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.
Applications can obtain the content of these accounts in two different ways:
* On-chain programs should pass these accounts to the instructions that require price feeds.
* Off-chain programs can access these accounts using the Solana RPC client (as in the [eth price example program](examples/eth_price.rs)).

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)).
To use the SDK, you will need to find the price feed account for the symbol you wish to consume. The [Pyth Network documentation](https://docs.pyth.network/consume-data/solana#price-feeds) explains how to do this. The public key of this account corresponds to the ID of the price feed.

### On-chain

Expand Down Expand Up @@ -65,29 +63,7 @@ let current_price: Price = price_feed.get_current_price().unwrap();
println!("price: ({} +- {}) x 10^{}", current_price.price, current_price.conf, current_price.expo);
```

## Low-Level Solana Account Structure

> :warning: The Solana account structure is an internal API that is subject to change. Prefer to use `load_price_feed_*` when possible.

This library also provides several `load_*` methods that allow users to translate the binary data in each account into an appropriate struct:

```rust
use pyth_sdk_solana::state::*;

// replace with account data, either passed to on-chain program or from RPC node
let price_account_data: Vec<u8> = ...;
let price_account: &PriceAccount = load_price_account( &price_account_data ).unwrap();

let product_account_data: Vec<u8> = ...;
let product_account: &ProductAccount = load_product_account( &product_account_data ).unwrap();

let mapping_account_data: Vec<u8> = ...;
let mapping_account: &MappingAccount = load_mapping_account( &mapping_account_data ).unwrap();
```

For more information on the different types of Pyth accounts, see the [account structure documentation](https://docs.pyth.network/how-pyth-works/account-structure).

## Off-chain Example Programs
## Off-chain Example Program

The example [eth_price](examples/eth_price.rs) program prints the product reference data and current price information for Pyth on Solana devnet.
Run the following commands to try this example program:
Expand All @@ -109,35 +85,6 @@ ema_price ....... 291343470000 x 10^-8
ema_conf ........ 98874533 x 10^-8
```

For [an example](examples/get_accounts.rs) of using Solana Account structure please run:
```
cargo run --example get_accounts
```

The output of this command is a listing of Pyth's accounts, such as:

```
product_account .. 6MEwdxe4g1NeAF9u6KDG14anJpFsVEa2cvr5H6iriFZ8
symbol.......... SRM/USD
asset_type...... Crypto
quote_currency.. USD
description..... SRM/USD
generic_symbol.. SRMUSD
base............ SRM
price_account .. 992moaMQKs32GKZ9dxi8keyM2bUmbrwBZpK4p2K6X5Vs
price ........ 7398000000
conf ......... 3200000
price_type ... price
exponent ..... -9
status ....... trading
corp_act ..... nocorpact
num_qt ....... 1
valid_slot ... 91340924
publish_slot . 91340925
ema_price .... 7426390900
ema_conf ..... 2259870
```

## Development

This library can be built for either your native platform or in BPF (used by Solana programs).
Expand Down