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

Add handling for max uint256 amount in withdrawERC20 #333

Merged
merged 6 commits into from
Dec 27, 2024
5 changes: 5 additions & 0 deletions src/access/workflows/WithdrawWorkflow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
Expand Down
12 changes: 12 additions & 0 deletions test/unit/access/WithdrawWorkflow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading