From 6c200713608b9b6f16169edbc43e67ca79e33649 Mon Sep 17 00:00:00 2001 From: viatrix Date: Tue, 3 Dec 2024 15:48:33 +0200 Subject: [PATCH] Fix approve for swap --- contracts/adapters/SwapAdapter.sol | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/adapters/SwapAdapter.sol b/contracts/adapters/SwapAdapter.sol index 47d96258..42783951 100644 --- a/contracts/adapters/SwapAdapter.sol +++ b/contracts/adapters/SwapAdapter.sol @@ -91,7 +91,6 @@ contract SwapAdapter is AccessControl { function setTokenResourceID(address token, bytes32 resourceID) external onlyAdmin { if (tokenToResourceID[token] == resourceID) revert AlreadySet(); tokenToResourceID[token] = resourceID; - IERC20(token).approve(address(_permit2), type(uint256).max); emit TokenResourceIDSet(token, resourceID); } @@ -270,8 +269,7 @@ contract SwapAdapter is AccessControl { uint24[] calldata pathFees ) external { LocalVars memory vars; - vars.resourceID = tokenToResourceID[token]; - if (vars.resourceID == bytes32(0)) revert TokenInvalid(); + vars.resourceID = _nativeResourceID; // Compose depositData vars.depositDataAfterAmount = abi.encodePacked( @@ -427,6 +425,7 @@ contract SwapAdapter is AccessControl { tokenIn, tokenOut ); + IERC20(tokenIn).approve(address(_permit2), amountInMaximum); IPermit2(_permit2).approve(tokenIn, address(_swapRouter), uint160(amountInMaximum), uint48(block.timestamp)); bytes memory commands = abi.encodePacked(V3_SWAP_EXACT_OUT); // V3_SWAP_EXACT_OUT bytes[] memory inputs = new bytes[](1);