Skip to content

Commit d545a61

Browse files
authored
Rename Price->PriceFeed, PriceConf->Price (#24)
1 parent caf75c0 commit d545a61

File tree

10 files changed

+112
-112
lines changed

10 files changed

+112
-112
lines changed

pyth-sdk-solana/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,29 @@ For more detailed information, please see the crate documentation.
5656
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:
5757

5858
```rust
59-
use pyth_sdk_solana::{load_price_from_account_info, Price};
59+
use pyth_sdk_solana::{load_price_feed_from_account_info, PriceFeed};
6060

6161
let price_account_info: AccountInfo = ...;
62-
let price: Price = load_price( &price_account_info ).unwrap();
62+
let price: PriceFeed = load_price_feed_from_account_info( &price_account_info ).unwrap();
6363
```
6464

6565
#### Off-chain
6666
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:
6767

6868
```rust
69-
use pyth_sdk_solana::{load_price_from_account, Price};
69+
use pyth_sdk_solana::{load_price_feed_from_account, PriceFeed};
7070

7171
let price_key: Pubkey = ...;
7272
let mut price_account: Account = ...;
73-
let price: Price = load_price_from_account( &price_key, &mut price_account ).unwrap();
73+
let price: PriceFeed = load_price_feed_from_account( &price_key, &mut price_account ).unwrap();
7474
```
7575

7676
### Get the current price
7777

78-
Read the current price from a `Price`:
78+
Read the current price from a `PriceFeed`:
7979

8080
```rust
81-
let current_price: PriceConf = price.get_current_price().unwrap();
81+
let current_price: Price = price_feed.get_current_price().unwrap();
8282
println!("price: ({} +- {}) x 10^{}", current_price.price, current_price.conf, current_price.expo);
8383
```
8484

@@ -92,10 +92,10 @@ Most assets in Pyth are priced in USD.
9292
Applications can combine two USD prices to price an asset in a different quote currency:
9393

9494
```rust
95-
let btc_usd: Price = ...;
96-
let eth_usd: Price = ...;
95+
let btc_usd: PriceFeed = ...;
96+
let eth_usd: PriceFeed = ...;
9797
// -8 is the desired exponent for the result
98-
let btc_eth: PriceConf = btc_usd.get_price_in_quote(&eth_usd, -8);
98+
let btc_eth: Price = btc_usd.get_price_in_quote(&eth_usd, -8);
9999
println!("BTC/ETH price: ({} +- {}) x 10^{}", price.price, price.conf, price.expo);
100100
```
101101

@@ -104,12 +104,12 @@ println!("BTC/ETH price: ({} +- {}) x 10^{}", price.price, price.conf, price.exp
104104
Applications can also compute the value of a basket of multiple assets:
105105

106106
```rust
107-
let btc_usd: Price = ...;
108-
let eth_usd: Price = ...;
107+
let btc_usd: PriceFeed = ...;
108+
let eth_usd: PriceFeed = ...;
109109
// Quantity of each asset in fixed-point a * 10^e.
110110
// This represents 0.1 BTC and .05 ETH.
111111
// -8 is desired exponent for result
112-
let basket_price: PriceConf = Price::price_basket(&[
112+
let basket_price: Price = Price::price_basket(&[
113113
(btc_usd, 10, -2),
114114
(eth_usd, 5, -2)
115115
], -8);
@@ -121,7 +121,7 @@ This function additionally propagates any uncertainty in the price into uncertai
121121

122122
### Solana Account Structure
123123

124-
> :warning: The Solana account structure is an internal API that is subject to change. Prefer to use `load_price` when possible.
124+
> :warning: The Solana account structure is an internal API that is subject to change. Prefer to use `load_price_feed_*` when possible.
125125
126126
This library also provides several `load_*` methods that allow users to translate the binary data in each account into an appropriate struct:
127127

pyth-sdk-solana/examples/eth_price.rs

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

3-
use pyth_sdk_solana::load_price_from_account;
3+
use pyth_sdk_solana::load_price_feed_from_account;
44
use solana_client::rpc_client::RpcClient;
55
use solana_program::pubkey::Pubkey;
66
use std::str::FromStr;
@@ -20,13 +20,13 @@ fn main() {
2020
loop {
2121
// get price data from key
2222
let mut eth_price_account = clnt.get_account(&eth_price_key).unwrap();
23-
let eth_price = load_price_from_account(&eth_price_key, &mut eth_price_account).unwrap();
23+
let eth_price_feed = load_price_feed_from_account(&eth_price_key, &mut eth_price_account).unwrap();
2424

2525
println!(".....ETH/USD.....");
26-
println!("status .......... {:?}", eth_price.status);
27-
println!("num_publishers .. {}", eth_price.num_publishers);
26+
println!("status .......... {:?}", eth_price_feed.status);
27+
println!("num_publishers .. {}", eth_price_feed.num_publishers);
2828

29-
let maybe_price = eth_price.get_current_price();
29+
let maybe_price = eth_price_feed.get_current_price();
3030
match maybe_price {
3131
Some(p) => {
3232
println!("price ........... {} x 10^{}", p.price, p.expo);
@@ -39,7 +39,7 @@ fn main() {
3939
}
4040

4141

42-
let maybe_ema_price = eth_price.get_ema_price();
42+
let maybe_ema_price = eth_price_feed.get_ema_price();
4343
match maybe_ema_price {
4444
Some(ema_price) => {
4545
println!(

pyth-sdk-solana/examples/get_accounts.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ fn main() {
7070
loop {
7171
let price_data = clnt.get_account_data(&px_pkey).unwrap();
7272
let price_account = load_price_account(&price_data).unwrap();
73-
let price = price_account.to_price(&px_pkey);
73+
let price_feed = price_account.to_price_feed(&px_pkey);
7474

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

77-
let maybe_price = price.get_current_price();
77+
let maybe_price = price_feed.get_current_price();
7878
match maybe_price {
7979
Some(p) => {
8080
println!(" price ........ {} x 10^{}", p.price, p.expo);
@@ -90,8 +90,8 @@ fn main() {
9090
" price_type ... {}",
9191
get_price_type(&price_account.ptype)
9292
);
93-
println!(" exponent ..... {}", price.expo);
94-
println!(" status ....... {}", get_status(&price.status));
93+
println!(" exponent ..... {}", price_feed.expo);
94+
println!(" status ....... {}", get_status(&price_feed.status));
9595
println!(
9696
" corp_act ..... {}",
9797
get_corp_act(&price_account.agg.corp_act)
@@ -101,7 +101,7 @@ fn main() {
101101
println!(" valid_slot ... {}", price_account.valid_slot);
102102
println!(" publish_slot . {}", price_account.agg.pub_slot);
103103

104-
let maybe_ema_price = price.get_ema_price();
104+
let maybe_ema_price = price_feed.get_ema_price();
105105
match maybe_ema_price {
106106
Some(ema_price) => {
107107
println!(

pyth-sdk-solana/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ use state::load_price_account;
1919

2020
pub use pyth_sdk::{
2121
Price,
22-
PriceConf,
22+
PriceFeed,
2323
PriceStatus,
2424
ProductIdentifier,
2525
};
2626

2727
/// Maximum valid slot period before price is considered to be stale.
2828
pub const VALID_SLOT_PERIOD: u64 = 25;
2929

30-
/// Loads Pyth Price from Price Account Info.
31-
pub fn load_price_from_account_info(price_account_info: &AccountInfo) -> Result<Price, PythError> {
30+
/// Loads Pyth Feed Price from Price Account Info.
31+
pub fn load_price_feed_from_account_info(price_account_info: &AccountInfo) -> Result<PriceFeed, PythError> {
3232
let data = price_account_info.try_borrow_data().map_err(|_| PythError::InvalidAccountData)?;
3333
let price_account = load_price_account(*data)?;
3434

35-
Ok(price_account.to_price(&price_account_info.key))
35+
Ok(price_account.to_price_feed(&price_account_info.key))
3636
}
3737

38-
/// Loads Pyth Price from Account when using Solana Client.
38+
/// Loads Pyth Price Feed from Account when using Solana Client.
3939
///
4040
/// It is a helper function which constructs Account Info when reading Account in clients.
41-
pub fn load_price_from_account(price_key: &Pubkey, price_account: &mut impl Account) -> Result<Price, PythError> {
41+
pub fn load_price_feed_from_account(price_key: &Pubkey, price_account: &mut impl Account) -> Result<PriceFeed, PythError> {
4242
let price_account_info = (price_key, price_account).into_account_info();
43-
load_price_from_account_info(&price_account_info)
43+
load_price_feed_from_account_info(&price_account_info)
4444
}

pyth-sdk-solana/src/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use solana_program::pubkey::Pubkey;
1616
use std::mem::size_of;
1717

1818
pub use pyth_sdk::{
19+
PriceFeed,
1920
Price,
20-
PriceConf,
2121
PriceStatus,
2222
};
2323

@@ -334,7 +334,7 @@ unsafe impl Pod for PriceAccount {
334334
}
335335

336336
impl PriceAccount {
337-
pub fn to_price(&self, price_key: &Pubkey) -> Price {
337+
pub fn to_price_feed(&self, price_key: &Pubkey) -> PriceFeed {
338338
#[allow(unused_mut)]
339339
let mut status = self.agg.status;
340340

@@ -345,7 +345,7 @@ impl PriceAccount {
345345
status = PriceStatus::Unknown;
346346
}
347347

348-
Price {
348+
PriceFeed {
349349
id: price_key.to_bytes(),
350350
price: self.agg.price,
351351
conf: self.agg.conf,

pyth-sdk-solana/test-contract/src/instruction.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bytemuck::bytes_of;
44

55
use pyth_sdk_solana::state::PriceAccount;
66
use pyth_sdk_solana::{
7-
PriceConf,
7+
Price,
88
PriceStatus,
99
};
1010

@@ -20,23 +20,23 @@ use solana_program::instruction::Instruction;
2020
#[derive(Clone, Debug, BorshSerialize, BorshDeserialize, PartialEq)]
2121
pub enum PythClientInstruction {
2222
Divide {
23-
numerator: PriceConf,
24-
denominator: PriceConf,
23+
numerator: Price,
24+
denominator: Price,
2525
},
2626
Multiply {
27-
x: PriceConf,
28-
y: PriceConf,
27+
x: Price,
28+
y: Price,
2929
},
3030
Add {
31-
x: PriceConf,
32-
y: PriceConf,
31+
x: Price,
32+
y: Price,
3333
},
3434
ScaleToExponent {
35-
x: PriceConf,
35+
x: Price,
3636
expo: i32,
3737
},
3838
Normalize {
39-
x: PriceConf,
39+
x: Price,
4040
},
4141
/// Don't do anything for comparison
4242
///
@@ -52,7 +52,7 @@ pub enum PythClientInstruction {
5252
},
5353
}
5454

55-
pub fn divide(numerator: PriceConf, denominator: PriceConf) -> Instruction {
55+
pub fn divide(numerator: Price, denominator: Price) -> Instruction {
5656
Instruction {
5757
program_id: id(),
5858
accounts: vec![],
@@ -65,7 +65,7 @@ pub fn divide(numerator: PriceConf, denominator: PriceConf) -> Instruction {
6565
}
6666
}
6767

68-
pub fn multiply(x: PriceConf, y: PriceConf) -> Instruction {
68+
pub fn multiply(x: Price, y: Price) -> Instruction {
6969
Instruction {
7070
program_id: id(),
7171
accounts: vec![],
@@ -75,15 +75,15 @@ pub fn multiply(x: PriceConf, y: PriceConf) -> Instruction {
7575
}
7676
}
7777

78-
pub fn add(x: PriceConf, y: PriceConf) -> Instruction {
78+
pub fn add(x: Price, y: Price) -> Instruction {
7979
Instruction {
8080
program_id: id(),
8181
accounts: vec![],
8282
data: PythClientInstruction::Add { x, y }.try_to_vec().unwrap(),
8383
}
8484
}
8585

86-
pub fn scale_to_exponent(x: PriceConf, expo: i32) -> Instruction {
86+
pub fn scale_to_exponent(x: Price, expo: i32) -> Instruction {
8787
Instruction {
8888
program_id: id(),
8989
accounts: vec![],
@@ -93,7 +93,7 @@ pub fn scale_to_exponent(x: PriceConf, expo: i32) -> Instruction {
9393
}
9494
}
9595

96-
pub fn normalize(x: PriceConf) -> Instruction {
96+
pub fn normalize(x: Price) -> Instruction {
9797
Instruction {
9898
program_id: id(),
9999
accounts: vec![],

pyth-sdk-solana/test-contract/src/processor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn process_instruction(
4545
expected_price_status,
4646
} => {
4747
let price_account = load_price_account(price_account_data.as_ref())?;
48-
let price = price_account.to_price(&Pubkey::default());
48+
let price = price_account.to_price_feed(&Pubkey::default());
4949

5050
if price.status == expected_price_status {
5151
Ok(())

pyth-sdk-solana/test-contract/tests/instruction_count.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use solana_program_test::*;
22
use test_contract::instruction;
33

4-
use pyth_sdk_solana::PriceConf;
4+
use pyth_sdk_solana::Price;
55

66
mod common;
77
use common::test_instr_exec_ok;
88

9-
fn pc(price: i64, conf: u64, expo: i32) -> PriceConf {
10-
PriceConf {
9+
fn pc(price: i64, conf: u64, expo: i32) -> Price {
10+
Price {
1111
price: price,
1212
conf: conf,
1313
expo: expo,

0 commit comments

Comments
 (0)