Skip to content

Commit

Permalink
Revert "Revert "Merge pull request #329 from morpho-labs/fix/zero-tra…
Browse files Browse the repository at this point in the history
…nsfer""

This reverts commit 1aa7ed8.
  • Loading branch information
Rubilmax committed Nov 9, 2023
1 parent 345311b commit 3bd94de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/TransferBundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ abstract contract TransferBundler is BaseBundler {

/// @notice Transfers the minimum between the given `amount` and the bundler's balance of native asset from the
/// bundler to `recipient`.
/// @dev If the minimum happens to be zero, the transfer is silently skipped.
/// @param recipient The address that will receive the native tokens.
/// @param amount The amount of native tokens to transfer from the initiator. Pass `type(uint256).max` to transfer
/// the initiator's balance.
Expand All @@ -28,13 +29,14 @@ 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);
}

/// @notice Transfers the minimum between the given `amount` and the bundler's balance of `asset` from the bundler
/// to `recipient`.
/// @dev If the minimum happens to be zero, the transfer is silently skipped.
/// @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. Pass `type(uint256).max` to transfer the bundler's balance.
Expand All @@ -44,7 +46,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

0 comments on commit 3bd94de

Please sign in to comment.