Skip to content

Commit

Permalink
revert if order isn't filled
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Jan 23, 2024
1 parent 7a85ff4 commit 846c758
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions programs/jit-proxy/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ pub enum ErrorCode {
UnprofitableArb,
#[msg("PositionLimitBreached")]
PositionLimitBreached,
#[msg("NoFill")]
NoFill,
}
23 changes: 21 additions & 2 deletions programs/jit-proxy/src/instructions/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,26 @@ pub fn jit<'info>(ctx: Context<'_, '_, '_, 'info, Jit<'info>>, params: JitParams
drop(taker);
drop(maker);

place_and_make(ctx, params.taker_order_id, order_params)?;
place_and_make(&ctx, params.taker_order_id, order_params)?;

let taker = ctx.accounts.taker.load()?;

let taker_base_asset_amount_unfilled_after = match taker.get_order(params.taker_order_id) {
Some(order) => order.get_base_asset_amount_unfilled(None)?,
None => 0,
};

if taker_base_asset_amount_unfilled_after == taker_base_asset_amount_unfilled {
// taker order failed to fill
msg!("taker order failed to fill");
msg!(
"taker price = {} maker price ={} oracle price {}",
taker_price,
maker_price,
oracle_price
);
return Err(ErrorCode::NoFill.into());
}

Ok(())
}
Expand Down Expand Up @@ -331,7 +350,7 @@ mod tests {
}

fn place_and_make<'info>(
ctx: Context<'_, '_, '_, 'info, Jit<'info>>,
ctx: &Context<'_, '_, '_, 'info, Jit<'info>>,
taker_order_id: u32,
order_params: OrderParams,
) -> Result<()> {
Expand Down

0 comments on commit 846c758

Please sign in to comment.