From f66a02f60e92f2ce1d8c7b7b42f2480a408b4b96 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 22 Mar 2024 19:30:51 +0000 Subject: [PATCH 1/7] docs: update solana readme, add sdk readme --- target_chains/solana/README.md | 10 ++-- .../solana/pyth_solana_receiver_sdk/README.md | 51 +++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 target_chains/solana/pyth_solana_receiver_sdk/README.md diff --git a/target_chains/solana/README.md b/target_chains/solana/README.md index 8ef2164ca6..b7cf2bda17 100644 --- a/target_chains/solana/README.md +++ b/target_chains/solana/README.md @@ -2,8 +2,10 @@ This folder contains: -- A Pyth receiver program to receive Pyth price updates on Solana in `programs/pyth-solana-receiver` -- A Cli that acts as a simple client to interact with the Pyth receiver program in `cli/` +- A Pyth Receiver program to receive Pyth price updates on Solana in `programs/pyth-solana-receiver` +- A Rust Cli that acts as a simple client to interact with the Pyth receiver program in `cli/` +- A Rust SDK to be used to consume Pyth price updates created by the Pyth Receiver in `pyth_solana_receiver_sdk` +- A JS SDK to be used in client side Javascript code to interact with the Pyth Receiver program in `sdk/js/pyth_solana_receiver` # Overview of the design @@ -22,9 +24,9 @@ This contract offers two ways to post a Pyth price update onto Solana: `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. 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. -# Devnet deployment +# Program addresses -The program is currently deployed on Devnet and Eclipse Testnet with addresses: +The program is currently deployed on Solana (Mainnet, Devnet) and Eclipse Testnet with addresses: - `HDwcJBJXjL9FpJ7UBsYBtaDjsBUhuLCUYoz3zr8SWWaQ` for the Wormhole receiver - `rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ` for the Pyth receiver diff --git a/target_chains/solana/pyth_solana_receiver_sdk/README.md b/target_chains/solana/pyth_solana_receiver_sdk/README.md new file mode 100644 index 0000000000..45548227cc --- /dev/null +++ b/target_chains/solana/pyth_solana_receiver_sdk/README.md @@ -0,0 +1,51 @@ +# Pyth Solana Receiver Rust SDK + +This is a Rust SDK to build Solana programs that consume Pyth price posted by the Pyth Solana Receiver. + +## Pull model + +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. + +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. +Price update accounts can be closed by whoever wrote them to recover the rent. + +## Example use + +A Solana program can consume price update accounts created by the Pyth Solana Receiver using this SDK: + +```rust +use anchor_lang::prelude::*; +use anchor_lang::solana_program::{native_token::LAMPORTS_PER_SOL, system_instruction}; +use pyth_solana_receiver_sdk::price_update::{get_feed_id_from_hex, PriceUpdateV2}; + +declare_id!("2e5gZD3suxgJgkCg4pkoogxDKszy1SAwokz8mNeZUj4M"); + +pub const MAXIMUM_AGE: u64 = 60; // One minute +pub const FEED_ID: &str = "0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d"; + +#[program] +pub mod my_first_pyth_app { + use super::*; + + pub fn initialize(ctx: Context) -> Result<()> { + let price_update = &mut ctx.accounts.price_update; + let price = price_update.get_price_no_older_than( + &Clock::get()?, + MAXIMUM_AGE, + &get_feed_id_from_hex(FEED_ID)?, + )?; + /// Do something with the price + Ok(()) + } +} + +#[derive(Accounts)] +pub struct Initialize<'info> { + #[account(mut)] + pub payer: Signer<'info>, + pub price_update: Account<'info, PriceUpdateV2>, + // Add more accounts here +} + + +``` From 6d0de79d5b230650d1a6d9f082f460d10cfbea73 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 22 Mar 2024 19:32:05 +0000 Subject: [PATCH 2/7] Clarify --- target_chains/solana/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target_chains/solana/README.md b/target_chains/solana/README.md index b7cf2bda17..ca2ee2029f 100644 --- a/target_chains/solana/README.md +++ b/target_chains/solana/README.md @@ -4,7 +4,7 @@ This folder contains: - A Pyth Receiver program to receive Pyth price updates on Solana in `programs/pyth-solana-receiver` - A Rust Cli that acts as a simple client to interact with the Pyth receiver program in `cli/` -- A Rust SDK to be used to consume Pyth price updates created by the Pyth Receiver in `pyth_solana_receiver_sdk` +- A Rust SDK to be used in Solana programs to consume Pyth price updates created by the Pyth Receiver in `pyth_solana_receiver_sdk` - A JS SDK to be used in client side Javascript code to interact with the Pyth Receiver program in `sdk/js/pyth_solana_receiver` # Overview of the design From b49905162c8de5abb64afce1e667c8f2fbde1449 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 22 Mar 2024 19:33:40 +0000 Subject: [PATCH 3/7] Created -> posted --- target_chains/solana/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target_chains/solana/README.md b/target_chains/solana/README.md index ca2ee2029f..2b4fbab4ac 100644 --- a/target_chains/solana/README.md +++ b/target_chains/solana/README.md @@ -4,7 +4,7 @@ This folder contains: - A Pyth Receiver program to receive Pyth price updates on Solana in `programs/pyth-solana-receiver` - A Rust Cli that acts as a simple client to interact with the Pyth receiver program in `cli/` -- A Rust SDK to be used in Solana programs to consume Pyth price updates created by the Pyth Receiver in `pyth_solana_receiver_sdk` +- A Rust SDK to be used in Solana programs to consume Pyth price updates posted by the Pyth Receiver in `pyth_solana_receiver_sdk` - A JS SDK to be used in client side Javascript code to interact with the Pyth Receiver program in `sdk/js/pyth_solana_receiver` # Overview of the design From 8099c4a1ebb4e8d12ffdb52da61c2268a37bbb1c Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 22 Mar 2024 19:35:59 +0000 Subject: [PATCH 4/7] Cleanup --- target_chains/solana/pyth_solana_receiver_sdk/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/target_chains/solana/pyth_solana_receiver_sdk/README.md b/target_chains/solana/pyth_solana_receiver_sdk/README.md index 45548227cc..204fe94901 100644 --- a/target_chains/solana/pyth_solana_receiver_sdk/README.md +++ b/target_chains/solana/pyth_solana_receiver_sdk/README.md @@ -1,6 +1,6 @@ # Pyth Solana Receiver Rust SDK -This is a Rust SDK to build Solana programs that consume Pyth price posted by the Pyth Solana Receiver. +This is a Rust SDK to build Solana programs that consume Pyth price updates posted by the Pyth Solana Receiver. ## Pull model @@ -15,7 +15,6 @@ A Solana program can consume price update accounts created by the Pyth Solana Re ```rust use anchor_lang::prelude::*; -use anchor_lang::solana_program::{native_token::LAMPORTS_PER_SOL, system_instruction}; use pyth_solana_receiver_sdk::price_update::{get_feed_id_from_hex, PriceUpdateV2}; declare_id!("2e5gZD3suxgJgkCg4pkoogxDKszy1SAwokz8mNeZUj4M"); From 2c7a91af75d7f3b5a85cf5eb177f0429365b78de Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Fri, 22 Mar 2024 19:43:10 +0000 Subject: [PATCH 5/7] Readmes --- target_chains/solana/README.md | 7 +++---- target_chains/solana/pyth_solana_receiver_sdk/README.md | 2 ++ target_chains/solana/sdk/js/pyth_solana_receiver/README.md | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/target_chains/solana/README.md b/target_chains/solana/README.md index 2b4fbab4ac..acdbce1b4d 100644 --- a/target_chains/solana/README.md +++ b/target_chains/solana/README.md @@ -2,10 +2,9 @@ This folder contains: -- A Pyth Receiver program to receive Pyth price updates on Solana in `programs/pyth-solana-receiver` -- A Rust Cli that acts as a simple client to interact with the Pyth receiver program in `cli/` -- A Rust SDK to be used in Solana programs to consume Pyth price updates posted by the Pyth Receiver in `pyth_solana_receiver_sdk` -- A JS SDK to be used in client side Javascript code to interact with the Pyth Receiver program in `sdk/js/pyth_solana_receiver` +- A Pyth Receiver program to receive Pyth price updates on Solana in [`programs/pyth-solana-receiver`](/target_chains/solana/programs/pyth-solana-receiver) +- 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) +- 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/) # Overview of the design diff --git a/target_chains/solana/pyth_solana_receiver_sdk/README.md b/target_chains/solana/pyth_solana_receiver_sdk/README.md index 204fe94901..c6217b6287 100644 --- a/target_chains/solana/pyth_solana_receiver_sdk/README.md +++ b/target_chains/solana/pyth_solana_receiver_sdk/README.md @@ -2,6 +2,8 @@ This is a Rust SDK to build Solana programs that consume Pyth price updates posted by the Pyth Solana Receiver. +It is available on [crates.io](https://crates.io/crates/pyth-solana-receiver-sdk). + ## Pull model 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. diff --git a/target_chains/solana/sdk/js/pyth_solana_receiver/README.md b/target_chains/solana/sdk/js/pyth_solana_receiver/README.md index f8fd78ee9a..2bead3142b 100644 --- a/target_chains/solana/sdk/js/pyth_solana_receiver/README.md +++ b/target_chains/solana/sdk/js/pyth_solana_receiver/README.md @@ -2,6 +2,8 @@ This is a Javascript SDK to interact with the Pyth Solana Receiver contract whose code lives [here](/target_chains/solana). +It is available on [npm](https://www.npmjs.com/package/@pythnetwork/pyth-solana-receiver). + ## Pull model 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. From 2d3e4c80ba46222696bc47f955fa9667d1650fa7 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Mon, 25 Mar 2024 12:28:35 +0000 Subject: [PATCH 6/7] More comments --- target_chains/solana/pyth_solana_receiver_sdk/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/target_chains/solana/pyth_solana_receiver_sdk/README.md b/target_chains/solana/pyth_solana_receiver_sdk/README.md index c6217b6287..f0eced00ba 100644 --- a/target_chains/solana/pyth_solana_receiver_sdk/README.md +++ b/target_chains/solana/pyth_solana_receiver_sdk/README.md @@ -11,6 +11,12 @@ The Pyth Solana Receiver allows users to consume Pyth price updates on a pull ba 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. Price update accounts can be closed by whoever wrote them to recover the rent. +## Warning + +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 makes check easy if you use Anchor's `Account` struct (ex: `Account<'info, PriceUpdateV2>`). + +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`. + ## Example use A Solana program can consume price update accounts created by the Pyth Solana Receiver using this SDK: @@ -22,7 +28,7 @@ use pyth_solana_receiver_sdk::price_update::{get_feed_id_from_hex, PriceUpdateV2 declare_id!("2e5gZD3suxgJgkCg4pkoogxDKszy1SAwokz8mNeZUj4M"); pub const MAXIMUM_AGE: u64 = 60; // One minute -pub const FEED_ID: &str = "0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d"; +pub const FEED_ID: &str = "0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d"; // SOL/USD price feed id from https://pyth.network/developers/price-feed-ids #[program] pub mod my_first_pyth_app { From aea8422092e328241ef982415b194c4a7025c905 Mon Sep 17 00:00:00 2001 From: Guillermo Bescos Date: Mon, 25 Mar 2024 12:30:21 +0000 Subject: [PATCH 7/7] Typo --- target_chains/solana/pyth_solana_receiver_sdk/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target_chains/solana/pyth_solana_receiver_sdk/README.md b/target_chains/solana/pyth_solana_receiver_sdk/README.md index f0eced00ba..031f56776f 100644 --- a/target_chains/solana/pyth_solana_receiver_sdk/README.md +++ b/target_chains/solana/pyth_solana_receiver_sdk/README.md @@ -13,7 +13,7 @@ Price update accounts can be closed by whoever wrote them to recover the rent. ## Warning -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 makes check easy if you use Anchor's `Account` struct (ex: `Account<'info, PriceUpdateV2>`). +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>`). 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`.