Skip to content

Commit

Permalink
Include necessary data for simulations within the auction json sent t…
Browse files Browse the repository at this point in the history
…o solvers
  • Loading branch information
m-lord-renkse committed Apr 15, 2024
1 parent aa5f448 commit a4aa3ed
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 33 deletions.
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.

24 changes: 2 additions & 22 deletions crates/driver/src/boundary/settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use {
OrderUid,
SellTokenSource,
},
signature::EcdsaSignature,
DomainSeparator,
},
shared::{
Expand Down Expand Up @@ -260,7 +259,7 @@ fn to_boundary_order(order: &competition::Order) -> Order {
is_liquidity_order: order.is_liquidity(),
full_app_data: Default::default(),
},
signature: to_boundary_signature(&order.signature),
signature: order.signature.to_boundary_signature(),
interactions: Interactions {
pre: order
.pre_interactions
Expand Down Expand Up @@ -321,7 +320,7 @@ fn to_boundary_jit_order(domain: &DomainSeparator, order: &order::Jit) -> Order
// encoding, so we just use the default values.
..Default::default()
};
let signature = to_boundary_signature(&order.signature);
let signature = order.signature.to_boundary_signature();

Order {
data,
Expand All @@ -331,25 +330,6 @@ fn to_boundary_jit_order(domain: &DomainSeparator, order: &order::Jit) -> Order
}
}

fn to_boundary_signature(signature: &order::Signature) -> model::signature::Signature {
// TODO Different signing schemes imply different sizes of signature data, which
// indicates that I'm missing an invariant in my types and I need to fix
// that PreSign, for example, carries no data. Everything should be
// reflected in the types!
match signature.scheme {
order::signature::Scheme::Eip712 => model::signature::Signature::Eip712(
EcdsaSignature::from_bytes(signature.data.0.as_slice().try_into().unwrap()),
),
order::signature::Scheme::EthSign => model::signature::Signature::EthSign(
EcdsaSignature::from_bytes(signature.data.0.as_slice().try_into().unwrap()),
),
order::signature::Scheme::Eip1271 => {
model::signature::Signature::Eip1271(signature.data.clone().into())
}
order::signature::Scheme::PreSign => model::signature::Signature::PreSign,
}
}

