Skip to content

Commit ebe72a5

Browse files
committed
better CU opt for amm_can_fill_order
1 parent 279d10c commit ebe72a5

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

programs/drift/src/state/perp_market.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,13 @@ impl PerpMarket {
868868
user_can_skip_auction_duration: bool,
869869
mm_oracle_price_data: &MMOraclePriceData,
870870
) -> DriftResult<bool> {
871-
let not_paused = !self.is_operation_paused(PerpOperation::AmmFill);
872-
let no_drawdown = !self.has_too_much_drawdown()?;
871+
if self.is_operation_paused(PerpOperation::AmmFill) {
872+
return Ok(false);
873+
}
874+
875+
if self.has_too_much_drawdown()? {
876+
return Ok(false);
877+
}
873878

874879
let min_auction_duration =
875880
self.get_min_perp_auction_duration(state.min_perp_auction_duration);
@@ -885,6 +890,11 @@ impl PerpMarket {
885890
true
886891
};
887892

893+
if !mm_oracle_not_too_volatile {
894+
msg!("AMM cannot fill order: MM oracle too volatile compared to exchange oracle");
895+
return Ok(false);
896+
}
897+
888898
// Determine if order is fillable with low risk
889899
let safe_oracle_price_data = mm_oracle_price_data.get_safe_oracle_price_data();
890900
let order_is_low_risk_for_amm = order.is_low_risk_for_amm(
@@ -919,7 +929,7 @@ impl PerpMarket {
919929
&& user_can_skip_auction_duration
920930
};
921931

922-
Ok(not_paused && no_drawdown && mm_oracle_not_too_volatile && can_fill_order)
932+
Ok(can_fill_order)
923933
}
924934
}
925935

0 commit comments

Comments
 (0)