Skip to content

Commit b09c15c

Browse files
committed
dont panic on settle-pnl when no position
1 parent d12614d commit b09c15c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

programs/drift/src/instructions/keeper.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ pub fn handle_settle_pnl<'c: 'info, 'info>(
11071107
)
11081108
.map(|_| ErrorCode::InvalidOracleForSettlePnl)?;
11091109

1110-
controller::pnl::settle_pnl(
1110+
let res = controller::pnl::settle_pnl(
11111111
market_index,
11121112
user,
11131113
ctx.accounts.authority.key,
@@ -1119,8 +1119,14 @@ pub fn handle_settle_pnl<'c: 'info, 'info>(
11191119
state,
11201120
None,
11211121
SettlePnlMode::MustSettle,
1122-
)
1123-
.map(|_| ErrorCode::InvalidOracleForSettlePnl)?;
1122+
);
1123+
if let Err(e) = res {
1124+
if e != ErrorCode::UserHasNoPositionInMarket {
1125+
return Err(e.into());
1126+
} else {
1127+
msg!("User has no position in market {}", market_index);
1128+
}
1129+
}
11241130
}
11251131

11261132
if state.builder_codes_enabled() || state.builder_referral_enabled() {
@@ -1223,7 +1229,7 @@ pub fn handle_settle_multiple_pnls<'c: 'info, 'info>(
12231229
)
12241230
.map(|_| ErrorCode::InvalidOracleForSettlePnl)?;
12251231

1226-
controller::pnl::settle_pnl(
1232+
let res = controller::pnl::settle_pnl(
12271233
*market_index,
12281234
user,
12291235
ctx.accounts.authority.key,
@@ -1235,8 +1241,14 @@ pub fn handle_settle_multiple_pnls<'c: 'info, 'info>(
12351241
state,
12361242
Some(meets_margin_requirement),
12371243
mode,
1238-
)
1239-
.map(|_| ErrorCode::InvalidOracleForSettlePnl)?;
1244+
);
1245+
if let Err(e) = res {
1246+
if e != ErrorCode::UserHasNoPositionInMarket {
1247+
return Err(e.into());
1248+
} else {
1249+
msg!("User has no position in market {}", market_index);
1250+
}
1251+
}
12401252
}
12411253

12421254
if state.builder_codes_enabled() || state.builder_referral_enabled() {

0 commit comments

Comments
 (0)