Skip to content

Commit

Permalink
Cleanup order class in autopilot (#2961)
Browse files Browse the repository at this point in the history
# Description
For autopilot domain, all orders are limit orders and therefore
OrderClass is not needed.

# Changes
<!-- List of detailed changes (how the change is accomplished) -->

- [ ] ...
- [ ] ...

## How to test
<!--- Include details of how to test your changes, including any
pre-requisites. If no unit tests are included, please explain why and
how to test manually
1.
2.
3.
-->

<!--
## Related Issues

Fixes #
-->
  • Loading branch information
sunce86 authored Sep 9, 2024
1 parent 067f45f commit 5f442ee
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 60 deletions.
1 change: 0 additions & 1 deletion crates/autopilot/src/boundary/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub fn to_domain(
.collect(),
sell_token_balance: order.data.sell_token_balance.into(),
buy_token_balance: order.data.buy_token_balance.into(),
class: order.metadata.class.into(),
app_data: order.data.app_data.into(),
signature: order.signature.into(),
quote,
Expand Down
20 changes: 0 additions & 20 deletions crates/autopilot/src/domain/auction/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub struct Order {
pub buy: eth::Asset,
pub protocol_fees: Vec<fee::Policy>,
pub side: Side,
pub class: Class,
pub created: u32,
pub valid_to: u32,
pub receiver: Option<eth::Address>,
Expand All @@ -32,18 +31,6 @@ pub struct Order {
pub quote: Option<domain::Quote>,
}

impl Order {
pub fn is_limit_order(&self) -> bool {
matches!(self.class, Class::Limit)
}

/// For some orders the protocol doesn't precompute a fee. Instead solvers
/// are supposed to compute a reasonable fee themselves.
pub fn solver_determines_fee(&self) -> bool {
self.is_limit_order()
}
}

// uid as 56 bytes: 32 for orderDigest, 20 for ownerAddress and 4 for validTo
#[derive(Copy, Clone, PartialEq, Hash, Eq)]
pub struct OrderUid(pub [u8; 56]);
Expand Down Expand Up @@ -87,13 +74,6 @@ pub enum Side {
Sell,
}

#[derive(Clone, Debug, PartialEq)]
pub enum Class {
Market,
Limit,
Liquidity,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Interaction {
pub target: H160,
Expand Down
23 changes: 1 addition & 22 deletions crates/autopilot/src/infra/persistence/dto/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn from_domain(order: domain::Order) -> Order {
.collect(),
sell_token_balance: order.sell_token_balance.into(),
buy_token_balance: order.buy_token_balance.into(),
class: order.class.into(),
class: boundary::OrderClass::Limit,
app_data: order.app_data.into(),
signature: order.signature.into(),
quote: order.quote.map(Into::into),
Expand Down Expand Up @@ -99,7 +99,6 @@ pub fn to_domain(order: Order) -> domain::Order {
.collect(),
sell_token_balance: order.sell_token_balance.into(),
buy_token_balance: order.buy_token_balance.into(),
class: order.class.into(),
app_data: order.app_data.into(),
signature: order.signature.into(),
quote: order.quote.map(|q| q.to_domain(order.uid.into())),
Expand Down Expand Up @@ -136,26 +135,6 @@ impl From<boundary::OrderKind> for domain::auction::order::Side {
}
}

impl From<domain::auction::order::Class> for boundary::OrderClass {
fn from(class: domain::auction::order::Class) -> Self {
match class {
domain::auction::order::Class::Limit => Self::Limit,
domain::auction::order::Class::Market => Self::Market,
domain::auction::order::Class::Liquidity => Self::Liquidity,
}
}
}

impl From<boundary::OrderClass> for domain::auction::order::Class {
fn from(class: boundary::OrderClass) -> Self {
match class {
boundary::OrderClass::Limit => Self::Limit,
boundary::OrderClass::Market => Self::Market,
boundary::OrderClass::Liquidity => Self::Liquidity,
}
}
}

impl From<domain::auction::order::Interaction> for boundary::InteractionData {
fn from(interaction: domain::auction::order::Interaction) -> Self {
Self {
Expand Down
7 changes: 1 addition & 6 deletions crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use {
database::competition::Competition,
domain::{
self,
auction::order::Class,
competition::{self, SolutionError, TradedAmounts},
OrderUid,
},
Expand Down Expand Up @@ -169,11 +168,7 @@ impl RunLoop {
}
};

if auction.orders.iter().all(|order| match order.class {
Class::Market => false,
Class::Liquidity => true,
Class::Limit => false,
}) {
if auction.orders.is_empty() {
// Updating liveness probe to not report unhealthy due to this optimization
self.liveness.auction();
tracing::debug!("skipping empty auction");
Expand Down
13 changes: 2 additions & 11 deletions crates/autopilot/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use {
crate::{
arguments::RunLoopMode,
domain::{self, auction::order::Class},
domain,
infra::{
self,
solvers::dto::{reveal, solve},
Expand Down Expand Up @@ -102,16 +102,7 @@ impl RunLoop {
return None;
}

if auction
.auction
.orders
.iter()
.all(|order| match order.class {
Class::Market => false,
Class::Liquidity => true,
Class::Limit => false,
})
{
if auction.auction.orders.is_empty() {
tracing::trace!("skipping empty auction");
return None;
}
Expand Down

0 comments on commit 5f442ee

Please sign in to comment.