Skip to content

Commit 074c1b4

Browse files
author
Bengt Lofgren
committed
added error code, and some program checks
1 parent d642880 commit 074c1b4

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,15 @@ pub enum MatchingEngineError {
100100
TokenTransferFailed = 0x70c,
101101
InvalidMint = 0x70e,
102102

103+
// Place initial offer errors
103104
#[msg("From and to router endpoints are the same")]
104105
SameEndpoints = 0x800,
105-
InvalidCctpMessage = 0x802,
106+
107+
// Close fast market order errors
108+
MismatchingCloseAccountRefundRecipient = 0xa10,
109+
110+
// Execute order errors
111+
InvalidCctpMessage = 0x902,
106112
}
107113

108114
#[cfg(test)]

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::error::MatchingEngineError;
12
use crate::state::FastMarketOrder;
23
use anchor_lang::prelude::*;
34
use solana_program::instruction::Instruction;
@@ -63,12 +64,14 @@ pub fn close_fast_market_order(accounts: &[AccountInfo]) -> Result<()> {
6364
if fast_market_order_data.close_account_refund_recipient
6465
!= close_account_refund_recipient.key().as_ref()
6566
{
66-
return Err(ProgramError::InvalidAccountData.into()).map_err(|e: Error| {
67-
e.with_pubkeys((
68-
Pubkey::from(fast_market_order_data.close_account_refund_recipient),
69-
close_account_refund_recipient.key(),
70-
))
71-
});
67+
return Err(MatchingEngineError::MismatchingCloseAccountRefundRecipient.into()).map_err(
68+
|e: Error| {
69+
e.with_pubkeys((
70+
Pubkey::from(fast_market_order_data.close_account_refund_recipient),
71+
close_account_refund_recipient.key(),
72+
))
73+
},
74+
);
7275
}
7376

7477
// First, get the current lamports value

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ pub fn handle_execute_order_shim(accounts: &[AccountInfo]) -> Result<()> {
358358
});
359359
};
360360

361-
// TODO: Done with auction checks, now on to executor token checks
362361
if executor_token_account.key() != active_auction.info.as_ref().unwrap().best_offer_token {
363362
msg!("Executor token is not equal to best offer token");
364363
return Err(ErrorCode::ConstraintAddress.into()).map_err(|e: Error| {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ pub fn initialise_fast_market_order(
122122
guardian_set_bump,
123123
_padding: _,
124124
} = *data;
125-
126125
// Start of cpi call to verify the shim.
127126
// ------------------------------------------------------------------------------------------------
128127
let fast_market_order_digest = fast_market_order.digest();
@@ -191,7 +190,6 @@ pub fn initialise_fast_market_order(
191190
&program_id,
192191
fast_market_order_signer_seeds,
193192
)?;
194-
195193
// Borrow the account data mutably
196194
let mut fast_market_order_account_data = fast_market_order_account.try_borrow_mut_data()?;
197195

@@ -206,7 +204,6 @@ pub fn initialise_fast_market_order(
206204
msg!("Account data buffer too small");
207205
return Err(MatchingEngineError::AccountDataTooSmall.into());
208206
}
209-
210207
// Write the fast_market_order struct to the account
211208
fast_market_order_account_data[8..8_usize.saturating_add(fast_market_order_bytes.len())]
212209
.copy_from_slice(fast_market_order_bytes);

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ pub fn place_initial_offer_cctp_shim(
182182
// Check all accounts are valid
183183
check_account_length(accounts, 11)?;
184184
// Extract data fields
185-
// TODO: Remove sequence, vaa_time because they are in the fast market order state
186185
let PlaceInitialOfferCctpShimData { offer_price } = *data;
187186

188187
let signer = &accounts[0];
@@ -198,6 +197,13 @@ pub fn place_initial_offer_cctp_shim(
198197
let auction_custody_token = &accounts[9];
199198
let usdc = &accounts[10];
200199

200+
// Check that the fast market order account is owned by the program
201+
if fast_market_order_account.owner != program_id {
202+
msg!("Fast market order account owner is invalid");
203+
return Err(ErrorCode::ConstraintOwner.into())
204+
.map_err(|e: Error| e.with_account_name("fast_market_order_account"));
205+
}
206+
201207
let fast_market_order_zero_copy =
202208
FastMarketOrderState::try_deserialize(&mut &fast_market_order_account.data.borrow()[..])?;
203209

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ impl<'ix> PrepareOrderResponseCctpShimAccounts<'ix> {
172172
}
173173
}
174174

175-
// TODO: Also close the fast market order account since it is no longer needed
176175
pub struct PrepareOrderResponseCctpShim<'ix> {
177176
pub program_id: &'ix Pubkey,
178177
pub accounts: PrepareOrderResponseCctpShimAccounts<'ix>,
@@ -256,7 +255,6 @@ pub fn prepare_order_response_cctp_shim(
256255
FastMarketOrderState::try_read(&fast_market_order_account_data[..])?;
257256
// Create pdas for addresses that need to be created
258257
// Check the prepared order response account is valid
259-
// TODO: Pass the digest so it isn't recomputed
260258
let fast_market_order_digest = fast_market_order_zero_copy.digest();
261259
// Construct the finalised vaa message digest data
262260
let finalized_vaa_message_digest = {
@@ -286,7 +284,6 @@ pub fn prepare_order_response_cctp_shim(
286284
Custodian::try_deserialize(&mut &custodian.data.borrow()[..]).map(Box::new)?;
287285
// Deserialise the to_endpoint account
288286

289-
// TODO: Scope this to do checks and deallocate stack
290287
let to_endpoint_account =
291288
RouterEndpoint::try_deserialize(&mut &to_endpoint.data.borrow()[..]).map(Box::new)?;
292289
// Deserialise the from_endpoint account
@@ -296,7 +293,7 @@ pub fn prepare_order_response_cctp_shim(
296293
let guardian_set_bump = finalized_vaa_message.guardian_set_bump;
297294

298295
// Check loaded vaa is deposit message
299-
// TODO: Fix errors
296+
// TODO: Fix errors to be more specific
300297
let liquidity_layer_message =
301298
LiquidityLayerDepositMessage::parse(&finalized_vaa_message.deposit_payload)
302299
.map_err(|_| MatchingEngineError::InvalidDepositPayloadId)?;

0 commit comments

Comments
 (0)