Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transfer): allow zero transfers #329

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/TransferBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract contract TransferBundler is BaseBundler {

amount = Math.min(amount, address(this).balance);

require(amount != 0, ErrorsLib.ZERO_AMOUNT);
if (amount == 0) return;

SafeTransferLib.safeTransferETH(recipient, amount);
}
Expand All @@ -40,7 +40,7 @@ abstract contract TransferBundler is BaseBundler {

amount = Math.min(amount, ERC20(asset).balanceOf(address(this)));

require(amount != 0, ErrorsLib.ZERO_AMOUNT);
if (amount == 0) return;

ERC20(asset).safeTransfer(recipient, amount);
}
Expand Down
21 changes: 10 additions & 11 deletions test/forge/TransferBundlerLocalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));

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

Expand Down
Loading