From 3b245a38df6a1ca9956a292a1d6ae3e77ecf78fd Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 3 Oct 2024 20:28:48 +0100 Subject: [PATCH] Use DTO directly --- .../src/price_estimation/trade_verifier.rs | 6 +-- crates/shared/src/trade_finding.rs | 37 +++---------------- crates/shared/src/trade_finding/external.rs | 36 ++---------------- 3 files changed, 13 insertions(+), 66 deletions(-) diff --git a/crates/shared/src/price_estimation/trade_verifier.rs b/crates/shared/src/price_estimation/trade_verifier.rs index a197cd53cf..8236e8cb9f 100644 --- a/crates/shared/src/price_estimation/trade_verifier.rs +++ b/crates/shared/src/price_estimation/trade_verifier.rs @@ -5,7 +5,7 @@ use { code_simulation::CodeSimulating, encoded_settlement::{encode_trade, EncodedSettlement}, interaction::EncodedInteraction, - trade_finding::{Interaction, Side, Trade}, + trade_finding::{external::dto, Interaction, Trade}, }, anyhow::{Context, Result}, app_data::AppDataHash, @@ -425,8 +425,8 @@ fn encode_settlement( app_data: AppDataHash::from_str(&jit_order.app_data)?, fee_amount: 0.into(), kind: match &jit_order.side { - Side::Buy => OrderKind::Buy, - Side::Sell => OrderKind::Sell, + dto::Side::Buy => OrderKind::Buy, + dto::Side::Sell => OrderKind::Sell, }, partially_fillable: false, sell_token_balance: jit_order.sell_token_source, diff --git a/crates/shared/src/trade_finding.rs b/crates/shared/src/trade_finding.rs index 0ad8054725..462cf656bd 100644 --- a/crates/shared/src/trade_finding.rs +++ b/crates/shared/src/trade_finding.rs @@ -4,15 +4,14 @@ pub mod external; use { - crate::price_estimation::{PriceEstimationError, Query}, + crate::{ + price_estimation::{PriceEstimationError, Query}, + trade_finding::external::dto, + }, anyhow::Result, derivative::Derivative, ethcontract::{contract::MethodBuilder, tokens::Tokenize, web3::Transport, Bytes, H160, U256}, - model::{ - interaction::InteractionData, - order::{BuyTokenDestination, SellTokenSource}, - signature::SigningScheme, - }, + model::interaction::InteractionData, serde::Serialize, thiserror::Error, }; @@ -52,7 +51,7 @@ pub struct Trade { /// If this is set the quote verification need to use this as the /// `tx.origin` to make the quote pass the simulation. pub tx_origin: Option, - pub jit_orders: Vec, + pub jit_orders: Vec, } /// Data for a raw GPv2 interaction. @@ -95,30 +94,6 @@ impl From for Interaction { pub type EncodedInteraction = (H160, U256, Bytes>); -#[derive(Clone, Debug, Default, Eq, PartialEq)] -pub struct JitOrder { - pub buy_token: H160, - pub sell_token: H160, - pub sell_amount: U256, - pub buy_amount: U256, - pub executed_amount: U256, - pub receiver: H160, - pub valid_to: u32, - pub app_data: String, - pub side: Side, - pub sell_token_source: SellTokenSource, - pub buy_token_destination: BuyTokenDestination, - pub signature: Vec, - pub signing_scheme: SigningScheme, -} - -#[derive(Clone, Debug, Default, Eq, PartialEq)] -pub enum Side { - #[default] - Buy, - Sell, -} - #[derive(Debug, Error)] pub enum TradeError { #[error("No liquidity")] diff --git a/crates/shared/src/trade_finding/external.rs b/crates/shared/src/trade_finding/external.rs index 2160b4dee1..2a7c64167f 100644 --- a/crates/shared/src/trade_finding/external.rs +++ b/crates/shared/src/trade_finding/external.rs @@ -4,7 +4,7 @@ use { crate::{ price_estimation::{PriceEstimationError, Query}, request_sharing::RequestSharing, - trade_finding::{Interaction, JitOrder, Quote, Side, Trade, TradeError, TradeFinding}, + trade_finding::{Interaction, Quote, Trade, TradeError, TradeFinding}, }, anyhow::{anyhow, Context}, ethrpc::block_stream::CurrentBlockWatcher, @@ -146,35 +146,6 @@ impl From for Interaction { } } -impl From for JitOrder { - fn from(jit_order: dto::JitOrder) -> Self { - Self { - buy_token: jit_order.buy_token, - sell_token: jit_order.sell_token, - sell_amount: jit_order.sell_amount, - buy_amount: jit_order.buy_amount, - executed_amount: jit_order.executed_amount, - receiver: jit_order.receiver, - valid_to: jit_order.valid_to, - app_data: jit_order.app_data, - side: jit_order.side.into(), - sell_token_source: jit_order.sell_token_source, - buy_token_destination: jit_order.buy_token_destination, - signature: jit_order.signature, - signing_scheme: jit_order.signing_scheme, - } - } -} - -impl From for Side { - fn from(side: dto::Side) -> Self { - match side { - dto::Side::Buy => Self::Buy, - dto::Side::Sell => Self::Sell, - } - } -} - #[async_trait::async_trait] impl TradeFinding for ExternalTradeFinder { async fn get_quote(&self, query: &Query) -> Result { @@ -251,7 +222,7 @@ pub(crate) mod dto { } #[serde_as] - #[derive(Clone, Debug, Deserialize)] + #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize)] #[serde(rename_all = "camelCase")] #[allow(unused)] pub struct JitOrder { @@ -283,9 +254,10 @@ pub(crate) mod dto { } #[serde_as] - #[derive(Clone, Debug, Deserialize)] + #[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize)] #[serde(rename_all = "camelCase")] pub enum Side { + #[default] Buy, Sell, }