Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn order_uid(
let owner = signature
.recover_owner(&trade.signature.0, &domain_separator, &order.hash_struct())
.map_err(error::Uid::RecoverOwner)?;
Ok(order.uid(&domain_separator, &owner).into())
Ok(order.uid(&domain_separator, &owner.into_legacy()).into())
}

/// Trade flags are encoded in a 256-bit integer field. For more information on
Expand Down
4 changes: 2 additions & 2 deletions crates/driver/src/infra/solver/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
util::Bytes,
},
app_data::AppDataHash,
ethrpc::alloy::conversions::IntoAlloy,
ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy},
itertools::Itertools,
model::{
DomainSeparator,
Expand Down Expand Up @@ -324,7 +324,7 @@ impl JitOrder {
signature.data = Bytes(self.0.signature[20..].to_vec());
}

signature.signer = signer.into();
signature.signer = signer.into_legacy().into();

Ok(signature)
}
Expand Down
7 changes: 3 additions & 4 deletions crates/e2e/src/setup/colocation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use {
crate::{nodes::NODE_WS_HOST, setup::*},
::alloy::primitives::Address,
ethcontract::H160,
reqwest::Url,
std::collections::HashSet,
tokio::task::JoinHandle,
Expand All @@ -13,15 +12,15 @@ pub struct SolverEngine {
pub name: String,
pub endpoint: Url,
pub account: TestAccount,
pub base_tokens: Vec<H160>,
pub base_tokens: Vec<Address>,
pub merge_solutions: bool,
}

pub async fn start_baseline_solver(
name: String,
account: TestAccount,
weth: Address,
base_tokens: Vec<H160>,
base_tokens: Vec<Address>,
max_hops: usize,
merge_solutions: bool,
) -> SolverEngine {
Expand Down Expand Up @@ -227,7 +226,7 @@ mempool = "public"
})
}

