Skip to content

Commit

Permalink
program: skip liq perp oracle twap check if market is in settlement (#…
Browse files Browse the repository at this point in the history
…1406)

* program: skip liq perp oracle twap check if market is in settlement

* CHANGELOG

* fmt --
  • Loading branch information
crispheaney authored Jan 2, 2025
1 parent 41f8743 commit f54daa2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixes

- program: skip liq perp oracle twap check if market is in settlement ([#1406](https://github.com/drift-labs/protocol-v2/pull/1406))

### Breaking

## [2.104.0] - 2024-12-23
Expand Down
31 changes: 18 additions & 13 deletions programs/drift/src/controller/liquidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,20 +309,25 @@ pub fn liquidate_perp(
"liquidator_max_base_asset_amount must be greater or equal to the step size",
)?;

let oracle_price_too_divergent = is_oracle_too_divergent_with_twap_5min(
oracle_price,
perp_market_map
.get_ref(&market_index)?
.amm
.historical_oracle_data
.last_oracle_price_twap_5min,
state
.oracle_guard_rails
.max_oracle_twap_5min_percent_divergence()
.cast()?,
)?;
{
let perp_market = perp_market_map.get_ref(&market_index)?;

if perp_market.status != MarketStatus::Settlement {
let oracle_price_too_divergent = is_oracle_too_divergent_with_twap_5min(
oracle_price,
perp_market
.amm
.historical_oracle_data
.last_oracle_price_twap_5min,
state
.oracle_guard_rails
.max_oracle_twap_5min_percent_divergence()
.cast()?,
)?;

validate!(!oracle_price_too_divergent, ErrorCode::PriceBandsBreached)?;
validate!(!oracle_price_too_divergent, ErrorCode::PriceBandsBreached)?;
}
}

let user_base_asset_amount = user.perp_positions[position_index]
.base_asset_amount
Expand Down

0 comments on commit f54daa2

Please sign in to comment.