From 4d697bfebfcb2827bb4411e42a4c5001b5f9d61e Mon Sep 17 00:00:00 2001 From: TAMARA LIPOWSKI Date: Thu, 30 Jan 2025 23:36:10 -0500 Subject: [PATCH] test: Router integration test with many TODOs --- foundry/src/TychoRouter.sol | 6 ++++ foundry/test/TychoRouter.t.sol | 32 ++++++++++++++----- foundry/test/TychoRouterTestSetup.sol | 5 ++- .../evm/strategy_encoder/strategy_encoders.rs | 3 ++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/foundry/src/TychoRouter.sol b/foundry/src/TychoRouter.sol index fffffb8..497c858 100644 --- a/foundry/src/TychoRouter.sol +++ b/foundry/src/TychoRouter.sol @@ -14,6 +14,7 @@ import "@uniswap/v3-updated/CallbackValidationV2.sol"; import "./ExecutionDispatcher.sol"; import "./CallbackVerificationDispatcher.sol"; import {LibSwap} from "../lib/LibSwap.sol"; +import "forge-std/console.sol"; error TychoRouter__WithdrawalFailed(); error TychoRouter__AddressZero(); @@ -197,6 +198,7 @@ contract TychoRouter is uint256[] memory remainingAmounts = new uint256[](nTokens); uint256[] memory amounts = new uint256[](nTokens); + console.logUint(amountIn); amounts[0] = amountIn; remainingAmounts[0] = amountIn; @@ -208,9 +210,13 @@ contract TychoRouter is currentAmountIn = split > 0 ? (amounts[tokenInIndex] * split) / 0xffffff : remainingAmounts[tokenInIndex]; + console.logUint(split); + console.logUint(tokenInIndex); // This gives 1, I guess it should be 0 + console.logUint(currentAmountIn); currentAmountOut = _callExecutor( swapData.executor(), swapData.executorSelector(), + // TODO 0 is being passed here which makes it fail currentAmountIn, swapData.protocolData() ); diff --git a/foundry/test/TychoRouter.t.sol b/foundry/test/TychoRouter.t.sol index 9a572ac..daf8957 100644 --- a/foundry/test/TychoRouter.t.sol +++ b/foundry/test/TychoRouter.t.sol @@ -673,21 +673,37 @@ contract TychoRouterTest is TychoRouterTestSetup { } function testSingleSwapIntegration() public { - // Test created with calldata from our router encoder + // Test created with calldata from our router encoder, replacing the executor + // address with the USV2 executor address. + // Tests swapping WETH -> DAI on a USV2 pool - vm.rollFork(21740300); - deal(WETH_ADDR, tychoRouterAddr, 1 ether); + deal(WETH_ADDR, ALICE, 1 ether); uint256 balancerBefore = IERC20(DAI_ADDR).balanceOf(ALICE); - // Encoded solution generated using `test_split_swap_strategy_encoder` with - // Alice's private key - (bool success,) = tychoRouterAddr.call( - hex"e73e3baa0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000002c6a3cd97c6283b95ac8c5a4459ebb0d5fd404f4000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000067c38a9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c6a3cd97c6283b95ac8c5a4459ebb0d5fd404f400000000000000000000000000000000000000000000000000000000679c0498000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000041eea332470b38c64899045460469146ef146969d3ed5f64fc58f25f58bc709dfb172ef15397b7591fcfd6642cd5a50509702c39a39d87ab79575d5c5388203e3b1b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c005a01000000005c2f5a71f67c01775180adc06909288b4c329308bd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc288e6a0c2ddd26feeb64f039a2c41296fcb3f56402c6a3cd97c6283b95ac8c5a4459ebb0d5fd404f40000000000" + // Approve permit2 + vm.startPrank(ALICE); + IERC20(WETH_ADDR).approve( + address(0x000000000022D473030F116dDEE9F6B43aC78BA3), + type(uint256).max ); + + // Encoded solution generated using `test_split_swap_strategy_encoder` but + // manually replacing the executor address `5c2f5a71f67c01775180adc06909288b4c329308` + // with the one in this test `5615deb798bb3e4dfa0139dfa1b3d433cc23b72f` + (bool success,) = tychoRouterAddr.call( + hex"4860f9ed0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc2000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000067c3df5a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ede3eca2a72b3aecc820e955b36f38437d0139500000000000000000000000000000000000000000000000000000000679c5962000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000041d3d0a64c002bdbedfa0dd859cba103fed3337b0bac6ec26ed22f83475426b83a58fd79adfeefea58c5f2e52e915e20a57220c8f32578d942ab5dc15fca3f47241c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c005a01000000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d013950000000000" + ); + + // TODO why does this only work when Alice is the caller? I tried to say the + // sender is address(this) but that doesn't work... + vm.stopPrank(); + + console.logAddress((address(usv2Executor))); + console.logAddress(address(this)); + console.logUint(block.timestamp); uint256 balancerAfter = IERC20(DAI_ADDR).balanceOf(ALICE); assertTrue(success, "Call Failed"); assertGt(balancerAfter, balancerBefore); - } } diff --git a/foundry/test/TychoRouterTestSetup.sol b/foundry/test/TychoRouterTestSetup.sol index 839e3ee..96b7107 100644 --- a/foundry/test/TychoRouterTestSetup.sol +++ b/foundry/test/TychoRouterTestSetup.sol @@ -39,7 +39,10 @@ contract TychoRouterTestSetup is Test, Constants { MockERC20[] tokens; function setUp() public { - uint256 forkBlock = 21000000; + // TODO I changed the forked block to match the signature + // of the integration test and now all the other tests fail + // fix this when the integration test passes. + uint256 forkBlock = 21742149; vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock); vm.startPrank(ADMIN); diff --git a/src/encoding/evm/strategy_encoder/strategy_encoders.rs b/src/encoding/evm/strategy_encoder/strategy_encoders.rs index 50c1737..c9dd737 100644 --- a/src/encoding/evm/strategy_encoder/strategy_encoders.rs +++ b/src/encoding/evm/strategy_encoder/strategy_encoders.rs @@ -124,6 +124,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder { U8::from( tokens .iter() + // TODO Something is wrong with our token in and out indices .position(|t| *t == swap.token_in) .ok_or_else(|| { EncodingError::InvalidInput( @@ -134,6 +135,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder { U8::from( tokens .iter() + // TODO Something is wrong with our token in and out indices .position(|t| *t == swap.token_out) .ok_or_else(|| { EncodingError::InvalidInput( @@ -385,6 +387,7 @@ mod tests { )); let hex_calldata = encode(&calldata); + println!("{}", hex_calldata); assert_eq!(hex_calldata[..520], expected_input); assert_eq!(hex_calldata[1288..], expected_swaps); }