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

@@ -4,14 +4,14 @@ pragma solidity ^0.8.26;
import "@interfaces/IExecutor.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@uniswap-v2/contracts/interfaces/IUniswapV2Pair.sol";
import "./ExecutorTransferMethods.sol";
import "./TokenTransfer.sol";
error UniswapV2Executor__InvalidDataLength();
error UniswapV2Executor__InvalidTarget();
error UniswapV2Executor__InvalidFactory();
error UniswapV2Executor__InvalidInitCode();
contract UniswapV2Executor is IExecutor, ExecutorTransferMethods {
contract UniswapV2Executor is IExecutor, TokenTransfer {
using SafeERC20 for IERC20;
address public immutable factory;
@@ -19,7 +19,7 @@ contract UniswapV2Executor is IExecutor, ExecutorTransferMethods {
address private immutable self;
constructor(address _factory, bytes32 _initCode, address _permit2)
ExecutorTransferMethods(_permit2)
TokenTransfer(_permit2)
{
if (_factory == address(0)) {
revert UniswapV2Executor__InvalidFactory();
@@ -42,14 +42,15 @@ contract UniswapV2Executor is IExecutor, ExecutorTransferMethods {
address target;
address receiver;
bool zeroForOne;
TransferMethod method;
TransferType transferType;
(tokenIn, target, receiver, zeroForOne, method) = _decodeData(data);
(tokenIn, target, receiver, zeroForOne, transferType) =
_decodeData(data);
_verifyPairAddress(target);
calculatedAmount = _getAmountOut(target, givenAmount, zeroForOne);
_transfer(tokenIn, msg.sender, target, givenAmount, method);
_transfer(tokenIn, msg.sender, target, givenAmount, transferType);
IUniswapV2Pair pool = IUniswapV2Pair(target);
if (zeroForOne) {
@@ -67,7 +68,7 @@ contract UniswapV2Executor is IExecutor, ExecutorTransferMethods {
address target,
address receiver,
bool zeroForOne,
TransferMethod method
TransferType transferType
)
{
if (data.length != 62) {
@@ -77,7 +78,7 @@ contract UniswapV2Executor is IExecutor, ExecutorTransferMethods {
target = address(bytes20(data[20:40]));
receiver = address(bytes20(data[40:60]));
zeroForOne = uint8(data[60]) > 0;
method = TransferMethod(uint8(data[61]));
transferType = TransferType(uint8(data[61]));
}
function _getAmountOut(address target, uint256 amountIn, bool zeroForOne)