Skip to content

Commit

Permalink
program: allow user to settle realized pnl in reduce only market stat…
Browse files Browse the repository at this point in the history
…us (#954)

* bigz/settle-pnl-with-position-non-active-market

* only allow settle pnl on zero base position under reduce only/active status

* cargo fmt --

* update CHANGELOG.md
  • Loading branch information
0xbigz committed Mar 13, 2024
1 parent 957478f commit 50a0746
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Features
- program: allow user to settle realized pnl in reduce only market status ([#954](https://github.com/drift-labs/protocol-v2/pull/954))

### Fixes

Expand Down
24 changes: 16 additions & 8 deletions programs/drift/src/controller/pnl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,6 @@ pub fn settle_pnl(
}
}

validate!(
perp_market.status == MarketStatus::Active,
ErrorCode::InvalidMarketStatusToSettlePnl,
"Cannot settle pnl under current market = {} status",
market_index
)?;

validate!(
!perp_market.is_operation_paused(PerpOperation::SettlePnl),
ErrorCode::InvalidMarketStatusToSettlePnl,
Expand All @@ -189,7 +182,22 @@ pub fn settle_pnl(
validate!(
!perp_market.is_operation_paused(PerpOperation::SettlePnlWithPosition),
ErrorCode::InvalidMarketStatusToSettlePnl,
"Cannot settle pnl with position under current market = {} status",
"Cannot settle pnl with position under current market = {} operation paused",
market_index
)?;

validate!(
perp_market.status == MarketStatus::Active,
ErrorCode::InvalidMarketStatusToSettlePnl,
"Cannot settle pnl with position under non-Active current market = {} status",
market_index
)?;
} else {
validate!(
perp_market.status == MarketStatus::Active
|| perp_market.status == MarketStatus::ReduceOnly,
ErrorCode::InvalidMarketStatusToSettlePnl,
"Cannot settle pnl under current market = {} status (neither Active or ReduceOnly)",
market_index
)?;
}
Expand Down

0 comments on commit 50a0746

Please sign in to comment.