Skip to content

Commit

Permalink
bigz/improve-oracle-validity-check-for-order-price (#919)
Browse files Browse the repository at this point in the history
* bigz/improve-oracle-validity-check-for-order-price

* simplify

* cargo fmt --

* update changelog
  • Loading branch information
0xbigz authored and crispheaney committed Feb 28, 2024
1 parent 200bccd commit c7580ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 1 addition & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- program: add pause operation for liquidation ([#880](https://github.com/drift-labs/protocol-v2/pull/880))

### Fixes

- program: fix entry/breakeven price calculations for lp remainders ([#864](https://github.com/drift-labs/protocol-v2/pull/864))
- program: handle derisk lp when orders array full ([#899](https://github.com/drift-labs/protocol-v2/pull/899))
- program: invalid borrow in get_referrer_info when maker is refferer ([#900](https://github.com/drift-labs/protocol-v2/pull/900))
- program: don't block oracle order prices when theres solely InsufficientDataPoints ([#919](https://github.com/drift-labs/protocol-v2/pull/919))

### Breaking

Expand Down
11 changes: 6 additions & 5 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,11 +997,12 @@ pub fn fill_perp_order(
}

// allow oracle price to be used to calculate limit price if it's valid or stale for amm
let valid_oracle_price = if is_oracle_valid || oracle_validity == OracleValidity::StaleForAMM {
Some(oracle_price)
} else {
None
};
let valid_oracle_price =
if is_oracle_valid_for_action(oracle_validity, Some(DriftAction::OracleOrderPrice))? {
Some(oracle_price)
} else {
None
};

let is_filler_taker = user_key == filler_key;
let is_filler_maker = makers_and_referrer.0.contains_key(&filler_key);
Expand Down
9 changes: 9 additions & 0 deletions programs/drift/src/math/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub enum DriftAction {
MarginCalc,
UpdateTwap,
UpdateAMMCurve,
OracleOrderPrice,
}

pub fn is_oracle_valid_for_action(
Expand All @@ -63,6 +64,14 @@ pub fn is_oracle_valid_for_action(
OracleValidity::Valid | OracleValidity::StaleForAMM
)
}
DriftAction::OracleOrderPrice => {
matches!(
oracle_validity,
OracleValidity::Valid
| OracleValidity::StaleForAMM
| OracleValidity::InsufficientDataPoints
)
}
DriftAction::MarginCalc => !matches!(
oracle_validity,
OracleValidity::Invalid
Expand Down

0 comments on commit c7580ab

Please sign in to comment.