fn encode_base_tokens(tokens: impl IntoIterator<Item = H160>) -> String {
fn encode_base_tokens(tokens: impl IntoIterator<Item = Address>) -> String {
tokens
.into_iter()
.map(|token| format!(r#""{token:x}""#))
Expand Down
3 changes: 2 additions & 1 deletion crates/e2e/src/setup/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use {
colocation::{self, SolverEngine},
wait_for_condition,
},
alloy::primitives::Address,
app_data::{AppDataDocument, AppDataHash},
autopilot::infra::persistence::dto,
clap::Parser,
Expand Down Expand Up @@ -532,7 +533,7 @@ impl<'a> Services<'a> {

pub async fn get_native_price(
&self,
token: &H160,
token: &Address,
) -> Result<NativeTokenPrice, (StatusCode, String)> {
let response = self
.http
Expand Down
3 changes: 2 additions & 1 deletion crates/e2e/src/setup/solver/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ impl JitOrder {
domain,
&signature
.recover_owner(&signature.to_bytes(), domain, &data.hash_struct())
.unwrap(),
.unwrap()
.into_legacy(),
);
let signature = match signature {
model::signature::Signature::Eip712(signature) => signature.to_bytes().to_vec(),
Expand Down
22 changes: 11 additions & 11 deletions crates/e2e/tests/e2e/app_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ async fn app_data(web3: Web3) {
let mut create_order = |app_data| {
let order = OrderCreation {
app_data,
sell_token: token_a.address().into_legacy(),
sell_amount: to_wei(2),
buy_token: token_b.address().into_legacy(),
buy_amount: to_wei(1),
sell_token: *token_a.address(),
sell_amount: eth(2),
buy_token: *token_b.address(),
buy_amount: eth(1),
valid_to,
kind: OrderKind::Sell,
..Default::default()
Expand Down Expand Up @@ -114,11 +114,11 @@ async fn app_data(web3: Web3) {
});
services
.submit_quote(&OrderQuoteRequest {
sell_token: order3.sell_token.into_alloy(),
buy_token: order3.buy_token.into_alloy(),
sell_token: order3.sell_token,
buy_token: order3.buy_token,
side: OrderQuoteSide::Sell {
sell_amount: SellAmount::AfterFee {
value: order3.sell_amount.try_into().unwrap(),
value: order3.sell_amount.into_legacy().try_into().unwrap(),
},
},
app_data: OrderCreationAppData::Hash {
Expand Down Expand Up @@ -213,10 +213,10 @@ async fn app_data_full_format(web3: Web3) {
let mut create_order = |app_data| {
let order = OrderCreation {
app_data,
sell_token: token_a.address().into_legacy(),
sell_amount: to_wei(2),
buy_token: token_b.address().into_legacy(),
buy_amount: to_wei(1),
sell_token: *token_a.address(),
sell_amount: eth(2),
buy_token: *token_b.address(),
buy_amount: eth(1),
valid_to,
kind: OrderKind::Sell,
..Default::default()
Expand Down
15 changes: 6 additions & 9 deletions crates/e2e/tests/e2e/app_data_signer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use {
alloy::primitives::Address,
e2e::setup::{OnchainComponents, Services, TestAccount, eth, run_test, safe::Safe, to_wei},
ethrpc::alloy::{
CallBuilderExt,
conversions::{IntoAlloy, IntoLegacy},
},
ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy},
model::{
order::{OrderCreation, OrderCreationAppData, OrderKind},
signature::EcdsaSigningScheme,
Expand Down Expand Up @@ -49,10 +46,10 @@ async fn order_creation_checks_metadata_signer(web3: Web3) {
let mut create_order = |app_data| {
let order = OrderCreation {
app_data,
sell_token: token_a.address().into_legacy(),
sell_amount: to_wei(2),
buy_token: token_b.address().into_legacy(),
buy_amount: to_wei(1),
sell_token: *token_a.address(),
sell_amount: eth(2),
buy_token: *token_b.address(),
buy_amount: eth(1),
valid_to,
kind: OrderKind::Sell,
..Default::default()
Expand Down Expand Up @@ -116,7 +113,7 @@ async fn order_creation_checks_metadata_signer(web3: Web3) {
// Rejected: from and signer are inconsistent.
let full_app_data = full_app_data_with_signer(adversary.address());
let mut order5 = create_order(full_app_data);
order5.from = Some(safe.address().into_legacy());
order5.from = Some(safe.address());
safe.sign_order(&mut order5, &onchain);
let err = services.create_order(&order5).await.unwrap_err();
assert!(err.1.contains("AppdataFromMismatch"));
Expand Down
8 changes: 4 additions & 4 deletions crates/e2e/tests/e2e/autopilot_leader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ async fn dual_autopilot_only_leader_produces_auctions(web3: Web3) {

let order = || {
OrderCreation {
sell_token: token_a.address().into_legacy(),
sell_amount: to_wei(10),
buy_token: onchain.contracts().weth.address().into_legacy(),
buy_amount: to_wei(5),
sell_token: *token_a.address(),
sell_amount: eth(10),
buy_token: *onchain.contracts().weth.address(),
buy_amount: eth(5),
valid_to: model::time::now_in_epoch_seconds() + 300,
kind: OrderKind::Sell,
..Default::default()
Expand Down
20 changes: 8 additions & 12 deletions crates/e2e/tests/e2e/buffers.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use {
::alloy::primitives::U256,
e2e::setup::{eth, *},
ethrpc::alloy::{
CallBuilderExt,
conversions::{IntoAlloy, IntoLegacy},
},
ethrpc::alloy::{CallBuilderExt, conversions::IntoAlloy},
model::{
order::{OrderCreation, OrderKind},
signature::EcdsaSigningScheme,
Expand Down Expand Up @@ -91,10 +88,10 @@ async fn onchain_settlement_without_liquidity(web3: Web3) {

// Place Order
let order = OrderCreation {
sell_token: token_a.address().into_legacy(),
sell_amount: to_wei(9),
buy_token: token_b.address().into_legacy(),
buy_amount: to_wei(5),
sell_token: *token_a.address(),
sell_amount: eth(9),
buy_token: *token_b.address(),
buy_amount: eth(5),
valid_to: model::time::now_in_epoch_seconds() + 300,
kind: OrderKind::Buy,
..Default::default()
Expand All @@ -108,9 +105,8 @@ async fn onchain_settlement_without_liquidity(web3: Web3) {

tracing::info!("waiting for first trade");
onchain.mint_block().await;
let trade_happened = || async {
token_b.balanceOf(trader.address()).call().await.unwrap() == order.buy_amount.into_alloy()
};
let trade_happened =
|| async { token_b.balanceOf(trader.address()).call().await.unwrap() == order.buy_amount };
wait_for_condition(TIMEOUT, trade_happened).await.unwrap();

// Check that settlement buffers were traded.
Expand Down Expand Up @@ -138,7 +134,7 @@ async fn onchain_settlement_without_liquidity(web3: Web3) {
let trade_happened = || async {
onchain.mint_block().await;
token_b.balanceOf(trader.address()).call().await.unwrap()
== (order.buy_amount.into_alloy() * U256::from(2))
== (order.buy_amount * ::alloy::primitives::U256::from(2))
};
wait_for_condition(TIMEOUT, trade_happened).await.unwrap();
}
46 changes: 22 additions & 24 deletions crates/e2e/tests/e2e/cow_amm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ async fn cow_amm_jit(web3: Web3) {

// place user order with the same limit price as the CoW AMM order
let user_order = OrderCreation {
sell_token: onchain.contracts().weth.address().into_legacy(),
sell_amount: ethcontract::U256::exp10(17), // 0.1 WETH
buy_token: dai.address().into_legacy(),
buy_amount: to_wei(230), // 230 DAI
sell_token: *onchain.contracts().weth.address(),
sell_amount: alloy::primitives::U256::from(10).pow(alloy::primitives::U256::from(17)), // 0.1 WETH
buy_token: *dai.address(),
buy_amount: eth(230), // 230 DAI
valid_to: model::time::now_in_epoch_seconds() + 300,
kind: OrderKind::Sell,
..Default::default()
Expand All @@ -307,6 +307,7 @@ async fn cow_amm_jit(web3: Web3) {
let bob_balance_before = dai.balanceOf(bob.address()).call().await.unwrap();

let fee = ethcontract::U256::exp10(16); // 0.01 WETH
let fee_alloy = alloy::primitives::U256::from(fee.low_u128());

mock_solver.configure_solution(Some(Solution {
id: 1,
Expand Down Expand Up @@ -340,7 +341,7 @@ async fn cow_amm_jit(web3: Web3) {
}),
solvers_dto::solution::Trade::Fulfillment(solvers_dto::solution::Fulfillment {
order: solvers_dto::solution::OrderUid(user_order_id.0),
executed_amount: user_order.sell_amount - fee,
executed_amount: (user_order.sell_amount - fee_alloy).into_legacy(),
fee: Some(fee),
}),
],
Expand All @@ -363,7 +364,7 @@ async fn cow_amm_jit(web3: Web3) {
let bob_received = bob_balance - bob_balance_before;

// bob and CoW AMM both got surplus and an equal amount
amm_received >= cow_amm_order.buyAmount && bob_received > user_order.buy_amount.into_alloy()
amm_received >= cow_amm_order.buyAmount && bob_received > user_order.buy_amount
})
.await
.unwrap();
Expand Down Expand Up @@ -589,10 +590,10 @@ factory = "0xf76c421bAb7df8548604E60deCCcE50477C10462"

// Place Orders
let order = OrderCreation {
sell_token: usdc.address().into_legacy(),
sell_amount: to_wei_with_exp(1000, 6),
buy_token: usdt.address().into_legacy(),
buy_amount: to_wei_with_exp(2000, 6),
sell_token: *usdc.address(),
sell_amount: alloy::primitives::U256::from(to_wei_with_exp(1000, 6).low_u128()),
buy_token: *usdt.address(),
buy_amount: alloy::primitives::U256::from(to_wei_with_exp(2000, 6).low_u128()),
valid_to: model::time::now_in_epoch_seconds() + 300,
kind: OrderKind::Sell,
..Default::default()
Expand Down Expand Up @@ -857,15 +858,15 @@ async fn cow_amm_opposite_direction(web3: Web3) {
.unwrap()
.unwrap();
let valid_to = block.timestamp.as_u32() + 300;
let executed_amount = to_wei(230);
let executed_amount = eth(230);

// CoW AMM order remains the same (selling WETH for DAI)
let cow_amm_order = contracts::alloy::cow_amm::CowAmm::GPv2Order::Data {
sellToken: *onchain.contracts().weth.address(),
buyToken: *dai.address(),
receiver: Default::default(),
sellAmount: U256::from(10).pow(U256::from(17)),
buyAmount: executed_amount.into_alloy(),
buyAmount: executed_amount,
validTo: valid_to,
appData: FixedBytes(APP_DATA),
feeAmount: U256::ZERO,
Expand Down Expand Up @@ -976,7 +977,7 @@ async fn cow_amm_opposite_direction(web3: Web3) {
}),
solvers_dto::solution::Trade::Fulfillment(solvers_dto::solution::Fulfillment {
order: solvers_dto::solution::OrderUid(order_uid.0),
executed_amount: executed_amount - fee_user,
executed_amount: executed_amount.into_legacy() - fee_user,
fee: Some(fee_user),
}),
],
Expand All @@ -999,7 +1000,7 @@ async fn cow_amm_opposite_direction(web3: Web3) {
buy_token: *onchain.contracts().weth.address(),
side: OrderQuoteSide::Sell {
sell_amount: SellAmount::AfterFee {
value: NonZeroU256::try_from(executed_amount).unwrap(),
value: NonZeroU256::try_from(executed_amount.into_legacy()).unwrap(),
},
},
..Default::default()
Expand All @@ -1014,22 +1015,20 @@ async fn cow_amm_opposite_direction(web3: Web3) {
*onchain.contracts().weth.address()
);
// Ensure the amounts are the same as the solution proposes.
assert_eq!(
quote_response.quote.sell_amount,
executed_amount.into_alloy()
);
assert_eq!(quote_response.quote.sell_amount, executed_amount);
assert_eq!(
quote_response.quote.buy_amount,
U256::from(10).pow(U256::from(17))
);

// Place user order where bob sells DAI to buy WETH (opposite direction)
let user_order = OrderCreation {
sell_token: dai.address().into_legacy(),
sell_token: *dai.address(),
sell_amount: executed_amount, // 230 DAI
buy_token: onchain.contracts().weth.address().into_legacy(),
buy_amount: ethcontract::U256::from(90000000000000000u64), /* 0.09 WETH to generate some
* surplus */
buy_token: *onchain.contracts().weth.address(),
buy_amount: alloy::primitives::U256::from(90000000000000000u64), /* 0.09 WETH to generate
* some
* surplus */
valid_to: model::time::now_in_epoch_seconds() + 300,
kind: OrderKind::Sell,
..Default::default()
Expand Down Expand Up @@ -1068,8 +1067,7 @@ async fn cow_amm_opposite_direction(web3: Web3) {
let bob_weth_received = bob_weth_balance_after - bob_weth_balance_before;

// Bob should receive WETH, CoW AMM's WETH balance decreases
bob_weth_received >= user_order.buy_amount.into_alloy()
&& amm_weth_sent == cow_amm_order.sellAmount
bob_weth_received >= user_order.buy_amount && amm_weth_sent == cow_amm_order.sellAmount
})
.await
.unwrap();
Expand Down
16 changes: 8 additions & 8 deletions crates/e2e/tests/e2e/eth_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ async fn eth_integration(web3: Web3) {
assert_ne!(*onchain.contracts().weth.address(), BUY_ETH_ADDRESS);
let order_buy_eth_a = OrderCreation {
kind: OrderKind::Buy,
sell_token: token.address().into_legacy(),
sell_amount: to_wei(50),
buy_token: BUY_ETH_ADDRESS.into_legacy(),
buy_amount: to_wei(49),
sell_token: *token.address(),
sell_amount: eth(50),
buy_token: BUY_ETH_ADDRESS,
buy_amount: eth(49),
valid_to: model::time::now_in_epoch_seconds() + 300,
..Default::default()
}
Expand All @@ -101,10 +101,10 @@ async fn eth_integration(web3: Web3) {
services.create_order(&order_buy_eth_a).await.unwrap();
let order_buy_eth_b = OrderCreation {
kind: OrderKind::Sell,
sell_token: token.address().into_legacy(),
sell_amount: to_wei(50),
buy_token: BUY_ETH_ADDRESS.into_legacy(),
buy_amount: to_wei(49),
sell_token: *token.address(),
sell_amount: eth(50),
buy_token: BUY_ETH_ADDRESS,
buy_amount: eth(49),
valid_to: model::time::now_in_epoch_seconds() + 300,
..Default::default()
}
Expand Down
Loading
Loading