feat: Add balancer v3 to transfer optimization constants

Also added a getForkBlock() on TychoRouterTestSetup.
 Moved the router balancer test inside the Balancer file and created a TychoRouterForBalancerV3Test to wrap it

Took 1 hour 10 minutes


Took 21 seconds
This commit is contained in:
Diana Carvalho
2025-06-06 10:31:37 +01:00
parent 269e328b5f
commit c03df8aa1e
6 changed files with 154 additions and 38 deletions

View File

@@ -31,6 +31,7 @@ pub static IN_TRANSFER_REQUIRED_PROTOCOLS: LazyLock<HashSet<&'static str>> = Laz
set.insert("uniswap_v4");
set.insert("ekubo_v2");
set.insert("vm:maverick_v2");
set.insert("vm:balancer_v3");
set
});
@@ -46,5 +47,6 @@ pub static CALLBACK_CONSTRAINED_PROTOCOLS: LazyLock<HashSet<&'static str>> = Laz
set.insert("pancakeswap_v3");
set.insert("uniswap_v4");
set.insert("ekubo_v2");
set.insert("vm:balancer_v3");
set
});

View File

@@ -2472,6 +2472,85 @@ mod tests {
let hex_calldata = encode(&calldata);
write_calldata_to_file("test_multi_protocol", hex_calldata.as_str());
}
#[test]
fn test_uniswap_v3_balancer_v3() {
// Note: This test does not assert anything. It is only used to obtain
// integration test data for our router solidity test.
//
// WETH ───(USV3)──> WBTC ───(balancer v3)──> QNT
let weth = weth();
let wbtc =
Bytes::from_str("0x2260fac5e5542a773aa44fbcfedf7c193bc2c599").unwrap();
let qnt =
Bytes::from_str("0x4a220e6096b25eadb88358cb44068a3248254675").unwrap();
let swap_weth_wbtc = Swap {
component: ProtocolComponent {
id: "0xCBCdF9626bC03E24f779434178A73a0B4bad62eD".to_string(),
protocol_system: "uniswap_v3".to_string(),
static_attributes: {
let mut attrs = HashMap::new();
attrs.insert(
"fee".to_string(),
Bytes::from(BigInt::from(3000).to_signed_bytes_be()),
);
attrs
},
..Default::default()
},
token_in: weth.clone(),
token_out: wbtc.clone(),
split: 0f64,
user_data: None,
};
let swap_wbtc_qnt = Swap {
component: 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,
};
let encoder = get_tycho_router_encoder(UserTransferType::TransferFrom);
let solution = Solution {
exact_out: false,
given_token: weth,
given_amount: BigUint::from_str("1_0000000000000000").unwrap(),
checked_token: qnt,
checked_amount: BigUint::from_str("26173932").unwrap(),
sender: Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2")
.unwrap(),
receiver: Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2")
.unwrap(),
swaps: vec![swap_weth_wbtc, swap_wbtc_qnt],
..Default::default()
};
let encoded_solution = encoder
.encode_solutions(vec![solution.clone()])
.unwrap()[0]
.clone();
let calldata = encode_tycho_router_call(
eth_chain().id,
encoded_solution,
&solution,
UserTransferType::TransferFrom,
eth(),
None,
)
.unwrap()
.data;
let hex_calldata = encode(&calldata);
write_calldata_to_file("test_uniswap_v3_balancer_v3", hex_calldata.as_str());
}
}
}