-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathGenericTokenSender.sol
67 lines (58 loc) · 2.11 KB
/
GenericTokenSender.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
59
60
61
62
63
64
65
66
67
pragma solidity ^0.5.17;
import "../../openzeppelin/Ownable.sol";
import "../../interfaces/IERC20.sol";
import "../../utils/AdminRole.sol";
/**
* @title Token sender contract.
*
* @notice This contract includes functions to transfer tokens
* to a recipient or to several recipients in a list. There is
* an ACL control check by modifier.
*
*/
contract GenericTokenSender is AdminRole {
/* Events */
event TokensTransferred(address indexed token, address indexed receiver, uint256 amount);
/* Functions */
/**
* @notice Transfer given amounts of tokens to the given addresses.
* @param _token The address of the token.
* @param _receivers The addresses of the receivers.
* @param _amounts The amounts to be transferred.
* */
function transferTokensUsingList(
address _token,
address[] calldata _receivers,
uint256[] calldata _amounts
) external onlyAuthorized {
require(_receivers.length == _amounts.length, "arrays mismatch");
for (uint256 i = 0; i < _receivers.length; i++) {
_transferTokens(_token, _receivers[i], _amounts[i]);
}
}
function() external payable {}
/**
* @notice Transfer tokens to given address.
* @param _token The address of the token.
* @param _receiver The address of the token receiver.
* @param _amount The amount to be transferred.
* */
function transferTokens(
address _token,
address _receiver,
uint256 _amount
) external onlyAuthorized {
_transferTokens(_token, _receiver, _amount);
}
function _transferTokens(address _token, address _receiver, uint256 _amount) internal {
require(_receiver != address(0), "receiver address invalid");
require(_amount != 0, "amount invalid");
if (_token != address(0)) {
require(IERC20(_token).transfer(_receiver, _amount), "transfer failed");
} else {
(bool success, ) = _receiver.call.value(_amount)("");
require(success, "RBTC transfer failed");
}
emit TokensTransferred(_token, _receiver, _amount);
}
}