@@ -148,21 +148,20 @@ contract AmoyTokenTransfer is OwnerIsCreator {
148148 /// It is automatically called when Ether is transferred to the contract without any data.
149149 receive () external payable {}
150150
151- /// @notice Allows the contract owner to withdraw the entire balance of Ether from the contract.
152- /// @dev This function reverts if there are no funds to withdraw or if the transfer fails.
153- /// It should only be callable by the owner of the contract.
154- /// @param _beneficiary The address to which the Ether should be transferred.
155- function withdraw (address _beneficiary ) public onlyOwner {
151+ /// @notice Allows the owner of the contract to withdraw all tokens of a specific ERC20 token.
152+ /// @dev This function reverts with a 'NothingToWithdraw' error if there are no tokens to withdraw.
153+ /// @param _beneficiary The address to which the tokens will be sent.
154+ /// @param _token The contract address of the ERC20 token to be withdrawn.
155+ function withdrawToken (
156+ address _beneficiary ,
157+ address _token
158+ ) public onlyOwner {
156159 // Retrieve the balance of this contract
157- uint256 amount = address (this ).balance ;
160+ uint256 amount = IERC20 (_token). balanceOf ( address (this )) ;
158161
159162 // Revert if there is nothing to withdraw
160163 if (amount == 0 ) revert NothingToWithdraw ();
161164
162- // Attempt to send the funds, capturing the success status and discarding any return data
163- (bool sent , ) = _beneficiary.call {value: amount}("" );
164-
165- // Revert if the send failed, with information about the attempted transfer
166- if (! sent) revert FailedToWithdrawEth (msg .sender , _beneficiary, amount);
165+ IERC20 (_token).safeTransfer (_beneficiary, amount);
167166 }
168167}
0 commit comments