From 9ca0c347b460f5a49407e5254a92dafd5b42589e Mon Sep 17 00:00:00 2001 From: Rooh Afza Date: Mon, 22 Jan 2024 14:59:27 -0800 Subject: [PATCH] fix: address comments regarding distribute and withdraw flow in splitWallet and warehouse --- packages/splits-v2/src/SplitsWarehouse.sol | 40 ++++- .../src/interfaces/ISplitsWarehouse.sol | 6 +- .../splits-v2/src/splitters/SplitWalletV2.sol | 123 +++++++------ .../test/splitters/SplitWalletV2.t.sol | 166 +++--------------- .../test/utils/ReentrantReceiver.sol | 2 +- .../test/warehouse/SplitsWarehouse.t.sol | 18 +- .../test/warehouse/SplitsWarehouseHandler.sol | 2 +- 7 files changed, 143 insertions(+), 214 deletions(-) diff --git a/packages/splits-v2/src/SplitsWarehouse.sol b/packages/splits-v2/src/SplitsWarehouse.sol index 5c1aa26..8ef7f23 100644 --- a/packages/splits-v2/src/SplitsWarehouse.sol +++ b/packages/splits-v2/src/SplitsWarehouse.sol @@ -176,27 +176,51 @@ contract SplitsWarehouse is ERC6909X { /** * @notice Withdraws token from the warehouse for msg.sender. * @dev It is recommended to withdraw balance - 1 to save gas. + * @param _owner The address whose tokens are withdrawn. * @param _token The address of the token to be withdrawn. * @param _amount The amount of the token to be withdrawn. */ - function withdraw(address _token, uint256 _amount) external { - _withdraw(msg.sender, _token.toUint256(), _token, _amount, msg.sender); + function withdraw(address _owner, address _token, uint256 _amount) external { + if (msg.sender == _owner) { + _withdraw(_owner, _token.toUint256(), _token, _amount, _owner); + } else { + WithdrawConfig memory config = withdrawConfig[_owner]; + if (config.paused) revert WithdrawalPaused(_owner); + if (_owner == address(0)) revert ZeroOwner(); + _withdraw(_owner, _token.toUint256(), _token, _amount, msg.sender); + } } /** * @notice Withdraws tokens from the warehouse for msg.sender. * @dev It is recommended to withdraw balance - 1 to save gas. + * @param _owner The address whose tokens are withdrawn. * @param _tokens The addresses of the tokens to be withdrawn. * @param _amounts The amounts of the tokens to be withdrawn. */ - function withdraw(address[] memory _tokens, uint256[] memory _amounts) external { - if (_tokens.length != _amounts.length) revert LengthMismatch(); + function withdraw(address _owner, address[] memory _tokens, uint256[] memory _amounts) external { + if (msg.sender == _owner) { + if (_tokens.length != _amounts.length) revert LengthMismatch(); - for (uint256 i; i < _tokens.length;) { - _withdraw(msg.sender, _tokens[i].toUint256(), _tokens[i], _amounts[i], msg.sender); + for (uint256 i; i < _tokens.length;) { + _withdraw(_owner, _tokens[i].toUint256(), _tokens[i], _amounts[i], _owner); - unchecked { - ++i; + unchecked { + ++i; + } + } + } else { + WithdrawConfig memory config = withdrawConfig[_owner]; + if (config.paused) revert WithdrawalPaused(_owner); + if (_owner == address(0)) revert ZeroOwner(); + if (_tokens.length != _amounts.length) revert LengthMismatch(); + + for (uint256 i; i < _tokens.length;) { + _withdraw(_owner, _tokens[i].toUint256(), _tokens[i], _amounts[i], msg.sender); + + unchecked { + ++i; + } } } } diff --git a/packages/splits-v2/src/interfaces/ISplitsWarehouse.sol b/packages/splits-v2/src/interfaces/ISplitsWarehouse.sol index 1598641..dcccb17 100644 --- a/packages/splits-v2/src/interfaces/ISplitsWarehouse.sol +++ b/packages/splits-v2/src/interfaces/ISplitsWarehouse.sol @@ -1,10 +1,14 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.18; -interface ISplitsWarehouse { +import { IERC6909 } from "./IERC6909.sol"; + +interface ISplitsWarehouse is IERC6909 { function NATIVE_TOKEN() external view returns (address); function deposit(address _owner, address _token, uint256 _amount) external payable; function batchTransfer(address _token, address[] memory _recipients, uint256[] memory _amounts) external; + + function withdraw(address _owner, address _token, uint256 _amount) external; } diff --git a/packages/splits-v2/src/splitters/SplitWalletV2.sol b/packages/splits-v2/src/splitters/SplitWalletV2.sol index 5c93adc..bd1e0e7 100644 --- a/packages/splits-v2/src/splitters/SplitWalletV2.sol +++ b/packages/splits-v2/src/splitters/SplitWalletV2.sol @@ -2,6 +2,8 @@ pragma solidity ^0.8.18; import { ISplitsWarehouse } from "../interfaces/ISplitsWarehouse.sol"; + +import { Cast } from "../libraries/Cast.sol"; import { SplitV2Lib } from "../libraries/SplitV2.sol"; import { Wallet } from "../utils/Wallet.sol"; @@ -17,6 +19,7 @@ import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol"; contract SplitWalletV2 is Wallet { using SplitV2Lib for SplitV2Lib.Split; using SafeTransferLib for address; + using Cast for address; /* -------------------------------------------------------------------------- */ /* ERRORS */ @@ -32,7 +35,13 @@ contract SplitWalletV2 is Wallet { event SplitUpdated(address indexed _owner, SplitV2Lib.Split _split); event DistributeDirectionUpdated(bool _distributeByPush); - event SplitDistributed(address indexed _token, uint256 _amount, address _distributor, bool _distributeByPush); + event SplitDistributed( + address indexed _token, + address indexed _distributor, + uint256 _amountDistributed, + uint256 _distributorReward, + bool _distributeByPush + ); /* -------------------------------------------------------------------------- */ /* CONSTANTS/IMMUTABLES */ @@ -87,62 +96,57 @@ contract SplitWalletV2 is Wallet { /* PUBLIC/EXTERNAL FUNCTIONS */ /* -------------------------------------------------------------------------- */ - /** - * @notice Approves the Splits Warehouse to spend the token and distributes the token to the recipients according to - * the split. It makes an approval to the Splits Warehouse if the token is not native and if the allowance is less - * than the amount being distributed. - * @dev Owner can bypass the paused state. - * @param _split the split struct containing the split data that gets distributed - * @param _token the token to distribute - * @param _amount the amount of token to distribute - */ - function approveAndDistribute( - SplitV2Lib.Split calldata _split, - address _token, - uint256 _amount, - address _distributor - ) - external - pausable - { - if (_token != NATIVE && IERC20(_token).allowance(address(this), address(SPLITS_WAREHOUSE)) < _amount) { - approveSplitsWarehouse(_token); + function distribute(SplitV2Lib.Split calldata _split, address _token, address _distributor) external pausable { + if (splitHash != _split.getHash()) revert InvalidSplit(); + (uint256 _splitBalance, uint256 _warehouseBalance) = _getSplitBalance(_token); + + if (distributeByPush) { + if (_warehouseBalance > 0) { + unchecked { + _warehouseBalance -= 1; + } + _withdrawFromWarehouse(_token, _warehouseBalance); + } + pushDistribute(_split, _token, _splitBalance + _warehouseBalance, _distributor); + } else { + if (_splitBalance > 0) { + unchecked { + _splitBalance -= 1; + } + _depositToWarehouse(_token, _splitBalance); + } + pullDistribute(_split, _token, _splitBalance + _warehouseBalance, _distributor); } - distribute(_split, _token, _amount, _distributor); } - /** - * @notice Distributes the token to the recipients according to the split - * @dev The token must be approved to the Splits Warehouse before calling this function. Owner can bypass the paused - * state. - * @param _split the split struct containing the split data that gets distributed - * @param _token the token to distribute - * @param _amount the amount of token to distribute - * @param _distributor the distributor of the split - */ function distribute( SplitV2Lib.Split calldata _split, address _token, uint256 _amount, address _distributor ) - public + external pausable { if (splitHash != _split.getHash()) revert InvalidSplit(); + if (distributeByPush) { - return pushDistribute(_split, _token, _amount, _distributor); + pushDistribute(_split, _token, _amount, _distributor); } else { - return pullDistribute(_split, _token, _amount, _distributor); + pullDistribute(_split, _token, _amount, _distributor); } } - /** - * @notice Approves the Splits Warehouse to spend the token - * @param _token the token to approve - */ - function approveSplitsWarehouse(address _token) public { - IERC20(_token).approve(address(SPLITS_WAREHOUSE), type(uint256).max); + function depositToWarehouse(address _token, uint256 _amount) external { + _depositToWarehouse(_token, _amount); + } + + function withdrawFromWarehouse(address _token, uint256 _amount) external { + _withdrawFromWarehouse(_token, _amount); + } + + function getSplitBalance(address _token) public view returns (uint256 _splitBalance, uint256 _warehouseBalance) { + return _getSplitBalance(_token); } /* -------------------------------------------------------------------------- */ @@ -175,6 +179,32 @@ contract SplitWalletV2 is Wallet { /* INTERNAL/PRIVATE */ /* -------------------------------------------------------------------------- */ + function _withdrawFromWarehouse(address _token, uint256 _amount) internal { + SPLITS_WAREHOUSE.withdraw(address(this), _token, _amount); + } + + function _depositToWarehouse(address _token, uint256 _amount) internal { + if (_token == NATIVE) { + SPLITS_WAREHOUSE.deposit{ value: _amount }(address(this), _token, _amount); + } else { + if (IERC20(_token).allowance(address(this), address(SPLITS_WAREHOUSE)) < _amount) { + IERC20(_token).approve(address(SPLITS_WAREHOUSE), type(uint256).max); + } + SPLITS_WAREHOUSE.deposit(address(this), _token, _amount); + } + } + + function _getSplitBalance(address _token) private view returns (uint256 _splitBalance, uint256 _warehouseBalance) { + if (_token == NATIVE) { + _splitBalance = address(this).balance; + _warehouseBalance = SPLITS_WAREHOUSE.balanceOf(address(this), _token.toUint256()); + } else { + _splitBalance = _token.balanceOf(address(this)); + _warehouseBalance = SPLITS_WAREHOUSE.balanceOf(address(this), _token.toUint256()); + } + } + + // assumes the amount is already present in the split wallet function pushDistribute( SplitV2Lib.Split calldata _split, address _token, @@ -217,9 +247,10 @@ contract SplitWalletV2 is Wallet { _token.safeTransfer(_distributor, distributorReward); } - emit SplitDistributed(_token, amountDistributed + distributorReward, _distributor, true); + emit SplitDistributed(_token, _distributor, amountDistributed, distributorReward, true); } + // assumes the amount is already deposited to the warehouse function pullDistribute( SplitV2Lib.Split calldata _split, address _token, @@ -230,14 +261,8 @@ contract SplitWalletV2 is Wallet { { (uint256[] memory amounts, uint256 amountDistributed, uint256 distibutorReward) = _split.getDistributions(_amount); - if (_token == NATIVE) { - SPLITS_WAREHOUSE.deposit{ value: amountDistributed }(address(this), _token, amountDistributed); - _distributor.safeTransferETH(distibutorReward); - } else { - SPLITS_WAREHOUSE.deposit(address(this), _token, amountDistributed); - _token.safeTransfer(_distributor, distibutorReward); - } + SPLITS_WAREHOUSE.transfer(_distributor, _token.toUint256(), distibutorReward); SPLITS_WAREHOUSE.batchTransfer(_token, _split.recipients, amounts); - emit SplitDistributed(_token, amountDistributed + distibutorReward, _distributor, false); + emit SplitDistributed(_token, _distributor, amountDistributed, distibutorReward, false); } } diff --git a/packages/splits-v2/test/splitters/SplitWalletV2.t.sol b/packages/splits-v2/test/splitters/SplitWalletV2.t.sol index 0dd758e..7c1d5cb 100644 --- a/packages/splits-v2/test/splitters/SplitWalletV2.t.sol +++ b/packages/splits-v2/test/splitters/SplitWalletV2.t.sol @@ -185,93 +185,7 @@ contract SplitWalletV2Test is BaseTest { /* DISTRIBUTE FUNCTIONS */ /* -------------------------------------------------------------------------- */ - function testFuzz_approveAndDistribute_ERC20_whenNoAllowance(uint256 _amount, bool _distributeByPush) public { - SplitV2Lib.Split memory split = getDefaultSplitWithNoIncentive(); - - wallet.initialize(split, ALICE.addr); - - _amount = bound(_amount, split.totalAllocation, type(uint160).max); - - deal(address(usdc), address(wallet), _amount); - - vm.prank(ALICE.addr); - wallet.updateDistributeDirection(_distributeByPush); - - vm.expectEmit(); - emit Approval(address(wallet), address(warehouse), type(uint256).max); - wallet.approveAndDistribute(split, address(usdc), _amount, ALICE.addr); - - assertAlmostEq(usdc.balanceOf(address(wallet)), 0, 9); - - if (_distributeByPush) { - for (uint256 i = 0; i < split.recipients.length; i++) { - assertGt(usdc.balanceOf(split.recipients[i]), 0); - } - } else { - for (uint256 i = 0; i < split.recipients.length; i++) { - assertGt(warehouse.balanceOf(split.recipients[i], tokenToId(address(usdc))), 0); - } - } - } - - function testFuzz_approveAndDistribute_native(uint256 _amount, bool _distributeByPush) public { - SplitV2Lib.Split memory split = getDefaultSplitWithNoIncentive(); - - wallet.initialize(split, ALICE.addr); - - _amount = bound(_amount, split.totalAllocation, type(uint160).max); - - deal(address(wallet), _amount); - - vm.prank(ALICE.addr); - wallet.updateDistributeDirection(_distributeByPush); - - wallet.approveAndDistribute(split, native, _amount, ALICE.addr); - - assertAlmostEq(usdc.balanceOf(address(wallet)), 0, 9); - - if (_distributeByPush) { - for (uint256 i = 0; i < split.recipients.length; i++) { - assertGt(split.recipients[i].balance, 0); - } - } else { - for (uint256 i = 0; i < split.recipients.length; i++) { - assertGt(warehouse.balanceOf(split.recipients[i], tokenToId(native)), 0); - } - } - } - - function testFuzz_approveAndDistribute_ERC20_whenAllowanceGiven(uint256 _amount, bool _distributeByPush) public { - SplitV2Lib.Split memory split = getDefaultSplitWithNoIncentive(); - - wallet.initialize(split, ALICE.addr); - - _amount = bound(_amount, split.totalAllocation, type(uint160).max); - - deal(address(usdc), address(wallet), _amount); - - vm.prank(ALICE.addr); - wallet.updateDistributeDirection(_distributeByPush); - - vm.prank(ALICE.addr); - wallet.approveSplitsWarehouse(address(usdc)); - - wallet.approveAndDistribute(split, address(usdc), _amount, ALICE.addr); - - assertAlmostEq(usdc.balanceOf(address(wallet)), 0, 9); - - if (_distributeByPush) { - for (uint256 i = 0; i < split.recipients.length; i++) { - assertGt(usdc.balanceOf(split.recipients[i]), 0); - } - } else { - for (uint256 i = 0; i < split.recipients.length; i++) { - assertGt(warehouse.balanceOf(split.recipients[i], tokenToId(address(usdc))), 0); - } - } - } - - function testFuzz_approveAndDistribute_Revert_whenPaused(uint256 _amount) public { + function test_distribute_Revert_whenPaused() public { SplitV2Lib.Split memory split = getDefaultSplitWithNoIncentive(); wallet.initialize(split, ALICE.addr); @@ -280,22 +194,10 @@ contract SplitWalletV2Test is BaseTest { wallet.setPaused(true); vm.expectRevert(Pausable.Paused.selector); - wallet.approveAndDistribute(split, address(usdc), _amount, ALICE.addr); + wallet.distribute(split, address(usdc), ALICE.addr); } - function testFuzz_distribute_Revert_whenPaused(uint256 _amount) public { - SplitV2Lib.Split memory split = getDefaultSplitWithNoIncentive(); - - wallet.initialize(split, ALICE.addr); - - vm.prank(ALICE.addr); - wallet.setPaused(true); - - vm.expectRevert(Pausable.Paused.selector); - wallet.distribute(split, address(usdc), _amount, ALICE.addr); - } - - function testFuzz_distribute_Revert_whenInvalidSplit(uint256 _amount) public { + function test_distribute_Revert_whenInvalidSplit() public { SplitV2Lib.Split memory split = getDefaultSplitWithNoIncentive(); wallet.initialize(split, ALICE.addr); @@ -303,17 +205,7 @@ contract SplitWalletV2Test is BaseTest { split.distributionIncentive += 1; vm.expectRevert(SplitWalletV2.InvalidSplit.selector); - wallet.distribute(split, address(usdc), _amount, ALICE.addr); - } - - function testFuzz_distributeERC20_Revert_whenInvalidToken(uint256 _amount) public { - vm.assume(_amount > 10); - SplitV2Lib.Split memory split = getDefaultSplitWithNoIncentive(); - - wallet.initialize(split, ALICE.addr); - - vm.expectRevert(); - wallet.distribute(split, native, _amount, ALICE.addr); + wallet.distribute(split, address(usdc), ALICE.addr); } function testFuzz_distribute_ERC20_whenPaused_byOwner(uint256 _amount, bool _distributeByPush) public { @@ -325,15 +217,13 @@ contract SplitWalletV2Test is BaseTest { deal(address(usdc), address(wallet), _amount); - wallet.approveSplitsWarehouse(address(usdc)); - vm.startPrank(ALICE.addr); wallet.updateDistributeDirection(_distributeByPush); wallet.setPaused(true); - wallet.distribute(split, address(usdc), _amount, ALICE.addr); + wallet.distribute(split, address(usdc), ALICE.addr); vm.stopPrank(); - assertAlmostEq(usdc.balanceOf(address(wallet)), 0, 9); + assertAlmostEq(usdc.balanceOf(address(wallet)), 0, 10); if (_distributeByPush) { for (uint256 i = 0; i < split.recipients.length; i++) { @@ -355,14 +245,12 @@ contract SplitWalletV2Test is BaseTest { deal(address(usdc), address(wallet), _amount); - wallet.approveSplitsWarehouse(address(usdc)); - vm.prank(ALICE.addr); wallet.updateDistributeDirection(_distributeByPush); - wallet.distribute(split, address(usdc), _amount, ALICE.addr); + wallet.distribute(split, address(usdc), ALICE.addr); - assertAlmostEq(usdc.balanceOf(address(wallet)), 0, 9); + assertAlmostEq(usdc.balanceOf(address(wallet)), 0, 10); if (_distributeByPush) { for (uint256 i = 0; i < split.recipients.length; i++) { @@ -387,22 +275,20 @@ contract SplitWalletV2Test is BaseTest { vm.prank(ALICE.addr); wallet.updateDistributeDirection(_distributeByPush); - uint256 distributorBalance = usdc.balanceOf(address(ALICE.addr)); - - wallet.approveSplitsWarehouse(address(usdc)); - wallet.distribute(split, address(usdc), _amount, ALICE.addr); + wallet.distribute(split, address(usdc), ALICE.addr); - assertAlmostEq(usdc.balanceOf(address(wallet)), 0, 9); - assertGt(usdc.balanceOf(address(ALICE.addr)), distributorBalance); + assertAlmostEq(usdc.balanceOf(address(wallet)), 0, 10); if (_distributeByPush) { for (uint256 i = 0; i < split.recipients.length; i++) { assertGt(usdc.balanceOf(split.recipients[i]), 0); } + assertGt(usdc.balanceOf(ALICE.addr), 0); } else { for (uint256 i = 0; i < split.recipients.length; i++) { assertGt(warehouse.balanceOf(split.recipients[i], tokenToId(address(usdc))), 0); } + assertGt(warehouse.balanceOf(ALICE.addr, tokenToId(address(usdc))), 0); } } @@ -418,9 +304,9 @@ contract SplitWalletV2Test is BaseTest { vm.prank(ALICE.addr); wallet.updateDistributeDirection(_distributeByPush); - wallet.distribute(split, native, _amount, ALICE.addr); + wallet.distribute(split, native, ALICE.addr); - assertAlmostEq(address(wallet).balance, 0, 9); + assertAlmostEq(address(wallet).balance, 0, 10); if (_distributeByPush) { for (uint256 i = 0; i < split.recipients.length; i++) { @@ -447,19 +333,20 @@ contract SplitWalletV2Test is BaseTest { uint256 distributorBalance = ALICE.addr.balance; - wallet.distribute(split, native, _amount, ALICE.addr); + wallet.distribute(split, native, ALICE.addr); - assertAlmostEq(address(wallet).balance, 0, 9); - assertGt(ALICE.addr.balance, distributorBalance); + assertAlmostEq(address(wallet).balance, 0, 10); if (_distributeByPush) { for (uint256 i = 0; i < split.recipients.length; i++) { assertGt(split.recipients[i].balance, 0); } + assertGt(ALICE.addr.balance, distributorBalance); } else { for (uint256 i = 0; i < split.recipients.length; i++) { assertGt(warehouse.balanceOf(split.recipients[i], tokenToId(native)), 0); } + assertGt(warehouse.balanceOf(ALICE.addr, tokenToId(native)), 0); } } @@ -478,9 +365,9 @@ contract SplitWalletV2Test is BaseTest { uint256 distributorBalance = ALICE.addr.balance; - wallet.approveAndDistribute(split, native, _amount, ALICE.addr); + wallet.distribute(split, native, ALICE.addr); - assertAlmostEq(address(wallet).balance, 0, 9); + assertAlmostEq(address(wallet).balance, 0, 10); assertGt(ALICE.addr.balance, distributorBalance); for (uint256 i = 0; i < split.recipients.length; i++) { @@ -490,17 +377,6 @@ contract SplitWalletV2Test is BaseTest { assertGt(warehouse.balanceOf(BAD_ACTOR, tokenToId(native)), 0); } - function test_approveSplitsWarehouse() public { - wallet.approveSplitsWarehouse(address(usdc)); - - assertEq(usdc.allowance(address(wallet), address(warehouse)), type(uint256).max); - } - - function test_approveSplitsWarehouse_revert_whenNonERC20() public { - vm.expectRevert(); - wallet.approveSplitsWarehouse(native); - } - function testFuzz_wallet_receiveEthEvent(uint256 _amount) public { deal(address(this), _amount); vm.expectEmit(); @@ -523,6 +399,6 @@ contract SplitWalletV2Test is BaseTest { receivers[i - 100] = SplitReceiver(address(uint160(i + 1)), uint32(10)); } - return createSplit(receivers, uint16(1e4)); + return createSplit(receivers, uint16(1.1e4)); } } diff --git a/packages/splits-v2/test/utils/ReentrantReceiver.sol b/packages/splits-v2/test/utils/ReentrantReceiver.sol index 97f674b..d7be53c 100644 --- a/packages/splits-v2/test/utils/ReentrantReceiver.sol +++ b/packages/splits-v2/test/utils/ReentrantReceiver.sol @@ -7,6 +7,6 @@ import { SplitsWarehouse } from "../../src/SplitsWarehouse.sol"; contract WarehouseReentrantReceiver { fallback() external payable { address token = SplitsWarehouse(msg.sender).NATIVE_TOKEN(); - SplitsWarehouse(msg.sender).withdraw(token, msg.value); + SplitsWarehouse(msg.sender).withdraw(msg.sender, token, msg.value); } } diff --git a/packages/splits-v2/test/warehouse/SplitsWarehouse.t.sol b/packages/splits-v2/test/warehouse/SplitsWarehouse.t.sol index b2adcea..226460c 100644 --- a/packages/splits-v2/test/warehouse/SplitsWarehouse.t.sol +++ b/packages/splits-v2/test/warehouse/SplitsWarehouse.t.sol @@ -153,7 +153,7 @@ contract SplitsWarehouseTest is BaseTest, Fuzzer { vm.prank(_owner); vm.expectEmit(); emit Withdraw(_owner, token, _owner, _amount, 0); - warehouse.withdraw(token, _amount); + warehouse.withdraw(_owner, token, _amount); assertEq(warehouse.balanceOf(_owner, tokenToId(token)), 0); assertEq(ERC20(token).balanceOf(address(warehouse)), 0); @@ -167,7 +167,7 @@ contract SplitsWarehouseTest is BaseTest, Fuzzer { vm.prank(_owner); vm.expectEmit(); emit Withdraw(_owner, native, _owner, _amount, 0); - warehouse.withdraw(native, _amount); + warehouse.withdraw(_owner, native, _amount); assertEq(warehouse.balanceOf(_owner, tokenToId(native)), 0); assertEq(address(warehouse).balance, 0); @@ -180,7 +180,7 @@ contract SplitsWarehouseTest is BaseTest, Fuzzer { vm.prank(owner); vm.expectRevert(); - warehouse.withdraw(token, 101 ether); + warehouse.withdraw(owner, token, 101 ether); } function test_withdrawOwner_Revert_whenOwnerReenters() public { @@ -190,7 +190,7 @@ contract SplitsWarehouseTest is BaseTest, Fuzzer { vm.prank(owner); vm.expectRevert("Address: unable to send value, recipient may have reverted"); - warehouse.withdraw(native, 100 ether); + warehouse.withdraw(owner, native, 100 ether); } function test_withdrawOwner_Revert_whenNonERC20() public { @@ -198,7 +198,7 @@ contract SplitsWarehouseTest is BaseTest, Fuzzer { vm.prank(owner); vm.expectRevert(); - warehouse.withdraw(address(this), 100 ether); + warehouse.withdraw(owner, address(this), 100 ether); } /* -------------------------------------------------------------------------- */ @@ -215,7 +215,7 @@ contract SplitsWarehouseTest is BaseTest, Fuzzer { for (uint256 i = 0; i < defaultTokens.length; i++) { emit Withdraw(owner, defaultTokens[i], owner, _amount, 0); } - warehouse.withdraw(defaultTokens, getAmounts(_amount)); + warehouse.withdraw(owner, defaultTokens, getAmounts(_amount)); for (uint256 i = 0; i < defaultTokens.length; i++) { assertEq(warehouse.balanceOf(owner, tokenToId(defaultTokens[i])), 0); @@ -234,7 +234,7 @@ contract SplitsWarehouseTest is BaseTest, Fuzzer { vm.prank(owner); vm.expectRevert(LengthMismatch.selector); - warehouse.withdraw(defaultTokens, new uint256[](1)); + warehouse.withdraw(owner, defaultTokens, new uint256[](1)); } function test_withdrawOwner_multipleTokens_Revert_whenWithdrawGreaterThanBalance() public { @@ -244,7 +244,7 @@ contract SplitsWarehouseTest is BaseTest, Fuzzer { vm.prank(owner); vm.expectRevert(); - warehouse.withdraw(defaultTokens, getAmounts(101 ether)); + warehouse.withdraw(owner, defaultTokens, getAmounts(101 ether)); } function test_withdrawOwner_multipleTokens_Revert_whenOwnerReenters() public { @@ -254,7 +254,7 @@ contract SplitsWarehouseTest is BaseTest, Fuzzer { vm.prank(owner); vm.expectRevert("Address: unable to send value, recipient may have reverted"); - warehouse.withdraw(defaultTokens, getAmounts(100 ether)); + warehouse.withdraw(owner, defaultTokens, getAmounts(100 ether)); } /* -------------------------------------------------------------------------- */ diff --git a/packages/splits-v2/test/warehouse/SplitsWarehouseHandler.sol b/packages/splits-v2/test/warehouse/SplitsWarehouseHandler.sol index b57ebf8..fc20d00 100644 --- a/packages/splits-v2/test/warehouse/SplitsWarehouseHandler.sol +++ b/packages/splits-v2/test/warehouse/SplitsWarehouseHandler.sol @@ -90,7 +90,7 @@ contract SplitsWarehouseHandler is CommonBase, StdCheats, StdUtils { if (user == badActor && token == native) { return; } - warehouse.withdraw(token, _amount); + warehouse.withdraw(user, token, _amount); warehouseBalance[token] -= _amount; }