From 6333072178b77bdc9a7950ed0ab84f30695d1b72 Mon Sep 17 00:00:00 2001 From: royvardhan Date: Tue, 4 Feb 2025 19:56:52 +0530 Subject: [PATCH 1/4] feat: add swap encoder test in balancer v2 executor --- .../test/executors/BalancerV2Executor.t.sol | 36 +++++++++++++++++++ .../evm/swap_encoder/swap_encoders.rs | 13 ++++--- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/foundry/test/executors/BalancerV2Executor.t.sol b/foundry/test/executors/BalancerV2Executor.t.sol index 6d34c9a..8999fa1 100644 --- a/foundry/test/executors/BalancerV2Executor.t.sol +++ b/foundry/test/executors/BalancerV2Executor.t.sol @@ -82,4 +82,40 @@ contract BalancerV2ExecutorTest is assertGt(balanceAfter, balanceBefore); assertEq(balanceAfter - balanceBefore, amountOut); } + + function testSwapExecutorEncoderData() public { + // Generated by the SwapEncoder - test_encode_balancer_v2 + bytes memory protocolData = + hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2ba100000625a3754423978a60c9317c58a424e3d5c6ee304399dbdb9c8ef030ab642b10820db8f560002000000000000000000141d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e01"; + + ( + IERC20 tokenIn, + IERC20 tokenOut, + bytes32 poolId, + address receiver, + bool needsApproval + ) = balancerV2Exposed.decodeParams(protocolData); + + assertEq(address(tokenIn), WETH_ADDR); + assertEq(address(tokenOut), BAL_ADDR); + assertEq(poolId, WETH_BAL_POOL_ID); + assertEq(receiver, BOB); + assertEq(needsApproval, true); + } + + function testSwapExecutorSwap() public { + // Generated by the SwapEncoder - test_encode_balancer_v2 + bytes memory protocolData = + hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2ba100000625a3754423978a60c9317c58a424e3d5c6ee304399dbdb9c8ef030ab642b10820db8f560002000000000000000000141d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e01"; + + uint256 amountIn = 10 ** 18; + deal(WETH_ADDR, address(balancerV2Exposed), amountIn); + uint256 balanceBefore = BAL.balanceOf(BOB); + + uint256 amountOut = balancerV2Exposed.swap(amountIn, protocolData); + + uint256 balanceAfter = BAL.balanceOf(BOB); + assertGt(balanceAfter, balanceBefore); + assertEq(balanceAfter - balanceBefore, amountOut); + } } diff --git a/src/encoding/evm/swap_encoder/swap_encoders.rs b/src/encoding/evm/swap_encoder/swap_encoders.rs index 6c0a894..432b2b0 100644 --- a/src/encoding/evm/swap_encoder/swap_encoders.rs +++ b/src/encoding/evm/swap_encoder/swap_encoders.rs @@ -168,7 +168,6 @@ impl SwapEncoder for BalancerV2SwapEncoder { bytes_to_address(&swap.token_out)?, component_id, bytes_to_address(&encoding_context.receiver)?, - encoding_context.exact_out, approval_needed, ); Ok(args.abi_encode_packed()) @@ -285,11 +284,12 @@ mod tests { let swap = Swap { component: balancer_pool, token_in: Bytes::from("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"), // WETH - token_out: Bytes::from("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"), // BAL + token_out: Bytes::from("0xba100000625a3754423978a60c9317c58a424e3D"), // BAL split: 0f64, }; let encoding_context = EncodingContext { - receiver: Bytes::from("0x0000000000000000000000000000000000000001"), + // The receiver was generated with `makeAddr("bob") using forge` + receiver: Bytes::from("0x1d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e"), exact_out: false, router_address: Bytes::zero(20), }; @@ -299,6 +299,7 @@ mod tests { .encode_swap(swap, encoding_context) .unwrap(); let hex_swap = encode(&encoded_swap); + println!("{}", hex_swap); assert_eq!( hex_swap, @@ -306,13 +307,11 @@ mod tests { // token in "c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // token out - "2791bca1f2de4661ed88a30c99a7a9449aa84174", + "ba100000625a3754423978a60c9317c58a424e3d", // pool id "5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014", // receiver - "0000000000000000000000000000000000000001", - // exact out - "00", + "1d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e", // approval needed "01" )) From e6310d65d1cb1c37ef0cef55090bf4abbe1fb275 Mon Sep 17 00:00:00 2001 From: royvardhan Date: Tue, 4 Feb 2025 20:56:21 +0530 Subject: [PATCH 2/4] fix: executor test naming --- foundry/test/executors/BalancerV2Executor.t.sol | 4 ++-- foundry/test/executors/UniswapV2Executor.t.sol | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/foundry/test/executors/BalancerV2Executor.t.sol b/foundry/test/executors/BalancerV2Executor.t.sol index 8999fa1..f537cbf 100644 --- a/foundry/test/executors/BalancerV2Executor.t.sol +++ b/foundry/test/executors/BalancerV2Executor.t.sol @@ -83,7 +83,7 @@ contract BalancerV2ExecutorTest is assertEq(balanceAfter - balanceBefore, amountOut); } - function testSwapExecutorEncoderData() public { + function testDecodeIntegration() public { // Generated by the SwapEncoder - test_encode_balancer_v2 bytes memory protocolData = hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2ba100000625a3754423978a60c9317c58a424e3d5c6ee304399dbdb9c8ef030ab642b10820db8f560002000000000000000000141d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e01"; @@ -103,7 +103,7 @@ contract BalancerV2ExecutorTest is assertEq(needsApproval, true); } - function testSwapExecutorSwap() public { + function testSwapIntegration() public { // Generated by the SwapEncoder - test_encode_balancer_v2 bytes memory protocolData = hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2ba100000625a3754423978a60c9317c58a424e3d5c6ee304399dbdb9c8ef030ab642b10820db8f560002000000000000000000141d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e01"; diff --git a/foundry/test/executors/UniswapV2Executor.t.sol b/foundry/test/executors/UniswapV2Executor.t.sol index 9c7066f..765d79c 100644 --- a/foundry/test/executors/UniswapV2Executor.t.sol +++ b/foundry/test/executors/UniswapV2Executor.t.sol @@ -94,7 +94,7 @@ contract UniswapV2ExecutorTest is UniswapV2ExecutorExposed, Test, Constants { assertGe(finalBalance, amountOut); } - function testSwapExecutorEncoderData() public { + function testDecodeIntegration() public { // Generated by the ExecutorStrategyEncoder - test_executor_strategy_encode bytes memory protocolData = hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc288e6a0c2ddd26feeb64f039a2c41296fcb3f5640000000000000000000000000000000000000000100"; @@ -108,7 +108,7 @@ contract UniswapV2ExecutorTest is UniswapV2ExecutorExposed, Test, Constants { assertEq(zeroForOne, false); } - function testSwapExecutorSwap() public { + function testSwapIntegration() public { // Generated by the ExecutorStrategyEncoder - test_executor_strategy_encode bytes memory protocolData = hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb111d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e00"; From 00171ea72e980dcef509a884cfe874c873836563 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 4 Feb 2025 15:37:28 +0000 Subject: [PATCH 3/4] chore(release): 0.28.0 [skip ci] ## [0.28.0](https://github.com/propeller-heads/tycho-execution/compare/0.27.0...0.28.0) (2025-02-04) ### Features * Tycho encoder validation ([4bc6159](https://github.com/propeller-heads/tycho-execution/commit/4bc615913ecb41a551a8b970ba5d96f0fc20ca42)) ### Bug Fixes * test_validate_fails_for_unwrap_wrong_last_swap ([0660321](https://github.com/propeller-heads/tycho-execution/commit/06603210bcd567ce50ec79344024ea2b722ebcd3)) --- CHANGELOG.md | 12 ++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cb75f6..cd9ec23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## [0.28.0](https://github.com/propeller-heads/tycho-execution/compare/0.27.0...0.28.0) (2025-02-04) + + +### Features + +* Tycho encoder validation ([4bc6159](https://github.com/propeller-heads/tycho-execution/commit/4bc615913ecb41a551a8b970ba5d96f0fc20ca42)) + + +### Bug Fixes + +* test_validate_fails_for_unwrap_wrong_last_swap ([0660321](https://github.com/propeller-heads/tycho-execution/commit/06603210bcd567ce50ec79344024ea2b722ebcd3)) + ## [0.27.0](https://github.com/propeller-heads/tycho-execution/compare/0.26.0...0.27.0) (2025-02-04) diff --git a/Cargo.lock b/Cargo.lock index 484282a..1f04723 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4163,7 +4163,7 @@ dependencies = [ [[package]] name = "tycho-execution" -version = "0.27.0" +version = "0.28.0" dependencies = [ "alloy", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index 958189f..6b66a70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tycho-execution" -version = "0.27.0" +version = "0.28.0" edition = "2021" [dependencies] From e21a8de6c999b72a66889a917871465d5cff8b29 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 4 Feb 2025 15:46:38 +0000 Subject: [PATCH 4/4] chore(release): 0.29.0 [skip ci] ## [0.29.0](https://github.com/propeller-heads/tycho-execution/compare/0.28.0...0.29.0) (2025-02-04) ### Features * add swap encoder test in balancer v2 executor ([6333072](https://github.com/propeller-heads/tycho-execution/commit/6333072178b77bdc9a7950ed0ab84f30695d1b72)) ### Bug Fixes * executor test naming ([e6310d6](https://github.com/propeller-heads/tycho-execution/commit/e6310d65d1cb1c37ef0cef55090bf4abbe1fb275)) --- CHANGELOG.md | 12 ++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd9ec23..91f9881 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## [0.29.0](https://github.com/propeller-heads/tycho-execution/compare/0.28.0...0.29.0) (2025-02-04) + + +### Features + +* add swap encoder test in balancer v2 executor ([6333072](https://github.com/propeller-heads/tycho-execution/commit/6333072178b77bdc9a7950ed0ab84f30695d1b72)) + + +### Bug Fixes + +* executor test naming ([e6310d6](https://github.com/propeller-heads/tycho-execution/commit/e6310d65d1cb1c37ef0cef55090bf4abbe1fb275)) + ## [0.28.0](https://github.com/propeller-heads/tycho-execution/compare/0.27.0...0.28.0) (2025-02-04) diff --git a/Cargo.lock b/Cargo.lock index 1f04723..772615d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4163,7 +4163,7 @@ dependencies = [ [[package]] name = "tycho-execution" -version = "0.28.0" +version = "0.29.0" dependencies = [ "alloy", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index 6b66a70..0774993 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tycho-execution" -version = "0.28.0" +version = "0.29.0" edition = "2021" [dependencies]