fix: use encodePacked to encode if approval needed

- Also approve max amount for the tycho router to use (to save on gas)
This commit is contained in:
TAMARA LIPOWSKI
2025-07-09 14:32:43 -04:00
parent 1b6a24fd75
commit 9e2f228a47
2 changed files with 7 additions and 8 deletions

View File

@@ -67,17 +67,15 @@ contract UniswapXFiller is AccessControl, IReactorCallback {
ResolvedOrder memory order = resolvedOrders[0]; ResolvedOrder memory order = resolvedOrders[0];
( bool tokenInApprovalNeeded = bool(uint8(callbackData[0]) == 1);
bool tokenInApprovalNeeded, bool tokenOutApprovalNeeded = bool(uint8(callbackData[1]) == 1);
bool tokenOutApprovalNeeded, bytes calldata tychoCalldata = bytes(callbackData[2:]);
bytes memory tychoCalldata
) = abi.decode(callbackData, (bool, bool, bytes));
// The TychoRouter will take the input tokens from the filler // The TychoRouter will take the input tokens from the filler
if (tokenInApprovalNeeded) { if (tokenInApprovalNeeded) {
// Native ETH input is not supported by UniswapX // Native ETH input is not supported by UniswapX
IERC20(order.input.token).forceApprove( IERC20(order.input.token).forceApprove(
tychoRouter, order.input.maxAmount tychoRouter, type(uint256).max
); );
} }

View File

@@ -68,7 +68,8 @@ contract UniswapXFillerTest is Test, TychoRouterTestSetup {
swap swap
); );
bytes memory callbackData = abi.encode(true, true, tychoRouterData); bytes memory callbackData =
abi.encodePacked(true, true, tychoRouterData);
deal(WETH_ADDR, address(filler), amountIn); deal(WETH_ADDR, address(filler), amountIn);
vm.startPrank(address(filler)); vm.startPrank(address(filler));
@@ -153,7 +154,7 @@ contract UniswapXFillerTest is Test, TychoRouterTestSetup {
swap swap
); );
bytes memory callbackData = abi.encode( bytes memory callbackData = abi.encodePacked(
true, // tokenIn approval needed true, // tokenIn approval needed
true, // tokenOut approval needed true, // tokenOut approval needed
tychoRouterData tychoRouterData