Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- program: sanitize long tail perp market orders less frequently ([#1641](https://github.com/drift-labs/protocol-v2/pull/1641))

### Fixes

### Breaking
Expand Down
15 changes: 10 additions & 5 deletions programs/drift/src/state/order_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,19 @@ impl OrderParams {
)?;
let current_start_price_offset = self.get_auction_start_price_offset(oracle_price)?;
let current_end_price_offset = self.get_auction_end_price_offset(oracle_price)?;

let is_tail_mkt = !perp_market
.contract_tier
.is_as_safe_as_contract(&ContractTier::B);

match self.direction {
PositionDirection::Long => {
let long_start_threshold = if is_signed_msg {
let long_start_threshold = if is_signed_msg || is_tail_mkt {
new_start_price_offset.safe_add(oracle_price.abs().safe_div(1000)?)?
} else {
new_start_price_offset
};
let long_end_threshold = if is_signed_msg {
let long_end_threshold = if is_signed_msg || is_tail_mkt {
new_end_price_offset.safe_add(oracle_price.abs().safe_div(1000)?)?
} else {
new_end_price_offset
Expand Down Expand Up @@ -428,12 +433,12 @@ impl OrderParams {
}
}
PositionDirection::Short => {
let short_start_threshold = if is_signed_msg {
let short_start_threshold = if is_signed_msg || is_tail_mkt {
new_start_price_offset.safe_sub(oracle_price.abs().safe_div(1000)?)?
} else {
new_start_price_offset
};
let short_end_threshold = if is_signed_msg {
let short_end_threshold = if is_signed_msg || is_tail_mkt {
new_end_price_offset.safe_sub(oracle_price.abs().safe_div(1000)?)?
} else {
new_end_price_offset
Expand Down Expand Up @@ -889,7 +894,7 @@ fn get_auction_duration(
Ok(percent_diff
.safe_mul(slots_per_bp)?
.safe_div_ceil(PERCENTAGE_PRECISION_U64 / 100)? // 1% = 60 slots
.clamp(10, 180) as u8) // 180 slots max
.clamp(1, 180) as u8) // 180 slots max
}

#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)]
Expand Down
10 changes: 6 additions & 4 deletions programs/drift/src/state/order_params/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ mod get_auction_duration {
let contract_tier = ContractTier::C;

let duration = get_auction_duration(price_diff, price, contract_tier).unwrap();
assert_eq!(duration, 10);
assert_eq!(duration, 1);

let price_diff = PRICE_PRECISION_U64 / 10;
let price = 100 * PRICE_PRECISION_U64;

let duration = get_auction_duration(price_diff, price, contract_tier).unwrap();
assert_eq!(duration, 10);
assert_eq!(duration, 6);

let price_diff = PRICE_PRECISION_U64 / 2;
let price = 100 * PRICE_PRECISION_U64;
Expand Down Expand Up @@ -168,6 +168,7 @@ mod update_perp_auction_params {
amm.historical_oracle_data.last_oracle_price = oracle_price;
let perp_market = PerpMarket {
amm,
contract_tier: ContractTier::A,
..PerpMarket::default()
};

Expand Down Expand Up @@ -262,7 +263,7 @@ mod update_perp_auction_params {
);
assert_eq!(
order_params_long_after_not_signed.auction_duration,
Some(30)
Some(31)
);
assert_eq!(sanitized, true);
}
Expand Down Expand Up @@ -290,6 +291,7 @@ mod update_perp_auction_params {
amm.historical_oracle_data.last_oracle_price = oracle_price;
let perp_market = PerpMarket {
amm,
contract_tier: ContractTier::A,
..PerpMarket::default()
};

Expand Down Expand Up @@ -387,7 +389,7 @@ mod update_perp_auction_params {
);
assert_eq!(
order_params_long_after_not_signed.auction_duration,
Some(30)
Some(31)
);
assert_eq!(sanitized, true);
}
Expand Down
Loading