SafeERC20.trySafeTransfer{,from} (#5483)
This commit is contained in:
@ -42,6 +42,20 @@ library SafeERC20 {
|
||||
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
|
||||
*/
|
||||
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
|
||||
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
|
||||
*/
|
||||
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
|
||||
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
|
||||
* non-reverting calls are assumed to be successful.
|
||||
|
||||
Reference in New Issue
Block a user