6
6
PriceFeedMessage ,
7
7
PriceInfo ,
8
8
PythAccount ,
9
+ TwapMessage ,
9
10
UPD_PRICE_WRITE_SEED ,
10
11
} ,
11
12
deserialize:: {
@@ -152,10 +153,8 @@ pub fn upd_price(
152
153
}
153
154
154
155
// Try to update the aggregate
155
- #[ allow( unused_variables) ]
156
156
let mut aggregate_updated = false ;
157
157
if clock. slot > latest_aggregate_price. pub_slot_ {
158
- #[ allow( unused_assignments) ]
159
158
unsafe {
160
159
aggregate_updated = c_upd_aggregate (
161
160
price_account. try_borrow_mut_data ( ) ?. as_mut_ptr ( ) ,
@@ -165,82 +164,86 @@ pub fn upd_price(
165
164
}
166
165
}
167
166
168
- {
169
- let account_len = price_account. try_data_len ( ) ?;
170
- if aggregate_updated && account_len >= PriceAccountV2 :: MINIMUM_SIZE {
171
- let mut price_data =
172
- load_checked :: < PriceAccountV2 > ( price_account, cmd_args. header . version ) ?;
167
+
168
+ let account_len = price_account. try_data_len ( ) ?;
169
+ if account_len >= PriceAccountV2 :: MINIMUM_SIZE {
170
+ let mut price_data =
171
+ load_checked :: < PriceAccountV2 > ( price_account, cmd_args. header . version ) ?;
172
+
173
+ if aggregate_updated {
173
174
price_data. update_price_cumulative ( ) ?;
175
+ // We want to send a message every time the aggregate price updates. However, during the migration,
176
+ // not every publisher will necessarily provide the accumulator accounts. The message_sent_ flag
177
+ // ensures that after every aggregate update, the next publisher who provides the accumulator accounts
178
+ // will send the message.
179
+ price_data. message_sent_ = 0 ;
174
180
}
175
- }
176
181
177
- let mut price_data = load_checked :: < PriceAccount > ( price_account, cmd_args. header . version ) ?;
178
- // We want to send a message every time the aggregate price updates. However, during the migration,
179
- // not every publisher will necessarily provide the accumulator accounts. The message_sent_ flag
180
- // ensures that after every aggregate update, the next publisher who provides the accumulator accounts
181
- // will send the message.
182
- if aggregate_updated {
183
- price_data. message_sent_ = 0 ;
184
- }
185
182
186
- if let Some ( accumulator_accounts) = maybe_accumulator_accounts {
187
- if price_data. message_sent_ == 0 {
188
- // Check that the oracle PDA is correctly configured for the program we are calling.
189
- let oracle_auth_seeds: & [ & [ u8 ] ] = & [
190
- UPD_PRICE_WRITE_SEED . as_bytes ( ) ,
191
- & accumulator_accounts. program_id . key . to_bytes ( ) ,
192
- ] ;
193
- let ( expected_oracle_auth_pda, bump) =
194
- Pubkey :: find_program_address ( oracle_auth_seeds, program_id) ;
195
- pyth_assert (
196
- expected_oracle_auth_pda == * accumulator_accounts. oracle_auth_pda . key ,
197
- OracleError :: InvalidPda . into ( ) ,
198
- ) ?;
183
+ if let Some ( accumulator_accounts) = maybe_accumulator_accounts {
184
+ if price_data. message_sent_ == 0 {
185
+ // Check that the oracle PDA is correctly configured for the program we are calling.
186
+ let oracle_auth_seeds: & [ & [ u8 ] ] = & [
187
+ UPD_PRICE_WRITE_SEED . as_bytes ( ) ,
188
+ & accumulator_accounts. program_id . key . to_bytes ( ) ,
189
+ ] ;
190
+ let ( expected_oracle_auth_pda, bump) =
191
+ Pubkey :: find_program_address ( oracle_auth_seeds, program_id) ;
192
+ pyth_assert (
193
+ expected_oracle_auth_pda == * accumulator_accounts. oracle_auth_pda . key ,
194
+ OracleError :: InvalidPda . into ( ) ,
195
+ ) ?;
199
196
200
- let account_metas = vec ! [
201
- AccountMeta {
202
- pubkey: * accumulator_accounts. whitelist. key,
203
- is_signer: false ,
204
- is_writable: false ,
205
- } ,
206
- AccountMeta {
207
- pubkey: * accumulator_accounts. oracle_auth_pda. key,
208
- is_signer: true ,
209
- is_writable: false ,
210
- } ,
211
- AccountMeta {
212
- pubkey: * accumulator_accounts. message_buffer_data. key,
213
- is_signer: false ,
214
- is_writable: true ,
215
- } ,
216
- ] ;
197
+ let account_metas = vec ! [
198
+ AccountMeta {
199
+ pubkey: * accumulator_accounts. whitelist. key,
200
+ is_signer: false ,
201
+ is_writable: false ,
202
+ } ,
203
+ AccountMeta {
204
+ pubkey: * accumulator_accounts. oracle_auth_pda. key,
205
+ is_signer: true ,
206
+ is_writable: false ,
207
+ } ,
208
+ AccountMeta {
209
+ pubkey: * accumulator_accounts. message_buffer_data. key,
210
+ is_signer: false ,
211
+ is_writable: true ,
212
+ } ,
213
+ ] ;
217
214
218
- let message =
219
- vec ! [
215
+ let message = vec ! [
220
216
PriceFeedMessage :: from_price_account( price_account. key, & price_data)
221
217
. as_bytes( )
222
218
. to_vec( ) ,
219
+ TwapMessage :: from_price_account( price_account. key, & price_data)
220
+ . as_bytes( )
221
+ . to_vec( ) ,
223
222
] ;
224
223
225
- // anchor discriminator for "global:put_all"
226
- let discriminator = [ 212 , 225 , 193 , 91 , 151 , 238 , 20 , 93 ] ;
227
- let create_inputs_ix = Instruction :: new_with_borsh (
228
- * accumulator_accounts. program_id . key ,
229
- & ( discriminator, price_account. key . to_bytes ( ) , message) ,
230
- account_metas,
231
- ) ;
224
+ // anchor discriminator for "global:put_all"
225
+ let discriminator = [ 212 , 225 , 193 , 91 , 151 , 238 , 20 , 93 ] ;
226
+ let create_inputs_ix = Instruction :: new_with_borsh (
227
+ * accumulator_accounts. program_id . key ,
228
+ & ( discriminator, price_account. key . to_bytes ( ) , message) ,
229
+ account_metas,
230
+ ) ;
232
231
233
- let auth_seeds_with_bump: & [ & [ u8 ] ] = & [
234
- UPD_PRICE_WRITE_SEED . as_bytes ( ) ,
235
- & accumulator_accounts. program_id . key . to_bytes ( ) ,
236
- & [ bump] ,
237
- ] ;
232
+ let auth_seeds_with_bump: & [ & [ u8 ] ] = & [
233
+ UPD_PRICE_WRITE_SEED . as_bytes ( ) ,
234
+ & accumulator_accounts. program_id . key . to_bytes ( ) ,
235
+ & [ bump] ,
236
+ ] ;
238
237
239
- invoke_signed ( & create_inputs_ix, accounts, & [ auth_seeds_with_bump] ) ?;
240
- price_data. message_sent_ = 1 ;
238
+ invoke_signed ( & create_inputs_ix, accounts, & [ auth_seeds_with_bump] ) ?;
239
+ price_data. message_sent_ = 1 ;
240
+ }
241
241
}
242
242
}
243
243
244
+
245
+ let mut price_data = load_checked :: < PriceAccount > ( price_account, cmd_args. header . version ) ?;
246
+
244
247
// Try to update the publisher's price
245
248
if is_component_update ( cmd_args) ? {
246
249
let status: u32 =
0 commit comments