Skip to content

Commit 5923b47

Browse files
jmg-duarteclaude
andauthored
[TRIVIAL] Migrate OrderQuoteRequest to use alloy Address types (#3922)
# Description Migrates `OrderQuoteRequest` struct from using ethcontract's `H160` to alloy's `Address` type for address fields (`from`, `sell_token`, `buy_token`, `receiver`). This is part of the ongoing ethcontract → alloy library migration. # Changes - [x] Update `OrderQuoteRequest` struct in `model/src/quote.rs` to use `alloy::primitives::Address` instead of `H160` - [x] Update `orderbook/src/api/post_quote.rs` tests to use alloy `Address` constructors - [x] Update `orderbook/src/quoter.rs` to handle alloy Address types - [x] Add `.into_legacy()` conversions in `shared/src/order_quoting.rs` when converting `OrderQuoteRequest` to `PreOrderData` (which still uses H160) - [x] Fix all e2e tests (14 files) to properly convert between H160 and alloy Address: - Use `.into_alloy()` when converting H160 → Address for OrderQuoteRequest - Use `.into_legacy()` when converting Address → H160 for legacy functions - Dereference address references where needed (`*token.address()`) ## How to test Existing tests <!-- ## Related Issues Fixes # --> --------- Co-authored-by: Claude <[email protected]>
1 parent b91aa96 commit 5923b47

File tree

18 files changed

+167
-152
lines changed

18 files changed

+167
-152
lines changed

crates/e2e/tests/e2e/app_data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ async fn app_data(web3: Web3) {
114114
});
115115
services
116116
.submit_quote(&OrderQuoteRequest {
117-
sell_token: order3.sell_token,
118-
buy_token: order3.buy_token,
117+
sell_token: order3.sell_token.into_alloy(),
118+
buy_token: order3.buy_token.into_alloy(),
119119
side: OrderQuoteSide::Sell {
120120
sell_amount: SellAmount::AfterFee {
121121
value: order3.sell_amount.try_into().unwrap(),

crates/e2e/tests/e2e/banned_users.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ use {
1212
to_wei,
1313
to_wei_with_exp,
1414
},
15-
ethrpc::{
16-
Web3,
17-
alloy::conversions::{IntoAlloy, IntoLegacy},
18-
},
15+
ethrpc::{Web3, alloy::conversions::IntoAlloy},
1916
model::quote::{OrderQuoteRequest, OrderQuoteSide, SellAmount},
2017
reqwest::StatusCode,
2118
};
@@ -96,14 +93,14 @@ async fn forked_mainnet_onchain_banned_user_test(web3: Web3) {
9693

9794
let result = services
9895
.submit_quote(&OrderQuoteRequest {
99-
sell_token: token_dai.address().into_legacy(),
100-
buy_token: token_usdt.address().into_legacy(),
96+
sell_token: *token_dai.address(),
97+
buy_token: *token_usdt.address(),
10198
side: OrderQuoteSide::Sell {
10299
sell_amount: SellAmount::BeforeFee {
103100
value: to_wei_with_exp(1000, 18).try_into().unwrap(),
104101
},
105102
},
106-
from: BANNED_USER.into_legacy(),
103+
from: BANNED_USER,
107104
..Default::default()
108105
})
109106
.await;

crates/e2e/tests/e2e/cow_amm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ factory = "0xf76c421bAb7df8548604E60deCCcE50477C10462"
621621
// may time out)
622622
let _ = services
623623
.submit_quote(&OrderQuoteRequest {
624-
sell_token: usdc.address().into_legacy(),
625-
buy_token: usdt.address().into_legacy(),
624+
sell_token: *usdc.address(),
625+
buy_token: *usdt.address(),
626626
side: OrderQuoteSide::Sell {
627627
sell_amount: SellAmount::BeforeFee {
628628
value: to_wei_with_exp(1000, 6).try_into().unwrap(),
@@ -1008,9 +1008,9 @@ async fn cow_amm_opposite_direction(web3: Web3) {
10081008
mock_solver.configure_solution(Some(mocked_quote_solution));
10091009

10101010
let quote_request = OrderQuoteRequest {
1011-
from: bob.address(),
1012-
sell_token: dai.address().into_legacy(),
1013-
buy_token: onchain.contracts().weth.address().into_legacy(),
1011+
from: bob.address().into_alloy(),
1012+
sell_token: *dai.address(),
1013+
buy_token: *onchain.contracts().weth.address(),
10141014
side: OrderQuoteSide::Sell {
10151015
sell_amount: SellAmount::AfterFee {
10161016
value: NonZeroU256::try_from(executed_amount).unwrap(),

crates/e2e/tests/e2e/eth_integration.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async fn eth_integration(web3: Web3) {
6262
let request = OrderQuoteRequest {
6363
sell_token,
6464
buy_token,
65-
from: Address::default(),
65+
from: Address::default().into_alloy(),
6666
side: OrderQuoteSide::Sell {
6767
sell_amount: SellAmount::AfterFee {
6868
value: NonZeroU256::try_from(to_wei(43)).unwrap(),
@@ -73,11 +73,11 @@ async fn eth_integration(web3: Web3) {
7373
services.submit_quote(&request).await
7474
}
7575
};
76-
quote(token.address().into_legacy(), BUY_ETH_ADDRESS)
76+
quote(*token.address(), BUY_ETH_ADDRESS.into_alloy())
7777
.await
7878
.unwrap();
7979
// Eth is only supported as the buy token
80-
let (status, body) = quote(BUY_ETH_ADDRESS, token.address().into_legacy())
80+
let (status, body) = quote(BUY_ETH_ADDRESS.into_alloy(), *token.address())
8181
.await
8282
.unwrap_err();
8383
assert_eq!(status, 400, "{body}");

crates/e2e/tests/e2e/ethflow.rs

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ async fn eth_flow_tx(web3: Web3) {
102102
.await;
103103

104104
// Get a quote from the services
105-
let buy_token = dai.address().into_legacy();
106-
let receiver = H160([0x42; 20]);
107-
let sell_amount = to_wei(1);
105+
let buy_token = *dai.address();
106+
let receiver = Address::repeat_byte(0x42);
107+
let sell_amount = eth(1);
108108
let intent = EthFlowTradeIntent {
109109
sell_amount,
110110
buy_token,
@@ -157,7 +157,10 @@ async fn eth_flow_tx(web3: Web3) {
157157
app_data: OrderCreationAppData::Hash {
158158
hash: app_data::AppDataHash(const_hex::decode(&hash[2..]).unwrap().try_into().unwrap()),
159159
},
160-
..intent.to_quote_request(trader.account().address(), &onchain.contracts().weth)
160+
..intent.to_quote_request(
161+
trader.account().address().into_alloy(),
162+
&onchain.contracts().weth,
163+
)
161164
};
162165

163166
let quote: OrderQuoteResponse = test_submit_quote(&services, &quote_request).await;
@@ -182,7 +185,7 @@ async fn eth_flow_tx(web3: Web3) {
182185
test_order_availability_in_api(
183186
&services,
184187
&ethflow_order,
185-
&trader.address(),
188+
&trader.address().into_alloy(),
186189
onchain.contracts(),
187190
ethflow_contract,
188191
)
@@ -299,7 +302,7 @@ async fn eth_flow_without_quote(web3: Web3) {
299302
test_order_availability_in_api(
300303
&services,
301304
&ethflow_order,
302-
&trader.address(),
305+
&trader.address().into_alloy(),
303306
onchain.contracts(),
304307
ethflow_contract,
305308
)
@@ -330,11 +333,14 @@ async fn eth_flow_indexing_after_refund(web3: Web3) {
330333
&test_submit_quote(
331334
&services,
332335
&(EthFlowTradeIntent {
333-
sell_amount: 42.into(),
334-
buy_token: dai.address().into_legacy(),
335-
receiver: H160([42; 20]),
336+
sell_amount: alloy::primitives::U256::from(42),
337+
buy_token: *dai.address(),
338+
receiver: Address::repeat_byte(42),
336339
})
337-
.to_quote_request(dummy_trader.account().address(), &onchain.contracts().weth),
340+
.to_quote_request(
341+
dummy_trader.account().address().into_alloy(),
342+
&onchain.contracts().weth,
343+
),
338344
)
339345
.await,
340346
valid_to,
@@ -356,7 +362,7 @@ async fn eth_flow_indexing_after_refund(web3: Web3) {
356362

357363
// Create the actual order that should be picked up by the services and matched.
358364
let buy_token = dai.address().into_legacy();
359-
let receiver = H160([0x42; 20]);
365+
let receiver = Address::repeat_byte(0x42);
360366
let sell_amount = to_wei(1);
361367
let valid_to = chrono::offset::Utc::now().timestamp() as u32
362368
+ timestamp_of_current_block_in_seconds(&web3.alloy)
@@ -367,11 +373,14 @@ async fn eth_flow_indexing_after_refund(web3: Web3) {
367373
&test_submit_quote(
368374
&services,
369375
&(EthFlowTradeIntent {
370-
sell_amount,
371-
buy_token,
376+
sell_amount: sell_amount.into_alloy(),
377+
buy_token: buy_token.into_alloy(),
372378
receiver,
373379
})
374-
.to_quote_request(trader.account().address(), &onchain.contracts().weth),
380+
.to_quote_request(
381+
trader.account().address().into_alloy(),
382+
&onchain.contracts().weth,
383+
),
375384
)
376385
.await,
377386
valid_to,
@@ -451,7 +460,7 @@ async fn submit_order(
451460
async fn test_order_availability_in_api(
452461
services: &Services<'_>,
453462
order: &ExtendedEthFlowOrder,
454-
owner: &H160,
463+
owner: &Address,
455464
contracts: &Contracts,
456465
ethflow_contract: &CoWSwapEthFlow::Instance,
457466
) {
@@ -460,16 +469,26 @@ async fn test_order_availability_in_api(
460469
let is_available = || async { services.get_order(&uid).await.is_ok() };
461470
wait_for_condition(TIMEOUT, is_available).await.unwrap();
462471

463-
test_orders_query(services, order, owner, contracts, ethflow_contract).await;
472+
test_orders_query(
473+
services,
474+
order,
475+
&owner.into_legacy(),
476+
contracts,
477+
ethflow_contract,
478+
)
479+
.await;
464480

465481
// Api returns eth flow orders for both eth-flow contract address and actual
466482
// owner
467-
for address in [owner, &ethflow_contract.address().into_legacy()] {
483+
for address in [
484+
&owner.into_legacy(),
485+
&ethflow_contract.address().into_legacy(),
486+
] {
468487
test_account_query(
469488
address,
470489
services.client(),
471490
order,
472-
owner,
491+
&owner.into_legacy(),
473492
contracts,
474493
ethflow_contract,
475494
)
@@ -821,18 +840,18 @@ impl From<CoWSwapEthFlow::CoWSwapEthFlow::ordersReturn> for EthFlowOrderOnchainS
821840
}
822841

823842
pub struct EthFlowTradeIntent {
824-
pub sell_amount: U256,
825-
pub buy_token: H160,
826-
pub receiver: H160,
843+
pub sell_amount: alloy::primitives::U256,
844+
pub buy_token: Address,
845+
pub receiver: Address,
827846
}
828847

829848
impl EthFlowTradeIntent {
830849
// How a user trade intent is converted into a quote request by the frontend
831-
pub fn to_quote_request(&self, from: H160, weth: &WETH9::Instance) -> OrderQuoteRequest {
850+
pub fn to_quote_request(&self, from: Address, weth: &WETH9::Instance) -> OrderQuoteRequest {
832851
OrderQuoteRequest {
833852
from,
834853
// Even if the user sells ETH, we request a quote for WETH
835-
sell_token: weth.address().into_legacy(),
854+
sell_token: *weth.address(),
836855
buy_token: self.buy_token,
837856
receiver: Some(self.receiver),
838857
validity: Validity::For(3600),
@@ -843,7 +862,7 @@ impl EthFlowTradeIntent {
843862
},
844863
side: OrderQuoteSide::Sell {
845864
sell_amount: model::quote::SellAmount::AfterFee {
846-
value: NonZeroU256::try_from(self.sell_amount).unwrap(),
865+
value: NonZeroU256::try_from(self.sell_amount.into_legacy()).unwrap(),
847866
},
848867
},
849868
buy_token_balance: BuyTokenDestination::Erc20,
@@ -898,7 +917,7 @@ async fn eth_flow_zero_buy_amount(web3: Web3) {
898917
test_order_availability_in_api(
899918
&services,
900919
&ethflow_order,
901-
&trader.address(),
920+
&trader.address().into_alloy(),
902921
onchain.contracts(),
903922
ethflow_contract,
904923
)

crates/e2e/tests/e2e/hooks.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,9 @@ async fn quote_verification(web3: Web3) {
647647

648648
let quote = services
649649
.submit_quote(&OrderQuoteRequest {
650-
from: trader.address(),
651-
sell_token: token.address().into_legacy(),
652-
buy_token: onchain.contracts().weth.address().into_legacy(),
650+
from: trader.address().into_alloy(),
651+
sell_token: *token.address(),
652+
buy_token: *onchain.contracts().weth.address(),
653653
side: OrderQuoteSide::Sell {
654654
sell_amount: SellAmount::BeforeFee {
655655
value: NonZeroU256::try_from(to_wei(5)).unwrap(),

crates/e2e/tests/e2e/limit_orders.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,9 @@ async fn limit_does_not_apply_to_in_market_orders_test(web3: Web3) {
734734
.await;
735735

736736
let quote_request = OrderQuoteRequest {
737-
from: trader.address(),
738-
sell_token: token.address().into_legacy(),
739-
buy_token: onchain.contracts().weth.address().into_legacy(),
737+
from: trader.address().into_alloy(),
738+
sell_token: *token.address(),
739+
buy_token: *onchain.contracts().weth.address(),
740740
side: OrderQuoteSide::Sell {
741741
sell_amount: SellAmount::BeforeFee {
742742
value: NonZeroU256::try_from(to_wei(5)).unwrap(),
@@ -894,8 +894,8 @@ async fn forked_mainnet_single_limit_order_test(web3: Web3) {
894894
// may time out)
895895
let _ = services
896896
.submit_quote(&OrderQuoteRequest {
897-
sell_token: token_usdc.address().into_legacy(),
898-
buy_token: token_usdt.address().into_legacy(),
897+
sell_token: *token_usdc.address(),
898+
buy_token: *token_usdt.address(),
899899
side: OrderQuoteSide::Sell {
900900
sell_amount: SellAmount::BeforeFee {
901901
value: to_wei_with_exp(1000, 6).try_into().unwrap(),

crates/e2e/tests/e2e/order_cancellation.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use {
22
database::order_events::OrderEventLabel,
33
e2e::setup::{eth, *},
4-
ethrpc::alloy::{
5-
CallBuilderExt,
6-
conversions::{IntoAlloy, IntoLegacy},
7-
},
4+
ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy},
85
model::{
96
order::{
107
CancellationPayload,
@@ -92,9 +89,9 @@ async fn order_cancellation(web3: Web3) {
9289
let trader = &trader;
9390

9491
let request = OrderQuoteRequest {
95-
from: trader.address(),
96-
sell_token: token.address().into_legacy(),
97-
buy_token: onchain.contracts().weth.address().into_legacy(),
92+
from: trader.address().into_alloy(),
93+
sell_token: *token.address(),
94+
buy_token: *onchain.contracts().weth.address(),
9895
side: OrderQuoteSide::Sell {
9996
sell_amount: SellAmount::AfterFee {
10097
value: NonZeroU256::try_from(to_wei(1)).unwrap(),

crates/e2e/tests/e2e/place_order_with_quote.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ async fn place_order_with_quote(web3: Web3) {
6363
tracing::info!("Quoting");
6464
let quote_sell_amount = to_wei(1);
6565
let quote_request = OrderQuoteRequest {
66-
from: trader.address(),
67-
sell_token: onchain.contracts().weth.address().into_legacy(),
68-
buy_token: token.address().into_legacy(),
66+
from: trader.address().into_alloy(),
67+
sell_token: *onchain.contracts().weth.address(),
68+
buy_token: *token.address(),
6969
side: OrderQuoteSide::Sell {
7070
sell_amount: SellAmount::BeforeFee {
7171
value: NonZeroU256::try_from(quote_sell_amount).unwrap(),

crates/e2e/tests/e2e/protocol_fee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ async fn get_quote(
606606
},
607607
};
608608
let quote_request = OrderQuoteRequest {
609-
sell_token,
610-
buy_token,
609+
sell_token: sell_token.into_alloy(),
610+
buy_token: buy_token.into_alloy(),
611611
side,
612612
validity: Validity::To(valid_to),
613613
..Default::default()

0 commit comments

Comments
 (0)