1
1
use anchor_lang:: prelude:: * ;
2
2
use anchor_lang:: Discriminator ;
3
+ use anchor_spl:: token_interface:: spl_token_metadata_interface:: borsh:: BorshDeserialize ;
3
4
use bytemuck:: { Pod , Zeroable } ;
4
5
use solana_program:: instruction:: Instruction ;
6
+ use solana_program:: keccak;
5
7
use solana_program:: program:: invoke_signed_unchecked;
8
+ use wormhole_svm_shim:: verify_vaa:: VerifyHash ;
9
+ use wormhole_svm_shim:: verify_vaa:: VerifyHashAccounts ;
10
+ use wormhole_svm_shim:: verify_vaa:: VerifyHashData ;
6
11
7
12
use super :: helpers:: create_account_reliably;
8
13
9
14
use super :: helpers:: check_account_length;
10
15
use super :: FallbackMatchingEngineInstruction ;
11
16
use crate :: error:: MatchingEngineError ;
12
17
use crate :: state:: FastMarketOrder as FastMarketOrderState ;
18
+ use crate :: ID ;
13
19
14
20
pub struct InitialiseFastMarketOrderAccounts < ' ix > {
15
21
/// The signer of the transaction
@@ -33,8 +39,8 @@ impl<'ix> InitialiseFastMarketOrderAccounts<'ix> {
33
39
AccountMeta :: new( * self . fast_market_order_account, false ) ,
34
40
AccountMeta :: new_readonly( * self . guardian_set, false ) ,
35
41
AccountMeta :: new_readonly( * self . guardian_set_signatures, false ) ,
36
- AccountMeta :: new ( * self . verify_vaa_shim_program, false ) ,
37
- AccountMeta :: new ( * self . system_program, false ) ,
42
+ AccountMeta :: new_readonly ( * self . verify_vaa_shim_program, false ) ,
43
+ AccountMeta :: new_readonly ( * self . system_program, false ) ,
38
44
]
39
45
}
40
46
}
@@ -108,7 +114,7 @@ pub fn initialise_fast_market_order(
108
114
) -> Result < ( ) > {
109
115
check_account_length ( accounts, 6 ) ?;
110
116
111
- let program_id = crate :: ID ;
117
+ let program_id = ID ;
112
118
113
119
let signer = & accounts[ 0 ] ;
114
120
let fast_market_order_account = & accounts[ 1 ] ;
@@ -123,33 +129,21 @@ pub fn initialise_fast_market_order(
123
129
// Start of cpi call to verify the shim.
124
130
// ------------------------------------------------------------------------------------------------
125
131
let fast_market_order_vaa_digest = fast_market_order. digest ( ) ;
126
- // Did not want to pass in the vaa hash here. So recreated it.
127
- let verify_hash_data = {
128
- let mut data = vec ! [ ] ;
129
- data. extend_from_slice (
130
- & wormhole_svm_shim:: verify_vaa:: VerifyVaaShimInstruction :: < false > :: VERIFY_HASH_SELECTOR ,
131
- ) ;
132
- data. push ( guardian_set_bump) ;
133
- data. extend_from_slice ( & fast_market_order_vaa_digest) ;
134
- data
135
- } ;
136
- let verify_shim_ix = Instruction {
137
- program_id : wormhole_svm_definitions:: solana:: VERIFY_VAA_SHIM_PROGRAM_ID , // Because program is hardcoded, the check is not needed.
138
- accounts : vec ! [
139
- AccountMeta :: new_readonly( guardian_set. key( ) , false ) ,
140
- AccountMeta :: new_readonly( guardian_set_signatures. key( ) , false ) ,
141
- ] ,
132
+ let fast_market_order_vaa_digest_hash =
133
+ keccak:: Hash :: try_from_slice ( & fast_market_order_vaa_digest) . unwrap ( ) ;
134
+ let verify_hash_data =
135
+ VerifyHashData :: new ( guardian_set_bump, fast_market_order_vaa_digest_hash) ;
136
+ let verify_hash_shim_ix = VerifyHash {
137
+ program_id : & wormhole_svm_definitions:: solana:: VERIFY_VAA_SHIM_PROGRAM_ID ,
138
+ accounts : VerifyHashAccounts {
139
+ guardian_set : & guardian_set. key ( ) ,
140
+ guardian_signatures : & guardian_set_signatures. key ( ) ,
141
+ } ,
142
142
data : verify_hash_data,
143
- } ;
143
+ }
144
+ . instruction ( ) ;
144
145
// Make the cpi call to verify the shim.
145
- invoke_signed_unchecked (
146
- & verify_shim_ix,
147
- & [
148
- guardian_set. to_account_info ( ) ,
149
- guardian_set_signatures. to_account_info ( ) ,
150
- ] ,
151
- & [ ] ,
152
- ) ?;
146
+ invoke_signed_unchecked ( & verify_hash_shim_ix, accounts, & [ ] ) ?;
153
147
// ------------------------------------------------------------------------------------------------
154
148
// End of cpi call to verify the shim.
155
149
@@ -196,12 +190,7 @@ pub fn initialise_fast_market_order(
196
190
fast_market_order_account_data[ 0 ..8 ] . copy_from_slice ( & discriminator) ;
197
191
198
192
let fast_market_order_bytes = bytemuck:: bytes_of ( & data. fast_market_order ) ;
199
- // Ensure the destination has enough space
200
- if fast_market_order_account_data. len ( ) < 8_usize . saturating_add ( fast_market_order_bytes. len ( ) )
201
- {
202
- msg ! ( "Account data buffer too small" ) ;
203
- return Err ( MatchingEngineError :: AccountDataTooSmall . into ( ) ) ;
204
- }
193
+
205
194
// Write the fast_market_order struct to the account
206
195
fast_market_order_account_data[ 8 ..8_usize . saturating_add ( fast_market_order_bytes. len ( ) ) ]
207
196
. copy_from_slice ( fast_market_order_bytes) ;
0 commit comments