-
Notifications
You must be signed in to change notification settings - Fork 0
/
FAIL Pool.txt
144 lines (121 loc) · 3.54 KB
/
FAIL Pool.txt
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
pragma solidity ^0.5.1;
interface ERC20Interface {
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract WithdrawFail
{
address token_contract;
address admin;
uint256 withdraw_value;
bool capReached ;
//address withdrawed
address[] public withdrawed_addresses;
//Whitelists of reward address
mapping(address => bool) public whitelists;
constructor() public {
// token_contract = tokenContractAddress;
admin = msg.sender;
withdraw_value = 5;
}
function adminAddress() public view returns (address)
{
return admin;
}
/**
* Whitelist reward address
* @param users Array of addresses to be whitelisted
*/
function whitelist(address[] memory users) public {
require(msg.sender==admin);
for (uint32 i = 0; i < users.length; i++) {
whitelists[users[i]] = true;
}
}
function whitelistRemove(address user) public {
require(msg.sender==admin);
require(whitelists[user]);
whitelists[user] = false;
}
//balance of tokens in contract
function tokensInContract() public view returns (uint256)
{
ERC20Interface token = ERC20Interface(token_contract);
return token.balanceOf(address(this));
}
// //withdraw all, just admin
// function withdraw_all() public
// {
// require(msg.sender==admin);
// ERC20Interface token = ERC20Interface(token_contract);
// token.transfer(admin, token.balanceOf(address(this)));
// }
//change the withdraw value
function setWithdrawValue(uint256 value) public
{
require(msg.sender==admin);
withdraw_value = value;
}
//set token contract address
function setTokenContractAddress(address addr) public
{
require(msg.sender==admin);
token_contract = addr;
}
function tokenContractAddress() public view returns (address)
{
return token_contract;
}
function getWithdrawValue() public view returns (uint256)
{
return withdraw_value;
}
//if he claimed once he cannot claim again
function ableToWithdraw(address addr) public view returns (bool)
{
for (uint i = 0; i < withdrawed_addresses.length; i++)
{
if(withdrawed_addresses[i]==addr)
{
return false;
}
}
return true;
}
function enoughBalance() public view returns (bool)
{
return withdraw_value <= tokensInContract();
}
function checkCap() public view returns (bool) {
return capReached;
}
function setCapReached(bool yea) public
{
require(msg.sender==admin);
capReached = yea;
}
//withdraw tokens from contract
function withdraw() external returns(bool)
{
require(enoughBalance());
require(ableToWithdraw(msg.sender));
ERC20Interface token = ERC20Interface(token_contract);
if (whitelists[msg.sender])
{
token.transfer(msg.sender, withdraw_value);
withdrawed_addresses.push(msg.sender);
}
else if (capReached == false)
{
token.transfer(msg.sender, 1);
withdrawed_addresses.push(msg.sender);
}
return true;
}
}