Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
NourAlharithi committed Jan 15, 2025
1 parent 58e91e9 commit 554df9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
32 changes: 13 additions & 19 deletions programs/jit-proxy/src/instructions/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ use drift::math::casting::Cast;
use drift::math::safe_math::SafeMath;
use drift::program::Drift;
use drift::state::order_params::OrderParams;
use drift::state::perp_market_map::PerpMarketMap;
use drift::state::perp_market_map::{get_writable_perp_market_set, PerpMarketMap};
use drift::state::spot_market_map::SpotMarketMap;
use drift::state::state::State;
use drift::state::swift_user::SwiftUserOrdersLoader;
use drift::state::user::Order;
use drift::state::user::{MarketType as DriftMarketType, OrderTriggerCondition, OrderType};
use drift::state::user::{User, UserStats};
use solana_program::sysvar::instructions::ID as IX_ID;
use std::collections::BTreeSet;

use crate::error::ErrorCode;
Expand Down Expand Up @@ -119,29 +118,29 @@ pub fn jit_swift<'c: 'info, 'info>(
let taker = ctx.accounts.taker.load()?;
let maker = ctx.accounts.user.load()?;

let taker_swift_account = ctx.accounts.taker_swift_user_orders.load()?;
let taker_order_id = taker_swift_account
.iter()
.find(|swift_order_id| swift_order_id.uuid == params.swift_order_uuid)
.ok_or(ErrorCode::SwiftOrderDoesNotExist)?
.order_id;
let taker_order = taker
.get_order(taker_order_id)
.ok_or(ErrorCode::TakerOrderNotFound)?;

let remaining_accounts_iter = &mut ctx.remaining_accounts.iter().peekable();
let AccountMaps {
perp_market_map,
spot_market_map,
mut oracle_map,
} = load_maps(
remaining_accounts_iter,
&BTreeSet::new(),
&get_writable_perp_market_set(taker_order.market_index),
&BTreeSet::new(),
slot,
None,
)?;

let taker_swift_account = ctx.accounts.taker_swift_user_orders.load()?;
let taker_order_id = taker_swift_account
.iter()
.find(|swift_order_id| swift_order_id.uuid == params.swift_order_uuid)
.ok_or(ErrorCode::SwiftOrderDoesNotExist)?
.order_id;
let taker_order = taker
.get_order(taker_order_id)
.ok_or(ErrorCode::TakerOrderNotFound)?;

let oracle_price = oracle_map
.get_price_data(
&perp_market_map
Expand Down Expand Up @@ -200,6 +199,7 @@ pub fn jit_swift<'c: 'info, 'info>(
Ok(())
}

#[inline(always)]
fn process_order(
maker: &User,
perp_market_map: &PerpMarketMap,
Expand Down Expand Up @@ -428,12 +428,6 @@ pub struct JitSwift<'info> {
pub taker_swift_user_orders: AccountInfo<'info>,
pub authority: Signer<'info>,
pub drift_program: Program<'info, Drift>,
/// CHECK: The address check is needed because otherwise
/// the supplied Sysvar could be anything else.
/// The Instruction Sysvar has not been implemented
/// in the Anchor framework yet, so this is the safe approach.
#[account(address = IX_ID)]
pub ix_sysvar: AccountInfo<'info>,
}

#[derive(Debug, Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq)]
Expand Down
7 changes: 1 addition & 6 deletions ts/sdk/src/jitProxyClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import {
UserAccount,
} from '@drift-labs/sdk';
import { IDL, JitProxy } from './types/jit_proxy';
import {
PublicKey,
SYSVAR_INSTRUCTIONS_PUBKEY,
TransactionInstruction,
} from '@solana/web3.js';
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
import { Program } from '@coral-xyz/anchor';
import { TxSigAndSlot } from '@drift-labs/sdk';
import { SignedSwiftOrderParams } from '@drift-labs/sdk/lib/node/swift/types';
Expand Down Expand Up @@ -245,7 +241,6 @@ export class JitProxyClient {
user: await this.driftClient.getUserAccountPublicKey(subAccountId),
userStats: this.driftClient.getUserStatsAccountPublicKey(),
driftProgram: this.driftClient.program.programId,
ixSysvar: SYSVAR_INSTRUCTIONS_PUBKEY,
})
.remainingAccounts(remainingAccounts)
.instruction();
Expand Down

0 comments on commit 554df9f

Please sign in to comment.