forked from howeguo/Token-BulkSender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BulkSender.sol
381 lines (312 loc) · 10.8 KB
/
BulkSender.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
pragma solidity ^ 0.4.0;
/**
* @title BulkSender MultiSender, support ETH and ERC20 Tokens, send ether or erc20 token to multiple addresses in batch
* @dev To Use this Dapp: https://bulksender.app
*/
library SafeMath {
function mul(uint a, uint b) internal pure returns(uint) {
uint c = a * b;
require(a == 0 || c / a == b);
return c;
}
function div(uint a, uint b) internal pure returns(uint) {
require(b > 0);
uint c = a / b;
require(a == b * c + a % b);
return c;
}
function sub(uint a, uint b) internal pure returns(uint) {
require(b <= a);
return a - b;
}
function add(uint a, uint b) internal pure returns(uint) {
uint c = a + b;
require(c >= a);
return c;
}
function max64(uint64 a, uint64 b) internal pure returns(uint64) {
return a >= b ? a: b;
}
function min64(uint64 a, uint64 b) internal pure returns(uint64) {
return a < b ? a: b;
}
function max256(uint256 a, uint256 b) internal pure returns(uint256) {
return a >= b ? a: b;
}
function min256(uint256 a, uint256 b) internal pure returns(uint256) {
return a < b ? a: b;
}
}
/**
* @title Bulksender MultiSender, support ETH and ERC20 Tokens, send ether or erc20 token to multiple addresses in batch
* @dev To Use this Dapp: https://bulksender.app
*/
contract ERC20Basic {
uint public totalSupply;
function balanceOf(address who) public constant returns(uint);
function transfer(address to, uint value) public;
event Transfer(address indexed from, address indexed to, uint value);
}
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public constant returns(uint);
function transferFrom(address from, address to, uint value) public;
function approve(address spender, uint value) public;
event Approval(address indexed owner, address indexed spender, uint value);
}
/**
* @title Bulksender MultiSender, support ETH and ERC20 Tokens
* @dev To Use this Dapp: https://bulksender.app
*/
contract BasicToken is ERC20Basic {
using SafeMath
for uint;
mapping(address = >uint) balances;
function transfer(address _to, uint _value) public {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
}
function balanceOf(address _owner) public constant returns(uint balance) {
return balances[_owner];
}
}
/**
* @title BulkSender MultiSender, support ETH and ERC20 Tokens, send ether or erc20 token to multiple addresses in batch
* @dev To Use this Dapp: https://bulksender.app
*/
contract StandardToken is BasicToken,
ERC20 {
mapping(address = >mapping(address = >uint)) allowed;
function transferFrom(address _from, address _to, uint _value) public {
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
}
function approve(address _spender, uint _value) public {
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
}
function allowance(address _owner, address _spender) public constant returns(uint remaining) {
return allowed[_owner][_spender];
}
}
/**
* @title BulkSender MultiSender, support ETH and ERC20 Tokens, send ether or erc20 token to multiple addresses in batch
* @dev To Use this Dapp: https://bulksender.app
*/
contract Ownable {
address public owner;
function Ownable() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) onlyOwner public {
if (newOwner != address(0)) {
owner = newOwner;
}
}
}
/**
* @title BulkSender MultiSender, support ETH and ERC20 Tokens, send ether or erc20 token to multiple addresses in batch
* @dev To Use this Dapp: https://bulksender.app
*/
contract BulkSender is Ownable {
using SafeMath
for uint;
event LogTokenBulkSent(address token, uint256 total);
event LogGetToken(address token, address receiver, uint256 balance);
address public receiverAddress;
uint public txFee = 0.01 ether;
uint public VIPFee = 1 ether;
/* VIP List */
mapping(address = >bool) public vipList;
/*
* get balance
*/
function getBalance(address _tokenAddress) onlyOwner public {
address _receiverAddress = getReceiverAddress();
if (_tokenAddress == address(0)) {
require(_receiverAddress.send(address(this).balance));
return;
}
StandardToken token = StandardToken(_tokenAddress);
uint256 balance = token.balanceOf(this);
token.transfer(_receiverAddress, balance);
emit LogGetToken(_tokenAddress, _receiverAddress, balance);
}
/*
* Register VIP
*/
function registerVIP() payable public {
require(msg.value >= VIPFee);
address _receiverAddress = getReceiverAddress();
require(_receiverAddress.send(msg.value));
vipList[msg.sender] = true;
}
/*
* VIP list
*/
function addToVIPList(address[] _vipList) onlyOwner public {
for (uint i = 0; i < _vipList.length; i++) {
vipList[_vipList[i]] = true;
}
}
/*
* Remove address from VIP List by Owner
*/
function removeFromVIPList(address[] _vipList) onlyOwner public {
for (uint i = 0; i < _vipList.length; i++) {
vipList[_vipList[i]] = false;
}
}
/*
* Check isVIP
*/
function isVIP(address _addr) public view returns(bool) {
return _addr == owner || vipList[_addr];
}
/*
* set receiver address
*/
function setReceiverAddress(address _addr) onlyOwner public {
require(_addr != address(0));
receiverAddress = _addr;
}
/*
* get receiver address
*/
function getReceiverAddress() public view returns(address) {
if (receiverAddress == address(0)) {
return owner;
}
return receiverAddress;
}
/*
* set vip fee
*/
function setVIPFee(uint _fee) onlyOwner public {
VIPFee = _fee;
}
/*
* set tx fee
*/
function setTxFee(uint _fee) onlyOwner public {
txFee = _fee;
}
function ethSendSameValue(address[] _to, uint _value) internal {
uint sendAmount = _to.length.sub(1).mul(_value);
uint remainingValue = msg.value;
bool vip = isVIP(msg.sender);
if (vip) {
require(remainingValue >= sendAmount);
} else {
require(remainingValue >= sendAmount.add(txFee));
}
require(_to.length <= 255);
for (uint8 i = 1; i < _to.length; i++) {
remainingValue = remainingValue.sub(_value);
require(_to[i].send(_value));
}
emit LogTokenBulkSent(0x000000000000000000000000000000000000bEEF, msg.value);
}
function ethSendDifferentValue(address[] _to, uint[] _value) internal {
uint sendAmount = _value[0];
uint remainingValue = msg.value;
bool vip = isVIP(msg.sender);
if (vip) {
require(remainingValue >= sendAmount);
} else {
require(remainingValue >= sendAmount.add(txFee));
}
require(_to.length == _value.length);
require(_to.length <= 255);
for (uint8 i = 1; i < _to.length; i++) {
remainingValue = remainingValue.sub(_value[i]);
require(_to[i].send(_value[i]));
}
emit LogTokenBulkSent(0x000000000000000000000000000000000000bEEF, msg.value);
}
function coinSendSameValue(address _tokenAddress, address[] _to, uint _value) internal {
uint sendValue = msg.value;
bool vip = isVIP(msg.sender);
if (!vip) {
require(sendValue >= txFee);
}
require(_to.length <= 255);
address from = msg.sender;
uint256 sendAmount = _to.length.sub(1).mul(_value);
StandardToken token = StandardToken(_tokenAddress);
for (uint8 i = 1; i < _to.length; i++) {
token.transferFrom(from, _to[i], _value);
}
emit LogTokenBulkSent(_tokenAddress, sendAmount);
}
function coinSendDifferentValue(address _tokenAddress, address[] _to, uint[] _value) internal {
uint sendValue = msg.value;
bool vip = isVIP(msg.sender);
if (!vip) {
require(sendValue >= txFee);
}
require(_to.length == _value.length);
require(_to.length <= 255);
uint256 sendAmount = _value[0];
StandardToken token = StandardToken(_tokenAddress);
for (uint8 i = 1; i < _to.length; i++) {
token.transferFrom(msg.sender, _to[i], _value[i]);
}
emit LogTokenBulkSent(_tokenAddress, sendAmount);
}
/*
Send ether with the same value by a explicit call method
*/
function sendEth(address[] _to, uint _value) payable public {
ethSendSameValue(_to, _value);
}
/*
Send ether with the different value by a explicit call method
*/
function bulksend(address[] _to, uint[] _value) payable public {
ethSendDifferentValue(_to, _value);
}
/*
Send ether with the different value by a implicit call method
*/
function bulkSendETHWithDifferentValue(address[] _to, uint[] _value) payable public {
ethSendDifferentValue(_to, _value);
}
/*
Send ether with the same value by a implicit call method
*/
function bulkSendETHWithSameValue(address[] _to, uint _value) payable public {
ethSendSameValue(_to, _value);
}
/*
Send coin with the same value by a implicit call method
*/
function bulkSendCoinWithSameValue(address _tokenAddress, address[] _to, uint _value) payable public {
coinSendSameValue(_tokenAddress, _to, _value);
}
/*
Send coin with the different value by a implicit call method, this method can save some fee.
*/
function bulkSendCoinWithDifferentValue(address _tokenAddress, address[] _to, uint[] _value) payable public {
coinSendDifferentValue(_tokenAddress, _to, _value);
}
/*
Send coin with the different value by a explicit call method
*/
function bulksendToken(address _tokenAddress, address[] _to, uint[] _value) payable public {
coinSendDifferentValue(_tokenAddress, _to, _value);
}
/*
Send coin with the same value by a explicit call method
*/
function drop(address _tokenAddress, address[] _to, uint _value) payable public {
coinSendSameValue(_tokenAddress, _to, _value);
}
}