-
Notifications
You must be signed in to change notification settings - Fork 3
/
splitbot.sol
49 lines (41 loc) · 1.6 KB
/
splitbot.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
pragma solidity ^0.4.15;
contract ERC20Interface {
function totalSupply() public constant returns (uint);
function balanceOf(address tokenOwner) public constant returns (uint balance);
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
contract Split {
address public donate;
address public owner;
uint public percent;
modifier validPercent(uint _percent) {
require(_percent >= 1 && _percent <= 99);
_;
}
function Split(address _owner, address _donate, uint _percent)
public
validPercent(_percent)
{
owner = _owner;
donate = _donate;
percent = _percent;
}
function() payable public {
if (msg.value > 0) {
uint toDonate = msg.value * percent / 100;
uint toOwner = msg.value - toDonate;
owner.transfer(toOwner);
donate.transfer(toDonate);
}
}
function transferAnyERC20Token(address tokenAddress) public returns (bool success) {
ERC20Interface token = ERC20Interface(tokenAddress);
uint balance = token.balanceOf(address(this));
return token.transfer(owner, balance);
}
}