feat: Support out transfer straight to the receiver
- The out transfer is now a responsibility of the Executors -> remove this from router methods - Also adding a check that the receiver got the full amount out - In encoding, if it is the last swap, pass the receiver as the trade receiver and not the router address (fix encoding tests) - Fixed some solidity tests (after rebasing with a PR that is still open, I will fix them all) TODO: Adapt curve and uniswap v4 to support this --- don't change below this line --- ENG-4315 Took 3 hours 7 minutes Took 20 minutes Took 59 seconds Took 7 minutes
This commit is contained in:
@@ -36,7 +36,7 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
encodeUniswapV2Swap(
|
||||
DAI_ADDR,
|
||||
DAI_USDC_POOL,
|
||||
tychoRouterAddr,
|
||||
ALICE,
|
||||
true,
|
||||
TokenTransfer.TransferType.TRANSFER_TO_PROTOCOL
|
||||
)
|
||||
@@ -44,22 +44,6 @@ contract TychoRouterSequentialSwapTest is TychoRouterTestSetup {
|
||||
return swaps;
|
||||
}
|
||||
|
||||
function testSequentialSwapInternalMethod() public {
|
||||
// Trade 1 WETH for USDC through DAI - see _getSequentialSwaps for more info
|
||||
uint256 amountIn = 1 ether;
|
||||
deal(WETH_ADDR, ALICE, amountIn);
|
||||
vm.startPrank(ALICE);
|
||||
IERC20(WETH_ADDR).approve(tychoRouterAddr, amountIn);
|
||||
|
||||
bytes[] memory swaps = _getSequentialSwaps(false);
|
||||
tychoRouter.exposedSequentialSwap(amountIn, pleEncode(swaps));
|
||||
vm.stopPrank();
|
||||
|
||||
uint256 usdcBalance = IERC20(USDC_ADDR).balanceOf(tychoRouterAddr);
|
||||
assertEq(usdcBalance, 2644659787);
|
||||
assertEq(IERC20(WETH_ADDR).balanceOf(tychoRouterAddr), 0);
|
||||
}
|
||||
|
||||
function testSequentialSwapPermit2() public {
|
||||
// Trade 1 WETH for USDC through DAI - see _getSequentialSwaps for more info
|
||||
uint256 amountIn = 1 ether;
|
||||
|
||||
@@ -21,11 +21,10 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
bytes memory signature
|
||||
) = handlePermit2Approval(WETH_ADDR, tychoRouterAddr, amountIn);
|
||||
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
WETH_ADDR,
|
||||
bytes memory protocolData =
|
||||
encodeUniswapV2Swap(WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
tychoRouterAddr,
|
||||
false,
|
||||
ALICE, false,
|
||||
TokenTransfer.TransferType.TRANSFER_PERMIT2_TO_PROTOCOL
|
||||
);
|
||||
|
||||
@@ -62,11 +61,10 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
// Approve the tokenIn to be transferred to the router
|
||||
IERC20(WETH_ADDR).approve(address(tychoRouterAddr), amountIn);
|
||||
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
WETH_ADDR,
|
||||
bytes memory protocolData =
|
||||
encodeUniswapV2Swap(WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
tychoRouterAddr,
|
||||
false,
|
||||
ALICE, false,
|
||||
TokenTransfer.TransferType.TRANSFER_FROM_TO_PROTOCOL
|
||||
);
|
||||
|
||||
@@ -103,11 +101,10 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
vm.startPrank(ALICE);
|
||||
IERC20(WETH_ADDR).approve(address(tychoRouterAddr), amountIn);
|
||||
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
WETH_ADDR,
|
||||
bytes memory protocolData =
|
||||
encodeUniswapV2Swap(WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
tychoRouterAddr,
|
||||
false,
|
||||
ALICE, false,
|
||||
TokenTransfer.TransferType.TRANSFER_FROM_TO_PROTOCOL
|
||||
);
|
||||
|
||||
@@ -129,11 +126,10 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
vm.startPrank(ALICE);
|
||||
IERC20(WETH_ADDR).approve(address(tychoRouterAddr), amountIn - 1);
|
||||
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
WETH_ADDR,
|
||||
bytes memory protocolData =
|
||||
encodeUniswapV2Swap(WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
tychoRouterAddr,
|
||||
false,
|
||||
ALICE, false,
|
||||
TokenTransfer.TransferType.TRANSFER_FROM_TO_PROTOCOL
|
||||
);
|
||||
|
||||
@@ -164,11 +160,10 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
// Approve the tokenIn to be transferred to the router
|
||||
IERC20(WETH_ADDR).approve(address(tychoRouterAddr), amountIn);
|
||||
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
WETH_ADDR,
|
||||
bytes memory protocolData =
|
||||
encodeUniswapV2Swap(WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
tychoRouterAddr,
|
||||
false,
|
||||
ALICE, false,
|
||||
TokenTransfer.TransferType.TRANSFER_FROM_TO_PROTOCOL
|
||||
);
|
||||
|
||||
@@ -213,11 +208,10 @@ contract TychoRouterSingleSwapTest is TychoRouterTestSetup {
|
||||
sigDeadline: 0
|
||||
});
|
||||
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
WETH_ADDR,
|
||||
bytes memory protocolData =
|
||||
encodeUniswapV2Swap(WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
tychoRouterAddr,
|
||||
false,
|
||||
ALICE, false,
|
||||
TokenTransfer.TransferType.TRANSFER_TO_PROTOCOL
|
||||
);
|
||||
|
||||
|
||||
@@ -44,11 +44,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
uint8(2),
|
||||
uint24(0),
|
||||
address(usv2Executor),
|
||||
encodeUniswapV2Swap(
|
||||
WBTC_ADDR,
|
||||
USDC_WBTC_POOL,
|
||||
tychoRouterAddr,
|
||||
true,
|
||||
encodeUniswapV2Swap(WBTC_ADDR, USDC_WBTC_POOL, ALICE, true,
|
||||
TokenTransfer.TransferType.TRANSFER_TO_PROTOCOL
|
||||
)
|
||||
);
|
||||
@@ -72,7 +68,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
encodeUniswapV2Swap(
|
||||
DAI_ADDR,
|
||||
DAI_USDC_POOL,
|
||||
tychoRouterAddr,
|
||||
ALICE,
|
||||
true,
|
||||
TokenTransfer.TransferType.TRANSFER_TO_PROTOCOL
|
||||
)
|
||||
@@ -92,7 +88,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
tychoRouter.exposedSplitSwap(amountIn, 4, pleEncode(swaps));
|
||||
vm.stopPrank();
|
||||
|
||||
uint256 usdcBalance = IERC20(USDC_ADDR).balanceOf(tychoRouterAddr);
|
||||
uint256 usdcBalance = IERC20(USDC_ADDR).balanceOf(ALICE);
|
||||
assertEq(usdcBalance, 2615491639);
|
||||
assertEq(IERC20(WETH_ADDR).balanceOf(tychoRouterAddr), 0);
|
||||
}
|
||||
@@ -136,7 +132,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
deal(WETH_ADDR, ALICE, amountIn);
|
||||
|
||||
vm.startPrank(ALICE);
|
||||
IERC20(WETH_ADDR).approve(address(tychoRouterAddr), amountIn);
|
||||
IERC20(WETH_ADDR).approve(tychoRouterAddr, amountIn);
|
||||
|
||||
bytes[] memory swaps = _getSplitSwaps(false);
|
||||
|
||||
@@ -154,7 +150,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
|
||||
uint256 usdcBalance = IERC20(USDC_ADDR).balanceOf(ALICE);
|
||||
assertEq(usdcBalance, 2615491639);
|
||||
assertEq(IERC20(WETH_ADDR).balanceOf(tychoRouterAddr), 0);
|
||||
assertEq(IERC20(WETH_ADDR).balanceOf(ALICE), 0);
|
||||
}
|
||||
|
||||
function testSplitSwapUndefinedMinAmount() public {
|
||||
@@ -265,11 +261,10 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
spender: address(0),
|
||||
sigDeadline: 0
|
||||
});
|
||||
bytes memory protocolData = encodeUniswapV2Swap(
|
||||
WETH_ADDR,
|
||||
bytes memory protocolData =
|
||||
encodeUniswapV2Swap(WETH_ADDR,
|
||||
WETH_DAI_POOL,
|
||||
tychoRouterAddr,
|
||||
false,
|
||||
ALICE, false,
|
||||
TokenTransfer.TransferType.TRANSFER_TO_PROTOCOL
|
||||
);
|
||||
|
||||
@@ -367,7 +362,7 @@ contract TychoRouterSplitSwapTest is TychoRouterTestSetup {
|
||||
bytes memory protocolData = encodeUniswapV3Swap(
|
||||
WETH_ADDR,
|
||||
DAI_ADDR,
|
||||
tychoRouterAddr,
|
||||
ALICE,
|
||||
DAI_WETH_USV3,
|
||||
zeroForOne,
|
||||
TokenTransfer.TransferType.TRANSFER_PERMIT2_TO_PROTOCOL
|
||||
|
||||
Reference in New Issue
Block a user