refactor: use SwapBuilder in integration tests

This commit is contained in:
adrian
2025-10-09 10:30:22 +02:00
committed by Adrian Benavides
parent 52e9f4da89
commit 3e92b1be66
6 changed files with 243 additions and 386 deletions

View File

@@ -7,7 +7,7 @@ use num_bigint::{BigInt, BigUint};
use tycho_common::{models::protocol::ProtocolComponent, Bytes};
use tycho_execution::encoding::{
evm::utils::write_calldata_to_file,
models::{Solution, Swap, UserTransferType},
models::{Solution, SwapBuilder, UserTransferType},
};
use crate::common::{
@@ -32,61 +32,47 @@ fn test_split_swap_strategy_encoder() {
let wbtc = wbtc();
let usdc = usdc();
let swap_weth_dai = Swap {
component: ProtocolComponent {
let swap_weth_dai = SwapBuilder::new(
ProtocolComponent {
id: "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11".to_string(),
protocol_system: "uniswap_v2".to_string(),
..Default::default()
},
token_in: weth.clone(),
token_out: dai.clone(),
split: 0.5f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let swap_weth_wbtc = Swap {
component: ProtocolComponent {
weth.clone(),
dai.clone(),
)
.split(0.5f64)
.build();
let swap_weth_wbtc = SwapBuilder::new(
ProtocolComponent {
id: "0xBb2b8038a1640196FbE3e38816F3e67Cba72D940".to_string(),
protocol_system: "uniswap_v2".to_string(),
..Default::default()
},
token_in: weth.clone(),
token_out: wbtc.clone(),
// This represents the remaining 50%, but to avoid any rounding errors we set
// this to 0 to signify "the remainder of the WETH value".
// It should still be very close to 50%
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let swap_dai_usdc = Swap {
component: ProtocolComponent {
weth.clone(),
wbtc.clone(),
)
.build();
let swap_dai_usdc = SwapBuilder::new(
ProtocolComponent {
id: "0xAE461cA67B15dc8dc81CE7615e0320dA1A9aB8D5".to_string(),
protocol_system: "uniswap_v2".to_string(),
..Default::default()
},
token_in: dai.clone(),
token_out: usdc.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let swap_wbtc_usdc = Swap {
component: ProtocolComponent {
dai.clone(),
usdc.clone(),
)
.build();
let swap_wbtc_usdc = SwapBuilder::new(
ProtocolComponent {
id: "0x004375Dff511095CC5A197A54140a24eFEF3A416".to_string(),
protocol_system: "uniswap_v2".to_string(),
..Default::default()
},
token_in: wbtc.clone(),
token_out: usdc.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
wbtc.clone(),
usdc.clone(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFromPermit2);
let solution = Solution {
@@ -135,8 +121,8 @@ fn test_split_input_cyclic_swap() {
let usdc = usdc();
// USDC -> WETH (Pool 1) - 60% of input
let swap_usdc_weth_pool1 = Swap {
component: ProtocolComponent {
let swap_usdc_weth_pool1 = SwapBuilder::new(
ProtocolComponent {
id: "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640".to_string(), /* USDC-WETH USV3
* Pool 1 */
protocol_system: "uniswap_v3".to_string(),
@@ -148,17 +134,15 @@ fn test_split_input_cyclic_swap() {
},
..Default::default()
},
token_in: usdc.clone(),
token_out: weth.clone(),
split: 0.6f64, // 60% of input
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
usdc.clone(),
weth.clone(),
)
.split(0.6f64) // 60% of input
.build();
// USDC -> WETH (Pool 2) - 40% of input (remaining)
let swap_usdc_weth_pool2 = Swap {
component: ProtocolComponent {
let swap_usdc_weth_pool2 = SwapBuilder::new(
ProtocolComponent {
id: "0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8".to_string(), /* USDC-WETH USV3
* Pool 2 */
protocol_system: "uniswap_v3".to_string(),
@@ -172,17 +156,14 @@ fn test_split_input_cyclic_swap() {
},
..Default::default()
},
token_in: usdc.clone(),
token_out: weth.clone(),
split: 0f64,
user_data: None, // Remaining 40%
protocol_state: None,
estimated_amount_in: None,
};
usdc.clone(),
weth.clone(),
)
.build();
// WETH -> USDC (Pool 2)
let swap_weth_usdc_pool2 = Swap {
component: ProtocolComponent {
let swap_weth_usdc_pool2 = SwapBuilder::new(
ProtocolComponent {
id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc".to_string(), /* USDC-WETH USV2
* Pool 2 */
protocol_system: "uniswap_v2".to_string(),
@@ -196,13 +177,10 @@ fn test_split_input_cyclic_swap() {
},
..Default::default()
},
token_in: weth.clone(),
token_out: usdc.clone(),
split: 0.0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
weth.clone(),
usdc.clone(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFromPermit2);
@@ -306,8 +284,8 @@ fn test_split_output_cyclic_swap() {
let weth = weth();
let usdc = usdc();
let swap_usdc_weth_v2 = Swap {
component: ProtocolComponent {
let swap_usdc_weth_v2 = SwapBuilder::new(
ProtocolComponent {
id: "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc".to_string(), /* USDC-WETH USV2 */
protocol_system: "uniswap_v2".to_string(),
static_attributes: {
@@ -318,16 +296,13 @@ fn test_split_output_cyclic_swap() {
},
..Default::default()
},
token_in: usdc.clone(),
token_out: weth.clone(),
split: 0.0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
usdc.clone(),
weth.clone(),
)
.build();
let swap_weth_usdc_v3_pool1 = Swap {
component: ProtocolComponent {
let swap_weth_usdc_v3_pool1 = SwapBuilder::new(
ProtocolComponent {
id: "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640".to_string(), /* USDC-WETH USV3
* Pool 1 */
protocol_system: "uniswap_v3".to_string(),
@@ -339,16 +314,14 @@ fn test_split_output_cyclic_swap() {
},
..Default::default()
},
token_in: weth.clone(),
token_out: usdc.clone(),
split: 0.6f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
weth.clone(),
usdc.clone(),
)
.split(0.6f64)
.build();
let swap_weth_usdc_v3_pool2 = Swap {
component: ProtocolComponent {
let swap_weth_usdc_v3_pool2 = SwapBuilder::new(
ProtocolComponent {
id: "0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8".to_string(), /* USDC-WETH USV3
* Pool 2 */
protocol_system: "uniswap_v3".to_string(),
@@ -362,13 +335,10 @@ fn test_split_output_cyclic_swap() {
},
..Default::default()
},
token_in: weth.clone(),
token_out: usdc.clone(),
split: 0.0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
weth.clone(),
usdc.clone(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFromPermit2);