Skip to content

Commit 096432f

Browse files
authored
Merge pull request #113 from pyth-network/push-nvlzuznkvoon
feat!: allow loading network-specific PriceAccount
2 parents 1acfc3d + 3a8c8e8 commit 096432f

File tree

14 files changed

+298
-45
lines changed

14 files changed

+298
-45
lines changed

.github/workflows/pyth-sdk-example-anchor-contract.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Install solana binaries
2323
run: |
2424
# Installing 1.16.x cli tools to have sbf instead of bpf. bpf does not work anymore.
25-
sh -c "$(curl -sSfL https://release.solana.com/v1.17.0/install)"
25+
sh -c "$(curl -sSfL https://release.solana.com/v1.18.1/install)"
2626
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
2727
- name: Install anchor binaries
2828
run: |

.github/workflows/pyth-sdk-example-solana-contract.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Install solana binaries
2323
run: |
2424
# Installing 1.16.x cli tools to have sbf instead of bpf. bpf does not work anymore.
25-
sh -c "$(curl -sSfL https://release.solana.com/v1.17.0/install)"
25+
sh -c "$(curl -sSfL https://release.solana.com/v1.18.1/install)"
2626
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
2727
- name: Build
2828
run: scripts/build.sh

.github/workflows/pyth-sdk-solana.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Install Solana Binaries
3636
run: |
3737
# Installing 1.17.x cli tools to have sbf instead of bpf. bpf does not work anymore.
38-
sh -c "$(curl -sSfL https://release.solana.com/v1.17.0/install)"
38+
sh -c "$(curl -sSfL https://release.solana.com/v1.18.1/install)"
3939
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
4040
- name: Build
4141
run: cargo build --verbose

examples/sol-anchor-contract/programs/sol-anchor-contract/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ default = []
1919
[dependencies]
2020
anchor-lang = "0.28.0"
2121
pyth-sdk = { path = "../../../../pyth-sdk", version = "0.8.0" }
22-
pyth-sdk-solana = { path = "../../../../pyth-sdk-solana", version = "0.9.0" }
22+
pyth-sdk-solana = { path = "../../../../pyth-sdk-solana", version = "0.10.0" }

examples/sol-anchor-contract/programs/sol-anchor-contract/src/state.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use anchor_lang::prelude::*;
22
use pyth_sdk_solana::state::load_price_account;
3+
use pyth_sdk_solana::state::SolanaPriceAccount;
34
use std::ops::Deref;
45
use std::str::FromStr;
56

