Skip to content

Commit 7188583

Browse files
committed
Merge branch 'main' into jemalloc-profiling-support
2 parents bc460c0 + b91aa96 commit 7188583

File tree

22 files changed

+460
-413
lines changed

22 files changed

+460
-413
lines changed

crates/autopilot/src/database/onchain_order_events/mod.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,11 @@ where
499499
gas_amount: quote.data.fee_parameters.gas_amount,
500500
gas_price: quote.data.fee_parameters.gas_price,
501501
sell_token_price: quote.data.fee_parameters.sell_token_price,
502-
sell_amount: u256_to_big_decimal(&quote.sell_amount),
503-
buy_amount: u256_to_big_decimal(&quote.buy_amount),
504-
solver: ByteArray(quote.data.solver.0),
502+
sell_amount: number::conversions::alloy::u256_to_big_decimal(
503+
&quote.sell_amount,
504+
),
505+
buy_amount: number::conversions::alloy::u256_to_big_decimal(&quote.buy_amount),
506+
solver: ByteArray(*quote.data.solver.0),
505507
verified: quote.data.verified,
506508
metadata: quote.data.metadata.try_into()?,
507509
}),
@@ -550,11 +552,11 @@ async fn get_quote(
550552
.map_err(|_| OnchainOrderPlacementError::Other)?;
551553

552554
let parameters = QuoteSearchParameters {
553-
sell_token: order_data.sell_token.into_legacy(),
554-
buy_token: order_data.buy_token.into_legacy(),
555-
sell_amount: order_data.sell_amount.into_legacy(),
556-
buy_amount: order_data.buy_amount.into_legacy(),
557-
fee_amount: order_data.fee_amount.into_legacy(),
555+
sell_token: order_data.sell_token,
556+
buy_token: order_data.buy_token,
557+
sell_amount: order_data.sell_amount,
558+
buy_amount: order_data.buy_amount,
559+
fee_amount: order_data.fee_amount,
558560
kind: order_data.kind,
559561
signing_scheme: quote_signing_scheme,
560562
additional_gas: 0,
@@ -598,9 +600,9 @@ fn convert_onchain_order_placement(
598600
// executed fast (we don't want to reserve the user's ETH for too long)
599601
if quote.as_ref().is_ok_and(|quote| {
600602
!order_data.within_market(QuoteAmounts {
601-
sell: quote.sell_amount,
602-
buy: quote.buy_amount,
603-
fee: quote.fee_amount,
603+
sell: quote.sell_amount.into_legacy(),
604+
buy: quote.buy_amount.into_legacy(),
605+
fee: quote.fee_amount.into_legacy(),
604606
})
605607
}) {
606608
tracing::debug!(%order_uid, ?owner, "order is outside market price");
@@ -1091,8 +1093,8 @@ mod test {
10911093
};
10921094
let settlement_contract = H160::from([8u8; 20]);
10931095
let quote = Quote {
1094-
sell_amount: sell_amount.into_legacy(),
1095-
buy_amount: (buy_amount / U256::from(2)).into_legacy(),
1096+
sell_amount,
1097+
buy_amount: buy_amount / U256::from(2),
10961098
..Default::default()
10971099
};
10981100
let order_uid = OrderUid([9u8; 56]);
@@ -1212,23 +1214,20 @@ mod test {
12121214
let quote = Quote {
12131215
id: Some(0i64),
12141216
data: QuoteData {
1215-
sell_token: sell_token.into_legacy(),
1216-
buy_token: buy_token.into_legacy(),
1217-
quoted_sell_amount: sell_amount
1218-
.checked_sub(U256::from(1))
1219-
.unwrap()
1220-
.into_legacy(),
1221-
quoted_buy_amount: buy_amount.checked_sub(U256::from(1)).unwrap().into_legacy(),
1217+
sell_token,
1218+
buy_token,
1219+
quoted_sell_amount: sell_amount.checked_sub(U256::from(1)).unwrap(),
1220+
quoted_buy_amount: buy_amount.checked_sub(U256::from(1)).unwrap(),
12221221
fee_parameters: FeeParameters {
12231222
gas_amount: 2.0f64,
12241223
gas_price: 3.0f64,
12251224
sell_token_price: 4.0f64,
12261225
},
12271226
..Default::default()
12281227
},
1229-
sell_amount: sell_amount.into_legacy(),
1230-
buy_amount: buy_amount.into_legacy(),
1231-
fee_amount: fee_amount.into_legacy(),
1228+
sell_amount,
1229+
buy_amount,
1230+
fee_amount,
12321231
};
12331232
let cloned_quote = quote.clone();
12341233
order_quoter
@@ -1304,9 +1303,9 @@ mod test {
13041303
gas_amount: quote.data.fee_parameters.gas_amount,
13051304
gas_price: quote.data.fee_parameters.gas_price,
13061305
sell_token_price: quote.data.fee_parameters.sell_token_price,
1307-
sell_amount: u256_to_big_decimal(&quote.sell_amount),
1308-
buy_amount: u256_to_big_decimal(&quote.buy_amount),
1309-
solver: ByteArray(quote.data.solver.0),
1306+
sell_amount: number::conversions::alloy::u256_to_big_decimal(&quote.sell_amount),
1307+
buy_amount: number::conversions::alloy::u256_to_big_decimal(&quote.buy_amount),
1308+
solver: ByteArray(*quote.data.solver.0),
13101309
verified: quote.data.verified,
13111310
metadata: quote.data.metadata.try_into().unwrap(),
13121311
};

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use {
22
super::OrderUid,
33
crate::{boundary::Amounts, domain::eth},
44
alloy::primitives::Address,
5+
ethrpc::alloy::conversions::IntoAlloy,
56
};
67

78
#[derive(Clone, Debug, PartialEq)]
@@ -16,9 +17,9 @@ pub struct Quote {
1617
impl From<&Quote> for Amounts {
1718
fn from(quote: &Quote) -> Self {
1819
Self {
19-
sell: quote.sell_amount.into(),
20-
buy: quote.buy_amount.into(),
21-
fee: quote.fee.into(),
20+
sell: quote.sell_amount.0.into_alloy(),
21+
buy: quote.buy_amount.0.into_alloy(),
22+
fee: quote.fee.0.into_alloy(),
2223
}
2324
}
2425
}

crates/autopilot/src/run_loop.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ use {
2929
::observe::metrics,
3030
anyhow::{Context, Result},
3131
database::order_events::OrderEventLabel,
32-
ethrpc::{alloy::conversions::IntoLegacy, block_stream::BlockInfo},
32+
ethrpc::{
33+
alloy::conversions::{IntoAlloy, IntoLegacy},
34+
block_stream::BlockInfo,
35+
},
3336
futures::{FutureExt, TryFutureExt},
3437
itertools::Itertools,
3538
model::solver_competition::{
@@ -468,7 +471,7 @@ impl RunLoop {
468471
.enumerated()
469472
.map(|(index, participant)| SolverSettlement {
470473
solver: participant.driver().name.clone(),
471-
solver_address: participant.solution().solver().0,
474+
solver_address: participant.solution().solver().0.into_alloy(),
472475
score: Some(Score::Solver(participant.solution().score().get().0)),
473476
ranking: index + 1,
474477
orders: participant
@@ -477,15 +480,15 @@ impl RunLoop {
477480
.iter()
478481
.map(|(id, order)| Order::Colocated {
479482
id: (*id).into(),
480-
sell_amount: order.executed_sell.into(),
481-
buy_amount: order.executed_buy.into(),
483+
sell_amount: order.executed_sell.0.into_alloy(),
484+
buy_amount: order.executed_buy.0.into_alloy(),
482485
})
483486
.collect(),
484487
clearing_prices: participant
485488
.solution()
486489
.prices()
487490
.iter()
488-
.map(|(token, price)| (token.0, price.get().into()))
491+
.map(|(token, price)| (token.0.into_alloy(), price.get().0.into_alloy()))
489492
.collect(),
490493
is_winner: participant.is_winner(),
491494
filtered_out: participant.filtered_out(),
@@ -507,7 +510,7 @@ impl RunLoop {
507510
prices: auction
508511
.prices
509512
.iter()
510-
.map(|(key, value)| ((*key).into(), value.get().into()))
513+
.map(|(key, value)| (key.0.into_alloy(), value.get().0.into_alloy()))
511514
.collect(),
512515
},
513516
solutions,

crates/cow-amm/src/maintainers.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use {
22
crate::{Amm, cache::Storage},
33
contracts::alloy::ERC20,
44
ethrpc::Web3,
5-
futures::future::{join_all, select_ok},
5+
futures::{
6+
future::{join_all, select_ok},
7+
stream::{FuturesUnordered, StreamExt},
8+
},
69
shared::maintenance::Maintaining,
710
std::sync::Arc,
811
tokio::sync::RwLock,
@@ -55,13 +58,20 @@ impl Maintaining for EmptyPoolRemoval {
5558
amms_to_check.extend(storage.cow_amms().await);
5659
}
5760
}
58-
let futures = amms_to_check.iter().map(|amm| async {
59-
self.has_zero_balance(amm.clone())
60-
.await
61-
.then_some(*amm.address())
62-
});
6361

64-
let empty_amms: Vec<_> = join_all(futures).await.into_iter().flatten().collect();
62+
let empty_amms: Vec<_> = amms_to_check
63+
.iter()
64+
.map(|amm| {
65+
let amm = amm.clone();
66+
async move {
67+
let address = *amm.address();
68+
self.has_zero_balance(amm).await.then_some(address)
69+
}
70+
})
71+
.collect::<FuturesUnordered<_>>()
72+
.filter_map(std::future::ready)
73+
.collect()
74+
.await;
6575
if !empty_amms.is_empty() {
6676
tracing::debug!(amms = ?empty_amms, "removing AMMs with zero token balance");
6777
let lock = self.storage.read().await;

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub struct Utilities {
6060
liquidity_fetcher: infra::liquidity::Fetcher,
6161
tokens: tokens::Fetcher,
6262
balance_fetcher: Arc<dyn BalanceFetching>,
63-
cow_amm_cache: cow_amm::Cache,
63+
cow_amm_cache: Option<cow_amm::Cache>,
6464
}
6565

6666
impl std::fmt::Debug for Utilities {
@@ -390,12 +390,16 @@ impl Utilities {
390390
}
391391

392392
async fn cow_amm_orders(self: Arc<Self>, auction: Arc<Auction>) -> Arc<Vec<Order>> {
393+
let Some(ref cow_amm_cache) = self.cow_amm_cache else {
394+
// CoW AMMs are not configured, return empty vec
395+
return Default::default();
396+
};
397+
393398
let _timer = metrics::get().processing_stage_timer("cow_amm_orders");
394399
let _timer2 =
395400
observe::metrics::metrics().on_auction_overhead_start("driver", "cow_amm_orders");
396401

397-
let cow_amms = self
398-
.cow_amm_cache
402+
let cow_amms = cow_amm_cache
399403
.get_or_create_amms(&auction.surplus_capturing_jit_order_owners)
400404
.await;
401405

crates/driver/src/domain/cow_amm.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ pub struct Cache {
2424
}
2525

2626
impl Cache {
27-
pub fn new(web3: DynProvider, factory_mapping: HashMap<Address, Address>) -> Self {
27+
pub fn new(web3: DynProvider, factory_mapping: HashMap<Address, Address>) -> Option<Self> {
28+
if factory_mapping.is_empty() {
29+
return None;
30+
}
31+
2832
let helper_by_factory = factory_mapping
2933
.into_iter()
3034
.map(|(factory, helper)| {
@@ -34,11 +38,11 @@ impl Cache {
3438
)
3539
})
3640
.collect();
37-
Self {
41+
Some(Self {
3842
inner: RwLock::new(HashMap::new()),
3943
web3: web3.clone(),
4044
helper_by_factory,
41-
}
45+
})
4246
}
4347

4448
/// Gets or creates AMM instances for the given surplus capturing JIT order

crates/e2e/tests/e2e/quote_verification.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ async fn test_bypass_verification_for_rfq_quotes(web3: Web3) {
175175
in_amount: NonZeroU256::new(12.into()).unwrap(),
176176
},
177177
&Verification {
178-
from: H160::from_str("0x73688c2b34bf6c09c125fed02fe92d17a94b897a").unwrap(),
178+
from: H160::from_str("0x73688c2b34bf6c09c125fed02fe92d17a94b897a").unwrap().into_alloy(),
179179
receiver: H160::from_str("0x73688c2b34bf6c09c125fed02fe92d17a94b897a")
180-
.unwrap(),
180+
.unwrap().into_alloy(),
181181
pre_interactions: vec![],
182182
post_interactions: vec![],
183183
sell_token_source: SellTokenSource::Erc20,

crates/model/src/order.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use {
99
quote::QuoteId,
1010
signature::{self, EcdsaSignature, EcdsaSigningScheme, Signature},
1111
},
12-
alloy::primitives::{Address, U512},
12+
alloy::primitives::{Address, B256, U512},
1313
anyhow::{Result, anyhow},
1414
app_data::{AppDataHash, hash_full_app_data},
1515
bigdecimal::BigDecimal,
@@ -647,7 +647,7 @@ pub struct CancellationPayload {
647647
#[serde(rename_all = "camelCase")]
648648
pub struct EthflowData {
649649
pub user_valid_to: i64,
650-
pub refund_tx_hash: Option<H256>,
650+
pub refund_tx_hash: Option<B256>,
651651
}
652652

653653
// We still want to have the `is_refunded` field in the JSON response to stay
@@ -663,7 +663,7 @@ impl ::serde::Serialize for EthflowData {
663663
#[serde(rename_all = "camelCase")]
664664
struct Extended {
665665
user_valid_to: i64,
666-
refund_tx_hash: Option<H256>,
666+
refund_tx_hash: Option<B256>,
667667
is_refunded: bool,
668668
}
669669

crates/model/src/solver_competition.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use {
22
crate::{AuctionId, order::OrderUid},
3-
alloy::primitives::B256,
3+
alloy::primitives::{Address, B256},
44
number::serialization::HexOrDecimalU256,
5-
primitive_types::{H160, U256},
5+
primitive_types::U256,
66
serde::{Deserialize, Serialize},
77
serde_with::serde_as,
88
std::collections::BTreeMap,
@@ -36,7 +36,7 @@ pub struct SolverCompetitionAPI {
3636
pub struct CompetitionAuction {
3737
pub orders: Vec<OrderUid>,
3838
#[serde_as(as = "BTreeMap<_, HexOrDecimalU256>")]
39-
pub prices: BTreeMap<H160, U256>,
39+
pub prices: BTreeMap<Address, alloy::primitives::U256>,
4040
}
4141

4242
#[serde_as]
@@ -45,13 +45,13 @@ pub struct CompetitionAuction {
4545
pub struct SolverSettlement {
4646
pub solver: String,
4747
#[serde(default)]
48-
pub solver_address: H160,
48+
pub solver_address: Address,
4949
#[serde(flatten)]
5050
pub score: Option<Score>,
5151
#[serde(default)]
5252
pub ranking: usize,
5353
#[serde_as(as = "BTreeMap<_, HexOrDecimalU256>")]
54-
pub clearing_prices: BTreeMap<H160, U256>,
54+
pub clearing_prices: BTreeMap<Address, alloy::primitives::U256>,
5555
pub orders: Vec<Order>,
5656
#[serde(default)]
5757
pub is_winner: bool,
@@ -106,16 +106,16 @@ pub enum Order {
106106
id: OrderUid,
107107
/// The effective amount that left the user's wallet including all fees.
108108
#[serde_as(as = "HexOrDecimalU256")]
109-
sell_amount: U256,
109+
sell_amount: alloy::primitives::U256,
110110
/// The effective amount the user received after all fees.
111111
#[serde_as(as = "HexOrDecimalU256")]
112-
buy_amount: U256,
112+
buy_amount: alloy::primitives::U256,
113113
},
114114
#[serde(rename_all = "camelCase")]
115115
Legacy {
116116
id: OrderUid,
117117
#[serde_as(as = "HexOrDecimalU256")]
118-
executed_amount: U256,
118+
executed_amount: alloy::primitives::U256,
119119
},
120120
}
121121

@@ -189,28 +189,28 @@ mod tests {
189189
OrderUid([0x33; 56]),
190190
],
191191
prices: btreemap! {
192-
H160([0x11; 20]) => 1000.into(),
193-
H160([0x22; 20]) => 2000.into(),
194-
H160([0x33; 20]) => 3000.into(),
192+
Address::repeat_byte(0x11) => alloy::primitives::U256::from(1000),
193+
Address::repeat_byte(0x22) => alloy::primitives::U256::from(2000),
194+
Address::repeat_byte(0x33) => alloy::primitives::U256::from(3000),
195195
},
196196
},
197197
solutions: vec![SolverSettlement {
198198
solver: "2".to_string(),
199-
solver_address: H160([0x22; 20]),
199+
solver_address: Address::repeat_byte(0x22),
200200
score: Some(Score::Solver(1.into())),
201201
ranking: 1,
202202
clearing_prices: btreemap! {
203-
H160([0x22; 20]) => 8.into(),
203+
Address::repeat_byte(0x22) => alloy::primitives::U256::from(8),
204204
},
205205
orders: vec![
206206
Order::Colocated {
207207
id: OrderUid([0x33; 56]),
208-
sell_amount: 12.into(),
209-
buy_amount: 13.into(),
208+
sell_amount: alloy::primitives::U256::from(12),
209+
buy_amount: alloy::primitives::U256::from(13),
210210
},
211211
Order::Legacy {
212212
id: OrderUid([0x44; 56]),
213-
executed_amount: 14.into(),
213+
executed_amount: alloy::primitives::U256::from(14),
214214
},
215215
],
216216
is_winner: true,

0 commit comments

Comments
 (0)