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

@@ -8,7 +8,7 @@ use tycho_execution::encoding::{
testing_utils::MockRFQState,
utils::{biguint_to_u256, write_calldata_to_file},
},
models::{Solution, Swap, SwapBuilder, UserTransferType},
models::{Solution, SwapBuilder, UserTransferType},
};
use crate::common::{
@@ -34,8 +34,8 @@ fn test_uniswap_v3_uniswap_v2() {
let wbtc = Bytes::from_str("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599").unwrap();
let usdc = Bytes::from_str("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48").unwrap();
let swap_weth_wbtc = Swap {
component: ProtocolComponent {
let swap_weth_wbtc = SwapBuilder::new(
ProtocolComponent {
id: "0xCBCdF9626bC03E24f779434178A73a0B4bad62eD".to_string(),
protocol_system: "uniswap_v3".to_string(),
static_attributes: {
@@ -48,26 +48,20 @@ fn test_uniswap_v3_uniswap_v2() {
},
..Default::default()
},
token_in: weth.clone(),
token_out: wbtc.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let swap_wbtc_usdc = Swap {
component: ProtocolComponent {
weth.clone(),
wbtc.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::TransferFrom);
let solution = Solution {
@@ -117,8 +111,8 @@ fn test_uniswap_v3_uniswap_v3() {
let wbtc = Bytes::from_str("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599").unwrap();
let usdc = Bytes::from_str("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48").unwrap();
let swap_weth_wbtc = Swap {
component: ProtocolComponent {
let swap_weth_wbtc = SwapBuilder::new(
ProtocolComponent {
id: "0xCBCdF9626bC03E24f779434178A73a0B4bad62eD".to_string(),
protocol_system: "uniswap_v3".to_string(),
static_attributes: {
@@ -131,15 +125,12 @@ fn test_uniswap_v3_uniswap_v3() {
},
..Default::default()
},
token_in: weth.clone(),
token_out: wbtc.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let swap_wbtc_usdc = Swap {
component: ProtocolComponent {
weth.clone(),
wbtc.clone(),
)
.build();
let swap_wbtc_usdc = SwapBuilder::new(
ProtocolComponent {
id: "0x99ac8cA7087fA4A2A1FB6357269965A2014ABc35".to_string(),
protocol_system: "uniswap_v3".to_string(),
static_attributes: {
@@ -152,13 +143,10 @@ fn test_uniswap_v3_uniswap_v3() {
},
..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::TransferFrom);
let solution = Solution {
@@ -207,8 +195,8 @@ fn test_uniswap_v3_curve() {
let wbtc = Bytes::from_str("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599").unwrap();
let usdt = Bytes::from_str("0xdAC17F958D2ee523a2206206994597C13D831ec7").unwrap();
let swap_weth_wbtc = Swap {
component: ProtocolComponent {
let swap_weth_wbtc = SwapBuilder::new(
ProtocolComponent {
id: "0xCBCdF9626bC03E24f779434178A73a0B4bad62eD".to_string(),
protocol_system: "uniswap_v3".to_string(),
static_attributes: {
@@ -221,16 +209,13 @@ fn test_uniswap_v3_curve() {
},
..Default::default()
},
token_in: weth.clone(),
token_out: wbtc.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
weth.clone(),
wbtc.clone(),
)
.build();
let swap_wbtc_usdt = Swap {
component: ProtocolComponent {
let swap_wbtc_usdt = SwapBuilder::new(
ProtocolComponent {
id: String::from("0xD51a44d3FaE010294C616388b506AcdA1bfAAE46"),
protocol_system: String::from("vm:curve"),
static_attributes: {
@@ -252,13 +237,9 @@ fn test_uniswap_v3_curve() {
},
..Default::default()
},
token_in: wbtc.clone(),
token_out: usdt.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
wbtc.clone(),
usdt.clone(),
).build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFrom);
let solution = Solution {
@@ -307,33 +288,27 @@ fn test_balancer_v2_uniswap_v2() {
let wbtc = Bytes::from_str("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599").unwrap();
let usdc = Bytes::from_str("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48").unwrap();
let swap_weth_wbtc = Swap {
component: ProtocolComponent {
let swap_weth_wbtc = SwapBuilder::new(
ProtocolComponent {
id: "0xa6f548df93de924d73be7d25dc02554c6bd66db500020000000000000000000e".to_string(),
protocol_system: "vm:balancer_v2".to_string(),
..Default::default()
},
token_in: weth.clone(),
token_out: wbtc.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
weth.clone(),
wbtc.clone(),
)
.build();
let swap_wbtc_usdc = Swap {
component: ProtocolComponent {
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::TransferFrom);
let solution = Solution {
@@ -385,36 +360,30 @@ fn test_multi_protocol() {
let usdt = Bytes::from_str("0xdAC17F958D2ee523a2206206994597C13D831ec7").unwrap();
let dai = Bytes::from_str("0x6B175474E89094C44Da98b954EedeAC495271d0F").unwrap();
let usv2_swap_dai_weth = Swap {
component: ProtocolComponent {
let usv2_swap_dai_weth = SwapBuilder::new(
ProtocolComponent {
id: "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11".to_string(),
protocol_system: "uniswap_v2".to_string(),
..Default::default()
},
token_in: dai.clone(),
token_out: weth.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
dai.clone(),
weth.clone(),
)
.build();
let balancer_swap_weth_wbtc = Swap {
component: ProtocolComponent {
let balancer_swap_weth_wbtc = SwapBuilder::new(
ProtocolComponent {
id: "0xa6f548df93de924d73be7d25dc02554c6bd66db500020000000000000000000e".to_string(),
protocol_system: "vm:balancer_v2".to_string(),
..Default::default()
},
token_in: weth.clone(),
token_out: wbtc.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
weth.clone(),
wbtc.clone(),
)
.build();
let curve_swap_wbtc_usdt = Swap {
component: ProtocolComponent {
let curve_swap_wbtc_usdt = SwapBuilder::new(
ProtocolComponent {
id: String::from("0xD51a44d3FaE010294C616388b506AcdA1bfAAE46"),
protocol_system: String::from("vm:curve"),
static_attributes: {
@@ -436,13 +405,9 @@ fn test_multi_protocol() {
},
..Default::default()
},
token_in: wbtc.clone(),
token_out: usdt.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
wbtc.clone(),
usdt.clone(),
).build();
// Ekubo
@@ -458,15 +423,7 @@ fn test_multi_protocol() {
]),
..Default::default()
};
let ekubo_swap_usdt_usdc = Swap {
component,
token_in: usdt.clone(),
token_out: usdc.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let ekubo_swap_usdt_usdc = SwapBuilder::new(component, usdt.clone(), usdc.clone()).build();
// USV4
// Fee and tick spacing information for this test is obtained by querying the
@@ -478,20 +435,17 @@ fn test_multi_protocol() {
static_attributes_usdc_eth.insert("key_lp_fee".into(), pool_fee_usdc_eth);
static_attributes_usdc_eth.insert("tick_spacing".into(), tick_spacing_usdc_eth);
let usv4_swap_usdc_eth = Swap {
component: ProtocolComponent {
let usv4_swap_usdc_eth = SwapBuilder::new(
ProtocolComponent {
id: "0xdce6394339af00981949f5f3baf27e3610c76326a700af57e4b3e3ae4977f78d".to_string(),
protocol_system: "uniswap_v4".to_string(),
static_attributes: static_attributes_usdc_eth,
..Default::default()
},
token_in: usdc.clone(),
token_out: eth.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
usdc.clone(),
eth.clone(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFromPermit2);
@@ -545,8 +499,8 @@ fn test_uniswap_v3_balancer_v3() {
let wbtc = Bytes::from_str("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599").unwrap();
let qnt = Bytes::from_str("0x4a220e6096b25eadb88358cb44068a3248254675").unwrap();
let swap_weth_wbtc = Swap {
component: ProtocolComponent {
let swap_weth_wbtc = SwapBuilder::new(
ProtocolComponent {
id: "0xCBCdF9626bC03E24f779434178A73a0B4bad62eD".to_string(),
protocol_system: "uniswap_v3".to_string(),
static_attributes: {
@@ -559,26 +513,20 @@ fn test_uniswap_v3_balancer_v3() {
},
..Default::default()
},
token_in: weth.clone(),
token_out: wbtc.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let swap_wbtc_qnt = Swap {
component: ProtocolComponent {
weth.clone(),
wbtc.clone(),
)
.build();
let swap_wbtc_qnt = SwapBuilder::new(
ProtocolComponent {
id: "0x571bea0e99e139cd0b6b7d9352ca872dfe0d72dd".to_string(),
protocol_system: "vm:balancer_v3".to_string(),
..Default::default()
},
token_in: wbtc.clone(),
token_out: qnt.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
wbtc.clone(),
qnt.clone(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFrom);
let solution = Solution {

View File

@@ -38,15 +38,7 @@ fn test_single_encoding_strategy_ekubo() {
..Default::default()
};
let swap = Swap {
component,
token_in: token_in.clone(),
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let swap = SwapBuilder::new(component, token_in.clone(), token_out.clone()).build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFrom);
@@ -92,15 +84,7 @@ fn test_single_encoding_strategy_maverick() {
};
let token_in = Bytes::from("0x40D16FC0246aD3160Ccc09B8D0D3A2cD28aE6C2f");
let token_out = usdc();
let swap = Swap {
component: maverick_pool,
token_in: token_in.clone(),
token_out: token_out.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let swap = SwapBuilder::new(maverick_pool, token_in.clone(), token_out.clone()).build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFrom);

View File

@@ -6,7 +6,7 @@ use num_bigint::{BigInt, BigUint};
use tycho_common::{models::protocol::ProtocolComponent, Bytes};
use tycho_execution::encoding::{
evm::utils::write_calldata_to_file,
models::{NativeAction, Solution, Swap, UserTransferType},
models::{NativeAction, Solution, SwapBuilder, UserTransferType},
};
use crate::common::{
@@ -27,32 +27,26 @@ fn test_sequential_swap_strategy_encoder() {
let wbtc = wbtc();
let usdc = usdc();
let swap_weth_wbtc = Swap {
component: ProtocolComponent {
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(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let swap_wbtc_usdc = Swap {
component: ProtocolComponent {
weth.clone(),
wbtc.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 {
@@ -97,32 +91,26 @@ fn test_sequential_swap_strategy_encoder_no_permit2() {
let wbtc = wbtc();
let usdc = usdc();
let swap_weth_wbtc = Swap {
component: ProtocolComponent {
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(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let swap_wbtc_usdc = Swap {
component: ProtocolComponent {
weth.clone(),
wbtc.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::TransferFrom);
let solution = Solution {
@@ -206,8 +194,8 @@ fn test_sequential_strategy_cyclic_swap() {
// Create two Uniswap V3 pools for the cyclic swap
// USDC -> WETH (Pool 1)
let swap_usdc_weth = Swap {
component: ProtocolComponent {
let swap_usdc_weth = SwapBuilder::new(
ProtocolComponent {
id: "0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640".to_string(), /* USDC-WETH USV3
* Pool 1 */
protocol_system: "uniswap_v3".to_string(),
@@ -219,17 +207,14 @@ fn test_sequential_strategy_cyclic_swap() {
},
..Default::default()
},
token_in: usdc.clone(),
token_out: weth.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
usdc.clone(),
weth.clone(),
)
.build();
// WETH -> USDC (Pool 2)
let swap_weth_usdc = Swap {
component: ProtocolComponent {
let swap_weth_usdc = SwapBuilder::new(
ProtocolComponent {
id: "0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8".to_string(), /* USDC-WETH USV3
* Pool 2 */
protocol_system: "uniswap_v3".to_string(),
@@ -243,13 +228,10 @@ fn test_sequential_strategy_cyclic_swap() {
},
..Default::default()
},
token_in: weth.clone(),
token_out: usdc.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
weth.clone(),
usdc.clone(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFromPermit2);
@@ -337,32 +319,26 @@ fn test_sequential_swap_strategy_encoder_unwrap() {
let wbtc = wbtc();
let usdc = usdc();
let swap_usdc_wbtc = Swap {
component: ProtocolComponent {
let swap_usdc_wbtc = SwapBuilder::new(
ProtocolComponent {
id: "0x004375Dff511095CC5A197A54140a24eFEF3A416".to_string(),
protocol_system: "uniswap_v2".to_string(),
..Default::default()
},
token_in: usdc.clone(),
token_out: wbtc.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let swap_wbtc_weth = Swap {
component: ProtocolComponent {
usdc.clone(),
wbtc.clone(),
)
.build();
let swap_wbtc_weth = SwapBuilder::new(
ProtocolComponent {
id: "0xBb2b8038a1640196FbE3e38816F3e67Cba72D940".to_string(),
protocol_system: "uniswap_v2".to_string(),
..Default::default()
},
token_in: wbtc.clone(),
token_out: weth.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
wbtc.clone(),
weth.clone(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFromPermit2);
let solution = Solution {

View File

@@ -7,7 +7,7 @@ use num_bigint::BigUint;
use tycho_common::{models::protocol::ProtocolComponent, Bytes};
use tycho_execution::encoding::{
evm::utils::{biguint_to_u256, write_calldata_to_file},
models::{NativeAction, Solution, Swap, UserTransferType},
models::{NativeAction, Solution, SwapBuilder, UserTransferType},
};
use crate::common::{
@@ -23,19 +23,16 @@ fn test_single_swap_strategy_encoder() {
let weth = weth();
let dai = dai();
let swap = Swap {
component: ProtocolComponent {
let swap = SwapBuilder::new(
ProtocolComponent {
id: "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11".to_string(),
protocol_system: "uniswap_v2".to_string(),
..Default::default()
},
token_in: weth.clone(),
token_out: dai.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
weth.clone(),
dai.clone(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFromPermit2);
@@ -111,19 +108,16 @@ fn test_single_swap_strategy_encoder_no_permit2() {
let checked_amount = BigUint::from_str("1_640_000000000000000000").unwrap();
let expected_min_amount = U256::from_str("1_640_000000000000000000").unwrap();
let swap = Swap {
component: ProtocolComponent {
let swap = SwapBuilder::new(
ProtocolComponent {
id: "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11".to_string(),
protocol_system: "uniswap_v2".to_string(),
..Default::default()
},
token_in: weth.clone(),
token_out: dai.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
weth.clone(),
dai.clone(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFrom);
let solution = Solution {
@@ -195,19 +189,16 @@ fn test_single_swap_strategy_encoder_no_transfer_in() {
let checked_amount = BigUint::from_str("1_640_000000000000000000").unwrap();
let expected_min_amount = U256::from_str("1_640_000000000000000000").unwrap();
let swap = Swap {
component: ProtocolComponent {
let swap = SwapBuilder::new(
ProtocolComponent {
id: "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11".to_string(),
protocol_system: "uniswap_v2".to_string(),
..Default::default()
},
token_in: weth.clone(),
token_out: dai.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
weth.clone(),
dai.clone(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::None);
let solution = Solution {
@@ -280,19 +271,16 @@ fn test_single_swap_strategy_encoder_wrap() {
let dai = dai();
let swap = Swap {
component: ProtocolComponent {
let swap = SwapBuilder::new(
ProtocolComponent {
id: "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11".to_string(),
protocol_system: "uniswap_v2".to_string(),
..Default::default()
},
token_in: weth(),
token_out: dai.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
weth(),
dai.clone(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFromPermit2);
let solution = Solution {
@@ -334,19 +322,16 @@ fn test_single_swap_strategy_encoder_unwrap() {
let dai = dai();
let swap = Swap {
component: ProtocolComponent {
let swap = SwapBuilder::new(
ProtocolComponent {
id: "0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11".to_string(),
protocol_system: "uniswap_v2".to_string(),
..Default::default()
},
token_in: dai.clone(),
token_out: weth(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
dai.clone(),
weth(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFromPermit2);
let solution = Solution {

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);

View File

@@ -8,7 +8,7 @@ use tycho_execution::encoding::{
approvals::protocol_approvals_manager::ProtocolApprovalsManager,
utils::{bytes_to_address, write_calldata_to_file},
},
models::{Solution, Swap, UserTransferType},
models::{Solution, SwapBuilder, UserTransferType},
};
use crate::common::{
@@ -35,8 +35,8 @@ fn test_sequential_swap_usx() {
let usdc = usdc();
let usdt = usdt();
let swap_dai_usdc = Swap {
component: ProtocolComponent {
let swap_dai_usdc = SwapBuilder::new(
ProtocolComponent {
id: "0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168".to_string(),
protocol_system: "uniswap_v3".to_string(),
static_attributes: {
@@ -47,15 +47,12 @@ fn test_sequential_swap_usx() {
},
..Default::default()
},
token_in: dai.clone(),
token_out: usdc.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
let swap_usdc_usdt = Swap {
component: ProtocolComponent {
dai.clone(),
usdc.clone(),
)
.build();
let swap_usdc_usdt = SwapBuilder::new(
ProtocolComponent {
id: "0x3416cF6C708Da44DB2624D63ea0AAef7113527C6".to_string(),
protocol_system: "uniswap_v3".to_string(),
static_attributes: {
@@ -66,13 +63,10 @@ fn test_sequential_swap_usx() {
},
..Default::default()
},
token_in: usdc.clone(),
token_out: usdt.clone(),
split: 0f64,
user_data: None,
protocol_state: None,
estimated_amount_in: None,
};
usdc.clone(),
usdt.clone(),
)
.build();
let encoder = get_tycho_router_encoder(UserTransferType::TransferFrom);
let solution = Solution {