File tree Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,16 @@ pub fn settle_pnl(
7979
8080 drop ( market) ;
8181
82- let position_index = get_position_index ( & user. perp_positions , market_index) ?;
82+ let position_index = match get_position_index ( & user. perp_positions , market_index) {
83+ Ok ( index) => index,
84+ Err ( e) => {
85+ return mode. result (
86+ e,
87+ market_index,
88+ & format ! ( "User has no position in market {}" , market_index) ,
89+ )
90+ }
91+ } ;
8392 let unrealized_pnl = user. perp_positions [ position_index] . get_unrealized_pnl ( oracle_price) ?;
8493
8594 // cannot settle negative pnl this way on a user who is in liquidation territory
Original file line number Diff line number Diff line change @@ -1104,8 +1104,7 @@ pub fn handle_settle_pnl<'c: 'info, 'info>(
11041104 & mut oracle_map,
11051105 state,
11061106 & clock,
1107- )
1108- . map ( |_| ErrorCode :: InvalidOracleForSettlePnl ) ?;
1107+ ) ?;
11091108
11101109 controller:: pnl:: settle_pnl (
11111110 market_index,
@@ -1119,8 +1118,7 @@ pub fn handle_settle_pnl<'c: 'info, 'info>(
11191118 state,
11201119 None ,
11211120 SettlePnlMode :: MustSettle ,
1122- )
1123- . map ( |_| ErrorCode :: InvalidOracleForSettlePnl ) ?;
1121+ ) ?;
11241122 }
11251123
11261124 if state. builder_codes_enabled ( ) || state. builder_referral_enabled ( ) {
@@ -1220,8 +1218,7 @@ pub fn handle_settle_multiple_pnls<'c: 'info, 'info>(
12201218 & mut oracle_map,
12211219 state,
12221220 & clock,
1223- )
1224- . map ( |_| ErrorCode :: InvalidOracleForSettlePnl ) ?;
1221+ ) ?;
12251222
12261223 controller:: pnl:: settle_pnl (
12271224 * market_index,
@@ -1235,8 +1232,7 @@ pub fn handle_settle_multiple_pnls<'c: 'info, 'info>(
12351232 state,
12361233 Some ( meets_margin_requirement) ,
12371234 mode,
1238- )
1239- . map ( |_| ErrorCode :: InvalidOracleForSettlePnl ) ?;
1235+ ) ?;
12401236 }
12411237
12421238 if state. builder_codes_enabled ( ) || state. builder_referral_enabled ( ) {
You can’t perform that action at this time.
0 commit comments