diff --git a/crates/e2e/tests/e2e/cow_amm.rs b/crates/e2e/tests/e2e/cow_amm.rs index a01f411b03..f8ee960452 100644 --- a/crates/e2e/tests/e2e/cow_amm.rs +++ b/crates/e2e/tests/e2e/cow_amm.rs @@ -816,12 +816,28 @@ async fn cow_amm_opposite_direction(web3: Web3) { }; // Fund trader "bob" with DAI and approve allowance - dai.mint(bob.address(), to_wei(230)).await; + dai.mint(bob.address(), to_wei(250)).await; tx!( bob.account(), dai.approve(onchain.contracts().allowance, U256::MAX) ); + // Get balances before the trade + let amm_weth_balance_before = onchain + .contracts() + .weth + .balance_of(cow_amm.address()) + .call() + .await + .unwrap(); + let bob_weth_balance_before = onchain + .contracts() + .weth + .balance_of(bob.address()) + .call() + .await + .unwrap(); + // Place user order where bob sells DAI to buy WETH (opposite direction) let user_order = OrderCreation { sell_token: dai.address(), @@ -839,23 +855,9 @@ async fn cow_amm_opposite_direction(web3: Web3) { ); let user_order_id = services.create_order(&user_order).await.unwrap(); - // Get balances before the trade - let amm_weth_balance_before = onchain - .contracts() - .weth - .balance_of(cow_amm.address()) - .call() - .await - .unwrap(); - let bob_weth_balance_before = onchain - .contracts() - .weth - .balance_of(bob.address()) - .call() - .await - .unwrap(); - - let fee = U256::exp10(15); // 0.001 WETH + // Set the fees appropriately + let fee_cow_amm = U256::exp10(16); // 0.01 WETH + let fee_user = to_wei(1); // 1 DAI // Configure the mock solver's solution mock_solver.configure_solution(Some(Solution { @@ -880,13 +882,13 @@ async fn cow_amm_opposite_direction(web3: Web3) { signing_scheme: SigningScheme::Eip1271, signature, }, - executed_amount: cow_amm_order.sell_amount - fee, - fee: Some(fee), + executed_amount: cow_amm_order.sell_amount - fee_cow_amm, + fee: Some(fee_cow_amm), }), solvers_dto::solution::Trade::Fulfillment(solvers_dto::solution::Fulfillment { order: user_order_id.0, - executed_amount: user_order.sell_amount - fee, - fee: Some(fee), + executed_amount: user_order.sell_amount - fee_user, + fee: Some(fee_user), }), ], pre_interactions: vec![cow_amm_commitment], @@ -913,11 +915,11 @@ async fn cow_amm_opposite_direction(web3: Web3) { .await .unwrap(); - let amm_weth_received = amm_weth_balance_after - amm_weth_balance_before; + let amm_weth_sent = amm_weth_balance_before - amm_weth_balance_after; 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 - fee && amm_weth_received <= U256::zero() + bob_weth_received >= user_order.buy_amount && amm_weth_sent >= cow_amm_order.sell_amount }) .await .unwrap();