@@ -22,10 +22,10 @@ pub trait PythAccount: Pod {
2222 const ACCOUNT_TYPE : u32 ;
2323 /// `INITIAL_SIZE` is the value that the field `size_` will take when the account is first
2424 /// initialized this one is slightly tricky because for mapping (resp. price) `size_` won't
25- /// include the unpopulated entries of `prod_` (resp. `comp_`). At the beginning there are 0
26- /// products (resp. 0 components) therefore `INITIAL_SIZE` will be equal to the offset of
27- /// `prod_` (resp. `comp_`) Similarly the product account `INITIAL_SIZE` won't include any
28- /// key values.
25+ /// include the unpopulated entries of `prod_` (resp. `comp_`). At the beginning there
26+ /// are 0 products (resp. 0 components) therefore `INITIAL_SIZE` will be equal to the offset
27+ /// of `prod_` (resp. `comp_`) Similarly the product account `INITIAL_SIZE` won't
28+ /// include any key values.
2929 const INITIAL_SIZE : u32 ;
3030 /// `minimum_size()` is the minimum size that the solana account holding the struct needs to
3131 /// have. `INITIAL_SIZE` <= `minimum_size()`
@@ -34,94 +34,128 @@ pub trait PythAccount: Pod {
3434 }
3535}
3636
37- impl PythAccount for pc_map_table_t {
37+ impl PythAccount for MappingAccount {
3838 const ACCOUNT_TYPE : u32 = PC_ACCTYPE_MAPPING ;
3939 const INITIAL_SIZE : u32 = PC_MAP_TABLE_T_PROD_OFFSET as u32 ;
4040}
4141
42- impl PythAccount for pc_prod_t {
42+ impl PythAccount for ProductAccount {
4343 const ACCOUNT_TYPE : u32 = PC_ACCTYPE_PRODUCT ;
44- const INITIAL_SIZE : u32 = size_of :: < pc_prod_t > ( ) as u32 ;
44+ const INITIAL_SIZE : u32 = size_of :: < ProductAccount > ( ) as u32 ;
4545 fn minimum_size ( ) -> usize {
4646 PC_PROD_ACC_SIZE as usize
4747 }
4848}
4949
50- impl PythAccount for pc_price_t {
50+ impl PythAccount for PriceAccount {
5151 const ACCOUNT_TYPE : u32 = PC_ACCTYPE_PRICE ;
5252 const INITIAL_SIZE : u32 = PC_PRICE_T_COMP_OFFSET as u32 ;
5353}
5454
55- #[ cfg( target_endian = "little" ) ]
56- unsafe impl Zeroable for pc_acc {
57- }
58-
59- #[ cfg( target_endian = "little" ) ]
60- unsafe impl Pod for pc_acc {
61- }
62-
63- #[ cfg( target_endian = "little" ) ]
64- unsafe impl Zeroable for pc_map_table {
65- }
66-
67- #[ cfg( target_endian = "little" ) ]
68- unsafe impl Pod for pc_map_table {
69- }
70-
71- #[ cfg( target_endian = "little" ) ]
72- unsafe impl Zeroable for pc_prod {
73- }
74-
75- #[ cfg( target_endian = "little" ) ]
76- unsafe impl Pod for pc_prod {
77- }
78-
79- #[ cfg( target_endian = "little" ) ]
80- unsafe impl Zeroable for pc_price {
81- }
82-
83- #[ cfg( target_endian = "little" ) ]
84- unsafe impl Pod for pc_price {
85- }
86-
87- #[ cfg( target_endian = "little" ) ]
88- unsafe impl Zeroable for pc_price_info {
89- }
90-
91- #[ cfg( target_endian = "little" ) ]
92- unsafe impl Pod for pc_price_info {
93- }
94-
95- #[ cfg( target_endian = "little" ) ]
96- unsafe impl Zeroable for pc_ema {
97- }
98-
99- #[ cfg( target_endian = "little" ) ]
100- unsafe impl Pod for pc_ema {
101- }
102-
103-
104- #[ cfg( target_endian = "little" ) ]
105- unsafe impl Zeroable for pc_pub_key_t {
106- }
107-
108- #[ cfg( target_endian = "little" ) ]
109- unsafe impl Pod for pc_pub_key_t {
110- }
111-
112-
113- #[ cfg( target_endian = "little" ) ]
114- unsafe impl Zeroable for pc_price_comp_t {
115- }
116-
117- #[ cfg( target_endian = "little" ) ]
118- unsafe impl Pod for pc_price_comp_t {
119- }
120-
121- impl pc_pub_key_t {
122- pub fn new_unique ( ) -> pc_pub_key_t {
55+ #[ repr( C ) ]
56+ #[ derive( Copy , Clone , Pod , Zeroable ) ]
57+ pub struct PriceAccount {
58+ pub header : AccountHeader ,
59+ pub price_type : u32 , // Type of the price account
60+ pub exponent : i32 , // Exponent for the published prices
61+ pub num_ : u32 , // Current number of authorized publishers
62+ pub num_qt_ : u32 , // Number of valid quotes for the last aggregation
63+ pub last_slot_ : u64 , // Last slot with a succesful aggregation (status : TRADING)
64+ pub valid_slot_ : u64 , // Second to last slot where aggregation was attempted
65+ pub twap_ : PriceEma , // Ema for price
66+ pub twac_ : PriceEma , // Ema for confidence
67+ pub timestamp_ : i64 , // Last time aggregation was attempted
68+ pub min_pub_ : u8 , // Minimum valid publisher quotes for a succesful aggregation
69+ pub unused_1_ : i8 ,
70+ pub unused_2_ : i16 ,
71+ pub unused_3_ : i32 ,
72+ pub product_account : CPubkey , // Corresponding mapping account
73+ pub next_price_account : CPubkey , // Next price account in the list
74+ pub prev_slot_ : u64 , /* Second to last slot where aggregation was succesful
75+ * (status : TRADING) */
76+ pub prev_price_ : i64 , // Aggregate price at prev_slot_
77+ pub prev_conf_ : u64 , // Confidence interval at prev_slot_
78+ pub prev_timestamp_ : i64 , // Timestamp of prev_slot_
79+ pub agg_ : PriceInfo , // Last attempted aggregate results
80+ pub comp_ : [ PriceComponent ; 32usize ] , // Publisher's price components
81+ }
82+
83+ #[ repr( C ) ]
84+ #[ derive( Copy , Clone , Pod , Zeroable ) ]
85+ pub struct PriceComponent {
86+ pub pub_ : CPubkey ,
87+ pub agg_ : PriceInfo ,
88+ pub latest_ : PriceInfo ,
89+ }
90+
91+ #[ repr( C ) ]
92+ #[ derive( Debug , Copy , Clone , Pod , Zeroable ) ]
93+ pub struct PriceInfo {
94+ pub price_ : i64 ,
95+ pub conf_ : u64 ,
96+ pub status_ : u32 ,
97+ pub corp_act_status_ : u32 ,
98+ pub pub_slot_ : u64 ,
99+ }
100+
101+ #[ repr( C ) ]
102+ #[ derive( Debug , Copy , Clone , Pod , Zeroable ) ]
103+ pub struct PriceEma {
104+ pub val_ : i64 ,
105+ pub numer_ : i64 ,
106+ pub denom_ : i64 ,
107+ }
108+
109+ #[ repr( C ) ]
110+ #[ derive( Copy , Clone , Zeroable , Pod ) ]
111+ pub struct AccountHeader {
112+ pub magic_number : u32 ,
113+ pub version : u32 ,
114+ pub account_type : u32 ,
115+ pub size : u32 ,
116+ }
117+
118+ #[ repr( C ) ]
119+ #[ derive( Copy , Clone , Pod , Zeroable ) ]
120+ pub struct ProductAccount {
121+ pub header : AccountHeader ,
122+ pub first_price_account : CPubkey ,
123+ }
124+
125+ #[ repr( C ) ]
126+ #[ derive( Copy , Clone ) ]
127+ pub struct MappingAccount {
128+ pub header : AccountHeader ,
129+ pub number_of_products : u32 ,
130+ pub unused_ : u32 ,
131+ pub next_mapping_account : CPubkey ,
132+ pub product_list : [ CPubkey ; 640usize ] ,
133+ }
134+
135+ // Unsafe impl because CPubkey is a union
136+ unsafe impl Pod for CPubkey {
137+ }
138+ unsafe impl Zeroable for CPubkey {
139+ }
140+
141+
142+ // Unsafe impl because product_list is of size 640 and there's no derived trait for this size
143+ unsafe impl Pod for MappingAccount {
144+ }
145+ unsafe impl Zeroable for MappingAccount {
146+ }
147+
148+ #[ repr( C ) ]
149+ #[ derive( Copy , Clone ) ]
150+ pub union CPubkey {
151+ pub k1_ : [ u8 ; 32usize ] ,
152+ pub k8_ : [ u64 ; 4usize ] ,
153+ }
154+
155+ impl CPubkey {
156+ pub fn new_unique ( ) -> CPubkey {
123157 let solana_unique = Pubkey :: new_unique ( ) ;
124- pc_pub_key_t {
158+ CPubkey {
125159 k1_ : solana_unique. to_bytes ( ) ,
126160 }
127161 }
0 commit comments