-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathTransferHelper.sol
26 lines (23 loc) · 986 Bytes
/
TransferHelper.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;
import {IERC20Minimal} from '../interfaces/IERC20Minimal.sol';
/// @title TransferHelper
/// @notice Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false
library TransferHelper {
error TF();
/// @notice Transfers tokens from msg.sender to a recipient
/// @dev Calls transfer on token contract, errors with TF if transfer fails
/// @param token The contract address of the token which will be transferred
/// @param to The recipient of the transfer
/// @param value The value of the transfer
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(IERC20Minimal.transfer.selector, to, value)
);
if (!(success && (data.length == 0 || abi.decode(data, (bool))))) revert TF();
}
}