-
Notifications
You must be signed in to change notification settings - Fork 2
/
Disperse.sol
36 lines (32 loc) · 1.3 KB
/
Disperse.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
// From: https://etherscan.io/address/0xd152f549545093347a162dce210e7293f1452150#code
pragma solidity ^0.4.25;
interface IERC20 {
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
contract Disperse {
function disperseEther(address[] recipients, uint256[] values) external payable {
for (uint256 i = 0; i < recipients.length; i++) {
recipients[i].transfer(values[i]);
}
uint256 balance = address(this).balance;
if (balance > 0) {
msg.sender.transfer(balance);
}
}
function disperseToken(IERC20 token, address[] recipients, uint256[] values) external {
uint256 total = 0;
for (uint256 i = 0; i < recipients.length; i++) {
total += values[i];
}
require(token.transferFrom(msg.sender, address(this), total));
for (i = 0; i < recipients.length; i++) {
require(token.transfer(recipients[i], values[i]));
}
}
function disperseTokenSimple(IERC20 token, address[] recipients, uint256[] values) external {
for (uint256 i = 0; i < recipients.length; i++) {
require(token.transferFrom(msg.sender, recipients[i], values[i]));
}
}
}