Skip to content

Trunk/swift #70

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

Merged
merged 9 commits into from
Nov 12, 2024
Merged
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
39 changes: 27 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,39 @@ fn main() {
fail_build();
}

// install the dylib to system path
let libffi_out_path =
drift_ffi_sys_crate.join(Path::new(&format!("target/{profile}/{LIB}.{lib_ext}")));
let output = std::process::Command::new("ln")
.args([
"-sf",
libffi_out_path.to_str().expect("ffi build path"),
"/usr/local/lib/",
])
.output()
.expect("install ok");

if !output.status.success() {
eprintln!(
"{LIB} could not be installed: {}",
String::from_utf8_lossy(output.stderr.as_slice())
);
}
// install the dylib to system path
let libffi_out_path =
drift_ffi_sys_crate.join(Path::new(&format!("target/{profile}/{LIB}.{lib_ext}")));

if let Ok(out_dir) = std::env::var("OUT_DIR") {
let _output = std::process::Command::new("cp")
.args([
libffi_out_path.to_str().expect("ffi build path"),
out_dir.as_str(),
])
.output()
.expect("install ok");
println!("{LIB}: searching for lib at: {out_dir}");
println!("cargo:rustc-link-search=native={out_dir}");
} else {
let _output = std::process::Command::new("ln")
.args([
"-sf",
libffi_out_path.to_str().expect("ffi build path"),
"/usr/local/lib/",
])
.output()
.expect("install ok");

println!("{LIB}: searching for lib at: /usr/local/lib");
println!("cargo:rustc-link-search=native=/usr/local/lib");
}
}

if let Ok(lib_path) = std::env::var("CARGO_DRIFT_FFI_PATH") {
Expand Down
11 changes: 4 additions & 7 deletions crates/src/dlob/dlob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ use crate::{
dlob_node::{create_node, get_order_signature, DLOBNode, DirectionalNode, Node, NodeType},
market::{get_node_subtype_and_type, Exchange, OpenOrders, SubType},
},
drift_idl::{
ffi::OraclePriceData,
types::{MarketType, Order, OrderStatus},
},
drift_idl::types::{MarketType, Order, OrderStatus},
ffi::OraclePriceData,
math::order::is_resting_limit_order,
usermap::UserMap,
utils::market_type_to_string,
usermap::GlobalUserMap as UserMap,
};

#[derive(Clone)]
Expand Down Expand Up @@ -80,7 +77,7 @@ impl DLOB {
}

pub fn insert_order(&self, order: &Order, user_account: Pubkey, slot: u64) {
let market_type = market_type_to_string(&order.market_type);
let market_type = order.market_type.as_str();
let market_index = order.market_index;

let (subtype, node_type) = get_node_subtype_and_type(order, slot);
Expand Down
24 changes: 9 additions & 15 deletions crates/src/dlob/dlob_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ use std::sync::Arc;
use tokio::sync::Mutex;

use crate::{
dlob::dlob::DLOB, event_emitter::EventEmitter, slot_subscriber::SlotSubscriber,
usermap::UserMap, SdkResult,
dlob::dlob::DLOB, slot_subscriber::SlotSubscriber, usermap::GlobalUserMap as UserMap, SdkResult,
};

pub struct DLOBBuilder {
slot_subscriber: SlotSubscriber,
usermap: UserMap,
rebuild_frequency: u64,
dlob: DLOB,
event_emitter: EventEmitter<DLOB>,
}

impl DLOBBuilder {
Expand All @@ -28,14 +26,13 @@ impl DLOBBuilder {
usermap,
rebuild_frequency,
dlob: DLOB::new(),
event_emitter: EventEmitter::new(),
}
}

pub async fn start_building(builder: Arc<Mutex<Self>>) -> SdkResult<()> {
let mut locked_builder = builder.lock().await;
let rebuild_frequency = locked_builder.rebuild_frequency;
locked_builder.slot_subscriber.subscribe().await?;
locked_builder.slot_subscriber.subscribe(move |_slot| {});
locked_builder.usermap.subscribe().await?;
drop(locked_builder);

Expand All @@ -54,10 +51,10 @@ impl DLOBBuilder {
Ok(())
}

pub fn build(&mut self) {
pub fn build(&mut self) -> &DLOB {
self.dlob
.build_from_usermap(&self.usermap, self.slot_subscriber.current_slot());
self.event_emitter.emit(self.dlob.clone());
&self.dlob
}

pub fn get_dlob(&self) -> DLOB {
Expand Down Expand Up @@ -91,14 +88,11 @@ mod tests {
);
let dlob_builder = DLOBBuilder::new(slot_subscriber, usermap, 5);

dlob_builder
.event_emitter
.clone()
.subscribe(DLOBBuilder::SUBSCRIPTION_ID, move |event| {
if let Some(_) = event.as_any().downcast_ref::<DLOB>() {
// dbg!("update received");
}
});
dlob_builder.subscribe(DLOBBuilder::SUBSCRIPTION_ID, move |event| {
if let Some(_) = event.as_any().downcast_ref::<DLOB>() {
// dbg!("update received");
}
});

DLOBBuilder::start_building(Arc::new(Mutex::new(dlob_builder)))
.await
Expand Down
5 changes: 1 addition & 4 deletions crates/src/dlob/dlob_node.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use solana_sdk::pubkey::Pubkey;

use crate::{
drift_idl::{ffi::OraclePriceData, types::Order},
math::order::get_limit_price,
};
use crate::{drift_idl::types::Order, ffi::OraclePriceData, math::order::get_limit_price};

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum NodeType {
Expand Down
9 changes: 8 additions & 1 deletion crates/src/dlob/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ impl Market {
}

pub(crate) fn get_node_subtype_and_type(order: &Order, slot: u64) -> (SubType, NodeType) {
let is_inactive_trigger_order = order.must_be_triggered() && !order.triggered();
// let is_inactive_trigger_order = order.must_be_triggered() && !order.triggered();
let is_inactive_trigger_order = match (order.order_type, order.trigger_condition) {
(
OrderType::TriggerMarket | OrderType::TriggerLimit,
OrderTriggerCondition::TriggeredAbove | OrderTriggerCondition::TriggeredBelow,
) => true,
_ => false,
};

let node_type = if is_inactive_trigger_order {
NodeType::Trigger
Expand Down
Loading
Loading