Skip to content

Cxp 13/fail on no fill place and take perp order #1215

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,6 @@ pub fn fill_perp_order(
) -> DriftResult<(u64, u64)> {
let now = clock.unix_timestamp;
let slot = clock.slot;

let filler_key = filler.key();
let user_key = user.key();
let user = &mut load_mut!(user)?;
Expand Down Expand Up @@ -1265,7 +1264,6 @@ pub fn fill_perp_order(
}

user.update_last_active_slot(slot);

Ok((base_asset_amount, quote_asset_amount))
}

Expand Down Expand Up @@ -1659,7 +1657,7 @@ fn fulfill_perp_order(
AMMLiquiditySplit::Shared,
fill_mode.is_liquidation(),
)?;

(fill_base_asset_amount, fill_quote_asset_amount)
}
PerpFulfillmentMethod::Match(maker_key, maker_order_index) => {
Expand Down
2 changes: 2 additions & 0 deletions programs/drift/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ pub enum ErrorCode {
LiquidationOrderFailedToFill,
#[msg("Invalid prediction market order")]
InvalidPredictionMarketOrder,
#[msg("Only partially completed")]
PartialFillError,
}

#[macro_export]
Expand Down
7 changes: 6 additions & 1 deletion programs/drift/src/instructions/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ pub fn handle_place_orders<'c: 'info, 'info>(
pub fn handle_place_and_take_perp_order<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, PlaceAndTake<'info>>,
params: OrderParams,
_maker_order_id: Option<u32>,
should_fail_on_partial_or_no_fill: Option<bool>,
) -> Result<()> {
let clock = Clock::get()?;
let state = &ctx.accounts.state;
Expand Down Expand Up @@ -1248,6 +1248,11 @@ pub fn handle_place_and_take_perp_order<'c: 'info, 'info>(
.iter()
.any(|order| order.order_id == order_id);

msg!("order_exists: {}", order_exists);
if Some(true) == should_fail_on_partial_or_no_fill && order_exists {
return Err(ErrorCode::PartialFillError.into());
}

if is_immediate_or_cancel && order_exists {
controller::orders::cancel_order_by_order_id(
order_id,
Expand Down
4 changes: 2 additions & 2 deletions programs/drift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ pub mod drift {
pub fn place_and_take_perp_order<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, PlaceAndTake<'info>>,
params: OrderParams,
maker_order_id: Option<u32>,
should_fail_on_partial_or_no_fill: Option<bool>,
) -> Result<()> {
handle_place_and_take_perp_order(ctx, params, maker_order_id)
handle_place_and_take_perp_order(ctx, params, should_fail_on_partial_or_no_fill)
}

pub fn place_and_make_perp_order<'c: 'info, 'info>(
Expand Down
8 changes: 7 additions & 1 deletion sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2893,6 +2893,7 @@ export class DriftClient {
baseAssetAmount: amount,
price: limitPrice,
},
false,
undefined,
undefined,
undefined,
Expand Down Expand Up @@ -4847,6 +4848,7 @@ export class DriftClient {

public async placeAndTakePerpOrder(
orderParams: OptionalOrderParams,
shouldFailOnPartialOrNoFill?: boolean,
makerInfo?: MakerInfo | MakerInfo[],
referrerInfo?: ReferrerInfo,
txParams?: TxParams,
Expand All @@ -4856,6 +4858,7 @@ export class DriftClient {
await this.buildTransaction(
await this.getPlaceAndTakePerpOrderIx(
orderParams,
shouldFailOnPartialOrNoFill,
makerInfo,
referrerInfo,
subAccountId
Expand Down Expand Up @@ -4903,6 +4906,7 @@ export class DriftClient {
const prepPlaceAndTakeTx = async () => {
const placeAndTakeIx = await this.getPlaceAndTakePerpOrderIx(
orderParams,
false,
makerInfo,
referrerInfo,
subAccountId
Expand Down Expand Up @@ -5092,6 +5096,7 @@ export class DriftClient {

public async getPlaceAndTakePerpOrderIx(
orderParams: OptionalOrderParams,
shouldFailOnPartialOrNoFill?: boolean,
makerInfo?: MakerInfo | MakerInfo[],
referrerInfo?: ReferrerInfo,
subAccountId?: number
Expand Down Expand Up @@ -5150,7 +5155,7 @@ export class DriftClient {

return await this.program.instruction.placeAndTakePerpOrder(
orderParams,
null,
shouldFailOnPartialOrNoFill || false,
{
accounts: {
state: await this.getStatePublicKey(),
Expand Down Expand Up @@ -5476,6 +5481,7 @@ export class DriftClient {
reduceOnly: true,
price: limitPrice,
},
false,
undefined,
undefined,
undefined,
Expand Down
Loading