Skip to content

Commit 8d46947

Browse files
author
Bengt Lofgren
committed
place initial offer and prepare order response
1 parent 8939621 commit 8d46947

File tree

3 files changed

+25
-47
lines changed

3 files changed

+25
-47
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub enum MatchingEngineError {
9494
AccountAlreadyInitialized = 0x700,
9595
AccountNotWritable = 0x702,
9696
BorshDeserializationError = 0x704,
97+
BorshSerializationError = 0x705,
9798
InvalidPda = 0x706,
9899
AccountDataTooSmall = 0x708,
99100
InvalidProgram = 0x70a,

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

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
use std::io::Cursor;
22

33
use super::helpers::create_account_reliably;
4+
use super::place_initial_offer::VaaMessageBodyHeader;
45
use super::FallbackMatchingEngineInstruction;
56
use crate::fallback::helpers::check_account_length;
7+
use crate::fallback::helpers::create_token_account_reliably;
68
use crate::state::PreparedOrderResponseInfo;
79
use crate::state::PreparedOrderResponseSeeds;
810
use crate::state::{
911
Custodian, FastMarketOrder as FastMarketOrderState, MessageProtocol, PreparedOrderResponse,
1012
RouterEndpoint,
1113
};
1214
use crate::CCTP_MINT_RECIPIENT;
15+
use crate::ID;
1316
use anchor_lang::prelude::*;
1417
use anchor_spl::token::spl_token;
1518
use common::messages::SlowOrderResponse;
@@ -42,24 +45,18 @@ pub struct FinalizedVaaMessageArgs {
4245
}
4346

4447
impl FinalizedVaaMessageArgs {
45-
#[allow(clippy::too_many_arguments)]
4648
pub fn digest(
4749
&self,
48-
sequence: u64,
49-
timestamp: u32,
50-
emitter_chain: u16,
51-
emitter_address: [u8; 32],
52-
nonce: u32,
53-
consistency_level: u8,
50+
vaa_message_body_header: VaaMessageBodyHeader,
5451
deposit_vaa_payload: Deposit,
5552
) -> [u8; 32] {
5653
let message_hash = keccak::hashv(&[
57-
timestamp.to_be_bytes().as_ref(),
58-
nonce.to_be_bytes().as_ref(),
59-
emitter_chain.to_be_bytes().as_ref(),
60-
&emitter_address,
61-
&sequence.to_be_bytes(),
62-
&[consistency_level],
54+
vaa_message_body_header.vaa_time.to_be_bytes().as_ref(),
55+
vaa_message_body_header.nonce.to_be_bytes().as_ref(),
56+
vaa_message_body_header.emitter_chain.to_be_bytes().as_ref(),
57+
&vaa_message_body_header.emitter_address,
58+
&vaa_message_body_header.sequence.to_be_bytes(),
59+
&[vaa_message_body_header.consistency_level],
6360
deposit_vaa_payload.to_vec().as_ref(),
6461
]);
6562
// Digest is the hash of the message
@@ -71,23 +68,9 @@ impl FinalizedVaaMessageArgs {
7168
}
7269

7370
impl PrepareOrderResponseCctpShimData {
74-
pub fn new(
75-
encoded_cctp_message: Vec<u8>,
76-
cctp_attestation: Vec<u8>,
77-
finalized_vaa_message_args: FinalizedVaaMessageArgs,
78-
) -> Self {
79-
Self {
80-
encoded_cctp_message,
81-
cctp_attestation,
82-
finalized_vaa_message_args,
83-
}
84-
}
8571
pub fn from_bytes(data: &[u8]) -> Option<Self> {
8672
Self::try_from_slice(data).ok()
8773
}
88-
pub fn to_bytes(&self) -> Vec<u8> {
89-
self.try_to_vec().unwrap()
90-
}
9174

9275
pub fn to_receive_message_args(&self) -> ReceiveMessageArgs {
9376
let mut encoded_message = Vec::with_capacity(self.encoded_cctp_message.len());
@@ -188,7 +171,7 @@ pub fn prepare_order_response_cctp_shim(
188171
accounts: &[AccountInfo],
189172
data: PrepareOrderResponseCctpShimData,
190173
) -> Result<()> {
191-
let program_id = &crate::ID;
174+
let program_id = &ID;
192175
check_account_length(accounts, 27)?;
193176

194177
let signer = &accounts[0];
@@ -366,7 +349,6 @@ pub fn prepare_order_response_cctp_shim(
366349
let finalised_vaa_sequence = fast_market_order_zero_copy.vaa_sequence.saturating_sub(1);
367350
let finalised_vaa_emitter_chain = fast_market_order_zero_copy.vaa_emitter_chain;
368351
let finalised_vaa_emitter_address = fast_market_order_zero_copy.vaa_emitter_address;
369-
let finalised_vaa_nonce = fast_market_order_zero_copy.vaa_nonce;
370352
let finalised_vaa_consistency_level = finalized_vaa_message_args.consistency_level;
371353
let slow_order_response = SlowOrderResponse {
372354
base_fee: finalized_vaa_message_args.base_fee,
@@ -383,12 +365,13 @@ pub fn prepare_order_response_cctp_shim(
383365
};
384366

385367
finalized_vaa_message_args.digest(
386-
finalised_vaa_sequence,
387-
finalised_vaa_timestamp,
388-
finalised_vaa_emitter_chain,
389-
finalised_vaa_emitter_address,
390-
finalised_vaa_nonce,
391-
finalised_vaa_consistency_level,
368+
VaaMessageBodyHeader::new(
369+
finalised_vaa_consistency_level,
370+
finalised_vaa_timestamp,
371+
finalised_vaa_sequence,
372+
finalised_vaa_emitter_chain,
373+
finalised_vaa_emitter_address,
374+
),
392375
deposit_vaa_payload,
393376
)
394377
};
@@ -488,23 +471,17 @@ pub fn prepare_order_response_cctp_shim(
488471
];
489472

490473
let prepared_custody_token_signer_seeds = &[&create_prepared_custody_token_seeds[..]];
491-
let prepared_custody_token_account_space = spl_token::state::Account::LEN;
492-
create_account_reliably(
474+
create_token_account_reliably(
493475
&signer.key(),
494476
&prepared_custody_token_pda,
477+
&prepared_order_response_pda,
478+
&usdc.key(),
479+
spl_token::state::Account::LEN,
495480
prepared_custody_token.lamports(),
496-
prepared_custody_token_account_space,
497481
accounts,
498-
&spl_token::ID,
499482
prepared_custody_token_signer_seeds,
500483
)?;
501-
let init_token_account_ix = spl_token::instruction::initialize_account3(
502-
&spl_token::ID,
503-
&prepared_custody_token_pda,
504-
&usdc.key(),
505-
&prepared_order_response_pda,
506-
)?;
507-
solana_program::program::invoke_signed_unchecked(&init_token_account_ix, accounts, &[])?;
484+
508485
// End create prepared custody token account
509486
// ------------------------------------------------------------------------------------------------
510487

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl FallbackMatchingEngineInstruction<'_> {
149149
out
150150
}
151151
Self::PrepareOrderResponseCctpShim(data) => {
152-
let data_slice = data.to_bytes();
152+
let data_slice = data.try_to_vec().unwrap();
153153
let total_capacity = 8_usize.saturating_add(data_slice.len()); // 8 for the selector, plus the data length
154154

155155
let mut out = Vec::with_capacity(total_capacity);

0 commit comments

Comments
 (0)