Skip to content

Commit 1015c1b

Browse files
committed
Merge branch 'orderbook/volume-fees' into protocol-fees-timestamp
2 parents ff799ff + ea0c5f7 commit 1015c1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+420
-225
lines changed

crates/autopilot/src/arguments.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ pub struct Arguments {
256256
#[clap(long, env, default_value = "false", action = clap::ArgAction::Set)]
257257
pub disable_order_filtering: bool,
258258

259+
// Filter out orders that have not been presigned even if disable_order_filtering is turned on.
260+
#[clap(long, env, default_value = "false", action = clap::ArgAction::Set)]
261+
pub force_presign_order_filtering: bool,
262+
259263
/// Enables the usage of leader lock in the database
260264
/// The second instance of autopilot will act as a follower
261265
/// and not cut any auctions.
@@ -392,6 +396,7 @@ impl std::fmt::Display for Arguments {
392396
db_based_solver_participation_guard,
393397
disable_order_filtering,
394398
enable_leader_lock,
399+
force_presign_order_filtering,
395400
} = self;
396401

397402
write!(f, "{shared}")?;
@@ -463,6 +468,10 @@ impl std::fmt::Display for Arguments {
463468
"db_based_solver_participation_guard: {db_based_solver_participation_guard:?}"
464469
)?;
465470
writeln!(f, "disable_order_filtering: {disable_order_filtering}")?;
471+
writeln!(
472+
f,
473+
"force_presign_order_filtering: {force_presign_order_filtering}"
474+
)?;
466475
writeln!(f, "enable_leader_lock: {enable_leader_lock}")?;
467476
Ok(())
468477
}

crates/autopilot/src/domain/fee/mod.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ use {
1212
boundary::{self},
1313
domain::{self, eth},
1414
},
15+
alloy::primitives::{Address, U256},
1516
app_data::Validator,
1617
chrono::{DateTime, Utc},
1718
derive_more::Into,
18-
primitive_types::{H160, U256},
19+
ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy},
20+
primitive_types::H160,
1921
rust_decimal::Decimal,
2022
std::{collections::HashSet, str::FromStr},
2123
};
@@ -205,10 +207,10 @@ impl ProtocolFees {
205207
factor,
206208
max_volume_factor,
207209
quote: Quote {
208-
sell_amount: quote.sell_amount.into(),
209-
buy_amount: quote.buy_amount.into(),
210-
fee: quote.fee.into(),
211-
solver: quote.solver.into(),
210+
sell_amount: quote.sell_amount.0.into_alloy(),
211+
buy_amount: quote.buy_amount.0.into_alloy(),
212+
fee: quote.fee.0.into_alloy(),
213+
solver: quote.solver,
212214
},
213215
}
214216
}
@@ -230,9 +232,9 @@ impl ProtocolFees {
230232
let reference_quote = quote.clone().unwrap_or(domain::Quote {
231233
order_uid: order.metadata.uid.into(),
232234
sell_amount: order.data.sell_amount.into(),
233-
buy_amount: U256::zero().into(),
235+
buy_amount: U256::ZERO.into_legacy().into(),
234236
fee: order.data.fee_amount.into(),
235-
solver: H160::zero().into(),
237+
solver: Address::ZERO,
236238
});
237239

238240
let partner_fee =
@@ -365,16 +367,16 @@ pub struct Quote {
365367
pub buy_amount: U256,
366368
/// The amount that needs to be paid, denominated in the sell token.
367369
pub fee: U256,
368-
pub solver: H160,
370+
pub solver: Address,
369371
}
370372

371373
impl Quote {
372374
fn from_domain(value: &domain::Quote) -> Self {
373375
Self {
374-
sell_amount: value.sell_amount.into(),
375-
buy_amount: value.buy_amount.into(),
376-
fee: value.fee.into(),
377-
solver: value.solver.into(),
376+
sell_amount: value.sell_amount.0.into_alloy(),
377+
buy_amount: value.buy_amount.0.into_alloy(),
378+
fee: value.fee.0.into_alloy(),
379+
solver: value.solver,
378380
}
379381
}
380382
}

crates/autopilot/src/domain/quote/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use {
22
super::OrderUid,
33
crate::{boundary::Amounts, domain::eth},
4+
alloy::primitives::Address,
45
};
56

67
#[derive(Clone, Debug, PartialEq)]
@@ -9,7 +10,7 @@ pub struct Quote {
910
pub sell_amount: eth::SellTokenAmount,
1011
pub buy_amount: eth::TokenAmount,
1112
pub fee: eth::SellTokenAmount,
12-
pub solver: eth::Address,
13+
pub solver: Address,
1314
}
1415

1516
impl From<&Quote> for Amounts {

crates/autopilot/src/domain/settlement/trade/math.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use {
1616
util::conv::U256Ext,
1717
},
1818
error::Math,
19+
ethrpc::alloy::conversions::IntoLegacy,
1920
num::{CheckedAdd, CheckedDiv, CheckedMul, CheckedSub},
2021
std::collections::HashMap,
2122
};
@@ -383,9 +384,9 @@ impl Trade {
383384
side: self.side,
384385
},
385386
Quote {
386-
sell: quote.sell_amount.into(),
387-
buy: quote.buy_amount.into(),
388-
fee: quote.fee.into(),
387+
sell: quote.sell_amount.into_legacy().into(),
388+
buy: quote.buy_amount.into_legacy().into(),
389+
fee: quote.fee.into_legacy().into(),
389390
},
390391
)?;
391392
self.surplus_over(&self.prices.custom, quote)

