Skip to content

Commit

Permalink
Use Rust 1.62 features (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkgnosis authored Jul 20, 2022
1 parent db6a768 commit 0a9dcf4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 36 deletions.
33 changes: 12 additions & 21 deletions crates/model/src/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,13 @@ impl<'de> Deserialize<'de> for OrderUid {
}
}

#[derive(Eq, PartialEq, Clone, Copy, Debug, Deserialize, Serialize, Hash, enum_utils::FromStr)]
#[derive(
Eq, PartialEq, Clone, Copy, Debug, Default, Deserialize, Serialize, Hash, enum_utils::FromStr,
)]
#[enumeration(case_insensitive)]
#[serde(rename_all = "lowercase")]
pub enum OrderKind {
#[default]
Buy,
Sell,
}
Expand All @@ -616,48 +619,36 @@ impl OrderKind {
}
}

impl Default for OrderKind {
fn default() -> Self {
Self::Buy
}
}

/// Source from which the sellAmount should be drawn upon order fulfilment
#[derive(Eq, PartialEq, Clone, Copy, Debug, Deserialize, Serialize, Hash, enum_utils::FromStr)]
#[derive(
Eq, PartialEq, Clone, Copy, Debug, Default, Deserialize, Serialize, Hash, enum_utils::FromStr,
)]
#[enumeration(case_insensitive)]
#[serde(rename_all = "snake_case")]
pub enum SellTokenSource {
/// Direct ERC20 allowances to the Vault relayer contract
#[default]
Erc20,
/// ERC20 allowances to the Vault with GPv2 relayer approval
Internal,
/// Internal balances to the Vault with GPv2 relayer approval
External,
}

impl Default for SellTokenSource {
fn default() -> Self {
Self::Erc20
}
}

/// Destination for which the buyAmount should be transferred to order's receiver to upon fulfilment
#[derive(Eq, PartialEq, Clone, Copy, Debug, Deserialize, Serialize, Hash, enum_utils::FromStr)]
#[derive(
Eq, PartialEq, Clone, Copy, Debug, Default, Deserialize, Serialize, Hash, enum_utils::FromStr,
)]
#[enumeration(case_insensitive)]
#[serde(rename_all = "snake_case")]
pub enum BuyTokenDestination {
/// Pay trade proceeds as an ERC20 token transfer
#[default]
Erc20,
/// Pay trade proceeds as a Vault internal balance transfer
Internal,
}

impl Default for BuyTokenDestination {
fn default() -> Self {
Self::Erc20
}
}

pub fn debug_app_data(
app_data: &[u8; 32],
formatter: &mut std::fmt::Formatter,
Expand Down
9 changes: 2 additions & 7 deletions crates/model/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ use chrono::{DateTime, Utc};
use primitive_types::{H160, U256};
use serde::{de, ser::SerializeStruct as _, Deserialize, Deserializer, Serialize, Serializer};

#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq)]
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum PriceQuality {
Fast,
#[default]
Optimal,
}

impl Default for PriceQuality {
fn default() -> Self {
Self::Optimal
}
}

/// The order parameters to quote a price and fee for.
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
Expand Down
9 changes: 2 additions & 7 deletions crates/model/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@ use web3::{
types::Recovery,
};

#[derive(Eq, PartialEq, Clone, Copy, Debug, Deserialize, Serialize, Hash)]
#[derive(Eq, PartialEq, Clone, Copy, Debug, Default, Deserialize, Serialize, Hash)]
#[serde(rename_all = "lowercase")]
pub enum SigningScheme {
#[default]
Eip712,
EthSign,
Eip1271,
PreSign,
}

impl Default for SigningScheme {
fn default() -> Self {
SigningScheme::Eip712
}
}

#[derive(Eq, PartialEq, Clone, Deserialize, Serialize, Hash)]
#[serde(into = "JsonSignature", try_from = "JsonSignature")]
pub enum Signature {
Expand Down
2 changes: 1 addition & 1 deletion crates/solver/src/liquidity/zeroex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn get_useful_orders(order_buckets: OrderBuckets, orders_per_type: usize) -> Vec
orders.sort_by(|order_1, order_2| {
let price_1 = order_1.order.maker_amount as f64 / order_1.order.taker_amount as f64;
let price_2 = order_2.order.maker_amount as f64 / order_2.order.taker_amount as f64;
price_1.partial_cmp(&price_2).unwrap()
price_1.total_cmp(&price_2)
});
filtered_zeroex_orders.extend(orders.drain(orders.len() - orders_per_type..));

Expand Down

0 comments on commit 0a9dcf4

Please sign in to comment.