17
17
} ,
18
18
} ,
19
19
} ,
20
- serde_wormhole:: RawMessage ,
21
20
solana_program:: {
22
21
keccak,
23
22
program_memory:: sol_memcpy,
@@ -29,23 +28,22 @@ use {
29
28
Config ,
30
29
DataSource ,
31
30
} ,
32
- price_update:: PriceUpdateV1 ,
31
+ price_update:: {
32
+ PriceUpdateV1 ,
33
+ VerificationLevel ,
34
+ } ,
33
35
} ,
34
36
wormhole_core_bridge_solana:: {
35
- sdk:: legacy:: AccountVariant ,
36
- state:: {
37
- EncodedVaa ,
38
- GuardianSet ,
37
+ sdk:: {
38
+ legacy:: AccountVariant ,
39
+ VaaAccount ,
39
40
} ,
41
+ state:: GuardianSet ,
40
42
} ,
41
43
wormhole_raw_vaas:: {
42
44
GuardianSetSig ,
43
45
Vaa ,
44
46
} ,
45
- wormhole_sdk:: vaa:: {
46
- Body ,
47
- Header ,
48
- } ,
49
47
} ;
50
48
51
49
pub mod error;
@@ -104,6 +102,11 @@ pub mod pyth_solana_receiver {
104
102
Ok ( ( ) )
105
103
}
106
104
105
+ pub fn set_minimum_signatures ( ctx : Context < Governance > , minimum_signatures : u8 ) -> Result < ( ) > {
106
+ let config = & mut ctx. accounts . config ;
107
+ config. minimum_signatures = minimum_signatures;
108
+ Ok ( ( ) )
109
+ }
107
110
108
111
/// Post a price update using a VAA and a MerklePriceUpdate.
109
112
/// This function allows you to post a price update in a single transaction.
@@ -126,7 +129,6 @@ pub mod pyth_solana_receiver {
126
129
ReceiverError :: GuardianSetMismatch
127
130
) ;
128
131
129
- // Do we have enough signatures for quorum?
130
132
let guardian_keys = & guardian_set. keys ;
131
133
132
134
// Generate the same message hash (using keccak) that the Guardians used to generate their
@@ -159,10 +161,16 @@ pub mod pyth_solana_receiver {
159
161
let treasury = & ctx. accounts . treasury ;
160
162
let price_update_account = & mut ctx. accounts . price_update_account ;
161
163
164
+ require_gte ! (
165
+ vaa. signature_count( ) ,
166
+ config. minimum_signatures,
167
+ ReceiverError :: InsufficientGuardianSignatures
168
+ ) ;
169
+
162
170
let vaa_components = VaaComponents {
163
- verified_signatures : vaa. signature_count ( ) ,
164
- emitter_address : vaa. body ( ) . emitter_address ( ) ,
165
- emitter_chain : vaa. body ( ) . emitter_chain ( ) ,
171
+ verification_level : VerificationLevel :: Partial ( vaa. signature_count ( ) ) ,
172
+ emitter_address : vaa. body ( ) . emitter_address ( ) ,
173
+ emitter_chain : vaa. body ( ) . emitter_chain ( ) ,
166
174
} ;
167
175
168
176
post_price_update_from_vaa (
@@ -185,18 +193,15 @@ pub mod pyth_solana_receiver {
185
193
pub fn post_updates ( ctx : Context < PostUpdates > , price_update : MerklePriceUpdate ) -> Result < ( ) > {
186
194
let config = & ctx. accounts . config ;
187
195
let payer: & Signer < ' _ > = & ctx. accounts . payer ;
188
- let encoded_vaa = & ctx. accounts . encoded_vaa ;
196
+ let encoded_vaa = VaaAccount :: load ( & ctx. accounts . encoded_vaa ) ? ;
189
197
let treasury: & AccountInfo < ' _ > = & ctx. accounts . treasury ;
190
198
let price_update_account: & mut Account < ' _ , PriceUpdateV1 > =
191
199
& mut ctx. accounts . price_update_account ;
192
200
193
- let ( _, body) : ( Header , Body < & RawMessage > ) =
194
- serde_wormhole:: from_slice ( & encoded_vaa. buf ) . unwrap ( ) ;
195
-
196
201
let vaa_components = VaaComponents {
197
- verified_signatures : encoded_vaa . header . verified_signatures ,
198
- emitter_address : body . emitter_address . 0 ,
199
- emitter_chain : body . emitter_chain . into ( ) ,
202
+ verification_level : VerificationLevel :: Full ,
203
+ emitter_address : encoded_vaa . try_emitter_address ( ) ? ,
204
+ emitter_chain : encoded_vaa . try_emitter_chain ( ) ? ,
200
205
} ;
201
206
202
207
post_price_update_from_vaa (
@@ -205,7 +210,7 @@ pub mod pyth_solana_receiver {
205
210
treasury,
206
211
price_update_account,
207
212
& vaa_components,
208
- body . payload ,
213
+ encoded_vaa . try_payload ( ) ? . as_ref ( ) ,
209
214
& price_update,
210
215
) ?;
211
216
@@ -253,7 +258,8 @@ pub struct PostUpdates<'info> {
253
258
#[ account( mut ) ]
254
259
pub payer : Signer < ' info > ,
255
260
#[ account( owner = config. wormhole) ]
256
- pub encoded_vaa : Account < ' info , EncodedVaa > ,
261
+ /// CHECK: We aren't deserializing the VAA here but later with VaaAccount::load, which is the recommended way
262
+ pub encoded_vaa : AccountInfo < ' info > ,
257
263
#[ account( seeds = [ CONFIG_SEED . as_ref( ) ] , bump) ]
258
264
pub config : Account < ' info , Config > ,
259
265
#[ account( seeds = [ TREASURY_SEED . as_ref( ) ] , bump) ]
@@ -351,10 +357,17 @@ impl crate::accounts::PostUpdates {
351
357
}
352
358
}
353
359
360
+ impl crate :: accounts:: Governance {
361
+ pub fn populate ( payer : Pubkey ) -> Self {
362
+ let config = Pubkey :: find_program_address ( & [ CONFIG_SEED . as_ref ( ) ] , & crate :: ID ) . 0 ;
363
+ crate :: accounts:: Governance { payer, config }
364
+ }
365
+ }
366
+
354
367
struct VaaComponents {
355
- verified_signatures : u8 ,
356
- emitter_address : [ u8 ; 32 ] ,
357
- emitter_chain : u16 ,
368
+ verification_level : VerificationLevel ,
369
+ emitter_address : [ u8 ; 32 ] ,
370
+ emitter_chain : u16 ,
358
371
}
359
372
360
373
fn post_price_update_from_vaa < ' info > (
@@ -410,7 +423,7 @@ fn post_price_update_from_vaa<'info>(
410
423
match message {
411
424
Message :: PriceFeedMessage ( price_feed_message) => {
412
425
price_update_account. write_authority = payer. key ( ) ;
413
- price_update_account. verified_signatures = vaa_components. verified_signatures ;
426
+ price_update_account. verification_level = vaa_components. verification_level ;
414
427
price_update_account. price_message = price_feed_message;
415
428
}
416
429
Message :: TwapMessage ( _) => {
0 commit comments