Skip to content

Commit 58de186

Browse files
0xbigzcrispheaney
andauthored
program: simplify user can skip duration (#1668)
* program: simplify user can skip duration * update context * CHANGELOG * fix test * fix pmm tests --------- Co-authored-by: Chris Heaney <[email protected]>
1 parent f2d00f0 commit 58de186

File tree

5 files changed

+22
-54
lines changed

5 files changed

+22
-54
lines changed

CHANGELOG.md

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

1010
### Features
1111

12+
- program: simplify user can skip duration ([#1668](https://github.com/drift-labs/protocol-v2/pull/1668))
1213
- program: allow limit orders without auctions in swift ([#1661](https://github.com/drift-labs/protocol-v2/pull/1661))
1314

1415
### Fixes

programs/drift/src/controller/orders.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,15 +1095,7 @@ pub fn fill_perp_order(
10951095
amm_can_skip_duration =
10961096
market.can_skip_auction_duration(&state, amm_lp_allowed_to_jit_make)?;
10971097

1098-
user_can_skip_duration = user.can_skip_auction_duration(
1099-
user_stats,
1100-
order_auction_duration > 0,
1101-
fill_mode.is_ioc(),
1102-
order_direction,
1103-
order_price,
1104-
order_oracle_price_offset,
1105-
oracle_price_data.price,
1106-
)?;
1098+
user_can_skip_duration = user.can_skip_auction_duration(user_stats)?;
11071099

11081100
reserve_price_before = market.amm.reserve_price()?;
11091101
oracle_price = oracle_price_data.price;

programs/drift/src/controller/orders/tests.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ pub mod fill_order_protected_maker {
181181
let user_account_loader: AccountLoader<User> =
182182
AccountLoader::try_from(&user_account_info).unwrap();
183183

184-
create_anchor_account_info!(UserStats::default(), UserStats, user_stats_account_info);
184+
let mut taker_stats = UserStats {
185+
disable_update_perp_bid_ask_twap: true,
186+
..UserStats::default()
187+
};
188+
189+
create_anchor_account_info!(taker_stats, UserStats, user_stats_account_info);
185190
let user_stats_account_loader: AccountLoader<UserStats> =
186191
AccountLoader::try_from(&user_stats_account_info).unwrap();
187192

@@ -263,9 +268,18 @@ pub mod fill_order_protected_maker {
263268
.unwrap();
264269

265270
assert_eq!(base_asset_amount, 1000000000);
266-
assert_eq!(quote_asset_amount, 100_000_000 + 100_000_000 / 1000); // $100 + 10 bps
271+
assert_eq!(quote_asset_amount, 100_000_000); // $100 + 10 bps
267272

268273
// user exempt, no 10 bps applied for pmm
274+
let mut taker_stats = UserStats {
275+
disable_update_perp_bid_ask_twap: false,
276+
..UserStats::default()
277+
};
278+
279+
create_anchor_account_info!(taker_stats, UserStats, user_stats_account_info);
280+
let user_stats_account_loader: AccountLoader<UserStats> =
281+
AccountLoader::try_from(&user_stats_account_info).unwrap();
282+
269283
let mut user = User {
270284
// next_order_id: 10000000,
271285
next_order_id: 3000 - 2,

programs/drift/src/instructions/admin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5057,10 +5057,10 @@ pub struct AdminUpdatePerpMarketOracle<'info> {
50575057

50585058
#[derive(Accounts)]
50595059
pub struct AdminDisableBidAskTwapUpdate<'info> {
5060-
pub admin: Signer<'info>,
50615060
#[account(
5062-
has_one = admin
5061+
constraint = admin.key() == admin_hot_wallet::id() || admin.key() == state.admin
50635062
)]
5063+
pub admin: Signer<'info>,
50645064
pub state: Box<Account<'info, State>>,
50655065
#[account(mut)]
50665066
pub user_stats: AccountLoader<'info, UserStats>,

programs/drift/src/state/user.rs

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -612,51 +612,12 @@ impl User {
612612
Ok(true)
613613
}
614614

615-
pub fn can_skip_auction_duration(
616-
&self,
617-
user_stats: &UserStats,
618-
is_auction: bool,
619-
is_ioc: bool,
620-
order_direction: PositionDirection,
621-
order_price: u64,
622-
oracle_price_offset: i32,
623-
oracle_price: i64,
624-
) -> DriftResult<bool> {
625-
if self.next_order_id > 9000 {
626-
return Ok(false);
627-
}
628-
629-
if self.next_order_id > 1000 && (!is_auction || is_ioc) {
630-
return Ok(false);
631-
}
632-
633-
if user_stats.number_of_sub_accounts_created > 10 {
634-
return Ok(false);
635-
}
636-
615+
pub fn can_skip_auction_duration(&self, user_stats: &UserStats) -> DriftResult<bool> {
637616
if user_stats.disable_update_perp_bid_ask_twap {
638617
return Ok(false);
639618
}
640619

641-
return if order_price == 0 {
642-
Ok(true)
643-
} else {
644-
let mut order_offset: i64 = if order_price != 0 {
645-
order_price.cast::<i64>()?.safe_sub(oracle_price)?
646-
} else {
647-
oracle_price_offset.cast::<i64>()?
648-
};
649-
650-
if order_direction == PositionDirection::Short {
651-
order_offset = -order_offset;
652-
}
653-
654-
// worst price is 10 bps past oracle
655-
Ok(order_offset
656-
.safe_mul(PERCENTAGE_PRECISION_I64)?
657-
.safe_div(oracle_price)?
658-
>= 1000)
659-
};
620+
return Ok(true);
660621
}
661622
}
662623

0 commit comments

Comments
 (0)