Skip to content

Commit

Permalink
Nick's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
josojo committed Oct 18, 2022
1 parent 7e783c9 commit 2a2e11f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 43 deletions.
22 changes: 2 additions & 20 deletions crates/shared/src/interaction.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use ethcontract::Bytes;
use model::interaction::InteractionData as InteractionDataFromOrder;
use primitive_types::{H160, U256};
use serde::{Deserialize, Serialize};

pub trait Interaction: std::fmt::Debug + Send + Sync {
// TODO: not sure if this should return a result.
Expand All @@ -23,24 +21,8 @@ impl Interaction for EncodedInteraction {
}
}

#[derive(Eq, PartialEq, Clone, Debug, Hash, Default, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InteractionData {
pub to: H160,
pub value: U256,
pub call_data: Vec<u8>,
}

impl Interaction for InteractionData {
impl Interaction for model::interaction::InteractionData {
fn encode(&self) -> Vec<EncodedInteraction> {
vec![(self.to, self.value, Bytes(self.call_data.clone()))]
}
}

pub fn interaction_data_from_order(interaction: InteractionDataFromOrder) -> InteractionData {
InteractionData {
to: interaction.target,
value: interaction.value,
call_data: interaction.call_data,
vec![(self.target, self.value, Bytes(self.call_data.clone()))]
}
}
32 changes: 9 additions & 23 deletions crates/solver/src/settlement/settlement_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use crate::{
};
use anyhow::{bail, ensure, Context as _, Result};
use itertools::Itertools;
use model::order::{Order, OrderKind};
use model::{
interaction::InteractionData,
order::{Order, OrderKind},
};
use num::{BigRational, One};
use number_conversions::big_rational_to_u256;
use primitive_types::{H160, U256};
use shared::{
conversions::U256Ext,
interaction::{interaction_data_from_order, Interaction, InteractionData},
};
use shared::{conversions::U256Ext, interaction::Interaction};
use std::{
collections::{hash_map::Entry, HashMap, HashSet},
iter,
Expand Down Expand Up @@ -165,15 +165,8 @@ impl SettlementEncoder {
.executed_amounts(*sell_price, *buy_price)
.context("impossible trade execution")?;

self.pre_interactions.append(
&mut order
.interactions
.pre
.into_iter()
.map(interaction_data_from_order)
.map(Arc::new)
.collect(),
);
self.pre_interactions
.append(&mut order.interactions.pre.into_iter().map(Arc::new).collect());
self.order_trades.push(order_trade);
Ok(execution)
}
Expand Down Expand Up @@ -243,15 +236,8 @@ impl SettlementEncoder {
.executed_amounts(*sell_price, buy_price)
.context("impossible trade execution")?;

self.pre_interactions.append(
&mut order
.interactions
.pre
.into_iter()
.map(interaction_data_from_order)
.map(Arc::new)
.collect(),
);
self.pre_interactions
.append(&mut order.interactions.pre.into_iter().map(Arc::new).collect());
self.liquidity_order_trades.push(liquidity_order_trade);
Ok(execution)
}
Expand Down

0 comments on commit 2a2e11f

Please sign in to comment.