Skip to content
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
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion programs/jit-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ default = []
anchor-lang = "0.29.0"
anchor-spl = "0.29.0"
bytemuck = { version = "1.4.0" }
drift = { git = "https://github.com/drift-labs/protocol-v2.git", rev = "3a7e11e2beea9118c35bcc83d80b75d91c69a196", features = ["cpi", "mainnet-beta"]}
drift = { git = "https://github.com/drift-labs/protocol-v2.git", rev = "607a687b853df54a79d490d296a6130a0f4fe691", features = ["cpi", "mainnet-beta"]}
static_assertions = "1.1.0"
solana-program = "1.16"
ahash = "=0.8.6"
27 changes: 25 additions & 2 deletions programs/jit-proxy/src/instructions/jit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anchor_lang::prelude::Pubkey;
use anchor_lang::prelude::*;
use drift::controller::position::PositionDirection;
use drift::cpi::accounts::{PlaceAndMake, PlaceAndMakeSignedMsg};
use drift::cpi::accounts::{PlaceAndMake, PlaceAndMakeSignedMsg, UpdateAMM};
use drift::error::DriftResult;
use drift::instructions::optional_accounts::{load_maps, AccountMaps};
use drift::math::casting::Cast;
Expand Down Expand Up @@ -58,6 +58,19 @@ pub fn jit<'c: 'info, 'info>(
oracle_map.get_price_data(&spot_market.oracle_id())?.price
};

if market_type == DriftMarketType::Perp {
let drift_program = ctx.accounts.drift_program.to_account_info().clone();
let cpi_accounts = UpdateAMM {
state: ctx.accounts.state.to_account_info().clone(),
authority: ctx.accounts.authority.to_account_info().clone(),
};

let cpi_context = CpiContext::new(drift_program, cpi_accounts)
.with_remaining_accounts(ctx.remaining_accounts.into());

drift::cpi::update_amms(cpi_context, vec![market_index])?;
}

let (order_params, taker_base_asset_amount_unfilled, taker_price, maker_price) = process_order(
&maker,
&perp_market_map,
Expand Down Expand Up @@ -141,6 +154,17 @@ pub fn jit_signed_msg<'c: 'info, 'info>(
None,
)?;

let drift_program = ctx.accounts.drift_program.to_account_info().clone();
let cpi_accounts = UpdateAMM {
state: ctx.accounts.state.to_account_info().clone(),
authority: ctx.accounts.authority.to_account_info().clone(),
};

let cpi_context = CpiContext::new(drift_program, cpi_accounts)
.with_remaining_accounts(ctx.remaining_accounts.into());

drift::cpi::update_amms(cpi_context, vec![taker_order.market_index])?;

let oracle_price = oracle_map
.get_price_data(
&perp_market_map
Expand Down Expand Up @@ -241,7 +265,6 @@ fn process_order(
let (tick_size, min_order_size, is_prediction_market) = if market_type == DriftMarketType::Perp
{
let perp_market = perp_market_map.get_ref(&market_index)?;

(
perp_market.amm.order_tick_size,
perp_market.amm.min_order_size,
Expand Down
Loading