Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit 0607b61

Browse files
upgrade to version2 structure
1 parent 980c485 commit 0607b61

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

examples/get_accounts.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ use pyth_client::{
77
Product,
88
Price,
99
PriceType,
10+
DeriveType,
1011
PriceStatus,
1112
CorpAction,
1213
cast,
1314
MAGIC,
14-
VERSION_1,
15+
VERSION_2,
1516
PROD_HDR_SIZE
1617
};
1718
use solana_client::{
@@ -41,8 +42,6 @@ fn get_price_type( ptype: &PriceType ) -> &'static str
4142
match ptype {
4243
PriceType::Unknown => "unknown",
4344
PriceType::Price => "price",
44-
PriceType::TWAP => "twap",
45-
PriceType::Volatility => "volatility",
4645
}
4746
}
4847

@@ -66,7 +65,7 @@ fn get_corp_act( cact: &CorpAction ) -> &'static str
6665
fn main() {
6766
// get pyth mapping account
6867
let url = "http://api.devnet.solana.com";
69-
let key = "ArppEFcsybCLE8CRtQJLQ9tLv2peGmQoKWFuiUWm4KBP";
68+
let key = "BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2";
7069
let clnt = RpcClient::new( url.to_string() );
7170
let mut akey = Pubkey::from_str( key ).unwrap();
7271

@@ -77,7 +76,7 @@ fn main() {
7776
assert_eq!( map_acct.magic, MAGIC, "not a valid pyth account" );
7877
assert_eq!( map_acct.atype, AccountType::Mapping as u32,
7978
"not a valid pyth mapping account" );
80-
assert_eq!( map_acct.ver, VERSION_1,
79+
assert_eq!( map_acct.ver, VERSION_2,
8180
"unexpected pyth mapping account version" );
8281

8382
// iget and print each Product in Mapping directory
@@ -89,7 +88,7 @@ fn main() {
8988
assert_eq!( prod_acct.magic, MAGIC, "not a valid pyth account" );
9089
assert_eq!( prod_acct.atype, AccountType::Product as u32,
9190
"not a valid pyth product account" );
92-
assert_eq!( prod_acct.ver, VERSION_1,
91+
assert_eq!( prod_acct.ver, VERSION_2,
9392
"unexpected pyth product account version" );
9493

9594
// print key and reference data for this Product
@@ -112,7 +111,7 @@ fn main() {
112111
assert_eq!( pa.magic, MAGIC, "not a valid pyth account" );
113112
assert_eq!( pa.atype, AccountType::Price as u32,
114113
"not a valid pyth price account" );
115-
assert_eq!( pa.ver, VERSION_1,
114+
assert_eq!( pa.ver, VERSION_2,
116115
"unexpected pyth price account version" );
117116
println!( " price_account .. {:?}", px_pkey );
118117
println!( " price_type ... {}", get_price_type(&pa.ptype));
@@ -123,6 +122,10 @@ fn main() {
123122
println!( " conf ......... {}", pa.agg.conf );
124123
println!( " valid_slot ... {}", pa.valid_slot );
125124
println!( " publish_slot . {}", pa.agg.pub_slot );
125+
println!( " twap ......... {}",
126+
pa.drv[(DeriveType::TWAP as usize)-1] );
127+
println!( " volatility ... {}",
128+
pa.drv[(DeriveType::Volatility as usize)-1] );
126129

127130
// go to next price account in list
128131
if pa.next.is_valid() {
@@ -146,3 +149,4 @@ fn main() {
146149
akey = Pubkey::new( &map_acct.next.val );
147150
}
148151
}
152+

src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub const MAGIC : u32 = 0xa1b2c3d4;
2-
pub const VERSION_1 : u32 = 1;
3-
pub const VERSION : u32 = VERSION_1;
2+
pub const VERSION_2 : u32 = 2;
3+
pub const VERSION : u32 = VERSION_2;
44
pub const MAP_TABLE_SIZE : usize = 640;
55
pub const PROD_ACCT_SIZE : usize = 512;
66
pub const PROD_HDR_SIZE : usize = 48;
@@ -39,7 +39,14 @@ pub enum CorpAction
3939
pub enum PriceType
4040
{
4141
Unknown,
42-
Price,
42+
Price
43+
}
44+
45+
// different types of calculations derived from aggregate price
46+
#[repr(C)]
47+
pub enum DeriveType
48+
{
49+
Unknown,
4350
TWAP,
4451
Volatility
4552
}
@@ -111,11 +118,12 @@ pub struct Price
111118
pub unused : u32,
112119
pub curr_slot : u64, // currently accumulating price slot
113120
pub valid_slot : u64, // valid slot-time of agg. price
121+
pub drv : [i64;8], // calculated values derived from agg. price
114122
pub prod : AccKey, // product account key
115123
pub next : AccKey, // next Price account in linked list
116124
pub agg_pub : AccKey, // quoter who computed last aggregate price
117125
pub agg : PriceInfo, // aggregate price info
118-
pub comp : [PriceComp;16] // price components one per quoter
126+
pub comp : [PriceComp;32] // price components one per quoter
119127
}
120128

121129
struct AccKeyU64

0 commit comments

Comments
 (0)