Skip to content

Commit

Permalink
program: place order returns early if max ts breached (#317)
Browse files Browse the repository at this point in the history
* program: place order returns early if max ts breached

* update CHANGELOG

* tweak clause
  • Loading branch information
crispheaney committed Jan 3, 2023
1 parent c44af8a commit 99da841
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
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

0 comments on commit 99da841

Please sign in to comment.