Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
soundsonacid committed Mar 21, 2024
1 parent a3fff43 commit fa7dae7
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 49 deletions.
13 changes: 6 additions & 7 deletions src/dlob/dlob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use drift::state::user::{MarketType, Order};
use rayon::prelude::*;
use solana_sdk::pubkey::Pubkey;
use std::any::Any;
use std::cell::Cell;
use std::collections::{BinaryHeap, HashMap};
use std::collections::BinaryHeap;
use std::str::FromStr;
use std::sync::Arc;

Expand Down Expand Up @@ -99,14 +98,14 @@ impl DLOB {
.get_mut(&market_index)
.expect(format!("Market index {} not found", market_index).as_str());

let (order_list, subtype, node_type) = market.get_info_for_order_insert(&order, slot);
let (order_list, subtype, node_type) = market.get_info_for_order_insert(order, slot);

let node = create_node(node_type, order.clone(), user_account);
let node = create_node(node_type, *order, user_account);

if let Some(order_list) = order_list {
match subtype {
SubType::Bid => order_list.insert_bid(node.clone()),
SubType::Ask => order_list.insert_ask(node.clone()),
SubType::Bid => order_list.insert_bid(node),
SubType::Ask => order_list.insert_ask(node),
_ => {}
}
} else {
Expand All @@ -118,7 +117,7 @@ impl DLOB {
let order_signature = get_order_signature(order_id, user_account);
for order_list in get_order_lists(&self.exchange) {
if let Some(node) = order_list.get_node(&order_signature) {
return Some(node.get_order().clone());
return Some(*node.get_order());
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/dlob/dlob_builder.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use crate::{
dlob::dlob::DLOB,
event_emitter::{Event, EventEmitter},
slot_subscriber::SlotSubscriber,
usermap::UserMap,
SdkResult,
dlob::dlob::DLOB, event_emitter::EventEmitter, slot_subscriber::SlotSubscriber,
usermap::UserMap, SdkResult,
};

pub struct DLOBBuilder {
Expand Down
2 changes: 1 addition & 1 deletion src/dlob/dlob_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ pub(crate) fn create_node(node_type: NodeType, order: Order, user_account: Pubke
}

pub(crate) fn get_order_signature(order_id: u32, user_account: Pubkey) -> String {
format!("{}-{}", order_id, user_account.to_string())
format!("{}-{}", order_id, user_account)
}

#[cfg(test)]
Expand Down
8 changes: 3 additions & 5 deletions src/dlob/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ impl Market {
NodeType::Market
} else if order.oracle_price_offset != 0 {
NodeType::FloatingLimit
} else if is_resting_limit_order(order, slot) {
NodeType::RestingLimit
} else {
if is_resting_limit_order(order, slot) {
NodeType::RestingLimit
} else {
NodeType::TakingLimit
}
NodeType::TakingLimit
};

let order_list = match node_type {
Expand Down
10 changes: 5 additions & 5 deletions src/dlob/order_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ impl Orderlist {

pub fn insert_bid(&mut self, node: Node) {
let order_sig = get_order_signature(node.get_order().order_id, node.get_user_account());
self.order_sigs.insert(order_sig.clone(), node.clone());
self.order_sigs.insert(order_sig.clone(), node);
let directional = DirectionalNode::new(node, self.bid_sort_direction);
self.bids.push(directional);
}

pub fn insert_ask(&mut self, node: Node) {
let order_sig = get_order_signature(node.get_order().order_id, node.get_user_account());
self.order_sigs.insert(order_sig.clone(), node.clone());
self.order_sigs.insert(order_sig.clone(), node);
let directional = DirectionalNode::new(node, self.ask_sort_direction);
self.asks.push(directional);
}

pub fn get_best_bid(&mut self) -> Option<Node> {
if let Some(node) = self.bids.pop().map(|node| node.node.clone()) {
if let Some(node) = self.bids.pop().map(|node| node.node) {
let order_sig = get_order_signature(node.get_order().order_id, node.get_user_account());
if self.order_sigs.contains_key(&order_sig) {
self.order_sigs.remove(&order_sig);
Expand All @@ -50,7 +50,7 @@ impl Orderlist {
}

pub fn get_best_ask(&mut self) -> Option<Node> {
if let Some(node) = self.asks.pop().map(|node| node.node.clone()) {
if let Some(node) = self.asks.pop().map(|node| node.node) {
let order_sig = get_order_signature(node.get_order().order_id, node.get_user_account());
if self.order_sigs.contains_key(&order_sig) {
self.order_sigs.remove(&order_sig);
Expand All @@ -61,7 +61,7 @@ impl Orderlist {
}

pub fn get_node(&self, order_sig: &String) -> Option<Node> {
self.order_sigs.get(order_sig).map(|node| node.clone())
self.order_sigs.get(order_sig).map(|node| *node)
}

pub fn bids_empty(&self) -> bool {
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Drift SDK
use std::{borrow::Cow, sync::Arc, time::Duration};
use std::{borrow::Cow, rc::Rc, sync::Arc, time::Duration};

use anchor_lang::{AccountDeserialize, Discriminator, InstructionData, ToAccountMetas};
use async_utils::{retry_policy, spawn_retry_task};
Expand Down Expand Up @@ -668,7 +668,7 @@ pub struct DriftClientBackend<T: AccountProvider> {
program_data: ProgramData,
perp_market_map: MarketMap<PerpMarket>,
spot_market_map: MarketMap<SpotMarket>,
oracle_map: Arc<OracleMap>,
oracle_map: Rc<OracleMap>,
}

impl<T: AccountProvider> DriftClientBackend<T> {
Expand Down Expand Up @@ -709,7 +709,7 @@ impl<T: AccountProvider> DriftClientBackend<T> {
program_data: ProgramData::uninitialized(),
perp_market_map,
spot_market_map,
oracle_map: Arc::new(oracle_map),
oracle_map: Rc::new(oracle_map),
};

let lookup_table_address = market_lookup_table(context);
Expand Down Expand Up @@ -1831,7 +1831,7 @@ mod tests {
program_data: ProgramData::uninitialized(),
perp_market_map,
spot_market_map,
oracle_map: Arc::new(OracleMap::new(
oracle_map: Rc::new(OracleMap::new(
CommitmentConfig::processed(),
DEVNET_ENDPOINT.to_string(),
true,
Expand Down
2 changes: 1 addition & 1 deletion src/marketmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<T: AccountDeserialize + Clone + Send + Sync + Market + 'static> MarketMap<T
}

pub async fn subscribe(&self) -> SdkResult<()> {
if let Some(_) = self.sync_lock {
if self.sync_lock.is_some() {
self.sync().await?;
}

Expand Down
19 changes: 8 additions & 11 deletions src/oraclemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl OracleMap {
}

pub async fn subscribe(&self) -> SdkResult<()> {
if let Some(_) = self.sync_lock {
if self.sync_lock.is_some() {
self.sync().await?;
}

Expand Down Expand Up @@ -139,7 +139,7 @@ impl OracleMap {
update.data.rent_epoch,
);
match get_oracle_price(
&oracle_source.value(),
oracle_source.value(),
&oracle_account_info,
update.slot,
) {
Expand Down Expand Up @@ -235,8 +235,8 @@ impl OracleMap {

for (i, account) in response.value.iter().enumerate() {
if let Some(oracle_account) = account {
let oracle_info = oracle_infos[i].clone();
let oracle_pubkey = oracle_info.0.clone();
let oracle_info = oracle_infos[i];
let oracle_pubkey = oracle_info.0;
let mut oracle_components = (oracle_pubkey, oracle_account.clone());
let account_info = oracle_components.into_account_info();
let price_data = get_oracle_price(&oracle_info.1, &account_info, slot)
Expand Down Expand Up @@ -267,22 +267,19 @@ impl OracleMap {
}

pub fn current_perp_oracle(&self, market_index: u16) -> Option<Pubkey> {
self.perp_oracles.get(&market_index).map(|x| x.clone())
self.perp_oracles.get(&market_index).map(|x| *x)
}

pub fn current_spot_oracle(&self, market_index: u16) -> Option<Pubkey> {
self.spot_oracles.get(&market_index).map(|x| x.clone())
self.spot_oracles.get(&market_index).map(|x| *x)
}

pub fn get(&self, key: &str) -> Option<OraclePriceDataAndSlot> {
self.oraclemap.get(key).map(|v| v.clone())
self.oraclemap.get(key).map(|v| *v)
}

pub fn values(&self) -> Vec<OraclePriceData> {
self.oraclemap
.iter()
.map(|x| x.value().data.clone())
.collect()
self.oraclemap.iter().map(|x| x.value().data).collect()
}

pub async fn add_oracle(&self, oracle: Pubkey, source: OracleSource) -> SdkResult<()> {
Expand Down
6 changes: 3 additions & 3 deletions src/usermap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex};

use crate::event_emitter::EventEmitter;
use crate::memcmp::{get_non_idle_user_filter, get_user_filter, get_user_with_order_filter};
use crate::memcmp::{get_non_idle_user_filter, get_user_filter};
use crate::utils::{decode, get_ws_url};
use crate::websocket_program_account_subscriber::{
ProgramAccountUpdate, WebsocketProgramAccountOptions, WebsocketProgramAccountSubscriber,
Expand Down Expand Up @@ -71,7 +71,7 @@ impl UserMap {
}

pub async fn subscribe(&mut self) -> SdkResult<()> {
if let Some(_) = self.sync_lock {
if self.sync_lock.is_some() {
self.sync().await?;
}

Expand Down Expand Up @@ -130,7 +130,7 @@ impl UserMap {
.get_account_data(&Pubkey::from_str(pubkey).unwrap())
.await?;
let user = User::try_deserialize(&mut user_data.as_slice()).unwrap();
self.usermap.insert(pubkey.to_string(), user.clone());
self.usermap.insert(pubkey.to_string(), user);
Ok(self.get(pubkey).unwrap())
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/websocket_account_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,11 @@ impl WebsocketAccountSubscriber {
}
}
unsub = unsub_rx.recv() => {
match unsub {
Some(_) => {
log::debug!("unsubscribing");
account_unsubscribe().await;
break;
}
None => {}
if let Some(_) = unsub {
log::debug!("{}: Unsubscribing from account stream", susbscription_name);
account_unsubscribe().await;
break;

}
}
}
Expand Down

0 comments on commit fa7dae7

Please sign in to comment.