Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

program: skip-isolated-tier-for-auction-start-end-override #958

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Features
- program: skip isolated tier for auction start/end sanitize ([#958](https://github.com/drift-labs/protocol-v2/pull/958))

### Fixes

Expand Down
64 changes: 33 additions & 31 deletions programs/drift/src/state/order_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,38 +207,40 @@

return Ok(());
}

let new_start_price_offset =
OrderParams::get_perp_baseline_start_price_offset(perp_market, self.direction)?;
match self.direction {
PositionDirection::Long => {
let current_start_price_offset =
self.get_auction_start_price_offset(oracle_price)?;
if current_start_price_offset > new_start_price_offset {
self.auction_start_price = if !is_market_order {
Some(new_start_price_offset)
} else {
Some(new_start_price_offset.safe_add(oracle_price)?)
};
msg!(
"Updating auction start price to {}",
self.auction_start_price.safe_unwrap()?
);
// only update auction start price if the contract tier isn't Isolated
if perp_market.contract_tier != ContractTier::Isolated {
let new_start_price_offset =
OrderParams::get_perp_baseline_start_price_offset(perp_market, self.direction)?;

Check warning on line 213 in programs/drift/src/state/order_params.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/state/order_params.rs#L213

Added line #L213 was not covered by tests
match self.direction {
PositionDirection::Long => {

Check warning on line 215 in programs/drift/src/state/order_params.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/state/order_params.rs#L215

Added line #L215 was not covered by tests
let current_start_price_offset =
self.get_auction_start_price_offset(oracle_price)?;

Check warning on line 217 in programs/drift/src/state/order_params.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/state/order_params.rs#L217

Added line #L217 was not covered by tests
if current_start_price_offset > new_start_price_offset {
self.auction_start_price = if !is_market_order {
Some(new_start_price_offset)
} else {
Some(new_start_price_offset.safe_add(oracle_price)?)
};
msg!(
"Updating auction start price to {}",
self.auction_start_price.safe_unwrap()?
);
}
}
}
PositionDirection::Short => {
let current_start_price_offset =
self.get_auction_start_price_offset(oracle_price)?;
if current_start_price_offset < new_start_price_offset {
self.auction_start_price = if !is_market_order {
Some(new_start_price_offset)
} else {
Some(new_start_price_offset.safe_add(oracle_price)?)
};
msg!(
"Updating auction start price to {}",
self.auction_start_price.safe_unwrap()?
);
PositionDirection::Short => {

Check warning on line 230 in programs/drift/src/state/order_params.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/state/order_params.rs#L230

Added line #L230 was not covered by tests
let current_start_price_offset =
self.get_auction_start_price_offset(oracle_price)?;

Check warning on line 232 in programs/drift/src/state/order_params.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/state/order_params.rs#L232

Added line #L232 was not covered by tests
if current_start_price_offset < new_start_price_offset {
self.auction_start_price = if !is_market_order {
Some(new_start_price_offset)

Check warning on line 235 in programs/drift/src/state/order_params.rs

View check run for this annotation

Codecov / codecov/patch

programs/drift/src/state/order_params.rs#L235

Added line #L235 was not covered by tests
} else {
Some(new_start_price_offset.safe_add(oracle_price)?)
};
msg!(
"Updating auction start price to {}",
self.auction_start_price.safe_unwrap()?
);
}
}
}
}
Expand Down
21 changes: 19 additions & 2 deletions programs/drift/src/state/order_params/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod update_perp_auction_params {
};

#[test]
fn test_limit() {
fn test_sanitize_limit() {
let oracle_price = 100 * PRICE_PRECISION_I64;
let mut amm = AMM {
base_asset_reserve: 100 * AMM_RESERVE_PRECISION,
Expand Down Expand Up @@ -237,7 +237,7 @@ mod update_perp_auction_params {
amm.last_bid_price_twap =
(amm.historical_oracle_data.last_oracle_price_twap as u64) + 17238;

let perp_market = PerpMarket {
let mut perp_market = PerpMarket {
amm,
contract_tier: ContractTier::B,
..PerpMarket::default()
Expand Down Expand Up @@ -280,6 +280,23 @@ mod update_perp_auction_params {
assert_ne!(order_params_before, order_params_after);
assert_eq!(order_params_after.auction_start_price.unwrap(), 99118879);

// skip for isolated tier
perp_market.contract_tier = ContractTier::Isolated;
let mut order_params_after = order_params_before;
order_params_after
.update_perp_auction_params(&perp_market, oracle_price)
.unwrap();
assert_eq!(
order_params_after.auction_start_price,
order_params_before.auction_start_price
);
assert_eq!(
order_params_after.auction_end_price,
order_params_before.auction_end_price
);

perp_market.contract_tier = ContractTier::B; // switch back

let order_params_before = OrderParams {
order_type: OrderType::Market,
direction: PositionDirection::Short,
Expand Down
Loading