pub fn to_boundary_interaction(
slippage_context: &SlippageContext,
settlement_contract: eth::ContractAddress,
Expand Down
24 changes: 23 additions & 1 deletion crates/driver/src/domain/competition/order/signature.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{domain::eth, util::Bytes};
use {
crate::{domain::eth, util::Bytes},
model::signature::EcdsaSignature,
};

/// Signature over the order data.
#[derive(Debug, Clone)]
Expand All @@ -9,6 +12,25 @@ pub struct Signature {
pub signer: eth::Address,
}

impl Signature {
pub fn to_boundary_signature(&self) -> model::signature::Signature {
// TODO Different signing schemes imply different sizes of signature data, which
// indicates that I'm missing an invariant in my types and I need to fix
// that PreSign, for example, carries no data. Everything should be
// reflected in the types!
match self.scheme {
Scheme::Eip712 => model::signature::Signature::Eip712(EcdsaSignature::from_bytes(
self.data.0.as_slice().try_into().unwrap(),
)),
Scheme::EthSign => model::signature::Signature::EthSign(EcdsaSignature::from_bytes(
self.data.0.as_slice().try_into().unwrap(),
)),
Scheme::Eip1271 => model::signature::Signature::Eip1271(self.data.clone().into()),
Scheme::PreSign => model::signature::Signature::PreSign,
}
}
}

/// The scheme used for signing the order. This is used by the solver and
/// the protocol, the driver does not care about the details of signature
/// verification.
Expand Down
10 changes: 10 additions & 0 deletions crates/driver/src/domain/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ pub struct Interaction {
pub call_data: Bytes<Vec<u8>>,
}

impl Into<model::interaction::InteractionData> for Interaction {
fn into(self) -> model::interaction::InteractionData {
model::interaction::InteractionData {
target: self.target.into(),
value: self.value.into(),
call_data: self.call_data.into(),
}
}
}

/// A transaction ID, AKA transaction hash.
#[derive(Clone, Debug)]
pub struct TxId(pub H256);
Expand Down
49 changes: 41 additions & 8 deletions crates/driver/src/infra/solver/dto/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
order,
order::{fees, Side},
},
eth,
eth::{self},
liquidity,
},
infra::config::file::FeeHandler,
Expand All @@ -16,6 +16,8 @@ use {
},
},
indexmap::IndexMap,
model::{interaction::InteractionData, signature::Signature},
primitive_types::H160,
serde::Serialize,
serde_with::serde_as,
std::collections::{BTreeMap, HashMap},
Expand Down Expand Up @@ -113,16 +115,32 @@ impl Auction {
buy_token: available.buy.token.into(),
sell_amount: available.sell.amount.into(),
buy_amount: available.buy.amount.into(),
full_sell_amount: order.sell.amount.into(),
full_buy_amount: order.buy.amount.into(),
kind: match order.side {
competition::order::Side::Buy => Kind::Buy,
competition::order::Side::Sell => Kind::Sell,
Side::Buy => Kind::Buy,
Side::Sell => Kind::Sell,
},
receiver: order.receiver.map(Into::into),
owner: order.signature.signer.into(),
partially_fillable: order.is_partial(),
class: match order.kind {
competition::order::Kind::Market => Class::Market,
competition::order::Kind::Limit { .. } => Class::Limit,
competition::order::Kind::Liquidity => Class::Liquidity,
order::Kind::Market => Class::Market,
order::Kind::Limit { .. } => Class::Limit,
order::Kind::Liquidity => Class::Liquidity,
},
pre_interactions: order
.pre_interactions
.iter()
.cloned()
.map(Into::into)
.collect::<Vec<_>>(),
post_interactions: order
.post_interactions
.iter()
.cloned()
.map(Into::into)
.collect::<Vec<_>>(),
fee_policies: (fee_handler == FeeHandler::Solver).then_some(
order
.protocol_fees
Expand All @@ -131,6 +149,8 @@ impl Auction {
.map(Into::into)
.collect(),
),
signature: order.signature.to_boundary_signature(),
valid_to: order.valid_to.into(),
}
})
.collect(),
Expand Down Expand Up @@ -298,13 +318,26 @@ struct Order {
buy_token: eth::H160,
#[serde_as(as = "serialize::U256")]
sell_amount: eth::U256,
/// Original order `buy amount`
#[serde_as(as = "serialize::U256")]
full_buy_amount: eth::U256,
#[serde_as(as = "serialize::U256")]
buy_amount: eth::U256,
/// Original order `sell amount`
#[serde_as(as = "serialize::U256")]
full_sell_amount: eth::U256,
#[serde(skip_serializing_if = "Option::is_none")]
fee_policies: Option<Vec<FeePolicy>>,
valid_to: u32,
kind: Kind,
receiver: Option<H160>,
owner: H160,
partially_fillable: bool,
pre_interactions: Vec<InteractionData>,
post_interactions: Vec<InteractionData>,
class: Class,
#[serde(skip_serializing_if = "Option::is_none")]
fee_policies: Option<Vec<FeePolicy>>,
#[serde(flatten)]
signature: Signature,
}

#[derive(Debug, Serialize)]
Expand Down
3 changes: 2 additions & 1 deletion crates/solvers-dto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
model = { path = "../model" }
bigdecimal = { workspace = true, features = ["serde"] }
chrono = { workspace = true }
hex = { workspace = true }
number = { path = "../number"}
number = { path = "../number" }
serde = { workspace = true }
serde_with = { workspace = true }
web3 = { workspace = true }
13 changes: 12 additions & 1 deletion crates/solvers-dto/src/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,22 @@ pub struct Order {
#[serde_as(as = "HexOrDecimalU256")]
pub sell_amount: U256,
#[serde_as(as = "HexOrDecimalU256")]
pub full_sell_amount: U256,
#[serde_as(as = "HexOrDecimalU256")]
pub buy_amount: U256,
#[serde_as(as = "HexOrDecimalU256")]
pub full_buy_amount: U256,
pub fee_policies: Option<Vec<FeePolicy>>,
pub valid_to: u32,
pub kind: Kind,
pub receiver: Option<H160>,
pub owner: H160,
pub partially_fillable: bool,
pub pre_interactions: Vec<model::interaction::InteractionData>,
pub post_interactions: Vec<model::interaction::InteractionData>,
pub class: Class,
pub fee_policies: Option<Vec<FeePolicy>>,
#[serde(flatten)]
pub signature: model::signature::Signature,
}

#[derive(Debug, Deserialize)]
Expand Down

0 comments on commit a4aa3ed

Please sign in to comment.