diff --git a/src/access/workflows/WithdrawWorkflow.sol b/src/access/workflows/WithdrawWorkflow.sol index 3cbd00a0..b242835f 100644 --- a/src/access/workflows/WithdrawWorkflow.sol +++ b/src/access/workflows/WithdrawWorkflow.sol @@ -18,6 +18,11 @@ contract WithdrawWorkflow { error NativeWithdrawalFailed(); function withdrawERC20(IERC20 asset, uint256 amount) external { + // If amount is max uint256, set it to the entire balance + if (amount == type(uint256).max) { + amount = asset.balanceOf(address(this)); + } + address owner = _getOwner(); asset.safeTransfer({to: owner, value: amount}); } diff --git a/test/unit/access/WithdrawWorkflow.t.sol b/test/unit/access/WithdrawWorkflow.t.sol index 4281eaa6..a1171f9c 100644 --- a/test/unit/access/WithdrawWorkflow.t.sol +++ b/test/unit/access/WithdrawWorkflow.t.sol @@ -69,6 +69,18 @@ contract WithdrawWorkflowTest is BaseTest { assertEq(token.balanceOf(_user), defaultAmount); } + function testWithdrawERC20__WhenAmountMax() public { + token.mint(address(accessPoint), defaultAmount); + + bytes memory data = + abi.encodeWithSelector(WithdrawWorkflow.withdrawERC20.selector, IERC20(token), type(uint256).max); + + vm.prank(_user); + accessPoint.execute(address(withdrawWorkflow), data); + + assertEq(token.balanceOf(_user), defaultAmount); + } + function testWithdrawNative() public { vm.deal(address(accessPoint), defaultAmount);