feat: ExecutorTransferMethods helper contract

- Also sketch its use in USV2 (missing proper decoding)
This commit is contained in:
TAMARA LIPOWSKI
2025-03-11 17:57:40 -04:00
committed by Diana Carvalho
parent 27cebdb3e1
commit 147ba68392
4 changed files with 91 additions and 17 deletions

View File

@@ -2,12 +2,13 @@
pragma solidity ^0.8.26;
import "@src/executors/UniswapV2Executor.sol";
import "@src/executors/ExecutorTransferMethods.sol";
import {Test} from "../../lib/forge-std/src/Test.sol";
import {Constants} from "../Constants.sol";
contract UniswapV2ExecutorExposed is UniswapV2Executor {
constructor(address _factory, bytes32 _initCode)
UniswapV2Executor(_factory, _initCode)
constructor(address _factory, bytes32 _initCode, address _permit2)
UniswapV2Executor(_factory, _initCode, _permit2)
{}
function decodeParams(bytes calldata data)
@@ -17,7 +18,8 @@ contract UniswapV2ExecutorExposed is UniswapV2Executor {
IERC20 inToken,
address target,
address receiver,
bool zeroForOne
bool zeroForOne,
TransferMethod method
)
{
return _decodeData(data);
@@ -59,13 +61,13 @@ contract UniswapV2ExecutorTest is Test, Constants {
uint256 forkBlock = 17323404;
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
uniswapV2Exposed = new UniswapV2ExecutorExposed(
USV2_FACTORY_ETHEREUM, USV2_POOL_CODE_INIT_HASH
USV2_FACTORY_ETHEREUM, USV2_POOL_CODE_INIT_HASH, PERMIT2_ADDRESS
);
sushiswapV2Exposed = new UniswapV2ExecutorExposed(
SUSHISWAPV2_FACTORY_ETHEREUM, SUSHIV2_POOL_CODE_INIT_HASH
SUSHISWAPV2_FACTORY_ETHEREUM, SUSHIV2_POOL_CODE_INIT_HASH, PERMIT2_ADDRESS
);
pancakeswapV2Exposed = new UniswapV2ExecutorExposed(
PANCAKESWAPV2_FACTORY_ETHEREUM, PANCAKEV2_POOL_CODE_INIT_HASH
PANCAKESWAPV2_FACTORY_ETHEREUM, PANCAKEV2_POOL_CODE_INIT_HASH, PERMIT2_ADDRESS
);
}
@@ -73,13 +75,19 @@ contract UniswapV2ExecutorTest is Test, Constants {
bytes memory params =
abi.encodePacked(WETH_ADDR, address(2), address(3), false);
(IERC20 tokenIn, address target, address receiver, bool zeroForOne) =
uniswapV2Exposed.decodeParams(params);
(
IERC20 tokenIn,
address target,
address receiver,
bool zeroForOne,
ExecutorTransferMethods.TransferMethod method
) = uniswapV2Exposed.decodeParams(params);
assertEq(address(tokenIn), WETH_ADDR);
assertEq(target, address(2));
assertEq(receiver, address(3));
assertEq(zeroForOne, false);
assertEq(0, uint8(method));
}
function testDecodeParamsInvalidDataLength() public {
@@ -145,13 +153,20 @@ contract UniswapV2ExecutorTest is Test, Constants {
bytes memory protocolData =
hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc288e6a0c2ddd26feeb64f039a2c41296fcb3f5640000000000000000000000000000000000000000100";
(IERC20 tokenIn, address target, address receiver, bool zeroForOne) =
uniswapV2Exposed.decodeParams(protocolData);
(
IERC20 tokenIn,
address target,
address receiver,
bool zeroForOne,
ExecutorTransferMethods.TransferMethod method
) = uniswapV2Exposed.decodeParams(protocolData);
assertEq(address(tokenIn), WETH_ADDR);
assertEq(target, 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640);
assertEq(receiver, 0x0000000000000000000000000000000000000001);
assertEq(zeroForOne, false);
// TRANSFER = 0
assertEq(0, uint8(method));
}
function testSwapIntegration() public {