fix: Fix tests (not there yet)
Took 58 minutes
This commit is contained in:
@@ -26,8 +26,7 @@ contract TychoRouterTestProtocolIntegration is TychoRouterTestSetup {
|
||||
USDE_ADDR,
|
||||
USDT_ADDR,
|
||||
true,
|
||||
true, // permit2 transferFrom to protocol
|
||||
false, // transfer to protocol
|
||||
RestrictTransferFrom.TransferType.TransferFrom,
|
||||
ALICE,
|
||||
pools
|
||||
);
|
||||
@@ -43,8 +42,6 @@ contract TychoRouterTestProtocolIntegration is TychoRouterTestSetup {
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
false,
|
||||
address(0),
|
||||
permitSingle,
|
||||
signature,
|
||||
swap
|
||||
@@ -77,8 +74,7 @@ contract TychoRouterTestProtocolIntegration is TychoRouterTestSetup {
|
||||
USDE_ADDR,
|
||||
WBTC_ADDR,
|
||||
true,
|
||||
true, // transferFrom to protocol
|
||||
false, // transfer to protocol
|
||||
RestrictTransferFrom.TransferType.TransferFrom,
|
||||
ALICE,
|
||||
pools
|
||||
);
|
||||
@@ -89,16 +85,7 @@ contract TychoRouterTestProtocolIntegration is TychoRouterTestSetup {
|
||||
vm.startPrank(ALICE);
|
||||
IERC20(USDE_ADDR).approve(tychoRouterAddr, amountIn);
|
||||
tychoRouter.singleSwap(
|
||||
amountIn,
|
||||
USDE_ADDR,
|
||||
WBTC_ADDR,
|
||||
118280,
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
false,
|
||||
address(0),
|
||||
swap
|
||||
amountIn, USDE_ADDR, WBTC_ADDR, 118280, false, false, ALICE, swap
|
||||
);
|
||||
|
||||
assertEq(IERC20(WBTC_ADDR).balanceOf(ALICE), 118281);
|
||||
@@ -277,8 +264,7 @@ contract TychoRouterTestProtocolIntegration is TychoRouterTestSetup {
|
||||
ALICE,
|
||||
DAI_WETH_USV3,
|
||||
zeroForOne,
|
||||
true, // permit2 transferFrom to protocol
|
||||
false // transfer to protocol
|
||||
RestrictTransferFrom.TransferType.TransferFrom
|
||||
);
|
||||
bytes memory swap =
|
||||
encodeSingleSwap(address(usv3Executor), protocolData);
|
||||
@@ -291,8 +277,6 @@ contract TychoRouterTestProtocolIntegration is TychoRouterTestSetup {
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
false,
|
||||
address(0),
|
||||
permitSingle,
|
||||
signature,
|
||||
swap
|
||||
|
||||
@@ -22,7 +22,7 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
WETH_DAI_POOL,
|
||||
DAI_USDC_POOL, // receiver (direct to next pool)
|
||||
false,
|
||||
false // transfer to protocol from router
|
||||
RestrictTransferFrom.TransferType.None // transfer to protocol from router
|
||||
)
|
||||
);
|
||||
|
||||
@@ -34,7 +34,7 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
DAI_USDC_POOL,
|
||||
ALICE,
|
||||
true,
|
||||
false // transfer to protocol from router
|
||||
RestrictTransferFrom.TransferType.None // transfer to protocol from router
|
||||
)
|
||||
);
|
||||
return swaps;
|
||||
@@ -60,8 +60,6 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
true,
|
||||
WETH_DAI_POOL,
|
||||
permitSingle,
|
||||
signature,
|
||||
pleEncode(swaps)
|
||||
@@ -89,8 +87,6 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
true,
|
||||
WETH_DAI_POOL,
|
||||
pleEncode(swaps)
|
||||
);
|
||||
|
||||
@@ -117,8 +113,6 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
true,
|
||||
WETH_DAI_POOL,
|
||||
pleEncode(swaps)
|
||||
);
|
||||
}
|
||||
@@ -141,8 +135,6 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
true,
|
||||
WETH_DAI_POOL,
|
||||
pleEncode(swaps)
|
||||
);
|
||||
}
|
||||
@@ -177,8 +169,6 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
true,
|
||||
WETH_DAI_POOL,
|
||||
permitSingle,
|
||||
signature,
|
||||
pleEncode(swaps)
|
||||
@@ -208,14 +198,24 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
swaps[0] = encodeSequentialSwap(
|
||||
address(usv2Executor),
|
||||
encodeUniswapV2Swap(
|
||||
WETH_ADDR, WETH_DAI_POOL, DAI_USDC_POOL, false, true
|
||||
WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
DAI_USDC_POOL,
|
||||
false,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
)
|
||||
);
|
||||
|
||||
// DAI -> USDC
|
||||
swaps[1] = encodeSequentialSwap(
|
||||
address(usv2Executor),
|
||||
encodeUniswapV2Swap(DAI_ADDR, DAI_USDC_POOL, ALICE, true, false)
|
||||
encodeUniswapV2Swap(
|
||||
DAI_ADDR,
|
||||
DAI_USDC_POOL,
|
||||
ALICE,
|
||||
true,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
)
|
||||
);
|
||||
|
||||
uint256 amountOut = tychoRouter.sequentialSwapPermit2{value: amountIn}(
|
||||
@@ -226,8 +226,6 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
true,
|
||||
false,
|
||||
ALICE,
|
||||
false,
|
||||
address(0),
|
||||
emptyPermitSingle,
|
||||
"",
|
||||
pleEncode(swaps)
|
||||
@@ -260,7 +258,11 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
swaps[0] = encodeSequentialSwap(
|
||||
address(usv2Executor),
|
||||
encodeUniswapV2Swap(
|
||||
USDC_ADDR, DAI_USDC_POOL, tychoRouterAddr, false, false
|
||||
USDC_ADDR,
|
||||
DAI_USDC_POOL,
|
||||
tychoRouterAddr,
|
||||
false,
|
||||
RestrictTransferFrom.TransferType.TransferFrom
|
||||
)
|
||||
);
|
||||
|
||||
@@ -268,7 +270,11 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
swaps[1] = encodeSequentialSwap(
|
||||
address(usv2Executor),
|
||||
encodeUniswapV2Swap(
|
||||
DAI_ADDR, WETH_DAI_POOL, tychoRouterAddr, true, true
|
||||
DAI_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
tychoRouterAddr,
|
||||
true,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
)
|
||||
);
|
||||
|
||||
@@ -280,8 +286,6 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
true,
|
||||
ALICE,
|
||||
true,
|
||||
DAI_USDC_POOL,
|
||||
permitSingle,
|
||||
signature,
|
||||
pleEncode(swaps)
|
||||
@@ -307,8 +311,7 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
tychoRouterAddr,
|
||||
USDC_WETH_USV3,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes memory usdcWethV3Pool2OneZeroData = encodeUniswapV3Swap(
|
||||
@@ -317,8 +320,7 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
tychoRouterAddr,
|
||||
USDC_WETH_USV3_2,
|
||||
false,
|
||||
false, // permit2 transferFrom to protocol
|
||||
true // transfer to protocol
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes[] memory swaps = new bytes[](2);
|
||||
|
||||
@@ -26,7 +26,7 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
WETH_DAI_POOL,
|
||||
ALICE,
|
||||
false,
|
||||
false // funds already in WETH_DAI_POOL, no transfer necessary
|
||||
RestrictTransferFrom.TransferType.None // funds already in WETH_DAI_POOL, no transfer necessary
|
||||
);
|
||||
|
||||
bytes memory swap =
|
||||
@@ -40,8 +40,6 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
true, // transferFrom to WETH_DAI_POOL
|
||||
WETH_DAI_POOL, // receiver of input tokens
|
||||
permitSingle,
|
||||
signature,
|
||||
swap
|
||||
@@ -69,7 +67,7 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
WETH_DAI_POOL,
|
||||
ALICE,
|
||||
false,
|
||||
false // funds already in WETH_DAI_POOL, no transfer necessary
|
||||
RestrictTransferFrom.TransferType.None // funds already in WETH_DAI_POOL, no transfer necessary
|
||||
);
|
||||
|
||||
bytes memory swap =
|
||||
@@ -84,8 +82,6 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
true,
|
||||
WETH_DAI_POOL,
|
||||
swap
|
||||
);
|
||||
|
||||
@@ -107,24 +103,20 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
vm.startPrank(ALICE);
|
||||
IERC20(WETH_ADDR).approve(address(tychoRouterAddr), amountIn);
|
||||
|
||||
bytes memory protocolData =
|
||||
encodeUniswapV2Swap(WETH_ADDR, WETH_DAI_POOL, ALICE, false, false);
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
ALICE,
|
||||
false,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
bytes memory swap =
|
||||
encodeSingleSwap(address(usv2Executor), protocolData);
|
||||
|
||||
vm.expectRevert(TychoRouter__UndefinedMinAmountOut.selector);
|
||||
tychoRouter.singleSwap(
|
||||
amountIn,
|
||||
WETH_ADDR,
|
||||
DAI_ADDR,
|
||||
0,
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
true,
|
||||
WETH_DAI_POOL,
|
||||
swap
|
||||
amountIn, WETH_ADDR, DAI_ADDR, 0, false, false, ALICE, swap
|
||||
);
|
||||
}
|
||||
|
||||
@@ -142,7 +134,7 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
WETH_DAI_POOL,
|
||||
ALICE,
|
||||
false,
|
||||
false // funds already in WETH_DAI_POOL, no transfer necessary
|
||||
RestrictTransferFrom.TransferType.None // funds already in WETH_DAI_POOL, no transfer necessary
|
||||
);
|
||||
|
||||
bytes memory swap =
|
||||
@@ -158,8 +150,6 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
true,
|
||||
WETH_DAI_POOL,
|
||||
swap
|
||||
);
|
||||
}
|
||||
@@ -179,7 +169,7 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
WETH_DAI_POOL,
|
||||
ALICE,
|
||||
false,
|
||||
false // funds already in WETH_DAI_POOL, no transfer necessary
|
||||
RestrictTransferFrom.TransferType.None // funds already in WETH_DAI_POOL, no transfer necessary
|
||||
);
|
||||
|
||||
bytes memory swap =
|
||||
@@ -202,8 +192,6 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
false,
|
||||
ALICE,
|
||||
true,
|
||||
WETH_DAI_POOL,
|
||||
swap
|
||||
);
|
||||
}
|
||||
@@ -225,8 +213,13 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
sigDeadline: 0
|
||||
});
|
||||
|
||||
bytes memory protocolData =
|
||||
encodeUniswapV2Swap(WETH_ADDR, WETH_DAI_POOL, ALICE, false, true);
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
ALICE,
|
||||
false,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
bytes memory swap =
|
||||
encodeSingleSwap(address(usv2Executor), protocolData);
|
||||
@@ -239,8 +232,6 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
true,
|
||||
false,
|
||||
ALICE,
|
||||
false,
|
||||
tychoRouterAddr,
|
||||
emptyPermitSingle,
|
||||
"",
|
||||
swap
|
||||
@@ -266,7 +257,11 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
) = handlePermit2Approval(DAI_ADDR, tychoRouterAddr, amountIn);
|
||||
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
DAI_ADDR, WETH_DAI_POOL, tychoRouterAddr, true, false
|
||||
DAI_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
tychoRouterAddr,
|
||||
true,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
bytes memory swap =
|
||||
@@ -280,8 +275,6 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
true,
|
||||
ALICE,
|
||||
true, // transferFrom to WETH_DAI_POOL
|
||||
WETH_DAI_POOL, // receiver of input tokens
|
||||
permitSingle,
|
||||
signature,
|
||||
swap
|
||||
|
||||
@@ -23,7 +23,11 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
(0xffffff * 60) / 100, // 60%
|
||||
address(usv2Executor),
|
||||
encodeUniswapV2Swap(
|
||||
WETH_ADDR, WETH_WBTC_POOL, tychoRouterAddr, false, true
|
||||
WETH_ADDR,
|
||||
WETH_WBTC_POOL,
|
||||
tychoRouterAddr,
|
||||
false,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
)
|
||||
);
|
||||
// WBTC -> USDC
|
||||
@@ -32,7 +36,13 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
uint8(2),
|
||||
uint24(0),
|
||||
address(usv2Executor),
|
||||
encodeUniswapV2Swap(WBTC_ADDR, USDC_WBTC_POOL, ALICE, true, true)
|
||||
encodeUniswapV2Swap(
|
||||
WBTC_ADDR,
|
||||
USDC_WBTC_POOL,
|
||||
ALICE,
|
||||
true,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
)
|
||||
);
|
||||
// WETH -> DAI
|
||||
swaps[2] = encodeSplitSwap(
|
||||
@@ -41,7 +51,11 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
uint24(0),
|
||||
address(usv2Executor),
|
||||
encodeUniswapV2Swap(
|
||||
WETH_ADDR, WETH_DAI_POOL, tychoRouterAddr, false, true
|
||||
WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
tychoRouterAddr,
|
||||
false,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
)
|
||||
);
|
||||
|
||||
@@ -51,7 +65,13 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
uint8(2),
|
||||
uint24(0),
|
||||
address(usv2Executor),
|
||||
encodeUniswapV2Swap(DAI_ADDR, DAI_USDC_POOL, ALICE, true, true)
|
||||
encodeUniswapV2Swap(
|
||||
DAI_ADDR,
|
||||
DAI_USDC_POOL,
|
||||
ALICE,
|
||||
true,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
)
|
||||
);
|
||||
|
||||
return swaps;
|
||||
@@ -95,7 +115,6 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
4,
|
||||
ALICE,
|
||||
true,
|
||||
permitSingle,
|
||||
signature,
|
||||
pleEncode(swaps)
|
||||
@@ -125,7 +144,6 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
4,
|
||||
ALICE,
|
||||
true,
|
||||
pleEncode(swaps)
|
||||
);
|
||||
|
||||
@@ -154,7 +172,6 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
4,
|
||||
ALICE,
|
||||
true,
|
||||
pleEncode(swaps)
|
||||
);
|
||||
vm.stopPrank();
|
||||
@@ -180,7 +197,6 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
2,
|
||||
ALICE,
|
||||
true,
|
||||
pleEncode(swaps)
|
||||
);
|
||||
|
||||
@@ -218,7 +234,6 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
4,
|
||||
ALICE,
|
||||
true,
|
||||
permitSingle,
|
||||
signature,
|
||||
pleEncode(swaps)
|
||||
@@ -245,8 +260,13 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
spender: address(0),
|
||||
sigDeadline: 0
|
||||
});
|
||||
bytes memory protocolData =
|
||||
encodeUniswapV2Swap(WETH_ADDR, WETH_DAI_POOL, ALICE, false, true);
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
ALICE,
|
||||
false,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes memory swap = encodeSplitSwap(
|
||||
uint8(0), uint8(1), uint24(0), address(usv2Executor), protocolData
|
||||
@@ -263,7 +283,6 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
2,
|
||||
ALICE,
|
||||
false,
|
||||
emptyPermitSingle,
|
||||
"",
|
||||
pleEncode(swaps)
|
||||
@@ -291,7 +310,11 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
) = handlePermit2Approval(DAI_ADDR, tychoRouterAddr, amountIn);
|
||||
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
DAI_ADDR, WETH_DAI_POOL, tychoRouterAddr, true, true
|
||||
DAI_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
tychoRouterAddr,
|
||||
true,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes memory swap = encodeSplitSwap(
|
||||
@@ -309,7 +332,6 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
true,
|
||||
2,
|
||||
ALICE,
|
||||
true,
|
||||
permitSingle,
|
||||
signature,
|
||||
pleEncode(swaps)
|
||||
@@ -349,8 +371,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
tychoRouterAddr,
|
||||
USDC_WETH_USV3,
|
||||
true,
|
||||
false, // transferFrom swapper required
|
||||
true // transfer from tycho router to protocol
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes memory usdcWethV3Pool2ZeroOneData = encodeUniswapV3Swap(
|
||||
@@ -359,8 +380,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
tychoRouterAddr,
|
||||
USDC_WETH_USV3_2,
|
||||
true,
|
||||
false, // transferFrom swapper required
|
||||
true // transfer from tycho router to protocol
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes memory wethUsdcV2OneZeroData = encodeUniswapV2Swap(
|
||||
@@ -368,7 +388,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
USDC_WETH_USV2,
|
||||
tychoRouterAddr,
|
||||
false,
|
||||
true // transfer from tycho router to protocol
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes[] memory swaps = new bytes[](3);
|
||||
@@ -424,8 +444,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
tychoRouterAddr,
|
||||
USDC_WETH_USV3,
|
||||
true,
|
||||
true, // transferFrom swapper required
|
||||
false // transfer from tycho router to protocol
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes memory usdcWethV3Pool2ZeroOneData = encodeUniswapV3Swap(
|
||||
@@ -434,8 +453,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
tychoRouterAddr,
|
||||
USDC_WETH_USV3_2,
|
||||
true,
|
||||
true, // transferFrom swapper required
|
||||
false // transfer from tycho router to protocol
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes[] memory swaps = new bytes[](2);
|
||||
@@ -465,7 +483,6 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
false,
|
||||
2,
|
||||
ALICE,
|
||||
false,
|
||||
pleEncode(swaps)
|
||||
);
|
||||
vm.stopPrank();
|
||||
@@ -488,7 +505,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
USDC_WETH_USV2,
|
||||
tychoRouterAddr,
|
||||
true,
|
||||
true // transfer required
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes memory usdcWethV3Pool1OneZeroData = encodeUniswapV3Swap(
|
||||
@@ -497,8 +514,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
tychoRouterAddr,
|
||||
USDC_WETH_USV3,
|
||||
false,
|
||||
false, // transferFrom required
|
||||
true // transfer required
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes memory usdcWethV3Pool2OneZeroData = encodeUniswapV3Swap(
|
||||
@@ -507,8 +523,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
tychoRouterAddr,
|
||||
USDC_WETH_USV3_2,
|
||||
false,
|
||||
false, // transferFrom required
|
||||
true // transfer required
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes[] memory swaps = new bytes[](3);
|
||||
@@ -547,7 +562,11 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
deal(BASE_USDC, tychoRouterAddr, amountIn);
|
||||
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
BASE_USDC, USDC_MAG7_POOL, tychoRouterAddr, true, true
|
||||
BASE_USDC,
|
||||
USDC_MAG7_POOL,
|
||||
tychoRouterAddr,
|
||||
true,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
bytes memory swap = encodeSplitSwap(
|
||||
|
||||
@@ -185,11 +185,10 @@ contract TychoRouterTestSetup is Constants, Permit2TestHelper, TestUtils {
|
||||
address target,
|
||||
address receiver,
|
||||
bool zero2one,
|
||||
bool transferNeeded
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
) internal pure returns (bytes memory) {
|
||||
return abi.encodePacked(
|
||||
tokenIn, target, receiver, zero2one, transferNeeded
|
||||
);
|
||||
return
|
||||
abi.encodePacked(tokenIn, target, receiver, zero2one, transferType);
|
||||
}
|
||||
|
||||
function encodeUniswapV3Swap(
|
||||
@@ -198,8 +197,7 @@ contract TychoRouterTestSetup is Constants, Permit2TestHelper, TestUtils {
|
||||
address receiver,
|
||||
address target,
|
||||
bool zero2one,
|
||||
bool transferFromNeeded,
|
||||
bool transferNeeded
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
) internal view returns (bytes memory) {
|
||||
IUniswapV3Pool pool = IUniswapV3Pool(target);
|
||||
return abi.encodePacked(
|
||||
@@ -209,8 +207,7 @@ contract TychoRouterTestSetup is Constants, Permit2TestHelper, TestUtils {
|
||||
receiver,
|
||||
target,
|
||||
zero2one,
|
||||
transferFromNeeded,
|
||||
transferNeeded
|
||||
transferType
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ contract BalancerV2ExecutorExposed is BalancerV2Executor {
|
||||
IERC20 tokenOut,
|
||||
bytes32 poolId,
|
||||
address receiver,
|
||||
bool needsApproval
|
||||
bool needsApproval,
|
||||
TransferType transferType
|
||||
)
|
||||
{
|
||||
return _decodeData(data);
|
||||
@@ -40,7 +41,12 @@ contract BalancerV2ExecutorTest is Constants, TestUtils {
|
||||
|
||||
function testDecodeParams() public view {
|
||||
bytes memory params = abi.encodePacked(
|
||||
WETH_ADDR, BAL_ADDR, WETH_BAL_POOL_ID, address(2), true
|
||||
WETH_ADDR,
|
||||
BAL_ADDR,
|
||||
WETH_BAL_POOL_ID,
|
||||
address(2),
|
||||
true,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
(
|
||||
@@ -48,7 +54,8 @@ contract BalancerV2ExecutorTest is Constants, TestUtils {
|
||||
IERC20 tokenOut,
|
||||
bytes32 poolId,
|
||||
address receiver,
|
||||
bool needsApproval
|
||||
bool needsApproval,
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
) = balancerV2Exposed.decodeParams(params);
|
||||
|
||||
assertEq(address(tokenIn), WETH_ADDR);
|
||||
@@ -56,6 +63,9 @@ contract BalancerV2ExecutorTest is Constants, TestUtils {
|
||||
assertEq(poolId, WETH_BAL_POOL_ID);
|
||||
assertEq(receiver, address(2));
|
||||
assertEq(needsApproval, true);
|
||||
assertEq(
|
||||
uint8(transferType), uint8(RestrictTransferFrom.TransferType.None)
|
||||
);
|
||||
}
|
||||
|
||||
function testDecodeParamsInvalidDataLength() public {
|
||||
@@ -89,7 +99,8 @@ contract BalancerV2ExecutorTest is Constants, TestUtils {
|
||||
IERC20 tokenOut,
|
||||
bytes32 poolId,
|
||||
address receiver,
|
||||
bool needsApproval
|
||||
bool needsApproval,
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
) = balancerV2Exposed.decodeParams(protocolData);
|
||||
|
||||
assertEq(address(tokenIn), WETH_ADDR);
|
||||
@@ -97,6 +108,9 @@ contract BalancerV2ExecutorTest is Constants, TestUtils {
|
||||
assertEq(poolId, WETH_BAL_POOL_ID);
|
||||
assertEq(receiver, BOB);
|
||||
assertEq(needsApproval, true);
|
||||
assertEq(
|
||||
uint8(transferType), uint8(RestrictTransferFrom.TransferType.None)
|
||||
);
|
||||
}
|
||||
|
||||
function testSwapIntegration() public {
|
||||
|
||||
@@ -37,6 +37,7 @@ contract CurveExecutorExposed is CurveExecutor {
|
||||
int128 i,
|
||||
int128 j,
|
||||
bool tokenApprovalNeeded,
|
||||
RestrictTransferFrom.TransferType transferType,
|
||||
address receiver
|
||||
)
|
||||
{
|
||||
@@ -67,6 +68,7 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint8(2),
|
||||
uint8(0),
|
||||
true,
|
||||
RestrictTransferFrom.TransferType.None,
|
||||
ALICE
|
||||
);
|
||||
|
||||
@@ -78,6 +80,7 @@ contract CurveExecutorTest is Test, Constants {
|
||||
int128 i,
|
||||
int128 j,
|
||||
bool tokenApprovalNeeded,
|
||||
RestrictTransferFrom.TransferType transferType,
|
||||
address receiver
|
||||
) = curveExecutorExposed.decodeData(data);
|
||||
|
||||
@@ -88,6 +91,9 @@ contract CurveExecutorTest is Test, Constants {
|
||||
assertEq(i, 2);
|
||||
assertEq(j, 0);
|
||||
assertEq(tokenApprovalNeeded, true);
|
||||
assertEq(
|
||||
uint8(transferType), uint8(RestrictTransferFrom.TransferType.None)
|
||||
);
|
||||
assertEq(receiver, ALICE);
|
||||
}
|
||||
|
||||
@@ -96,7 +102,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 1 ether;
|
||||
deal(DAI_ADDR, address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data = _getData(DAI_ADDR, USDC_ADDR, TRIPOOL, 1, ALICE);
|
||||
bytes memory data = _getData(
|
||||
DAI_ADDR,
|
||||
USDC_ADDR,
|
||||
TRIPOOL,
|
||||
1,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -109,8 +122,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 1 ether;
|
||||
deal(address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data =
|
||||
_getData(ETH_ADDR_FOR_CURVE, STETH_ADDR, STETH_POOL, 1, ALICE);
|
||||
bytes memory data = _getData(
|
||||
ETH_ADDR_FOR_CURVE,
|
||||
STETH_ADDR,
|
||||
STETH_POOL,
|
||||
1,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -126,8 +145,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 1 ether;
|
||||
deal(WETH_ADDR, address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data =
|
||||
_getData(WETH_ADDR, WBTC_ADDR, TRICRYPTO2_POOL, 3, ALICE);
|
||||
bytes memory data = _getData(
|
||||
WETH_ADDR,
|
||||
WBTC_ADDR,
|
||||
TRICRYPTO2_POOL,
|
||||
3,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -140,7 +165,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 100 * 10 ** 6;
|
||||
deal(USDC_ADDR, address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data = _getData(USDC_ADDR, SUSD_ADDR, SUSD_POOL, 1, ALICE);
|
||||
bytes memory data = _getData(
|
||||
USDC_ADDR,
|
||||
SUSD_ADDR,
|
||||
SUSD_POOL,
|
||||
1,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -153,8 +185,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 1 ether;
|
||||
deal(FRAX_ADDR, address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data =
|
||||
_getData(FRAX_ADDR, USDC_ADDR, FRAX_USDC_POOL, 1, ALICE);
|
||||
bytes memory data = _getData(
|
||||
FRAX_ADDR,
|
||||
USDC_ADDR,
|
||||
FRAX_USDC_POOL,
|
||||
1,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -167,8 +205,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 100 * 10 ** 6;
|
||||
deal(USDC_ADDR, address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data =
|
||||
_getData(USDC_ADDR, USDE_ADDR, USDE_USDC_POOL, 1, ALICE);
|
||||
bytes memory data = _getData(
|
||||
USDC_ADDR,
|
||||
USDE_ADDR,
|
||||
USDE_USDC_POOL,
|
||||
1,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -181,8 +225,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 100 * 10 ** 6;
|
||||
deal(DOLA_ADDR, address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data =
|
||||
_getData(DOLA_ADDR, FRAXPYUSD_POOL, DOLA_FRAXPYUSD_POOL, 1, ALICE);
|
||||
bytes memory data = _getData(
|
||||
DOLA_ADDR,
|
||||
FRAXPYUSD_POOL,
|
||||
DOLA_FRAXPYUSD_POOL,
|
||||
1,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -196,8 +246,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 initialBalance = address(ALICE).balance; // this address already has some ETH assigned to it
|
||||
deal(XYO_ADDR, address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data =
|
||||
_getData(XYO_ADDR, ETH_ADDR_FOR_CURVE, ETH_XYO_POOL, 2, ALICE);
|
||||
bytes memory data = _getData(
|
||||
XYO_ADDR,
|
||||
ETH_ADDR_FOR_CURVE,
|
||||
ETH_XYO_POOL,
|
||||
2,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -210,8 +266,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 1000 ether;
|
||||
deal(BSGG_ADDR, address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data =
|
||||
_getData(BSGG_ADDR, USDT_ADDR, BSGG_USDT_POOL, 2, ALICE);
|
||||
bytes memory data = _getData(
|
||||
BSGG_ADDR,
|
||||
USDT_ADDR,
|
||||
BSGG_USDT_POOL,
|
||||
2,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -224,8 +286,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 1 ether;
|
||||
deal(WETH_ADDR, address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data =
|
||||
_getData(WETH_ADDR, USDC_ADDR, TRICRYPTO_POOL, 2, ALICE);
|
||||
bytes memory data = _getData(
|
||||
WETH_ADDR,
|
||||
USDC_ADDR,
|
||||
TRICRYPTO_POOL,
|
||||
2,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -238,8 +306,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 1 ether;
|
||||
deal(UWU_ADDR, address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data =
|
||||
_getData(UWU_ADDR, WETH_ADDR, UWU_WETH_POOL, 2, ALICE);
|
||||
bytes memory data = _getData(
|
||||
UWU_ADDR,
|
||||
WETH_ADDR,
|
||||
UWU_WETH_POOL,
|
||||
2,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -252,8 +326,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 1 ether;
|
||||
deal(USDT_ADDR, address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data =
|
||||
_getData(USDT_ADDR, CRVUSD_ADDR, CRVUSD_USDT_POOL, 1, ALICE);
|
||||
bytes memory data = _getData(
|
||||
USDT_ADDR,
|
||||
CRVUSD_ADDR,
|
||||
CRVUSD_USDT_POOL,
|
||||
1,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -266,8 +346,14 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint256 amountIn = 100 * 10 ** 9; // 9 decimals
|
||||
deal(WTAO_ADDR, address(curveExecutorExposed), amountIn);
|
||||
|
||||
bytes memory data =
|
||||
_getData(WTAO_ADDR, WSTTAO_ADDR, WSTTAO_WTAO_POOL, 1, ALICE);
|
||||
bytes memory data = _getData(
|
||||
WTAO_ADDR,
|
||||
WSTTAO_ADDR,
|
||||
WSTTAO_WTAO_POOL,
|
||||
1,
|
||||
ALICE,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
uint256 amountOut = curveExecutorExposed.swap(amountIn, data);
|
||||
|
||||
@@ -280,7 +366,8 @@ contract CurveExecutorTest is Test, Constants {
|
||||
address tokenOut,
|
||||
address pool,
|
||||
uint8 poolType,
|
||||
address receiver
|
||||
address receiver,
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
) internal view returns (bytes memory data) {
|
||||
(int128 i, int128 j) = _getIndexes(tokenIn, tokenOut, pool);
|
||||
data = abi.encodePacked(
|
||||
@@ -291,6 +378,7 @@ contract CurveExecutorTest is Test, Constants {
|
||||
uint8(uint256(uint128(i))),
|
||||
uint8(uint256(uint128(j))),
|
||||
true,
|
||||
transferType,
|
||||
receiver
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ pragma solidity ^0.8.26;
|
||||
|
||||
import "../TestUtils.sol";
|
||||
import {Constants} from "../Constants.sol";
|
||||
import {EkuboExecutor} from "@src/executors/EkuboExecutor.sol";
|
||||
import "@src/executors/EkuboExecutor.sol";
|
||||
import {ICore} from "@ekubo/interfaces/ICore.sol";
|
||||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import {NATIVE_TOKEN_ADDRESS} from "@ekubo/math/constants.sol";
|
||||
@@ -45,8 +45,7 @@ contract EkuboExecutorTest is Constants, TestUtils {
|
||||
uint256 usdcBalanceBeforeExecutor = USDC.balanceOf(address(executor));
|
||||
|
||||
bytes memory data = abi.encodePacked(
|
||||
false, // transferFromNeeded (transfer user to core)
|
||||
true, // transferNeeded (transfer from executor to core)
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer), // transfer type (transfer from executor to core)
|
||||
address(executor), // receiver
|
||||
NATIVE_TOKEN_ADDRESS, // tokenIn
|
||||
USDC_ADDR, // tokenOut
|
||||
@@ -83,8 +82,7 @@ contract EkuboExecutorTest is Constants, TestUtils {
|
||||
uint256 ethBalanceBeforeExecutor = address(executor).balance;
|
||||
|
||||
bytes memory data = abi.encodePacked(
|
||||
false, // transferFromNeeded (transfer user to core)
|
||||
true, // transferNeeded (transfer from executor to core)
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer), // transferNeeded (transfer from executor to core)
|
||||
address(executor), // receiver
|
||||
USDC_ADDR, // tokenIn
|
||||
NATIVE_TOKEN_ADDRESS, // tokenOut
|
||||
@@ -142,8 +140,7 @@ contract EkuboExecutorTest is Constants, TestUtils {
|
||||
// Same test case as in swap_encoder::tests::ekubo::test_encode_swap_multi
|
||||
function testMultiHopSwap() public {
|
||||
bytes memory data = abi.encodePacked(
|
||||
false, // transferFromNeeded (transfer user to core)
|
||||
true, // transferNeeded (transfer from executor to core)
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer), // transferNeeded (transfer from executor to core)
|
||||
address(executor), // receiver
|
||||
NATIVE_TOKEN_ADDRESS, // tokenIn
|
||||
USDC_ADDR, // tokenOut of 1st swap
|
||||
|
||||
@@ -17,7 +17,7 @@ contract MaverickV2ExecutorExposed is MaverickV2Executor {
|
||||
IERC20 tokenIn,
|
||||
address target,
|
||||
address receiver,
|
||||
bool transferNeeded
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
)
|
||||
{
|
||||
return _decodeData(data);
|
||||
@@ -39,16 +39,28 @@ contract MaverickV2ExecutorTest is TestUtils, Constants {
|
||||
}
|
||||
|
||||
function testDecodeParams() public view {
|
||||
bytes memory params =
|
||||
abi.encodePacked(GHO_ADDR, GHO_USDC_POOL, address(2), true);
|
||||
bytes memory params = abi.encodePacked(
|
||||
GHO_ADDR,
|
||||
GHO_USDC_POOL,
|
||||
address(2),
|
||||
true,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
(IERC20 tokenIn, address target, address receiver, bool transferNeeded)
|
||||
= maverickV2Exposed.decodeParams(params);
|
||||
(
|
||||
IERC20 tokenIn,
|
||||
address target,
|
||||
address receiver,
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
) = maverickV2Exposed.decodeParams(params);
|
||||
|
||||
assertEq(address(tokenIn), GHO_ADDR);
|
||||
assertEq(target, GHO_USDC_POOL);
|
||||
assertEq(receiver, address(2));
|
||||
assertEq(transferNeeded, true);
|
||||
assertEq(
|
||||
uint8(transferType),
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer)
|
||||
);
|
||||
}
|
||||
|
||||
function testDecodeParamsInvalidDataLength() public {
|
||||
@@ -61,8 +73,12 @@ contract MaverickV2ExecutorTest is TestUtils, Constants {
|
||||
|
||||
function testSwap() public {
|
||||
uint256 amountIn = 10e18;
|
||||
bytes memory protocolData =
|
||||
abi.encodePacked(GHO_ADDR, GHO_USDC_POOL, BOB, true);
|
||||
bytes memory protocolData = abi.encodePacked(
|
||||
GHO_ADDR,
|
||||
GHO_USDC_POOL,
|
||||
BOB,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
deal(GHO_ADDR, address(maverickV2Exposed), amountIn);
|
||||
uint256 balanceBefore = USDC.balanceOf(BOB);
|
||||
@@ -79,13 +95,20 @@ contract MaverickV2ExecutorTest is TestUtils, Constants {
|
||||
bytes memory protocolData =
|
||||
loadCallDataFromFile("test_encode_maverick_v2");
|
||||
|
||||
(IERC20 tokenIn, address pool, address receiver, bool transferNeeded) =
|
||||
maverickV2Exposed.decodeParams(protocolData);
|
||||
(
|
||||
IERC20 tokenIn,
|
||||
address pool,
|
||||
address receiver,
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
) = maverickV2Exposed.decodeParams(protocolData);
|
||||
|
||||
assertEq(address(tokenIn), GHO_ADDR);
|
||||
assertEq(pool, GHO_USDC_POOL);
|
||||
assertEq(receiver, BOB);
|
||||
assertEq(transferNeeded, true);
|
||||
assertEq(
|
||||
uint8(transferType),
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer)
|
||||
);
|
||||
}
|
||||
|
||||
function testSwapIntegration() public {
|
||||
|
||||
@@ -23,7 +23,7 @@ contract UniswapV2ExecutorExposed is UniswapV2Executor {
|
||||
address target,
|
||||
address receiver,
|
||||
bool zeroForOne,
|
||||
bool transferNeeded
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
)
|
||||
{
|
||||
return _decodeData(data);
|
||||
@@ -82,22 +82,30 @@ contract UniswapV2ExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
}
|
||||
|
||||
function testDecodeParams() public view {
|
||||
bytes memory params =
|
||||
abi.encodePacked(WETH_ADDR, address(2), address(3), false, true);
|
||||
bytes memory params = abi.encodePacked(
|
||||
WETH_ADDR,
|
||||
address(2),
|
||||
address(3),
|
||||
false,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
(
|
||||
IERC20 tokenIn,
|
||||
address target,
|
||||
address receiver,
|
||||
bool zeroForOne,
|
||||
bool transferNeeded
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
) = uniswapV2Exposed.decodeParams(params);
|
||||
|
||||
assertEq(address(tokenIn), WETH_ADDR);
|
||||
assertEq(target, address(2));
|
||||
assertEq(receiver, address(3));
|
||||
assertEq(zeroForOne, false);
|
||||
assertEq(transferNeeded, true);
|
||||
assertEq(
|
||||
uint8(transferType),
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer)
|
||||
);
|
||||
}
|
||||
|
||||
function testDecodeParamsInvalidDataLength() public {
|
||||
@@ -148,8 +156,13 @@ contract UniswapV2ExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
uint256 amountIn = 10 ** 18;
|
||||
uint256 amountOut = 1847751195973566072891;
|
||||
bool zeroForOne = false;
|
||||
bytes memory protocolData =
|
||||
abi.encodePacked(WETH_ADDR, WETH_DAI_POOL, BOB, zeroForOne, true);
|
||||
bytes memory protocolData = abi.encodePacked(
|
||||
WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
BOB,
|
||||
zeroForOne,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
deal(WETH_ADDR, address(uniswapV2Exposed), amountIn);
|
||||
uniswapV2Exposed.swap(amountIn, protocolData);
|
||||
@@ -162,8 +175,13 @@ contract UniswapV2ExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
uint256 amountIn = 10 ** 18;
|
||||
uint256 amountOut = 1847751195973566072891;
|
||||
bool zeroForOne = false;
|
||||
bytes memory protocolData =
|
||||
abi.encodePacked(WETH_ADDR, WETH_DAI_POOL, BOB, zeroForOne, false);
|
||||
bytes memory protocolData = abi.encodePacked(
|
||||
WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
BOB,
|
||||
zeroForOne,
|
||||
RestrictTransferFrom.TransferType.None
|
||||
);
|
||||
|
||||
deal(WETH_ADDR, address(this), amountIn);
|
||||
IERC20(WETH_ADDR).transfer(address(WETH_DAI_POOL), amountIn);
|
||||
@@ -175,21 +193,24 @@ contract UniswapV2ExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
|
||||
function testDecodeIntegration() public view {
|
||||
bytes memory protocolData =
|
||||
hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc288e6a0c2ddd26feeb64f039a2c41296fcb3f564000000000000000000000000000000000000000010000";
|
||||
hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc288e6a0c2ddd26feeb64f039a2c41296fcb3f564000000000000000000000000000000000000000010001";
|
||||
|
||||
(
|
||||
IERC20 tokenIn,
|
||||
address target,
|
||||
address receiver,
|
||||
bool zeroForOne,
|
||||
bool transferNeeded
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
) = uniswapV2Exposed.decodeParams(protocolData);
|
||||
|
||||
assertEq(address(tokenIn), WETH_ADDR);
|
||||
assertEq(target, 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640);
|
||||
assertEq(receiver, 0x0000000000000000000000000000000000000001);
|
||||
assertEq(zeroForOne, false);
|
||||
assertEq(transferNeeded, false);
|
||||
assertEq(
|
||||
uint8(transferType),
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer)
|
||||
);
|
||||
}
|
||||
|
||||
function testSwapIntegration() public {
|
||||
@@ -208,8 +229,13 @@ contract UniswapV2ExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
uint256 amountIn = 10 ** 18;
|
||||
bool zeroForOne = false;
|
||||
address fakePool = address(new FakeUniswapV2Pool(WETH_ADDR, DAI_ADDR));
|
||||
bytes memory protocolData =
|
||||
abi.encodePacked(WETH_ADDR, fakePool, BOB, zeroForOne, true);
|
||||
bytes memory protocolData = abi.encodePacked(
|
||||
WETH_ADDR,
|
||||
fakePool,
|
||||
BOB,
|
||||
zeroForOne,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
deal(WETH_ADDR, address(uniswapV2Exposed), amountIn);
|
||||
vm.expectRevert(UniswapV2Executor__InvalidTarget.selector);
|
||||
@@ -223,8 +249,13 @@ contract UniswapV2ExecutorTest is Constants, Permit2TestHelper, TestUtils {
|
||||
vm.rollFork(26857267);
|
||||
uint256 amountIn = 10 * 10 ** 6;
|
||||
bool zeroForOne = true;
|
||||
bytes memory protocolData =
|
||||
abi.encodePacked(BASE_USDC, USDC_MAG7_POOL, BOB, zeroForOne, true);
|
||||
bytes memory protocolData = abi.encodePacked(
|
||||
BASE_USDC,
|
||||
USDC_MAG7_POOL,
|
||||
BOB,
|
||||
zeroForOne,
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
deal(BASE_USDC, address(uniswapV2Exposed), amountIn);
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@ contract UniswapV3ExecutorExposed is UniswapV3Executor {
|
||||
address receiver,
|
||||
address target,
|
||||
bool zeroForOne,
|
||||
bool transferFromNeeded,
|
||||
bool transferNeeded
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
)
|
||||
{
|
||||
return _decodeData(data);
|
||||
@@ -72,8 +71,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
|
||||
address(2),
|
||||
address(3),
|
||||
false,
|
||||
false,
|
||||
true
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
(
|
||||
@@ -83,8 +81,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
|
||||
address receiver,
|
||||
address target,
|
||||
bool zeroForOne,
|
||||
bool transferFromNeeded,
|
||||
bool transferNeeded
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
) = uniswapV3Exposed.decodeData(data);
|
||||
|
||||
assertEq(tokenIn, WETH_ADDR);
|
||||
@@ -93,8 +90,10 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
|
||||
assertEq(receiver, address(2));
|
||||
assertEq(target, address(3));
|
||||
assertEq(zeroForOne, false);
|
||||
assertEq(transferFromNeeded, false);
|
||||
assertEq(transferNeeded, true);
|
||||
assertEq(
|
||||
uint8(transferType),
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer)
|
||||
);
|
||||
}
|
||||
|
||||
function testSwapIntegration() public {
|
||||
@@ -110,8 +109,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
|
||||
address(this),
|
||||
DAI_WETH_USV3,
|
||||
zeroForOne,
|
||||
false,
|
||||
true
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
uint256 amountOut = uniswapV3Exposed.swap(amountIn, data);
|
||||
@@ -149,7 +147,11 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
|
||||
|
||||
vm.startPrank(DAI_WETH_USV3);
|
||||
bytes memory protocolData = abi.encodePacked(
|
||||
WETH_ADDR, DAI_ADDR, poolFee, false, true, address(uniswapV3Exposed)
|
||||
WETH_ADDR,
|
||||
DAI_ADDR,
|
||||
poolFee,
|
||||
RestrictTransferFrom.TransferType.Transfer,
|
||||
address(uniswapV3Exposed)
|
||||
);
|
||||
uint256 dataOffset = 3; // some offset
|
||||
uint256 dataLength = protocolData.length;
|
||||
@@ -182,8 +184,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
|
||||
address(this),
|
||||
fakePool,
|
||||
zeroForOne,
|
||||
false,
|
||||
true
|
||||
RestrictTransferFrom.TransferType.Transfer
|
||||
);
|
||||
|
||||
vm.expectRevert(UniswapV3Executor__InvalidTarget.selector);
|
||||
@@ -196,8 +197,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
|
||||
address receiver,
|
||||
address target,
|
||||
bool zero2one,
|
||||
bool transferFromNeeded,
|
||||
bool transferNeeded
|
||||
RestrictTransferFrom.TransferType transferType
|
||||
) internal view returns (bytes memory) {
|
||||
IUniswapV3Pool pool = IUniswapV3Pool(target);
|
||||
return abi.encodePacked(
|
||||
@@ -207,8 +207,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
|
||||
receiver,
|
||||
target,
|
||||
zero2one,
|
||||
transferFromNeeded,
|
||||
transferNeeded
|
||||
transferType
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,7 @@ contract UniswapV4ExecutorExposed is UniswapV4Executor {
|
||||
address tokenIn,
|
||||
address tokenOut,
|
||||
bool zeroForOne,
|
||||
bool transferFromNeeded,
|
||||
bool transferNeeded,
|
||||
RestrictTransferFrom.TransferType transferType,
|
||||
address receiver,
|
||||
UniswapV4Pool[] memory pools
|
||||
)
|
||||
@@ -53,8 +52,6 @@ contract UniswapV4ExecutorTest is Constants, TestUtils {
|
||||
int24 tickSpacing1 = 60;
|
||||
uint24 pool2Fee = 1000;
|
||||
int24 tickSpacing2 = -10;
|
||||
bool transferFromNeeded = false;
|
||||
bool transferNeeded = true;
|
||||
|
||||
UniswapV4Executor.UniswapV4Pool[] memory pools =
|
||||
new UniswapV4Executor.UniswapV4Pool[](2);
|
||||
@@ -73,8 +70,7 @@ contract UniswapV4ExecutorTest is Constants, TestUtils {
|
||||
USDE_ADDR,
|
||||
USDT_ADDR,
|
||||
zeroForOne,
|
||||
transferFromNeeded,
|
||||
transferNeeded,
|
||||
RestrictTransferFrom.TransferType.Transfer,
|
||||
ALICE,
|
||||
pools
|
||||
);
|
||||
@@ -83,8 +79,7 @@ contract UniswapV4ExecutorTest is Constants, TestUtils {
|
||||
address tokenIn,
|
||||
address tokenOut,
|
||||
bool zeroForOneDecoded,
|
||||
bool transferFromNeededDecoded,
|
||||
bool transferNeededDecoded,
|
||||
RestrictTransferFrom.TransferType transferType,
|
||||
address receiver,
|
||||
UniswapV4Executor.UniswapV4Pool[] memory decodedPools
|
||||
) = uniswapV4Exposed.decodeData(data);
|
||||
@@ -92,8 +87,10 @@ contract UniswapV4ExecutorTest is Constants, TestUtils {
|
||||
assertEq(tokenIn, USDE_ADDR);
|
||||
assertEq(tokenOut, USDT_ADDR);
|
||||
assertEq(zeroForOneDecoded, zeroForOne);
|
||||
assertEq(transferFromNeededDecoded, transferFromNeeded);
|
||||
assertEq(transferNeededDecoded, transferNeeded);
|
||||
assertEq(
|
||||
uint8(transferType),
|
||||
uint8(RestrictTransferFrom.TransferType.Transfer)
|
||||
);
|
||||
assertEq(receiver, ALICE);
|
||||
assertEq(decodedPools.length, 2);
|
||||
assertEq(decodedPools[0].intermediaryToken, USDT_ADDR);
|
||||
@@ -120,7 +117,12 @@ contract UniswapV4ExecutorTest is Constants, TestUtils {
|
||||
});
|
||||
|
||||
bytes memory data = UniswapV4Utils.encodeExactInput(
|
||||
USDE_ADDR, USDT_ADDR, true, false, true, ALICE, pools
|
||||
USDE_ADDR,
|
||||
USDT_ADDR,
|
||||
true,
|
||||
RestrictTransferFrom.TransferType.Transfer,
|
||||
ALICE,
|
||||
pools
|
||||
);
|
||||
|
||||
uint256 amountOut = uniswapV4Exposed.swap(amountIn, data);
|
||||
@@ -172,7 +174,12 @@ contract UniswapV4ExecutorTest is Constants, TestUtils {
|
||||
});
|
||||
|
||||
bytes memory data = UniswapV4Utils.encodeExactInput(
|
||||
USDE_ADDR, WBTC_ADDR, true, false, true, ALICE, pools
|
||||
USDE_ADDR,
|
||||
WBTC_ADDR,
|
||||
true,
|
||||
RestrictTransferFrom.TransferType.Transfer,
|
||||
ALICE,
|
||||
pools
|
||||
);
|
||||
|
||||
uint256 amountOut = uniswapV4Exposed.swap(amountIn, data);
|
||||
|
||||
@@ -8,8 +8,7 @@ library UniswapV4Utils {
|
||||
address tokenIn,
|
||||
address tokenOut,
|
||||
bool zeroForOne,
|
||||
bool transferFromNeeded,
|
||||
bool transferNeeded,
|
||||
RestrictTransferFrom.TransferType transferType,
|
||||
address receiver,
|
||||
UniswapV4Executor.UniswapV4Pool[] memory pools
|
||||
) public pure returns (bytes memory) {
|
||||
@@ -25,13 +24,7 @@ library UniswapV4Utils {
|
||||
}
|
||||
|
||||
return abi.encodePacked(
|
||||
tokenIn,
|
||||
tokenOut,
|
||||
zeroForOne,
|
||||
transferFromNeeded,
|
||||
transferNeeded,
|
||||
receiver,
|
||||
encodedPools
|
||||
tokenIn, tokenOut, zeroForOne, transferType, receiver, encodedPools
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user