Skip to content

Commit dd56e0f

Browse files
author
Bengt Lofgren
committed
helper function for custodian check
1 parent f2f7a07 commit dd56e0f

File tree

4 files changed

+15
-25
lines changed

4 files changed

+15
-25
lines changed

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use super::helpers::require_min_account_infos_len;
21
use crate::fallback::burn_and_post::PostMessageDerivedAccounts;
2+
use crate::fallback::helpers::*;
33
use crate::state::{
44
Auction, AuctionConfig, AuctionStatus, Custodian, FastMarketOrder as FastMarketOrderState,
55
MessageProtocol, RouterEndpoint,
@@ -222,15 +222,7 @@ pub fn handle_execute_order_shim(accounts: &[AccountInfo]) -> Result<()> {
222222
};
223223

224224
// Check custodian owner
225-
if custodian_account.owner != &ID {
226-
msg!(
227-
"Custodian owner is invalid: expected {}, got {}",
228-
&ID,
229-
custodian_account.owner
230-
);
231-
return Err(ErrorCode::ConstraintOwner.into())
232-
.map_err(|e: Error| e.with_account_name("custodian"));
233-
};
225+
check_custodian_owner_is_program_id(custodian_account)?;
234226

235227
// Check custodian deserialises into a checked custodian account
236228
let _checked_custodian = Custodian::try_deserialize(&mut &custodian_account.data.borrow()[..])?;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use anchor_lang::prelude::*;
22

3+
use crate::ID;
34
use anchor_spl::mint::USDC;
45
use anchor_spl::token::spl_token;
56
use solana_program::program_pack::Pack;
@@ -18,6 +19,12 @@ pub fn require_min_account_infos_len(accounts: &[AccountInfo], len: usize) -> Re
1819
Ok(())
1920
}
2021

22+
#[inline(always)]
23+
pub fn check_custodian_owner_is_program_id(custodian: &AccountInfo) -> Result<()> {
24+
require_eq!(custodian.owner, &ID, ErrorCode::ConstraintOwner);
25+
Ok(())
26+
}
27+
2128
pub fn create_account_reliably(
2229
payer_key: &Pubkey,
2330
account_key: &Pubkey,

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use super::helpers::create_account_reliably;
2-
use super::helpers::create_usdc_token_account_reliably;
3-
use super::helpers::require_min_account_infos_len;
1+
use super::helpers::*;
42
use crate::state::MessageProtocol;
53
use crate::state::{
64
Auction, AuctionConfig, AuctionInfo, AuctionStatus, Custodian,
@@ -239,15 +237,8 @@ pub fn place_initial_offer_cctp_shim(
239237
}
240238

241239
// Check custodian owner
242-
if custodian.owner != program_id {
243-
msg!(
244-
"Custodian owner is invalid: expected {}, got {}",
245-
program_id,
246-
custodian.owner
247-
);
248-
return Err(ErrorCode::ConstraintOwner.into())
249-
.map_err(|e: Error| e.with_account_name("custodian"));
250-
}
240+
check_custodian_owner_is_program_id(custodian)?;
241+
251242
// Check custodian is not paused
252243
let checked_custodian = Custodian::try_deserialize(&mut &custodian.data.borrow()[..])?;
253244
if checked_custodian.paused {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::io::Cursor;
33
use super::helpers::create_account_reliably;
44
use super::place_initial_offer::VaaMessageBodyHeader;
55
use super::FallbackMatchingEngineInstruction;
6+
use crate::fallback::helpers::check_custodian_owner_is_program_id;
67
use crate::fallback::helpers::create_usdc_token_account_reliably;
78
use crate::fallback::helpers::require_min_account_infos_len;
89
use crate::state::PreparedOrderResponseInfo;
@@ -227,6 +228,8 @@ pub fn prepare_order_response_cctp_shim(
227228
ErrorCode::ConstraintOwner
228229
);
229230

231+
// Check custodian owner
232+
check_custodian_owner_is_program_id(custodian)?;
230233
// Check that custodian deserializes correctly
231234
let _checked_custodian =
232235
Custodian::try_deserialize(&mut &custodian.data.borrow()[..]).map(Box::new)?;
@@ -256,9 +259,6 @@ pub fn prepare_order_response_cctp_shim(
256259
let (prepared_custody_token_pda, prepared_custody_token_bump) =
257260
Pubkey::find_program_address(&prepared_custody_token_seeds, program_id);
258261

259-
// Check custodian account
260-
require_eq!(custodian.owner, program_id, ErrorCode::ConstraintOwner);
261-
262262
// Check usdc mint
263263
require_eq!(
264264
usdc.key(),

0 commit comments

Comments
 (0)