Skip to content

Commit e338fad

Browse files
Bengt Lofgrenbengtlofgren
authored andcommitted
place initial offer helper function with reuse
1 parent 5a0ec3d commit e338fad

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use solana_program::{instruction::Instruction, program::invoke_signed_unchecked}
66

77
use crate::{
88
error::MatchingEngineError,
9+
processor::calculate_security_deposit,
910
state::{Auction, AuctionInfo, AuctionStatus, MessageProtocol},
1011
ID,
1112
};
@@ -261,11 +262,10 @@ pub(super) fn process(
261262

262263
// The total amount being transferred to the auction's custody token account
263264
// is the order's amount and auction participant's security deposit.
264-
let security_deposit = fast_market_order.max_fee.saturating_add(
265-
crate::utils::auction::compute_notional_security_deposit(
266-
&auction_config,
267-
fast_market_order.amount_in,
268-
),
265+
let security_deposit = calculate_security_deposit(
266+
fast_market_order.max_fee,
267+
fast_market_order.amount_in,
268+
&auction_config,
269269
);
270270

271271
let transfer_ix = spl_token::instruction::transfer(

solana/programs/matching-engine/src/processor/auction/execute_fast_order/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ pub struct ActiveAuctionAccountInfos<'ix> {
105105
pub auction_custodian: AccountInfo<'ix>,
106106
}
107107

108-
pub fn get_user_amount_and_new_status_and_penalized<'ix>(
108+
pub fn get_user_amount_and_new_status_and_penalized(
109109
auction: &Auction,
110110
custody_token: &TokenAccount,
111111
auction_config: &AuctionConfig,
112112
init_auction_fee: u64,
113-
active_auction_account_infos: ActiveAuctionAccountInfos<'ix>,
113+
active_auction_account_infos: ActiveAuctionAccountInfos<'_>,
114114
accounts: &[AccountInfo],
115115
) -> Result<(u64, AuctionStatus, bool)> {
116116
let auction_info = auction.info.as_ref().unwrap();
@@ -288,9 +288,9 @@ pub fn get_user_amount_and_new_status_and_penalized<'ix>(
288288
))
289289
}
290290

291-
pub fn get_order_executed_event<'ix>(
291+
pub fn get_order_executed_event(
292292
auction: &Auction,
293-
fast_vaa: &AccountInfo<'ix>,
293+
fast_vaa: &AccountInfo<'_>,
294294
auction_info: &AuctionInfo,
295295
penalized: bool,
296296
) -> OrderExecuted {

solana/programs/matching-engine/src/processor/auction/offer/place_initial/cctp.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::{
22
composite::*,
33
error::MatchingEngineError,
4-
state::{Auction, AuctionConfig, AuctionInfo, AuctionStatus, MessageProtocol},
4+
state::{
5+
Auction, AuctionConfig, AuctionInfo, AuctionParameters, AuctionStatus, MessageProtocol,
6+
},
57
utils,
68
};
79
use anchor_lang::prelude::*;
@@ -131,12 +133,7 @@ pub fn place_initial_offer_cctp(
131133
// Saturating to u64::MAX is safe here. If the amount really ends up being this large, the
132134
// checked addition below will catch it.
133135
let security_deposit =
134-
order
135-
.max_fee()
136-
.saturating_add(utils::auction::compute_notional_security_deposit(
137-
&ctx.accounts.auction_config,
138-
amount_in,
139-
));
136+
calculate_security_deposit(order.max_fee(), amount_in, &ctx.accounts.auction_config);
140137

141138
// Set up the Auction account for this auction.
142139
let config = &ctx.accounts.auction_config;
@@ -206,3 +203,14 @@ pub fn place_initial_offer_cctp(
206203
.ok_or_else(|| MatchingEngineError::U64Overflow)?,
207204
)
208205
}
206+
207+
pub fn calculate_security_deposit(
208+
max_fee: u64,
209+
amount_in: u64,
210+
auction_parameters: &AuctionParameters,
211+
) -> u64 {
212+
max_fee.saturating_add(utils::auction::compute_notional_security_deposit(
213+
auction_parameters,
214+
amount_in,
215+
))
216+
}

0 commit comments

Comments
 (0)