Skip to content

Commit

Permalink
Fix approve for swap
Browse files Browse the repository at this point in the history
  • Loading branch information
viatrix committed Dec 3, 2024
1 parent c4a8ffe commit 6c20071
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions contracts/adapters/SwapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6c20071

Please sign in to comment.