feat: Adapt SplitSwapStrategyEncoder to have optional permit2 logic

- If the signer_pk is not passed -> use the swap method that expects the tokens to be already in the Router
- If it is passed -> compute permit2 and use swap method that does the token in transfer
- Extend builder to have another shortcut
- Add integration test with contract
- Update bin (and simplified it) and quickstart

--- don't change below this line ---
ENG-4255 Took 1 hour 51 minutes

Took 2 minutes

Took 7 seconds
This commit is contained in:
Diana Carvalho
2025-02-20 17:14:49 +00:00
parent 30a7d5bbe4
commit 20e6419a20
6 changed files with 213 additions and 92 deletions

View File

@@ -710,7 +710,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
uint256 balancerAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
assertTrue(success, "Call Failed");
assertGt(balancerAfter - balancerBefore, 26173932);
assertEq(balancerAfter - balancerBefore, 2659881924818443699787);
}
function testSingleSwapWithoutPermit2Integration() public {
@@ -720,17 +720,18 @@ contract TychoRouterTest is TychoRouterTestSetup {
// Tests swapping WETH -> DAI on a USV2 pool without permit2
deal(WETH_ADDR, tychoRouterAddr, 1 ether);
uint256 balancerBefore = IERC20(DAI_ADDR).balanceOf(ALICE);
// Encoded solution generated using `test_split_swap_strategy_encoder_simple_route_no_permit2`
// but manually replacing the executor address
// `5c2f5a71f67c01775180adc06909288b4c329308` with the one in this test
// `5615deb798bb3e4dfa0139dfa1b3d433cc23b72f`
(bool success,) = tychoRouterAddr.call(
hex"0a83cb080000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000008f1d5c1cae37400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc20000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000005c005a00010000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d013950000000000"
);
// TODO replace this calldata once we have the encoder side
// (bool success,) = tychoRouterAddr.call(
// hex"d499aa880000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc2000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000067d481bb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ede3eca2a72b3aecc820e955b36f38437d013950000000000000000000000000000000000000000000000000000000067acfbc3000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000041f2740fde9662d8bc1f8fe8e8fc29447c1832d625f06f4a56ee5103ad555c12323af5d50eb840f73d17873383ae3b7573956d5df7b2bf76bddba768c2837894a51b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c005a00010000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d013950000000000"
// );
//
// vm.stopPrank();
//
// uint256 balancerAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
// assertTrue(success, "Call Failed");
// assertGt(balancerAfter - balancerBefore, 26173932);
vm.stopPrank();
uint256 balancerAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
assertTrue(success, "Call Failed");
assertEq(balancerAfter - balancerBefore, 2659881924818443699787);
}
function testUSV4Integration() public {
@@ -790,7 +791,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
uint256 balancerAfter = IERC20(DAI_ADDR).balanceOf(ALICE);
assertTrue(success, "Call Failed");
assertGt(balancerAfter - balancerBefore, 26173932);
assertEq(balancerAfter - balancerBefore, 2659881924818443699787);
}
function testSingleSwapWithUnwrapIntegration() public {
@@ -819,7 +820,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
uint256 balancerAfter = ALICE.balance;
assertTrue(success, "Call Failed");
assertGt(balancerAfter - balancerBefore, 26173932);
assertEq(balancerAfter - balancerBefore, 1120007305574805922);
}
function testSplitSwapIntegration() public {