chore: remove redundant data from _decodeData

This commit is contained in:
royvardhan
2025-02-11 22:02:59 +05:30
parent a8cc84ddce
commit 120c96215f
2 changed files with 4 additions and 62 deletions

View File

@@ -31,17 +31,8 @@ contract UniswapV4Executor is IExecutor, V4Router {
payable payable
returns (uint256 amountOut) returns (uint256 amountOut)
{ {
( (address tokenOut, address receiver, bool isExactInput, uint256 amount)
, = _decodeData(data);
address tokenOut,
,
address receiver,
,
,
bool isExactInput,
,
uint256 amount
) = _decodeData(data);
uint256 balanceBefore = IERC20(tokenOut).balanceOf(receiver); uint256 balanceBefore = IERC20(tokenOut).balanceOf(receiver);
@@ -71,14 +62,9 @@ contract UniswapV4Executor is IExecutor, V4Router {
internal internal
pure pure
returns ( returns (
address tokenIn,
address tokenOut, address tokenOut,
uint24 fee,
address receiver, address receiver,
bool zeroForOne,
uint24 tickSpacing,
bool isExactInput, bool isExactInput,
bool isSingle,
uint256 amount uint256 amount
) )
{ {
@@ -97,60 +83,35 @@ contract UniswapV4Executor is IExecutor, V4Router {
IV4Router.ExactInputSingleParams memory swapParams = IV4Router.ExactInputSingleParams memory swapParams =
abi.decode(params[0], (IV4Router.ExactInputSingleParams)); abi.decode(params[0], (IV4Router.ExactInputSingleParams));
tokenIn = swapParams.zeroForOne
? address(uint160(swapParams.poolKey.currency0.toId()))
: address(uint160(swapParams.poolKey.currency1.toId()));
tokenOut = swapParams.zeroForOne tokenOut = swapParams.zeroForOne
? address(uint160(swapParams.poolKey.currency1.toId())) ? address(uint160(swapParams.poolKey.currency1.toId()))
: address(uint160(swapParams.poolKey.currency0.toId())); : address(uint160(swapParams.poolKey.currency0.toId()));
fee = swapParams.poolKey.fee;
zeroForOne = swapParams.zeroForOne;
tickSpacing = uint24(swapParams.poolKey.tickSpacing);
isExactInput = true; isExactInput = true;
isSingle = true;
amount = swapParams.amountIn; amount = swapParams.amountIn;
} else if (action == uint8(Actions.SWAP_EXACT_OUT_SINGLE)) { } else if (action == uint8(Actions.SWAP_EXACT_OUT_SINGLE)) {
IV4Router.ExactOutputSingleParams memory swapParams = IV4Router.ExactOutputSingleParams memory swapParams =
abi.decode(params[0], (IV4Router.ExactOutputSingleParams)); abi.decode(params[0], (IV4Router.ExactOutputSingleParams));
tokenIn = swapParams.zeroForOne
? address(uint160(swapParams.poolKey.currency0.toId()))
: address(uint160(swapParams.poolKey.currency1.toId()));
tokenOut = swapParams.zeroForOne tokenOut = swapParams.zeroForOne
? address(uint160(swapParams.poolKey.currency1.toId())) ? address(uint160(swapParams.poolKey.currency1.toId()))
: address(uint160(swapParams.poolKey.currency0.toId())); : address(uint160(swapParams.poolKey.currency0.toId()));
fee = swapParams.poolKey.fee;
zeroForOne = swapParams.zeroForOne;
tickSpacing = uint24(swapParams.poolKey.tickSpacing);
isExactInput = false; isExactInput = false;
isSingle = true;
amount = swapParams.amountOut; amount = swapParams.amountOut;
} else if (action == uint8(Actions.SWAP_EXACT_IN)) { } else if (action == uint8(Actions.SWAP_EXACT_IN)) {
IV4Router.ExactInputParams memory swapParams = IV4Router.ExactInputParams memory swapParams =
abi.decode(params[0], (IV4Router.ExactInputParams)); abi.decode(params[0], (IV4Router.ExactInputParams));
tokenIn = address(uint160(swapParams.currencyIn.toId()));
PathKey memory lastPath = PathKey memory lastPath =
swapParams.path[swapParams.path.length - 1]; swapParams.path[swapParams.path.length - 1];
tokenOut = address(uint160(lastPath.intermediateCurrency.toId())); tokenOut = address(uint160(lastPath.intermediateCurrency.toId()));
fee = lastPath.fee;
zeroForOne = tokenIn < tokenOut;
tickSpacing = uint24(lastPath.tickSpacing);
isExactInput = true; isExactInput = true;
isSingle = false;
amount = swapParams.amountIn; amount = swapParams.amountIn;
} else if (action == uint8(Actions.SWAP_EXACT_OUT)) { } else if (action == uint8(Actions.SWAP_EXACT_OUT)) {
IV4Router.ExactOutputParams memory swapParams = IV4Router.ExactOutputParams memory swapParams =
abi.decode(params[0], (IV4Router.ExactOutputParams)); abi.decode(params[0], (IV4Router.ExactOutputParams));
tokenOut = address(uint160(swapParams.currencyOut.toId())); tokenOut = address(uint160(swapParams.currencyOut.toId()));
PathKey memory firstPath = swapParams.path[0];
tokenIn = address(uint160(firstPath.intermediateCurrency.toId()));
fee = firstPath.fee;
zeroForOne = tokenIn < tokenOut;
tickSpacing = uint24(firstPath.tickSpacing);
isExactInput = false; isExactInput = false;
isSingle = false;
amount = swapParams.amountOut; amount = swapParams.amountOut;
} }
} }

View File

@@ -13,14 +13,9 @@ contract UniswapV4ExecutorExposed is UniswapV4Executor {
external external
pure pure
returns ( returns (
address tokenIn,
address tokenOut, address tokenOut,
uint24 fee,
address receiver, address receiver,
bool zeroForOne,
uint24 tickSpacing,
bool isExactInput, bool isExactInput,
bool isSingle,
uint256 amount uint256 amount
) )
{ {
@@ -58,26 +53,12 @@ contract UniswapV4ExecutorTest is Test, Constants {
expectedAmount expectedAmount
); );
( (address tokenOut, address receiver, bool isExactInput, uint256 amount)
address tokenIn, = uniswapV4Exposed.decodeData(data);
address tokenOut,
uint24 fee,
address receiver,
bool zeroForOne,
uint24 tickSpacing,
bool isExactInput,
bool isSingle,
uint256 amount
) = uniswapV4Exposed.decodeData(data);
assertEq(tokenIn, USDE_ADDR);
assertEq(tokenOut, USDT_ADDR); assertEq(tokenOut, USDT_ADDR);
assertEq(fee, expectedPoolFee);
assertEq(receiver, expectedReceiver); assertEq(receiver, expectedReceiver);
assertEq(zeroForOne, false);
assertEq(tickSpacing, 1);
assertTrue(isExactInput); assertTrue(isExactInput);
assertTrue(isSingle);
assertEq(amount, expectedAmount); assertEq(amount, expectedAmount);
} }