@@ -34,94 +34,156 @@ pub trait PythAccount: Pod {
34
34
}
35
35
}
36
36
37
- impl PythAccount for pc_map_table_t {
37
+ impl PythAccount for MappingAccount {
38
38
const ACCOUNT_TYPE : u32 = PC_ACCTYPE_MAPPING ;
39
+ /// Equal to the offset of `prod_` in `MappingAccount`, see the trait comment for more detail
39
40
const INITIAL_SIZE : u32 = PC_MAP_TABLE_T_PROD_OFFSET as u32 ;
40
41
}
41
42
42
- impl PythAccount for pc_prod_t {
43
+ impl PythAccount for ProductAccount {
43
44
const ACCOUNT_TYPE : u32 = PC_ACCTYPE_PRODUCT ;
44
- const INITIAL_SIZE : u32 = size_of :: < pc_prod_t > ( ) as u32 ;
45
+ const INITIAL_SIZE : u32 = size_of :: < ProductAccount > ( ) as u32 ;
45
46
fn minimum_size ( ) -> usize {
46
47
PC_PROD_ACC_SIZE as usize
47
48
}
48
49
}
49
50
50
- impl PythAccount for pc_price_t {
51
+ impl PythAccount for PriceAccount {
51
52
const ACCOUNT_TYPE : u32 = PC_ACCTYPE_PRICE ;
53
+ /// Equal to the offset of `comp_` in `PriceAccount`, see the trait comment for more detail
52
54
const INITIAL_SIZE : u32 = PC_PRICE_T_COMP_OFFSET as u32 ;
53
55
}
54
56
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 {
57
+ #[ repr( C ) ]
58
+ #[ derive( Copy , Clone , Pod , Zeroable ) ]
59
+ pub struct PriceAccount {
60
+ pub magic_ : u32 ,
61
+ pub ver_ : u32 ,
62
+ pub type_ : u32 ,
63
+ pub size_ : u32 ,
64
+ /// Type of the price account
65
+ pub ptype_ : u32 ,
66
+ /// Exponent for the published prices
67
+ pub expo_ : i32 ,
68
+ /// Current number of authorized publishers
69
+ pub num_ : u32 ,
70
+ /// Number of valid quotes for the last aggregation
71
+ pub num_qt_ : u32 ,
72
+ /// Last slot with a succesful aggregation (status : TRADING)
73
+ pub last_slot_ : u64 ,
74
+ /// Second to last slot where aggregation was attempted
75
+ pub valid_slot_ : u64 ,
76
+ /// Ema for price
77
+ pub twap_ : PriceEma ,
78
+ /// Ema for confidence
79
+ pub twac_ : PriceEma ,
80
+ /// Last time aggregation was attempted
81
+ pub timestamp_ : i64 ,
82
+ /// Minimum valid publisher quotes for a succesful aggregation
83
+ pub min_pub_ : u8 ,
84
+ pub unused_1_ : i8 ,
85
+ pub unused_2_ : i16 ,
86
+ pub unused_3_ : i32 ,
87
+ /// Corresponding product account
88
+ pub prod_ : CPubkey ,
89
+ /// Next price account in the list
90
+ pub next_ : CPubkey ,
91
+ /// Second to last slot where aggregation was succesful (i.e. status : TRADING)
92
+ pub prev_slot_ : u64 ,
93
+ /// Aggregate price at prev_slot_
94
+ pub prev_price_ : i64 ,
95
+ /// Confidence interval at prev_slot_
96
+ pub prev_conf_ : u64 ,
97
+ /// Timestamp of prev_slot_
98
+ pub prev_timestamp_ : i64 ,
99
+ /// Last attempted aggregate results
100
+ pub agg_ : PriceInfo ,
101
+ /// Publishers' price components
102
+ pub comp_ : [ PriceComponent ; PC_COMP_SIZE as usize ] ,
103
+ }
104
+
105
+ #[ repr( C ) ]
106
+ #[ derive( Copy , Clone , Pod , Zeroable ) ]
107
+ pub struct PriceComponent {
108
+ pub pub_ : CPubkey ,
109
+ pub agg_ : PriceInfo ,
110
+ pub latest_ : PriceInfo ,
111
+ }
112
+
113
+ #[ repr( C ) ]
114
+ #[ derive( Debug , Copy , Clone , Pod , Zeroable ) ]
115
+ pub struct PriceInfo {
116
+ pub price_ : i64 ,
117
+ pub conf_ : u64 ,
118
+ pub status_ : u32 ,
119
+ pub corp_act_status_ : u32 ,
120
+ pub pub_slot_ : u64 ,
121
+ }
122
+
123
+ #[ repr( C ) ]
124
+ #[ derive( Debug , Copy , Clone , Pod , Zeroable ) ]
125
+ pub struct PriceEma {
126
+ pub val_ : i64 ,
127
+ pub numer_ : i64 ,
128
+ pub denom_ : i64 ,
129
+ }
130
+
131
+ #[ repr( C ) ]
132
+ #[ derive( Copy , Clone , Zeroable , Pod ) ]
133
+ pub struct AccountHeader {
134
+ pub magic_ : u32 ,
135
+ pub ver_ : u32 ,
136
+ pub type_ : u32 ,
137
+ pub size_ : u32 ,
138
+ }
139
+
140
+ #[ repr( C ) ]
141
+ #[ derive( Copy , Clone , Pod , Zeroable ) ]
142
+ pub struct ProductAccount {
143
+ pub magic_ : u32 ,
144
+ pub ver_ : u32 ,
145
+ pub type_ : u32 ,
146
+ pub size_ : u32 ,
147
+ pub px_acc_ : CPubkey ,
148
+ }
149
+
150
+ #[ repr( C ) ]
151
+ #[ derive( Copy , Clone ) ]
152
+ pub struct MappingAccount {
153
+ pub magic_ : u32 ,
154
+ pub ver_ : u32 ,
155
+ pub type_ : u32 ,
156
+ pub size_ : u32 ,
157
+ pub num_ : u32 ,
158
+ pub unused_ : u32 ,
159
+ pub next_ : CPubkey ,
160
+ pub prod_ : [ CPubkey ; PC_MAP_TABLE_SIZE as usize ] ,
161
+ }
162
+
163
+ // Unsafe impl because CPubkey is a union
164
+ unsafe impl Pod for CPubkey {
165
+ }
166
+ unsafe impl Zeroable for CPubkey {
167
+ }
168
+
169
+
170
+ // Unsafe impl because product_list is of size 640 and there's no derived trait for this size
171
+ unsafe impl Pod for MappingAccount {
172
+ }
173
+ unsafe impl Zeroable for MappingAccount {
174
+ }
175
+
176
+ #[ repr( C ) ]
177
+ #[ derive( Copy , Clone ) ]
178
+ pub union CPubkey {
179
+ pub k1_ : [ u8 ; 32usize ] ,
180
+ pub k8_ : [ u64 ; 4usize ] ,
181
+ }
182
+
183
+ impl CPubkey {
184
+ pub fn new_unique ( ) -> CPubkey {
123
185
let solana_unique = Pubkey :: new_unique ( ) ;
124
- pc_pub_key_t {
186
+ CPubkey {
125
187
k1_ : solana_unique. to_bytes ( ) ,
126
188
}
127
189
}
0 commit comments