-
Notifications
You must be signed in to change notification settings - Fork 10
/
LowLevelERC20Transfer.sol
58 lines (50 loc) · 1.61 KB
/
LowLevelERC20Transfer.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;
import {IERC20} from "../interfaces/IERC20.sol";
/**
* @title LowLevelERC20Transfer
* @notice This contract contains low-level calls to transfer ERC20 tokens.
* @author LooksRare protocol team (👀,💎)
*/
contract LowLevelERC20Transfer {
error ERC20TransferFail();
error ERC20TransferFromFail();
/**
* @notice Execute ERC20 transferFrom
* @param currency Currency address
* @param from Sender address
* @param to Recipient address
* @param amount Amount to transfer
*/
function _executeERC20TransferFrom(
address currency,
address from,
address to,
uint256 amount
) internal {
(bool status, bytes memory data) = currency.call(
abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, amount)
);
if (!status) revert ERC20TransferFromFail();
if (data.length > 0) {
if (!abi.decode(data, (bool))) revert ERC20TransferFromFail();
}
}
/**
* @notice Execute ERC20 (direct) transfer
* @param currency Currency address
* @param to Recipient address
* @param amount Amount to transfer
*/
function _executeERC20DirectTransfer(
address currency,
address to,
uint256 amount
) internal {
(bool status, bytes memory data) = currency.call(abi.encodeWithSelector(IERC20.transfer.selector, to, amount));
if (!status) revert ERC20TransferFail();
if (data.length > 0) {
if (!abi.decode(data, (bool))) revert ERC20TransferFail();
}
}
}