@@ -210,76 +210,74 @@ pub fn upd_price(
210
210
!flags. contains ( PriceAccountFlags :: MESSAGE_BUFFER_CLEARED )
211
211
} else {
212
212
// V1
213
- true
213
+ price_data . message_sent_ == 0
214
214
} ;
215
215
216
216
if need_message_buffer_update {
217
217
if let Some ( accumulator_accounts) = maybe_accumulator_accounts {
218
- if price_data. message_sent_ == 0 {
219
- // Check that the oracle PDA is correctly configured for the program we are calling.
220
- let oracle_auth_seeds: & [ & [ u8 ] ] = & [
221
- UPD_PRICE_WRITE_SEED . as_bytes ( ) ,
222
- & accumulator_accounts. program_id . key . to_bytes ( ) ,
223
- ] ;
224
- let ( expected_oracle_auth_pda, bump) =
225
- Pubkey :: find_program_address ( oracle_auth_seeds, program_id) ;
226
- pyth_assert (
227
- expected_oracle_auth_pda == * accumulator_accounts. oracle_auth_pda . key ,
228
- OracleError :: InvalidPda . into ( ) ,
229
- ) ?;
230
-
231
- let account_metas = vec ! [
232
- AccountMeta {
233
- pubkey: * accumulator_accounts. whitelist. key,
234
- is_signer: false ,
235
- is_writable: false ,
236
- } ,
237
- AccountMeta {
238
- pubkey: * accumulator_accounts. oracle_auth_pda. key,
239
- is_signer: true ,
240
- is_writable: false ,
241
- } ,
242
- AccountMeta {
243
- pubkey: * accumulator_accounts. message_buffer_data. key,
244
- is_signer: false ,
245
- is_writable: true ,
246
- } ,
247
- ] ;
248
-
249
- let message = if flags. contains ( PriceAccountFlags :: ACCUMULATOR_V2 ) {
250
- vec ! [ ]
251
- } else {
252
- vec ! [
253
- price_data
254
- . as_price_feed_message( price_account. key)
255
- . to_bytes( ) ,
256
- price_data. as_twap_message( price_account. key) . to_bytes( ) ,
257
- ]
258
- } ;
259
-
260
- // Append a TWAP message if available
261
-
262
- // anchor discriminator for "global:put_all"
263
- let discriminator: [ u8 ; 8 ] = [ 212 , 225 , 193 , 91 , 151 , 238 , 20 , 93 ] ;
264
- let create_inputs_ix = Instruction :: new_with_borsh (
265
- * accumulator_accounts. program_id . key ,
266
- & ( discriminator, price_account. key . to_bytes ( ) , message) ,
267
- account_metas,
268
- ) ;
269
-
270
- let auth_seeds_with_bump: & [ & [ u8 ] ] = & [
271
- UPD_PRICE_WRITE_SEED . as_bytes ( ) ,
272
- & accumulator_accounts. program_id . key . to_bytes ( ) ,
273
- & [ bump] ,
274
- ] ;
275
-
276
- invoke_signed ( & create_inputs_ix, accounts, & [ auth_seeds_with_bump] ) ?;
277
- price_data. message_sent_ = 1 ;
278
- if flags. contains ( PriceAccountFlags :: ACCUMULATOR_V2 ) {
218
+ // Check that the oracle PDA is correctly configured for the program we are calling.
219
+ let oracle_auth_seeds: & [ & [ u8 ] ] = & [
220
+ UPD_PRICE_WRITE_SEED . as_bytes ( ) ,
221
+ & accumulator_accounts. program_id . key . to_bytes ( ) ,
222
+ ] ;
223
+ let ( expected_oracle_auth_pda, bump) =
224
+ Pubkey :: find_program_address ( oracle_auth_seeds, program_id) ;
225
+ pyth_assert (
226
+ expected_oracle_auth_pda == * accumulator_accounts. oracle_auth_pda . key ,
227
+ OracleError :: InvalidPda . into ( ) ,
228
+ ) ?;
229
+
230
+ let account_metas = vec ! [
231
+ AccountMeta {
232
+ pubkey: * accumulator_accounts. whitelist. key,
233
+ is_signer: false ,
234
+ is_writable: false ,
235
+ } ,
236
+ AccountMeta {
237
+ pubkey: * accumulator_accounts. oracle_auth_pda. key,
238
+ is_signer: true ,
239
+ is_writable: false ,
240
+ } ,
241
+ AccountMeta {
242
+ pubkey: * accumulator_accounts. message_buffer_data. key,
243
+ is_signer: false ,
244
+ is_writable: true ,
245
+ } ,
246
+ ] ;
247
+
248
+ let message = if flags. contains ( PriceAccountFlags :: ACCUMULATOR_V2 ) {
249
+ vec ! [ ]
250
+ } else {
251
+ vec ! [
279
252
price_data
280
- . flags
281
- . insert ( PriceAccountFlags :: MESSAGE_BUFFER_CLEARED ) ;
282
- }
253
+ . as_price_feed_message( price_account. key)
254
+ . to_bytes( ) ,
255
+ price_data. as_twap_message( price_account. key) . to_bytes( ) ,
256
+ ]
257
+ } ;
258
+
259
+ // Append a TWAP message if available
260
+
261
+ // anchor discriminator for "global:put_all"
262
+ let discriminator: [ u8 ; 8 ] = [ 212 , 225 , 193 , 91 , 151 , 238 , 20 , 93 ] ;
263
+ let create_inputs_ix = Instruction :: new_with_borsh (
264
+ * accumulator_accounts. program_id . key ,
265
+ & ( discriminator, price_account. key . to_bytes ( ) , message) ,
266
+ account_metas,
267
+ ) ;
268
+
269
+ let auth_seeds_with_bump: & [ & [ u8 ] ] = & [
270
+ UPD_PRICE_WRITE_SEED . as_bytes ( ) ,
271
+ & accumulator_accounts. program_id . key . to_bytes ( ) ,
272
+ & [ bump] ,
273
+ ] ;
274
+
275
+ invoke_signed ( & create_inputs_ix, accounts, & [ auth_seeds_with_bump] ) ?;
276
+ price_data. message_sent_ = 1 ;
277
+ if flags. contains ( PriceAccountFlags :: ACCUMULATOR_V2 ) {
278
+ price_data
279
+ . flags
280
+ . insert ( PriceAccountFlags :: MESSAGE_BUFFER_CLEARED ) ;
283
281
}
284
282
}
285
283
}
0 commit comments