Skip to content

Commit

Permalink
Add handling for max uint256 amount in withdrawERC20 and correspondin…
Browse files Browse the repository at this point in the history
…g test case.
  • Loading branch information
ylv-io committed Dec 23, 2024
1 parent 98e9a96 commit ec54702
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit ec54702

Please sign in to comment.