crates/autopilot/src/infra/persistence/dto/fee_policy.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use {
22
crate::{boundary, domain},
33
anyhow::Context,
44
database::fee_policies::{FeePolicy, FeePolicyKind},
5+
ethrpc::alloy::conversions::IntoAlloy,
56
};
67

78
pub fn from_domain(
@@ -83,10 +84,10 @@ pub fn try_into_domain(
8384
quote: {
8485
let quote = quote.ok_or(Error::MissingQuote)?;
8586
domain::fee::Quote {
86-
sell_amount: quote.sell_amount.into(),
87-
buy_amount: quote.buy_amount.into(),
88-
fee: quote.fee.into(),
89-
solver: quote.solver.into(),
87+
sell_amount: quote.sell_amount.0.into_alloy(),
88+
buy_amount: quote.buy_amount.0.into_alloy(),
89+
fee: quote.fee.0.into_alloy(),
90+
solver: quote.solver,
9091
}
9192
},
9293
},

crates/autopilot/src/infra/persistence/dto/order.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use {
33
boundary::{self},
44
domain::{self, OrderUid, eth, fee::FeeFactor},
55
},
6+
alloy::primitives::Address,
67
app_data::AppDataHash,
78
ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy},
89
number::serialization::HexOrDecimalU256,
@@ -336,31 +337,31 @@ impl FeePolicy {
336337
#[serde(rename_all = "camelCase")]
337338
pub struct Quote {
338339
#[serde_as(as = "HexOrDecimalU256")]
339-
pub sell_amount: U256,
340+
pub sell_amount: alloy::primitives::U256,
340341
#[serde_as(as = "HexOrDecimalU256")]
341-
pub buy_amount: U256,
342+
pub buy_amount: alloy::primitives::U256,
342343
#[serde_as(as = "HexOrDecimalU256")]
343-
pub fee: U256,
344-
pub solver: H160,
344+
pub fee: alloy::primitives::U256,
345+
pub solver: Address,
345346
}
346347

347348
impl Quote {
348349
fn from_domain(quote: domain::Quote) -> Self {
349350
Quote {
350-
sell_amount: quote.sell_amount.0,
351-
buy_amount: quote.buy_amount.0,
352-
fee: quote.fee.0,
353-
solver: quote.solver.0,
351+
sell_amount: quote.sell_amount.0.into_alloy(),
352+
buy_amount: quote.buy_amount.0.into_alloy(),
353+
fee: quote.fee.0.into_alloy(),
354+
solver: quote.solver,
354355
}
355356
}
356357

357358
pub fn to_domain(&self, order_uid: OrderUid) -> domain::Quote {
358359
domain::Quote {
359360
order_uid,
360-
sell_amount: self.sell_amount.into(),
361-
buy_amount: self.buy_amount.into(),
362-
fee: self.fee.into(),
363-
solver: self.solver.into(),
361+
sell_amount: self.sell_amount.into_legacy().into(),
362+
buy_amount: self.buy_amount.into_legacy().into(),
363+
fee: self.fee.into_legacy().into(),
364+
solver: self.solver,
364365
}
365366
}
366367
}

crates/autopilot/src/infra/persistence/dto/quote.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use {
22
crate::{
33
boundary,
4-
domain::{self, eth},
4+
domain::{self},
55
},
6+
alloy::primitives::Address,
67
bigdecimal::{
78
FromPrimitive,
89
num_traits::{CheckedDiv, CheckedMul},
@@ -33,7 +34,7 @@ pub fn into_domain(quote: boundary::database::orders::Quote) -> Result<domain::Q
3334
.ok_or(QuoteError::U256Overflow)?
3435
.into(),
3536
fee: fee.into(),
36-
solver: eth::H160::from(quote.solver.0).into(),
37+
solver: Address::new(quote.solver.0),
3738
})
3839
}
3940

crates/autopilot/src/run.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ pub async fn run(args: Arguments, shutdown_controller: ShutdownController) {
543543
args.run_loop_native_price_timeout,
544544
eth.contracts().settlement().address().into_legacy(),
545545
args.disable_order_filtering,
546+
args.force_presign_order_filtering,
546547
);
547548

548549
let liveness = Arc::new(Liveness::new(args.max_auction_age));

crates/autopilot/src/solvable_orders.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub struct SolvableOrdersCache {
102102
native_price_timeout: Duration,
103103
settlement_contract: H160,
104104
disable_order_filters: bool,
105+
force_presign_order_filtering: bool,
105106
}
106107

107108
type Balances = HashMap<Query, U256>;
@@ -128,6 +129,7 @@ impl SolvableOrdersCache {
128129
native_price_timeout: Duration,
129130
settlement_contract: H160,
130131
disable_order_filters: bool,
132+
force_presign_order_filtering: bool,
131133
) -> Arc<Self> {
132134
Arc::new(Self {
133135
min_order_validity_period,
@@ -146,6 +148,7 @@ impl SolvableOrdersCache {
146148
native_price_timeout,
147149
settlement_contract,
148150
disable_order_filters,
151+
force_presign_order_filtering,
149152
})
150153
}
151154

@@ -230,7 +233,7 @@ impl SolvableOrdersCache {
230233
.timed_future(
231234
"weth_price_fetch",
232235
self.native_price_estimator
233-
.estimate_native_price(self.weth, Default::default()),
236+
.estimate_native_price(self.weth.into_alloy(), Default::default()),
234237
)
235238
.await
236239
.expect("weth price fetching can never fail");
@@ -390,7 +393,7 @@ impl SolvableOrdersCache {
390393
invalid_order_uids: &mut HashSet<OrderUid>,
391394
) -> Vec<Order> {
392395
let filter_invalid_signatures = async {
393-
if self.disable_order_filters {
396+
if self.disable_order_filters && !self.force_presign_order_filtering {
394397
return Default::default();
395398
}
396399
find_invalid_signature_orders(&orders, self.signature_validator.as_ref()).await
@@ -924,17 +927,17 @@ mod tests {
924927
let mut native_price_estimator = MockNativePriceEstimating::new();
925928
native_price_estimator
926929
.expect_estimate_native_price()
927-
.withf(move |token, _| *token == token1)
930+
.withf(move |token, _| *token == token1.into_alloy())
928931
.returning(|_, _| async { Ok(2.) }.boxed());
929932
native_price_estimator
930933
.expect_estimate_native_price()
931934
.times(1)
932-
.withf(move |token, _| *token == token2)
935+
.withf(move |token, _| *token == token2.into_alloy())
933936
.returning(|_, _| async { Err(PriceEstimationError::NoLiquidity) }.boxed());
934937
native_price_estimator
935938
.expect_estimate_native_price()
936939
.times(1)
937-
.withf(move |token, _| *token == token3)
940+
.withf(move |token, _| *token == token3.into_alloy())
938941
.returning(|_, _| async { Ok(0.25) }.boxed());
939942

940943
let native_price_estimator = CachingNativePriceEstimator::new(
@@ -1005,27 +1008,27 @@ mod tests {
10051008
let mut native_price_estimator = MockNativePriceEstimating::new();
10061009
native_price_estimator
10071010
.expect_estimate_native_price()
1008-
.withf(move |token, _| *token == token1)
1011+
.withf(move |token, _| *token == token1.into_alloy())
10091012
.returning(|_, _| async { Ok(2.) }.boxed());
10101013
native_price_estimator
10111014
.expect_estimate_native_price()
10121015
.times(1)
1013-
.withf(move |token, _| *token == token2)
1016+
.withf(move |token, _| *token == token2.into_alloy())
10141017
.returning(|_, _| async { Err(PriceEstimationError::NoLiquidity) }.boxed());
10151018
native_price_estimator
10161019
.expect_estimate_native_price()
10171020
.times(1)
1018-
.withf(move |token, _| *token == token3)
1021+
.withf(move |token, _| *token == token3.into_alloy())
10191022
.returning(|_, _| async { Ok(0.25) }.boxed());
10201023
native_price_estimator
10211024
.expect_estimate_native_price()
10221025
.times(1)
1023-
.withf(move |token, _| *token == token4)
1026+
.withf(move |token, _| *token == token4.into_alloy())
10241027
.returning(|_, _| async { Ok(0.) }.boxed());
10251028
native_price_estimator
10261029
.expect_estimate_native_price()
10271030
.times(1)
1028-
.withf(move |token, _| *token == token5)
1031+
.withf(move |token, _| *token == token5.into_alloy())
10291032
.returning(|_, _| async { Ok(5.) }.boxed());
10301033

10311034
let native_price_estimator = CachingNativePriceEstimator::new(
@@ -1112,17 +1115,17 @@ mod tests {
11121115
native_price_estimator
11131116
.expect_estimate_native_price()
11141117
.times(1)
1115-
.withf(move |token, _| *token == token3)
1118+
.withf(move |token, _| *token == token3.into_alloy())
11161119
.returning(|_, _| async { Ok(3.) }.boxed());
11171120
native_price_estimator
11181121
.expect_estimate_native_price()
11191122
.times(1)
1120-
.withf(move |token, _| *token == token_approx1)
1123+
.withf(move |token, _| *token == token_approx1.into_alloy())
11211124
.returning(|_, _| async { Ok(40.) }.boxed());
11221125
native_price_estimator
11231126
.expect_estimate_native_price()
11241127
.times(1)
1125-
.withf(move |token, _| *token == token_approx2)
1128+
.withf(move |token, _| *token == token_approx2.into_alloy())
11261129
.returning(|_, _| async { Ok(50.) }.boxed());
11271130

11281131
let native_price_estimator = CachingNativePriceEstimator::new(

crates/driver/src/domain/competition/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use {
2121
},
2222
util::{Bytes, math},
2323
},
24-
ethrpc::alloy::conversions::IntoLegacy,
24+
ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy},
2525
futures::{StreamExt, future::Either, stream::FuturesUnordered},
2626
itertools::Itertools,
2727
num::Zero,
@@ -495,8 +495,13 @@ impl Competition {
495495
// following: `available + (fee * available / sell) <= allocated_balance`
496496
if let order::Partial::Yes { available } = &mut order.partial {
497497
*available = order::TargetAmount(
498-
math::mul_ratio(available.0, allocated_balance.0, max_sell.0)
499-
.unwrap_or_default(),
498+
math::mul_ratio(
499+
available.0.into_alloy(),
500+
allocated_balance.0.into_alloy(),
501+
max_sell.0.into_alloy(),
502+
)
503+
.unwrap_or_default()
504+
.into_legacy(),
500505
);
501506
}
502507
if order.available().is_zero() {

0 commit comments

Comments
 (0)