Skip to content
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

frank/market & oracle maps #17

Merged
merged 21 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ spl-associated-token-account = "1.1.2"
anchor-client = "0.27.0"
anchor-lang = "*"
bytes = "*"
futures = "0.3.30"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<img height="120x" src="https://uploads-ssl.webflow.com/611580035ad59b20437eb024/616f97a42f5637c4517d0193_Logo%20(1)%20(1).png" />

<h1 style="margin-top:20px;">Drift Protocol v2 (Rust SDK)</h1>
<h1 style="margin-top:20px;">drift-rs</h1>

<p>
<a href="https://crates.io/crates/drift-sdk"><img alt="Crates.io" src="https://img.shields.io/crates/v/drift-sdk.img" /></a>
Expand All @@ -11,9 +11,9 @@
</p>
</div>

# Drift Protocol v2 (Rust SDK)
# drift-rs

Rust SDK for building off chain clients for interacting with the [Drift V2](https://github.com/drift-labs/protocol-v2) protocol.
Experimental, high performance Rust SDK for building off chain clients for interacting with the [Drift V2](https://github.com/drift-labs/protocol-v2) protocol.

## Setup

Expand Down
4 changes: 2 additions & 2 deletions src/dlob/dlob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::dlob::dlob_node::{
use crate::dlob::market::{get_order_lists, Exchange, Market, OpenOrders, SubType};
use crate::event_emitter::Event;
use crate::math::order::is_resting_limit_order;
use crate::usermap::Usermap;
use crate::usermap::UserMap;
use crate::utils::market_type_to_string;

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

pub fn build_from_usermap(&mut self, usermap: &Usermap, slot: u64) {
pub fn build_from_usermap(&mut self, usermap: &UserMap, slot: u64) {
usermap.usermap.iter().par_bridge().for_each(|user_ref| {
let user = user_ref.value();
let user_key = user_ref.key();
Expand Down
23 changes: 17 additions & 6 deletions src/dlob/dlob_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::{
dlob::dlob::DLOB,
event_emitter::{Event, EventEmitter},
slot_subscriber::SlotSubscriber,
usermap::Usermap,
usermap::UserMap,
SdkResult,
};

pub struct DLOBBuilder {
slot_subscriber: SlotSubscriber,
usermap: Usermap,
usermap: UserMap,
rebuild_frequency: u64,
dlob: DLOB,
event_emitter: EventEmitter,
Expand All @@ -17,7 +17,7 @@ pub struct DLOBBuilder {
impl DLOBBuilder {
pub fn new(
slot_subscriber: SlotSubscriber,
usermap: Usermap,
usermap: UserMap,
rebuild_frequency: u64,
) -> DLOBBuilder {
DLOBBuilder {
Expand Down Expand Up @@ -56,6 +56,7 @@ impl DLOBBuilder {
#[cfg(test)]
mod tests {
use super::*;
use crate::memcmp::get_user_with_order_filter;
use crate::utils::get_ws_url;
use solana_sdk::commitment_config::CommitmentConfig;
use solana_sdk::commitment_config::CommitmentLevel;
Expand All @@ -70,7 +71,12 @@ mod tests {
};

let slot_subscriber = SlotSubscriber::new(get_ws_url(&endpoint.clone()).unwrap());
let usermap = Usermap::new(commitment, endpoint, true);
let mut usermap = UserMap::new(
commitment,
endpoint,
true,
Some(vec![get_user_with_order_filter()]),
);
let mut dlob_builder = DLOBBuilder::new(slot_subscriber, usermap, 30);

dlob_builder
Expand All @@ -90,13 +96,18 @@ mod tests {
#[tokio::test]
#[cfg(rpc_tests)]
async fn test_build_time() {
let endpoint = "url".to_string();
let endpoint = "rpc".to_string();
let commitment = CommitmentConfig {
commitment: CommitmentLevel::Processed,
};

let mut slot_subscriber = SlotSubscriber::new(get_ws_url(&endpoint.clone()).unwrap());
let mut usermap = Usermap::new(commitment, endpoint, true);
let mut usermap = UserMap::new(
commitment,
endpoint,
true,
Some(vec![get_user_with_order_filter()]),
);
let _ = slot_subscriber.subscribe().await;
let _ = usermap.subscribe().await;

Expand Down
Loading
Loading