Skip to content

Commit 85a7004

Browse files
author
Bengt Lofgren
committed
initialise fast market order comments attended
1 parent 8d46947 commit 85a7004

File tree

2 files changed

+23
-35
lines changed

2 files changed

+23
-35
lines changed

solana/programs/matching-engine/src/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ pub enum MatchingEngineError {
9696
BorshDeserializationError = 0x704,
9797
BorshSerializationError = 0x705,
9898
InvalidPda = 0x706,
99-
AccountDataTooSmall = 0x708,
10099
InvalidProgram = 0x70a,
101100
TokenTransferFailed = 0x70c,
102101
InvalidMint = 0x70e,

solana/programs/matching-engine/src/fallback/processor/initialise_fast_market_order.rs

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
use anchor_lang::prelude::*;
22
use anchor_lang::Discriminator;
3+
use anchor_spl::token_interface::spl_token_metadata_interface::borsh::BorshDeserialize;
34
use bytemuck::{Pod, Zeroable};
45
use solana_program::instruction::Instruction;
6+
use solana_program::keccak;
57
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;
611

712
use super::helpers::create_account_reliably;
813

914
use super::helpers::check_account_length;
1015
use super::FallbackMatchingEngineInstruction;
1116
use crate::error::MatchingEngineError;
1217
use crate::state::FastMarketOrder as FastMarketOrderState;
18+
use crate::ID;
1319

1420
pub struct InitialiseFastMarketOrderAccounts<'ix> {
1521
/// The signer of the transaction
@@ -33,8 +39,8 @@ impl<'ix> InitialiseFastMarketOrderAccounts<'ix> {
3339
AccountMeta::new(*self.fast_market_order_account, false),
3440
AccountMeta::new_readonly(*self.guardian_set, false),
3541
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),
3844
]
3945
}
4046
}
@@ -108,7 +114,7 @@ pub fn initialise_fast_market_order(
108114
) -> Result<()> {
109115
check_account_length(accounts, 6)?;
110116

111-
let program_id = crate::ID;
117+
let program_id = ID;
112118

113119
let signer = &accounts[0];
114120
let fast_market_order_account = &accounts[1];
@@ -123,33 +129,21 @@ pub fn initialise_fast_market_order(
123129
// Start of cpi call to verify the shim.
124130
// ------------------------------------------------------------------------------------------------
125131
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+
},
142142
data: verify_hash_data,
143-
};
143+
}
144+
.instruction();
144145
// 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, &[])?;
153147
// ------------------------------------------------------------------------------------------------
154148
// End of cpi call to verify the shim.
155149

@@ -196,12 +190,7 @@ pub fn initialise_fast_market_order(
196190
fast_market_order_account_data[0..8].copy_from_slice(&discriminator);
197191

198192
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+
205194
// Write the fast_market_order struct to the account
206195
fast_market_order_account_data[8..8_usize.saturating_add(fast_market_order_bytes.len())]
207196
.copy_from_slice(fast_market_order_bytes);

0 commit comments

Comments
 (0)