Skip to content

Commit 32e7915

Browse files
crispheaney0xbigz
andauthored
program: less order param sanitization for long tail perps (#1680)
* program: allow-auction-start-buffer-on-tail-mkt * fix test * cargo fmt -- * CHANGELOG --------- Co-authored-by: 0xbigz <[email protected]>
1 parent f0b7666 commit 32e7915

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Features
1111

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

1416
### Breaking

programs/drift/src/state/order_params.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,19 @@ impl OrderParams {
391391
)?;
392392
let current_start_price_offset = self.get_auction_start_price_offset(oracle_price)?;
393393
let current_end_price_offset = self.get_auction_end_price_offset(oracle_price)?;
394+
395+
let is_tail_mkt = !perp_market
396+
.contract_tier
397+
.is_as_safe_as_contract(&ContractTier::B);
398+
394399
match self.direction {
395400
PositionDirection::Long => {
396-
let long_start_threshold = if is_signed_msg {
401+
let long_start_threshold = if is_signed_msg || is_tail_mkt {
397402
new_start_price_offset.safe_add(oracle_price.abs().safe_div(1000)?)?
398403
} else {
399404
new_start_price_offset
400405
};
401-
let long_end_threshold = if is_signed_msg {
406+
let long_end_threshold = if is_signed_msg || is_tail_mkt {
402407
new_end_price_offset.safe_add(oracle_price.abs().safe_div(1000)?)?
403408
} else {
404409
new_end_price_offset
@@ -428,12 +433,12 @@ impl OrderParams {
428433
}
429434
}
430435
PositionDirection::Short => {
431-
let short_start_threshold = if is_signed_msg {
436+
let short_start_threshold = if is_signed_msg || is_tail_mkt {
432437
new_start_price_offset.safe_sub(oracle_price.abs().safe_div(1000)?)?
433438
} else {
434439
new_start_price_offset
435440
};
436-
let short_end_threshold = if is_signed_msg {
441+
let short_end_threshold = if is_signed_msg || is_tail_mkt {
437442
new_end_price_offset.safe_sub(oracle_price.abs().safe_div(1000)?)?
438443
} else {
439444
new_end_price_offset
@@ -889,7 +894,7 @@ fn get_auction_duration(
889894
Ok(percent_diff
890895
.safe_mul(slots_per_bp)?
891896
.safe_div_ceil(PERCENTAGE_PRECISION_U64 / 100)? // 1% = 60 slots
892-
.clamp(10, 180) as u8) // 180 slots max
897+
.clamp(1, 180) as u8) // 180 slots max
893898
}
894899

895900
#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)]

programs/drift/src/state/order_params/tests.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ mod get_auction_duration {
1111
let contract_tier = ContractTier::C;
1212

1313
let duration = get_auction_duration(price_diff, price, contract_tier).unwrap();
14-
assert_eq!(duration, 10);
14+
assert_eq!(duration, 1);
1515

1616
let price_diff = PRICE_PRECISION_U64 / 10;
1717
let price = 100 * PRICE_PRECISION_U64;
1818

1919
let duration = get_auction_duration(price_diff, price, contract_tier).unwrap();
20-
assert_eq!(duration, 10);
20+
assert_eq!(duration, 6);
2121

2222
let price_diff = PRICE_PRECISION_U64 / 2;
2323
let price = 100 * PRICE_PRECISION_U64;
@@ -168,6 +168,7 @@ mod update_perp_auction_params {
168168
amm.historical_oracle_data.last_oracle_price = oracle_price;
169169
let perp_market = PerpMarket {
170170
amm,
171+
contract_tier: ContractTier::A,
171172
..PerpMarket::default()
172173
};
173174

@@ -262,7 +263,7 @@ mod update_perp_auction_params {
262263
);
263264
assert_eq!(
264265
order_params_long_after_not_signed.auction_duration,
265-
Some(30)
266+
Some(31)
266267
);
267268
assert_eq!(sanitized, true);
268269
}
@@ -290,6 +291,7 @@ mod update_perp_auction_params {
290291
amm.historical_oracle_data.last_oracle_price = oracle_price;
291292
let perp_market = PerpMarket {
292293
amm,
294+
contract_tier: ContractTier::A,
293295
..PerpMarket::default()
294296
};
295297

@@ -387,7 +389,7 @@ mod update_perp_auction_params {
387389
);
388390
assert_eq!(
389391
order_params_long_after_not_signed.auction_duration,
390-
Some(30)
392+
Some(31)
391393
);
392394
assert_eq!(sanitized, true);
393395
}

0 commit comments

Comments
 (0)