diff --git a/src/TransferBundler.sol b/src/TransferBundler.sol index 8d559259..c6bc3e34 100644 --- a/src/TransferBundler.sol +++ b/src/TransferBundler.sol @@ -21,14 +21,14 @@ abstract contract TransferBundler is BaseBundler { /// bundler to `recipient`. /// @dev Pass `amount = type(uint256).max` to transfer all. /// @param recipient The address that will receive the native tokens. - /// @param amount The amount of native tokens to transfer. + /// @param amount The amount of native tokens to transfer. Passing zero will skip the transfer. function nativeTransfer(address recipient, uint256 amount) external payable { require(recipient != address(0), ErrorsLib.ZERO_ADDRESS); require(recipient != address(this), ErrorsLib.BUNDLER_ADDRESS); amount = Math.min(amount, address(this).balance); - require(amount != 0, ErrorsLib.ZERO_AMOUNT); + if (amount == 0) return; SafeTransferLib.safeTransferETH(recipient, amount); } @@ -38,14 +38,14 @@ abstract contract TransferBundler is BaseBundler { /// @dev Pass `amount = type(uint256).max` to transfer all. /// @param asset The address of the ERC20 token to transfer. /// @param recipient The address that will receive the tokens. - /// @param amount The amount of `asset` to transfer. + /// @param amount The amount of `asset` to transfer. Passing zero will skip the transfer. function erc20Transfer(address asset, address recipient, uint256 amount) external payable { require(recipient != address(0), ErrorsLib.ZERO_ADDRESS); require(recipient != address(this), ErrorsLib.BUNDLER_ADDRESS); amount = Math.min(amount, ERC20(asset).balanceOf(address(this))); - require(amount != 0, ErrorsLib.ZERO_AMOUNT); + if (amount == 0) return; ERC20(asset).safeTransfer(recipient, amount); } diff --git a/test/forge/TransferBundlerLocalTest.sol b/test/forge/TransferBundlerLocalTest.sol index 3b3d0dbf..f1d34bb6 100644 --- a/test/forge/TransferBundlerLocalTest.sol +++ b/test/forge/TransferBundlerLocalTest.sol @@ -15,7 +15,7 @@ contract TransferBundlerLocalTest is LocalTest { } function testTransfer(uint256 amount) public { - amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT); + amount = bound(amount, 0, MAX_AMOUNT); bundle.push(_erc20Transfer(address(loanToken), RECEIVER, amount)); @@ -45,11 +45,17 @@ contract TransferBundlerLocalTest is LocalTest { bundler.multicall(bundle); } - function testTranferZeroAmount() public { - bundle.push(_erc20Transfer(address(loanToken), RECEIVER, 0)); + function testNativeTransfer(uint256 amount) public { + amount = bound(amount, 0, MAX_AMOUNT); + + bundle.push(_nativeTransfer(RECEIVER, amount)); + + deal(address(bundler), amount); - vm.expectRevert(bytes(ErrorsLib.ZERO_AMOUNT)); bundler.multicall(bundle); + + assertEq(address(bundler).balance, 0, "bundler.balance"); + assertEq(RECEIVER.balance, amount, "RECEIVER.balance"); } function testNativeTransferZeroAddress(uint256 amount) public { @@ -70,13 +76,6 @@ contract TransferBundlerLocalTest is LocalTest { bundler.multicall(bundle); } - function testNativeTransferZeroAmount() public { - bundle.push(_nativeTransfer(RECEIVER, 0)); - - vm.expectRevert(bytes(ErrorsLib.ZERO_AMOUNT)); - bundler.multicall(bundle); - } - function testTransferFrom(uint256 amount) public { amount = bound(amount, MIN_AMOUNT, MAX_AMOUNT);