-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy path0x4c382f8e09615ac86e08ce58266cc227e7d4d913-SKR-Skrilla.sol
305 lines (232 loc) · 10.4 KB
/
0x4c382f8e09615ac86e08ce58266cc227e7d4d913-SKR-Skrilla.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
pragma solidity ^0.4.13;
contract ERC20 {
function totalSupply() constant returns (uint totalSupply);
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);
function approve(address _spender, uint _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns (uint remaining);
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
library SafeMath {
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal constant 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 sub(uint256 a, uint256 b) internal constant returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract SkrillaToken is ERC20 {
using SafeMath for uint;
string public constant name = "Skrilla";
string public constant symbol = "SKR";
uint8 public constant decimals = 6;
uint256 public totalSupply;
//Multiply to get from a SKR to the number of subunits
//Note the cast here otherwise solidity uses a uint8
uint256 internal constant SUBUNIT_MULTIPLIER = 10 ** uint256(decimals);
//Token balances
mapping (address => uint256) tokenSaleBalances;
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
mapping (address => uint256) whiteList;
//Contract conditions
uint256 internal constant SALE_CAP = 600 * 10**6 * SUBUNIT_MULTIPLIER;
uint256 internal constant TEAM_TOKENS = 100 * 10**6 * SUBUNIT_MULTIPLIER;
uint256 internal constant GROWTH_TOKENS = 300 * 10**6 * SUBUNIT_MULTIPLIER;
uint256 internal constant TOTAL_SUPPLY_CAP = SALE_CAP + TEAM_TOKENS + GROWTH_TOKENS;
address internal withdrawAddress;
//State values
uint256 public ethRaised;
address internal owner;
address internal growth;
address internal team;
uint256[7] public saleStageStartDates;
//The prices for each stage. The number of tokens a user will receive for 1ETH.
uint16[6] public tokens = [3000,2500,0,2400,2200,2000];
function tokenSaleBalanceOf(address _owner) public constant returns (uint256 balance) {
balance = tokenSaleBalances[_owner];
}
function getPreSaleStart() public constant returns (uint256) {
return saleStageStartDates[0];
}
function getPreSaleEnd() public constant returns (uint256) {
return saleStageStartDates[2];
}
function getSaleStart() public constant returns (uint256) {
return saleStageStartDates[3];
}
function getSaleEnd() public constant returns (uint256) {
return saleStageStartDates[6];
}
// Tokens per ETH
function getCurrentPrice(address _buyer) public constant returns (uint256) {
uint256 price = whiteList[_buyer];
if (price > 0) {
return SUBUNIT_MULTIPLIER.mul(price);
} else {
uint256 stage = getStage();
return SUBUNIT_MULTIPLIER.mul(tokens[stage]);
}
}
function inPreSalePeriod() public constant returns (bool) {
return (now >= getPreSaleStart() && now <= getPreSaleEnd());
}
function inSalePeriod() public constant returns (bool) {
return (now >= getSaleStart() && now <= getSaleEnd());
//In rounds 1 - 3 period
}
// Set start date on contract deploy
function SkrillaToken(uint256 _preSaleStart, uint256 _saleStart, address _team, address _growth, address _withdrawAddress) {
owner = msg.sender;
require(owner != _team && owner != _growth);
require(_team != _growth);
//Ensure there was no overflow
require(SALE_CAP / SUBUNIT_MULTIPLIER == 600 * 10**6);
require(GROWTH_TOKENS / SUBUNIT_MULTIPLIER == 300 * 10**6);
require(TEAM_TOKENS / SUBUNIT_MULTIPLIER == 100 * 10**6);
team = _team;
growth = _growth;
withdrawAddress = _withdrawAddress;
tokenSaleBalances[team] = TEAM_TOKENS ;
tokenSaleBalances[growth] = GROWTH_TOKENS ;
totalSupply = (TEAM_TOKENS + GROWTH_TOKENS);
if (_preSaleStart == 0) {
_preSaleStart = 1508533200; //Oct 20 2017 9pm
}
if (_saleStart == 0) {
_saleStart = 1510002000; //Nov 6 2017 9pm
}
uint256 preSaleEnd = _preSaleStart.add(3 days);
require(_saleStart > preSaleEnd);
saleStageStartDates[0] = _preSaleStart;
saleStageStartDates[1] = _preSaleStart.add(1 days);
saleStageStartDates[2] = preSaleEnd;
saleStageStartDates[3] = _saleStart;
saleStageStartDates[4] = _saleStart.add(1 days);
saleStageStartDates[5] = _saleStart.add(7 days);
saleStageStartDates[6] = _saleStart.add(14 days);
ethRaised = 0;
}
//Move a user's token sale balance into the ERC20 balances mapping.
//The user must call this before they can use their tokens as ERC20 tokens.
function withdraw() public returns (bool) {
require(now > getSaleEnd() + 14 days);
uint256 tokenSaleBalance = tokenSaleBalances[msg.sender];
balances[msg.sender] = balances[msg.sender].add(tokenSaleBalance);
delete tokenSaleBalances[msg.sender];
Withdraw(msg.sender, tokenSaleBalance);
return true;
}
function balanceOf(address _owner) public constant returns (uint256 balance) {
balance = balances[_owner];
}
function totalSupply() public constant returns (uint256) {
//Although this function shadows the public field removing it causes all the tests to fail.
return totalSupply;
}
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_to != address(0));
require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value >= balances[_to]);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(_from,_to, _value);
return true;
}
function approve(address _spender, uint256 _amount) public returns (bool success) {
//Prevent attack mentioned here: https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/edit
//Requires that the spender can only set the allowance to a non zero amount if the current allowance is 0
//This may have backward compatibility issues with older clients.
require(allowed[msg.sender][_spender] == 0 || _amount == 0);
allowed[msg.sender][_spender] = _amount;
Approval(msg.sender, _spender, _amount);
return true;
}
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
function addToWhitelist(address _buyer, uint256 _price) public onlyOwner {
require(_price < 10000);
whiteList[_buyer] = _price;
}
function removeFromWhitelist(address _buyer) public onlyOwner {
delete whiteList[_buyer];
}
// Fallback function can be used to buy tokens
function() payable {
buyTokens();
}
// Low level token purchase function
function buyTokens() public payable saleHasNotClosed {
// No 0 contributions
require(msg.value > 0);
require(ethRaised.add(msg.value) <= 150000 ether);
// Ignore inSalePeriod for whitelisted buyers, just check before saleEnd
require(inPreSalePeriod() || inSalePeriod() || (whiteList[msg.sender] > 0));
if (inPreSalePeriod()) {
require(msg.value >= 10 ether || whiteList[msg.sender] > 0);
}
// Get price for buyer
uint256 price = getCurrentPrice(msg.sender);
require (price > 0);
uint256 tokenAmount = price.mul(msg.value);
tokenAmount = tokenAmount.div(1 ether);
require (tokenAmount > 0);
require (totalSupply.add(tokenAmount) <= TOTAL_SUPPLY_CAP);
totalSupply = totalSupply.add(tokenAmount);
ethRaised = ethRaised.add(msg.value);
tokenSaleBalances[msg.sender] = tokenSaleBalances[msg.sender].add(tokenAmount);
// Raise event
Transfer(address(0), msg.sender, tokenAmount);
TokenPurchase(msg.sender, msg.value, tokenAmount);
}
// empty the contract ETH
function transferEth() public onlyOwner {
require(now > getSaleEnd() + 14 days);
withdrawAddress.transfer(this.balance);
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
modifier saleHasNotClosed() {
//Sale must not have closed
require(now <= getSaleEnd());
_;
}
function getStage() public constant returns (uint256) {
for (uint256 i = 1; i < saleStageStartDates.length; i++) {
if (now < saleStageStartDates[i]) {
return i - 1;
}
}
return saleStageStartDates.length - 1;
}
event TokenPurchase(address indexed _purchaser, uint256 _value, uint256 _amount);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event Withdraw(address indexed _owner, uint256 _value);
}