@@ -25,7 +26,8 @@ impl anchor_lang::Owner for PriceFeed {
2526

2627
impl anchor_lang::AccountDeserialize for PriceFeed {
2728
fn try_deserialize_unchecked(data: &mut &[u8]) -> Result<Self> {
28-
let account = load_price_account(data).map_err(|_x| error!(ErrorCode::PythError))?;
29+
let account: &SolanaPriceAccount =
30+
load_price_account(data).map_err(|_x| error!(ErrorCode::PythError))?;
2931

3032
// Use a dummy key since the key field will be removed from the SDK
3133
let zeros: [u8; 32] = [0; 32];

examples/sol-contract/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ crate-type = ["cdylib", "lib"]
1111
borsh = "0.10.3"
1212
arrayref = "0.3.6"
1313
solana-program = ">= 1.10"
14-
pyth-sdk-solana = { path = "../../pyth-sdk-solana", version = "0.9.0" }
14+
pyth-sdk-solana = { path = "../../pyth-sdk-solana", version = "0.10.0" }

examples/sol-contract/src/processor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use borsh::{
1818
BorshDeserialize,
1919
BorshSerialize,
2020
};
21-
use pyth_sdk_solana::load_price_feed_from_account_info;
21+
use pyth_sdk_solana::state::SolanaPriceAccount;
2222

2323
use crate::instruction::ExampleInstructions;
2424
use crate::state::AdminConfig;
@@ -53,8 +53,8 @@ pub fn process_instruction(
5353
config.collateral_price_feed_id = *pyth_collateral_account.key;
5454

5555
// Make sure these Pyth price accounts can be loaded
56-
load_price_feed_from_account_info(pyth_loan_account)?;
57-
load_price_feed_from_account_info(pyth_collateral_account)?;
56+
SolanaPriceAccount::account_info_to_feed(pyth_loan_account)?;
57+
SolanaPriceAccount::account_info_to_feed(pyth_collateral_account)?;
5858

5959
let config_data = config.try_to_vec()?;
6060
let config_dst = &mut admin_config_account.try_borrow_mut_data()?;
@@ -85,7 +85,7 @@ pub fn process_instruction(
8585
// (price + conf) * loan_qty * 10 ^ (expo).
8686
// Here is more explanation on confidence interval in Pyth:
8787
// https://docs.pyth.network/consume-data/best-practices
88-
let feed1 = load_price_feed_from_account_info(pyth_loan_account)?;
88+
let feed1 = SolanaPriceAccount::account_info_to_feed(pyth_loan_account)?;
8989
let current_timestamp1 = Clock::get()?.unix_timestamp;
9090
let result1 = feed1
9191
.get_price_no_older_than(current_timestamp1, 60)
@@ -107,7 +107,7 @@ pub fn process_instruction(
107107
// (price - conf) * collateral_qty * 10 ^ (expo).
108108
// Here is more explanation on confidence interval in Pyth:
109109
// https://docs.pyth.network/consume-data/best-practices
110-
let feed2 = load_price_feed_from_account_info(pyth_collateral_account)?;
110+
let feed2 = SolanaPriceAccount::account_info_to_feed(pyth_collateral_account)?;
111111
let current_timestamp2 = Clock::get()?.unix_timestamp;
112112
let result2 = feed2
113113
.get_price_no_older_than(current_timestamp2, 60)

pyth-sdk-solana/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-sdk-solana"
3-
version = "0.9.0"
3+
version = "0.10.0"
44
authors = ["Pyth Data Foundation"]
55
edition = "2018"
66
license = "Apache-2.0"

pyth-sdk-solana/examples/eth_price.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// example usage of reading pyth price from solana/pythnet price account
22

3-
use pyth_sdk_solana::load_price_feed_from_account;
3+
use pyth_sdk_solana::state::SolanaPriceAccount;
44
use solana_client::rpc_client::RpcClient;
55
use solana_program::pubkey::Pubkey;
66
use std::str::FromStr;
@@ -25,7 +25,7 @@ fn main() {
2525
// get price data from key
2626
let mut eth_price_account = clnt.get_account(&eth_price_key).unwrap();
2727
let eth_price_feed =
28-
load_price_feed_from_account(&eth_price_key, &mut eth_price_account).unwrap();
28+
SolanaPriceAccount::account_to_feed(&eth_price_key, &mut eth_price_account).unwrap();
2929

3030
println!(".....ETH/USD.....");
3131

pyth-sdk-solana/examples/get_accounts.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use pyth_sdk_solana::state::{
99
load_product_account,
1010
CorpAction,
1111
PriceType,
12+
SolanaPriceAccount,
1213
};
1314
use solana_client::rpc_client::RpcClient;
1415
use solana_program::pubkey::Pubkey;
@@ -62,7 +63,8 @@ fn main() {
6263
let mut px_pkey = prod_acct.px_acc;
6364
loop {
6465
let price_data = clnt.get_account_data(&px_pkey).unwrap();
65-
let price_account = load_price_account(&price_data).unwrap();
66+
let price_account: &SolanaPriceAccount =
67+
load_price_account(&price_data).unwrap();
6668
let price_feed = price_account.to_price_feed(&px_pkey);
6769

6870
println!(" price_account .. {:?}", px_pkey);

0 commit comments

Comments
 (0)