feat: ExecutorTransferMethods helper contract
- Also sketch its use in USV2 (missing proper decoding)
This commit is contained in:
committed by
Diana Carvalho
parent
27cebdb3e1
commit
147ba68392
@@ -4,20 +4,23 @@ 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";
|
||||
|
||||
error UniswapV2Executor__InvalidDataLength();
|
||||
error UniswapV2Executor__InvalidTarget();
|
||||
error UniswapV2Executor__InvalidFactory();
|
||||
error UniswapV2Executor__InvalidInitCode();
|
||||
|
||||
contract UniswapV2Executor is IExecutor {
|
||||
contract UniswapV2Executor is IExecutor, ExecutorTransferMethods {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
address public immutable factory;
|
||||
bytes32 public immutable initCode;
|
||||
address private immutable self;
|
||||
|
||||
constructor(address _factory, bytes32 _initCode) {
|
||||
constructor(address _factory, bytes32 _initCode, address _permit2)
|
||||
ExecutorTransferMethods(_permit2)
|
||||
{
|
||||
if (_factory == address(0)) {
|
||||
revert UniswapV2Executor__InvalidFactory();
|
||||
}
|
||||
@@ -35,17 +38,18 @@ contract UniswapV2Executor is IExecutor {
|
||||
payable
|
||||
returns (uint256 calculatedAmount)
|
||||
{
|
||||
IERC20 tokenIn;
|
||||
address target;
|
||||
address receiver;
|
||||
bool zeroForOne;
|
||||
IERC20 tokenIn;
|
||||
TransferMethod method;
|
||||
|
||||
(tokenIn, target, receiver, zeroForOne) = _decodeData(data);
|
||||
(tokenIn, target, receiver, zeroForOne, method) = _decodeData(data);
|
||||
|
||||
_verifyPairAddress(target);
|
||||
|
||||
calculatedAmount = _getAmountOut(target, givenAmount, zeroForOne);
|
||||
tokenIn.safeTransfer(target, givenAmount);
|
||||
_transfer(tokenIn, target, givenAmount, method);
|
||||
|
||||
IUniswapV2Pair pool = IUniswapV2Pair(target);
|
||||
if (zeroForOne) {
|
||||
@@ -62,7 +66,8 @@ contract UniswapV2Executor is IExecutor {
|
||||
IERC20 inToken,
|
||||
address target,
|
||||
address receiver,
|
||||
bool zeroForOne
|
||||
bool zeroForOne,
|
||||
TransferMethod method
|
||||
)
|
||||
{
|
||||
if (data.length != 61) {
|
||||
@@ -72,6 +77,8 @@ contract UniswapV2Executor is IExecutor {
|
||||
target = address(bytes20(data[20:40]));
|
||||
receiver = address(bytes20(data[40:60]));
|
||||
zeroForOne = uint8(data[60]) > 0;
|
||||
// TODO properly decode, assume encoded using just 1 byte.
|
||||
method = TransferMethod.TRANSFER;
|
||||
}
|
||||
|
||||
function _getAmountOut(address target, uint256 amountIn, bool zeroForOne)
|
||||
|
||||
Reference in New Issue
Block a user