@@ -36,7 +36,7 @@ use crate::state::settle_pnl_mode::SettlePnlMode;
3636use crate :: state:: spot_market:: { SpotBalance , SpotBalanceType } ;
3737use crate :: state:: spot_market_map:: SpotMarketMap ;
3838use crate :: state:: state:: State ;
39- use crate :: state:: user:: { MarketType , User } ;
39+ use crate :: state:: user:: { MarketType , Order , OrderStatus , OrderType , User } ;
4040use crate :: validate;
4141use anchor_lang:: prelude:: Pubkey ;
4242use anchor_lang:: prelude:: * ;
@@ -480,9 +480,29 @@ pub fn settle_expired_position(
480480 let fill_record_id = { get_then_update_id ! ( perp_market, next_fill_record_id) } ;
481481
482482 let base_asset_amount = position_delta. base_asset_amount ;
483+ let user_existing_position_direction = user. perp_positions [ position_index] . get_direction ( ) ;
483484 let user_position_direction_to_close =
484485 user. perp_positions [ position_index] . get_direction_to_close ( ) ;
485486
487+ let user_order = Order {
488+ slot,
489+ base_asset_amount : base_asset_amount. unsigned_abs ( ) ,
490+ order_id : user_order_id,
491+ market_index : perp_market. market_index ,
492+ status : OrderStatus :: Open ,
493+ order_type : OrderType :: Market ,
494+ market_type : MarketType :: Perp ,
495+ direction : user_position_direction_to_close,
496+ existing_position_direction : user_existing_position_direction,
497+ ..Order :: default ( )
498+ } ;
499+
500+ emit ! ( OrderRecord {
501+ ts: now,
502+ user: * user_key,
503+ order: user_order
504+ } ) ;
505+
486506 let fill_record = OrderActionRecord {
487507 ts : now,
488508 action : OrderAction :: Fill ,
0 commit comments