-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy path0x779b7b713c86e3e6774f5040d9ccc2d43ad375f8-POOL-StakePool.sol
342 lines (292 loc) · 12 KB
/
0x779b7b713c86e3e6774f5040d9ccc2d43ad375f8-POOL-StakePool.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
pragma solidity ^0.4.11;
/**
* @author Jefferson Davis
* StakePool_ICO.sol creates the client's token for crowdsale and allows for subsequent token sales and minting of tokens
* In addition, there is a quarterly dividend payout triggered by the owner, plus creates a transaction record prior to payout
* Crowdsale contracts edited from original contract code at https://www.ethereum.org/crowdsale#crowdfund-your-idea
* Additional crowdsale contracts, functions, libraries from OpenZeppelin
* at https://github.com/OpenZeppelin/zeppelin-solidity/tree/master/contracts/token
* Token contract edited from original contract code at https://www.ethereum.org/token
* ERC20 interface and certain token functions adapted from https://github.com/ConsenSys/Tokens
**/
contract ERC20 {
//Sets events and functions for ERC20 token
event Approval(address indexed _owner, address indexed _spender, uint _value);
event Transfer(address indexed _from, address indexed _to, uint _value);
function allowance(address _owner, address _spender) constant returns (uint remaining);
function approve(address _spender, uint _value) returns (bool success);
function balanceOf(address _owner) constant returns (uint balance);
function transfer(address _to, uint _value) returns (bool success);
function transferFrom(address _from, address _to, uint _value) returns (bool success);
}
contract Owned {
//Public variable
address public owner;
//Sets contract creator as the owner
function Owned() {
owner = msg.sender;
}
//Sets onlyOwner modifier for specified functions
modifier onlyOwner {
require(msg.sender == owner);
_;
}
//Allows for transfer of contract ownership
function transferOwnership(address newOwner) onlyOwner {
owner = newOwner;
}
}
library SafeMath {
function add(uint256 a, uint256 b) internal returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
function div(uint256 a, uint256 b) internal returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function max64(uint64 a, uint64 b) internal constant returns (uint64) {
return a >= b ? a : b;
}
function max256(uint256 a, uint256 b) internal constant returns (uint256) {
return a >= b ? a : b;
}
function min64(uint64 a, uint64 b) internal constant returns (uint64) {
return a < b ? a : b;
}
function min256(uint256 a, uint256 b) internal constant returns (uint256) {
return a < b ? a : b;
}
function mul(uint256 a, uint256 b) internal returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function sub(uint256 a, uint256 b) internal returns (uint256) {
assert(b <= a);
return a - b;
}
}
contract StakePool is ERC20, Owned {
//Applies SafeMath library to uint256 operations
using SafeMath for uint256;
//Public variables
string public name;
string public symbol;
uint256 public decimals;
uint256 public initialSupply;
uint256 public totalSupply;
//Variables
uint256 multiplier;
//Creates arrays for balances
mapping (address => uint256) balance;
mapping (address => mapping (address => uint256)) allowed;
//Creates modifier to prevent short address attack
modifier onlyPayloadSize(uint size) {
if(msg.data.length < size + 4) revert();
_;
}
//Constructor
function StakePool(string tokenName, string tokenSymbol, uint8 decimalUnits, uint256 decimalMultiplier, uint256 initialAmount) {
name = tokenName;
symbol = tokenSymbol;
decimals = decimalUnits;
multiplier = decimalMultiplier;
initialSupply = initialAmount;
totalSupply = initialSupply;
}
//Provides the remaining balance of approved tokens from function approve
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
//Allows for a certain amount of tokens to be spent on behalf of the account owner
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
//Returns the account balance
function balanceOf(address _owner) constant returns (uint256 remainingBalance) {
return balance[_owner];
}
//Allows contract owner to mint new tokens, prevents numerical overflow
function mintToken(address target, uint256 mintedAmount) onlyOwner returns (bool success) {
require(mintedAmount > 0);
uint256 addTokens = mintedAmount;
balance[target] += addTokens;
totalSupply += addTokens;
Transfer(0, target, addTokens);
return true;
}
//Sends tokens from sender's account
function transfer(address _to, uint256 _value) onlyPayloadSize(2 * 32) returns (bool success) {
if ((balance[msg.sender] >= _value) && (balance[_to] + _value > balance[_to])) {
balance[msg.sender] -= _value;
balance[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else {
return false;
}
}
//Transfers tokens from an approved account
function transferFrom(address _from, address _to, uint256 _value) onlyPayloadSize(3 * 32) returns (bool success) {
if ((balance[_from] >= _value) && (allowed[_from][msg.sender] >= _value) && (balance[_to] + _value > balance[_to])) {
balance[_to] += _value;
balance[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else {
return false;
}
}
}
contract StakePoolICO is Owned, StakePool {
//Applies SafeMath library to uint256 operations
using SafeMath for uint256;
//Public Variables
address public multiSigWallet;
uint256 public amountRaised;
uint256 public dividendPayment;
uint256 public numberOfRecordEntries;
uint256 public numberOfTokenHolders;
uint256 public startTime;
uint256 public stopTime;
uint256 public hardcap;
uint256 public price;
//Variables
address[] recordTokenHolders;
address[] tokenHolders;
bool crowdsaleClosed = true;
mapping (address => uint256) recordBalance;
mapping (address => uint256) recordTokenHolderID;
mapping (address => uint256) tokenHolderID;
string tokenName = "StakePool";
string tokenSymbol = "POOL";
uint256 initialTokens = 20000000000000000;
uint256 multiplier = 100000000;
uint8 decimalUnits = 8;
//Initializes the token
function StakePoolICO()
StakePool(tokenName, tokenSymbol, decimalUnits, multiplier, initialTokens) {
balance[msg.sender] = initialTokens;
Transfer(0, msg.sender, initialTokens);
multiSigWallet = msg.sender;
hardcap = 30000000000000000;
setPrice(3000);
dividendPayment = 50000000000000;
recordTokenHolders.length = 2;
tokenHolders.length = 2;
tokenHolders[1] = msg.sender;
numberOfTokenHolders++;
}
//Fallback function creates tokens and sends to investor when crowdsale is open
function () payable {
require((!crowdsaleClosed)
&& (now < stopTime)
&& (totalSupply.add(msg.value.mul(getPrice()).mul(multiplier).div(1 ether)) <= hardcap));
address recipient = msg.sender;
amountRaised = amountRaised.add(msg.value.div(1 ether));
uint256 tokens = msg.value.mul(getPrice()).mul(multiplier).div(1 ether);
totalSupply = totalSupply.add(tokens);
balance[recipient] = balance[recipient].add(tokens);
require(multiSigWallet.send(msg.value));
Transfer(0, recipient, tokens);
if (tokenHolderID[recipient] == 0) {
addTokenHolder(recipient);
}
}
//Adds an address to the recorrdEntry list
function addRecordEntry(address account) internal {
if (recordTokenHolderID[account] == 0) {
recordTokenHolderID[account] = recordTokenHolders.length;
recordTokenHolders.length++;
recordTokenHolders[recordTokenHolders.length.sub(1)] = account;
numberOfRecordEntries++;
}
}
//Adds an address to the tokenHolders list
function addTokenHolder(address account) returns (bool success) {
bool status = false;
if (balance[account] != 0) {
tokenHolderID[account] = tokenHolders.length;
tokenHolders.length++;
tokenHolders[tokenHolders.length.sub(1)] = account;
numberOfTokenHolders++;
status = true;
}
return status;
}
//Allows the owner to create an record of token owners and their balances
function createRecord() internal {
for (uint i = 0; i < (tokenHolders.length.sub(1)); i++ ) {
address holder = getTokenHolder(i);
uint256 holderBal = balanceOf(holder);
addRecordEntry(holder);
recordBalance[holder] = holderBal;
}
}
//Returns the current price of the token for the crowdsale
function getPrice() returns (uint256 result) {
return price;
}
//Returns record contents
function getRecordBalance(address record) constant returns (uint256) {
return recordBalance[record];
}
//Returns the address of a specific index value
function getRecordHolder(uint256 index) constant returns (address) {
return address(recordTokenHolders[index.add(1)]);
}
//Returns time remaining on crowdsale
function getRemainingTime() constant returns (uint256) {
return stopTime;
}
//Returns the address of a specific index value
function getTokenHolder(uint256 index) constant returns (address) {
return address(tokenHolders[index.add(1)]);
}
//Pays out dividends to tokens holders of record, based on 500,000 token payment
function payOutDividend() onlyOwner returns (bool success) {
createRecord();
uint256 volume = totalSupply;
for (uint i = 0; i < (tokenHolders.length.sub(1)); i++) {
address payee = getTokenHolder(i);
uint256 stake = volume.div(dividendPayment.div(multiplier));
uint256 dividendPayout = balanceOf(payee).div(stake).mul(multiplier);
balance[payee] = balance[payee].add(dividendPayout);
totalSupply = totalSupply.add(dividendPayout);
Transfer(0, payee, dividendPayout);
}
return true;
}
//Sets the multisig wallet for a crowdsale
function setMultiSigWallet(address wallet) onlyOwner returns (bool success) {
multiSigWallet = wallet;
return true;
}
//Sets the token price
function setPrice(uint256 newPriceperEther) onlyOwner returns (uint256) {
require(newPriceperEther > 0);
price = newPriceperEther;
return price;
}
//Allows owner to start the crowdsale from the time of execution until a specified stopTime
function startSale(uint256 saleStart, uint256 saleStop) onlyOwner returns (bool success) {
require(saleStop > now);
startTime = saleStart;
stopTime = saleStop;
crowdsaleClosed = false;
return true;
}
//Allows owner to stop the crowdsale immediately
function stopSale() onlyOwner returns (bool success) {
stopTime = now;
crowdsaleClosed = true;
return true;
}
}