Skip to content

Commit

Permalink
feat: balancer v3 gateway fixes (#153)
Browse files Browse the repository at this point in the history
* feat: balancer v3 router gateway

* fix: change safeApprove to forceApprove in balancer gateway

* fix: change balancer gateway to handle fee on transfer tokens
  • Loading branch information
Van0k authored Feb 15, 2025
1 parent f6d3a3e commit 16c0b7d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions contracts/helpers/balancer/BalancerV3RouterGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ contract BalancerV3RouterGateway is IBalancerV3Router {
bool wethIsEth,
bytes calldata userData
) external returns (uint256 amountOut) {
uint256 balanceBefore = tokenIn.balanceOf(address(this));

tokenIn.safeTransferFrom(msg.sender, address(this), exactAmountIn);
tokenIn.safeApprove(permit2, exactAmountIn);

exactAmountIn = tokenIn.balanceOf(address(this)) - balanceBefore;

tokenIn.forceApprove(permit2, exactAmountIn);
IPermit2(permit2).approve(address(tokenIn), balancerV3Router, uint160(exactAmountIn), uint48(block.timestamp));

IBalancerV3Router(balancerV3Router).swapSingleTokenExactIn(
Expand All @@ -47,7 +52,7 @@ contract BalancerV3RouterGateway is IBalancerV3Router {

amountOut = _transferBalance(tokenOut);

tokenIn.safeApprove(permit2, 1);
tokenIn.forceApprove(permit2, 1);

return amountOut;
}
Expand Down

0 comments on commit 16c0b7d

Please sign in to comment.