chore: Renamings + comment fixes

- Renamed ExecutorTransferMethods to TokenTransfer to avoid leaking information about how the transfer happens into the executor. The executor shouldn't care if there are multiple methods or one single method that takes care of everything.
- Also renamed TransferMethod to TransferType to match the rust encoding
This commit is contained in:
TAMARA LIPOWSKI
2025-04-10 11:02:04 -04:00
committed by Diana Carvalho
parent 4a20fa6215
commit 4bc29f283b
6 changed files with 63 additions and 65 deletions

View File

@@ -2,7 +2,7 @@
pragma solidity ^0.8.26;
import "@src/executors/UniswapV2Executor.sol";
import "@src/executors/ExecutorTransferMethods.sol";
import "@src/executors/TokenTransfer.sol";
import {Test} from "../../lib/forge-std/src/Test.sol";
import {Constants} from "../Constants.sol";
import {Permit2TestHelper} from "../Permit2TestHelper.sol";
@@ -20,7 +20,7 @@ contract UniswapV2ExecutorExposed is UniswapV2Executor {
address target,
address receiver,
bool zeroForOne,
TransferMethod method
TransferType transferType
)
{
return _decodeData(data);
@@ -84,7 +84,7 @@ contract UniswapV2ExecutorTest is Test, Constants, Permit2TestHelper {
address(2),
address(3),
false,
ExecutorTransferMethods.TransferMethod.TRANSFER
TokenTransfer.TransferType.TRANSFER
);
(
@@ -92,7 +92,7 @@ contract UniswapV2ExecutorTest is Test, Constants, Permit2TestHelper {
address target,
address receiver,
bool zeroForOne,
ExecutorTransferMethods.TransferMethod method
TokenTransfer.TransferType transferType
) = uniswapV2Exposed.decodeParams(params);
assertEq(address(tokenIn), WETH_ADDR);
@@ -100,8 +100,7 @@ contract UniswapV2ExecutorTest is Test, Constants, Permit2TestHelper {
assertEq(receiver, address(3));
assertEq(zeroForOne, false);
assertEq(
uint8(ExecutorTransferMethods.TransferMethod.TRANSFER),
uint8(method)
uint8(TokenTransfer.TransferType.TRANSFER), uint8(transferType)
);
}
@@ -158,7 +157,7 @@ contract UniswapV2ExecutorTest is Test, Constants, Permit2TestHelper {
WETH_DAI_POOL,
BOB,
zeroForOne,
uint8(ExecutorTransferMethods.TransferMethod.TRANSFER)
uint8(TokenTransfer.TransferType.TRANSFER)
);
deal(WETH_ADDR, address(uniswapV2Exposed), amountIn);
@@ -177,7 +176,7 @@ contract UniswapV2ExecutorTest is Test, Constants, Permit2TestHelper {
WETH_DAI_POOL,
BOB,
zeroForOne,
uint8(ExecutorTransferMethods.TransferMethod.TRANSFERFROM)
uint8(TokenTransfer.TransferType.TRANSFERFROM)
);
deal(WETH_ADDR, address(this), amountIn);
@@ -198,7 +197,7 @@ contract UniswapV2ExecutorTest is Test, Constants, Permit2TestHelper {
WETH_DAI_POOL,
ALICE,
zeroForOne,
uint8(ExecutorTransferMethods.TransferMethod.TRANSFERPERMIT2)
uint8(TokenTransfer.TransferType.TRANSFERPERMIT2)
);
deal(WETH_ADDR, ALICE, amountIn);
@@ -211,7 +210,7 @@ contract UniswapV2ExecutorTest is Test, Constants, Permit2TestHelper {
);
// Assume the permit2.approve method will be called from the TychoRouter
// Replicate this secnario in this test.
// Replicate this scenario in this test.
permit2.permit(ALICE, permitSingle, signature);
uniswapV2Exposed.swap(amountIn, protocolData);
@@ -230,7 +229,7 @@ contract UniswapV2ExecutorTest is Test, Constants, Permit2TestHelper {
WETH_DAI_POOL,
BOB,
zeroForOne,
uint8(ExecutorTransferMethods.TransferMethod.NONE)
uint8(TokenTransfer.TransferType.NONE)
);
deal(WETH_ADDR, address(this), amountIn);
@@ -251,7 +250,7 @@ contract UniswapV2ExecutorTest is Test, Constants, Permit2TestHelper {
address target,
address receiver,
bool zeroForOne,
ExecutorTransferMethods.TransferMethod method
TokenTransfer.TransferType transferType
) = uniswapV2Exposed.decodeParams(protocolData);
assertEq(address(tokenIn), WETH_ADDR);
@@ -259,7 +258,7 @@ contract UniswapV2ExecutorTest is Test, Constants, Permit2TestHelper {
assertEq(receiver, 0x0000000000000000000000000000000000000001);
assertEq(zeroForOne, false);
// TRANSFER = 0
assertEq(0, uint8(method));
assertEq(0, uint8(transferType));
}
function testSwapIntegration() public {
@@ -284,7 +283,7 @@ contract UniswapV2ExecutorTest is Test, Constants, Permit2TestHelper {
fakePool,
BOB,
zeroForOne,
uint8(ExecutorTransferMethods.TransferMethod.TRANSFER)
uint8(TokenTransfer.TransferType.TRANSFER)
);
deal(WETH_ADDR, address(uniswapV2Exposed), amountIn);
@@ -304,7 +303,7 @@ contract UniswapV2ExecutorTest is Test, Constants, Permit2TestHelper {
USDC_MAG7_POOL,
BOB,
zeroForOne,
uint8(ExecutorTransferMethods.TransferMethod.TRANSFER)
uint8(TokenTransfer.TransferType.TRANSFER)
);
deal(BASE_USDC, address(uniswapV2Exposed), amountIn);

View File

@@ -22,7 +22,7 @@ contract UniswapV3ExecutorExposed is UniswapV3Executor {
address receiver,
address target,
bool zeroForOne,
TransferMethod method
TransferType method
)
{
return _decodeData(data);
@@ -71,7 +71,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
address(2),
address(3),
false,
ExecutorTransferMethods.TransferMethod.TRANSFER
TokenTransfer.TransferType.TRANSFER
);
(
@@ -81,7 +81,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
address receiver,
address target,
bool zeroForOne,
ExecutorTransferMethods.TransferMethod method
TokenTransfer.TransferType method
) = uniswapV3Exposed.decodeData(data);
assertEq(tokenIn, WETH_ADDR);
@@ -90,10 +90,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
assertEq(receiver, address(2));
assertEq(target, address(3));
assertEq(zeroForOne, false);
assertEq(
uint8(method),
uint8(ExecutorTransferMethods.TransferMethod.TRANSFER)
);
assertEq(uint8(method), uint8(TokenTransfer.TransferType.TRANSFER));
}
function testDecodeParamsInvalidDataLength() public {
@@ -124,10 +121,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
vm.startPrank(DAI_WETH_USV3);
bytes memory protocolData = abi.encodePacked(
WETH_ADDR,
DAI_ADDR,
poolFee,
ExecutorTransferMethods.TransferMethod.TRANSFER
WETH_ADDR, DAI_ADDR, poolFee, TokenTransfer.TransferType.TRANSFER
);
uint256 dataOffset = 3; // some offset
uint256 dataLength = protocolData.length;
@@ -161,7 +155,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
address(this),
DAI_WETH_USV3,
zeroForOne,
ExecutorTransferMethods.TransferMethod.TRANSFER
TokenTransfer.TransferType.TRANSFER
);
uint256 amountOut = uniswapV3Exposed.swap(amountIn, data);
@@ -185,7 +179,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
address(this),
DAI_WETH_USV3,
zeroForOne,
ExecutorTransferMethods.TransferMethod.TRANSFERFROM
TokenTransfer.TransferType.TRANSFERFROM
);
uint256 amountOut = uniswapV3Exposed.swap(amountIn, data);
@@ -207,7 +201,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
address(this),
DAI_WETH_USV3,
zeroForOne,
ExecutorTransferMethods.TransferMethod.TRANSFERPERMIT2
TokenTransfer.TransferType.TRANSFERPERMIT2
);
deal(WETH_ADDR, ALICE, amountIn);
@@ -220,7 +214,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
);
// Assume the permit2.approve method will be called from the TychoRouter
// Replicate this secnario in this test.
// Replicate this scenario in this test.
permit2.permit(ALICE, permitSingle, signature);
uint256 amountOut = uniswapV3Exposed.swap(amountIn, data);
vm.stopPrank();
@@ -243,7 +237,7 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
address(this),
fakePool,
zeroForOne,
ExecutorTransferMethods.TransferMethod.TRANSFER
TokenTransfer.TransferType.TRANSFER
);
vm.expectRevert(UniswapV3Executor__InvalidTarget.selector);
@@ -256,11 +250,17 @@ contract UniswapV3ExecutorTest is Test, Constants, Permit2TestHelper {
address receiver,
address target,
bool zero2one,
ExecutorTransferMethods.TransferMethod method
TokenTransfer.TransferType transferType
) internal view returns (bytes memory) {
IUniswapV3Pool pool = IUniswapV3Pool(target);
return abi.encodePacked(
tokenIn, tokenOut, pool.fee(), receiver, target, zero2one, method
tokenIn,
tokenOut,
pool.fee(),
receiver,
target,
zero2one,
transferType
);
}
}