@@ -51,9 +51,7 @@ use crate::math::spot_balance::{get_signed_token_amount, get_token_amount};
5151use crate :: math:: spot_swap:: select_margin_type_for_swap;
5252use crate :: math:: { amm, fees, margin:: * , orders:: * } ;
5353use crate :: print_error;
54- use crate :: state:: events:: {
55- emit_stack, get_order_action_record, LPAction , LPRecord , OrderActionRecord , OrderRecord ,
56- } ;
54+ use crate :: state:: events:: { emit_stack, get_order_action_record, OrderActionRecord , OrderRecord } ;
5755use crate :: state:: events:: { OrderAction , OrderActionExplanation } ;
5856use crate :: state:: fill_mode:: FillMode ;
5957use crate :: state:: fulfillment:: { PerpFulfillmentMethod , SpotFulfillmentMethod } ;
@@ -1001,23 +999,12 @@ pub fn fill_perp_order(
1001999 . position ( |order| order. order_id == order_id && order. status == OrderStatus :: Open )
10021000 . ok_or_else ( print_error ! ( ErrorCode :: OrderDoesNotExist ) ) ?;
10031001
1004- let (
1005- order_status,
1006- market_index,
1007- order_market_type,
1008- order_price,
1009- order_oracle_price_offset,
1010- order_direction,
1011- order_auction_duration,
1012- ) = get_struct_values ! (
1002+ let ( order_status, market_index, order_market_type, order_direction) = get_struct_values ! (
10131003 user. orders[ order_index] ,
10141004 status,
10151005 market_index,
10161006 market_type,
1017- price,
1018- oracle_price_offset,
1019- direction,
1020- auction_duration
1007+ direction
10211008 ) ;
10221009
10231010 validate ! (
@@ -2229,12 +2216,13 @@ pub fn fulfill_perp_order_with_amm(
22292216 } ;
22302217
22312218 // if user position is less than min order size, step size is the threshold
2232- let amm_size_threshold =
2233- if existing_base_asset_amount. unsigned_abs ( ) > market. amm . min_order_size {
2234- market. amm . min_order_size
2235- } else {
2236- market. amm . order_step_size
2237- } ;
2219+ let amm_size_threshold = if !user. orders [ order_index] . reduce_only
2220+ && existing_base_asset_amount. unsigned_abs ( ) > market. amm . min_order_size
2221+ {
2222+ market. amm . min_order_size
2223+ } else {
2224+ market. amm . order_step_size
2225+ } ;
22382226
22392227 if base_asset_amount < amm_size_threshold {
22402228 // if is an actual swap (and not amm jit order) then msg!
@@ -2316,7 +2304,7 @@ pub fn fulfill_perp_order_with_amm(
23162304 filler_reward,
23172305 referee_discount,
23182306 referrer_reward,
2319- fee_to_market_for_lp,
2307+ fee_to_market_for_lp : _fee_to_market_for_lp ,
23202308 maker_rebate,
23212309 builder_fee,
23222310 } = fees:: calculate_fee_for_fulfillment_with_amm (
@@ -2340,9 +2328,6 @@ pub fn fulfill_perp_order_with_amm(
23402328 order. fees_accrued = order. fees_accrued . safe_add ( builder_fee) ?;
23412329 }
23422330
2343- let user_position_delta =
2344- get_position_delta_for_fill ( base_asset_amount, quote_asset_amount, order_direction) ?;
2345-
23462331 // Increment the protocol's total fee variables
23472332 market. amm . total_fee = market. amm . total_fee . safe_add ( fee_to_market. cast ( ) ?) ?;
23482333 market. amm . total_exchange_fee = market. amm . total_exchange_fee . safe_add ( user_fee. cast ( ) ?) ?;
0 commit comments