Skip to content

Commit f31ef9e

Browse files
authored
docs: update solana readme, add rust sdk readme (#1387)
* docs: update solana readme, add sdk readme * Clarify * Created -> posted * Cleanup * Readmes * More comments * Typo
1 parent 93598f8 commit f31ef9e

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

target_chains/solana/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
This folder contains:
44

5-
- A Pyth receiver program to receive Pyth price updates on Solana in `programs/pyth-solana-receiver`
6-
- A Cli that acts as a simple client to interact with the Pyth receiver program in `cli/`
5+
- A Pyth Receiver program to receive Pyth price updates on Solana in [`programs/pyth-solana-receiver`](/target_chains/solana/programs/pyth-solana-receiver)
6+
- A Rust SDK to be used in Solana programs to consume Pyth price updates posted by the Pyth Receiver in [`pyth_solana_receiver_sdk`](/target_chains/solana/pyth_solana_receiver_sdk)
7+
- A JS SDK to be used in client side Javascript code to interact with the Pyth Receiver program in [`sdk/js/pyth_solana_receiver`](/target_chains/solana/sdk/js/pyth_solana_receiver/)
78

89
# Overview of the design
910

@@ -22,9 +23,9 @@ This contract offers two ways to post a Pyth price update onto Solana:
2223
`post_update` is also a more efficient way to post updates if you're looking to post data for many different price feeds at a single point in time.
2324
This is because it persists a verified encoded VAA, so guardian signatures will only get checked once. Then that single posted VAA can be used to prove the price update for all price feeds for that given point in time.
2425

25-
# Devnet deployment
26+
# Program addresses
2627

27-
The program is currently deployed on Devnet and Eclipse Testnet with addresses:
28+
The program is currently deployed on Solana (Mainnet, Devnet) and Eclipse Testnet with addresses:
2829

2930
- `HDwcJBJXjL9FpJ7UBsYBtaDjsBUhuLCUYoz3zr8SWWaQ` for the Wormhole receiver
3031
- `rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ` for the Pyth receiver
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Pyth Solana Receiver Rust SDK
2+
3+
This is a Rust SDK to build Solana programs that consume Pyth price updates posted by the Pyth Solana Receiver.
4+
5+
It is available on [crates.io](https://crates.io/crates/pyth-solana-receiver-sdk).
6+
7+
## Pull model
8+
9+
The Pyth Solana Receiver allows users to consume Pyth price updates on a pull basis. This means that the user is responsible for submitting the price data on-chain whenever they want to interact with an app that requires a price update.
10+
11+
Price updates get posted into price update accounts, owned by the Receiver contract. Once an update has been posted to a price update account, it can be used by anyone by simply passing the price update account as one of the accounts in a Solana instruction.
12+
Price update accounts can be closed by whoever wrote them to recover the rent.
13+
14+
## Warning
15+
16+
When using price update accounts, you should check that the accounts are owned by the Pyth Solana Receiver contract to avoid impersonation attacks. This SDK checks this if you use Anchor's `Account` struct (ex: `Account<'info, PriceUpdateV2>`).
17+
18+
You should also check the `verification_level` of the account. Read more about this [here](/target_chains/solana/pyth_solana_receiver_sdk/src/price_update.rs) in the documentation for `VerificationLevel`.
19+
20+
## Example use
21+
22+
A Solana program can consume price update accounts created by the Pyth Solana Receiver using this SDK:
23+
24+
```rust
25+
use anchor_lang::prelude::*;
26+
use pyth_solana_receiver_sdk::price_update::{get_feed_id_from_hex, PriceUpdateV2};
27+
28+
declare_id!("2e5gZD3suxgJgkCg4pkoogxDKszy1SAwokz8mNeZUj4M");
29+
30+
pub const MAXIMUM_AGE: u64 = 60; // One minute
31+
pub const FEED_ID: &str = "0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d"; // SOL/USD price feed id from https://pyth.network/developers/price-feed-ids
32+
33+
#[program]
34+
pub mod my_first_pyth_app {
35+
use super::*;
36+
37+
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
38+
let price_update = &mut ctx.accounts.price_update;
39+
let price = price_update.get_price_no_older_than(
40+
&Clock::get()?,
41+
MAXIMUM_AGE,
42+
&get_feed_id_from_hex(FEED_ID)?,
43+
)?;
44+
/// Do something with the price
45+
Ok(())
46+
}
47+
}
48+
49+
#[derive(Accounts)]
50+
pub struct Initialize<'info> {
51+
#[account(mut)]
52+
pub payer: Signer<'info>,
53+
pub price_update: Account<'info, PriceUpdateV2>,
54+
// Add more accounts here
55+
}
56+
57+
58+
```

target_chains/solana/sdk/js/pyth_solana_receiver/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This is a Javascript SDK to interact with the Pyth Solana Receiver contract whose code lives [here](/target_chains/solana).
44

5+
It is available on [npm](https://www.npmjs.com/package/@pythnetwork/pyth-solana-receiver).
6+
57
## Pull model
68

79
The Pyth Solana Receiver allows users to consume Pyth price updates on a pull basis. This means that the user is responsible for submitting the price data on-chain whenever they want to interact with an app that requires a price update.

0 commit comments

Comments
 (0)