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: place order returns early if max ts breached #317

Merged
merged 3 commits into from
Jan 3, 2023
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 @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

program: place order returns early if max ts breached ([#317](https://github.com/drift-labs/protocol-v2/pull/317))
ts-sdk: batch getMultipleAccount calls in bulkAccountLoader ([#315](https://github.com/drift-labs/protocol-v2/pull/315))
program: add clippy deny for panic, expect and unwrap
program: add market index offset trait ([#287](https://github.com/drift-labs/protocol-v2/pull/287))
Expand Down
58 changes: 26 additions & 32 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ pub fn place_perp_order(
slot,
)?;

let max_ts = match params.max_ts {
Some(max_ts) => max_ts,
None => match params.order_type {
OrderType::Market | OrderType::Oracle => now.safe_add(30)?,
_ => 0_i64,
},
};

if max_ts != 0 && max_ts < now {
msg!("max_ts ({}) < now ({}), skipping order", max_ts, now);
return Ok(());
}

let new_order_index = user
.orders
.iter()
Expand Down Expand Up @@ -205,22 +218,6 @@ pub fn place_perp_order(
state.min_perp_auction_duration,
);

let max_ts = match params.max_ts {
Some(max_ts) => max_ts,
None => match params.order_type {
OrderType::Market | OrderType::Oracle => now.safe_add(30)?,
_ => 0_i64,
},
};

validate!(
max_ts == 0 || max_ts > now,
ErrorCode::InvalidOrderMaxTs,
"max_ts ({}) <= now ({})",
max_ts,
now
)?;

let new_order = Order {
status: OrderStatus::Open,
order_type: params.order_type,
Expand Down Expand Up @@ -2557,6 +2554,19 @@ pub fn place_spot_order(
slot,
)?;

let max_ts = match params.max_ts {
Some(max_ts) => max_ts,
None => match params.order_type {
OrderType::Market | OrderType::Oracle => now.safe_add(30)?,
_ => 0_i64,
},
};

if max_ts != 0 && max_ts < now {
msg!("max_ts ({}) < now ({}), skipping order", max_ts, now);
return Ok(());
}

let new_order_index = user
.orders
.iter()
Expand Down Expand Up @@ -2660,22 +2670,6 @@ pub fn place_spot_order(
.auction_duration
.unwrap_or(state.default_spot_auction_duration);

let max_ts = match params.max_ts {
Some(max_ts) => max_ts,
None => match params.order_type {
OrderType::Market | OrderType::Oracle => now.safe_add(30)?,
_ => 0_i64,
},
};

validate!(
max_ts == 0 || max_ts > now,
ErrorCode::InvalidOrderMaxTs,
"max_ts ({}) <= now ({})",
max_ts,
now
)?;

let new_order = Order {
status: OrderStatus::Open,
order_type: params.order_type,
Expand Down