-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathTokenSender.sol
99 lines (80 loc) · 2.74 KB
/
TokenSender.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
pragma solidity ^0.5.17;
import "../../openzeppelin/Ownable.sol";
import "../../interfaces/IERC20.sol";
/**
* @title SOV Token sender contract.
*
* @notice This contract includes functions to transfer SOV tokens
* to a recipient or to several recipients in a list. There is
* an ACL control check by modifier.
*
*/
contract TokenSender is Ownable {
/* Storage */
/// @notice The SOV token contract.
address public SOV;
/// @dev user => flag whether user has admin role
mapping(address => bool) public admins;
/* Events */
event SOVTransferred(address indexed receiver, uint256 amount);
event AdminAdded(address admin);
event AdminRemoved(address admin);
/* Functions */
constructor(address _SOV) public {
require(_SOV != address(0), "SOV address invalid");
SOV = _SOV;
}
/* Modifiers */
/**
* @dev Throws if called by any account other than the owner or admin.
* */
modifier onlyAuthorized() {
require(isOwner() || admins[msg.sender], "unauthorized");
_;
}
/* Functions */
/**
* @notice Add account to ACL.
* @param _admin The addresses of the account to grant permissions.
* */
function addAdmin(address _admin) public onlyOwner {
admins[_admin] = true;
emit AdminAdded(_admin);
}
/**
* @notice Remove account from ACL.
* @param _admin The addresses of the account to revoke permissions.
* */
function removeAdmin(address _admin) public onlyOwner {
admins[_admin] = false;
emit AdminRemoved(_admin);
}
/**
* @notice Transfer given amounts of SOV to the given addresses.
* @param _receivers The addresses of the SOV receivers.
* @param _amounts The amounts to be transferred.
* */
function transferSOVusingList(
address[] memory _receivers,
uint256[] memory _amounts
) public onlyAuthorized {
require(_receivers.length == _amounts.length, "arrays mismatch");
for (uint256 i = 0; i < _receivers.length; i++) {
_transferSOV(_receivers[i], _amounts[i]);
}
}
/**
* @notice Transfer SOV tokens to given address.
* @param _receiver The address of the SOV receiver.
* @param _amount The amount to be transferred.
* */
function transferSOV(address _receiver, uint256 _amount) public onlyAuthorized {
_transferSOV(_receiver, _amount);
}
function _transferSOV(address _receiver, uint256 _amount) internal {
require(_receiver != address(0), "receiver address invalid");
require(_amount != 0, "amount invalid");
require(IERC20(SOV).transfer(_receiver, _amount), "transfer failed");
emit SOVTransferred(_receiver, _amount);
}
}