-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy path0x5136c98a80811c3f46bdda8b5c4555cfd9f812f0-IDH-indaHash_Coin.sol
590 lines (424 loc) · 18.4 KB
/
0x5136c98a80811c3f46bdda8b5c4555cfd9f812f0-IDH-indaHash_Coin.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
pragma solidity ^0.4.16;
// ----------------------------------------------------------------------------
//
// IDH indaHash token public sale contract
//
// For details, please visit: https://indahash.com/ico
//
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
//
// SafeMath3
//
// Adapted from https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/math/SafeMath.sol
// (no need to implement division)
//
// ----------------------------------------------------------------------------
library SafeMath3 {
function mul(uint a, uint b) internal constant returns (uint c) {
c = a * b;
assert( a == 0 || c / a == b );
}
function sub(uint a, uint b) internal constant returns (uint) {
assert( b <= a );
return a - b;
}
function add(uint a, uint b) internal constant returns (uint c) {
c = a + b;
assert( c >= a );
}
}
// ----------------------------------------------------------------------------
//
// Owned contract
//
// ----------------------------------------------------------------------------
contract Owned {
address public owner;
address public newOwner;
// Events ---------------------------
event OwnershipTransferProposed(address indexed _from, address indexed _to);
event OwnershipTransferred(address indexed _from, address indexed _to);
// Modifier -------------------------
modifier onlyOwner {
require( msg.sender == owner );
_;
}
// Functions ------------------------
function Owned() {
owner = msg.sender;
}
function transferOwnership(address _newOwner) onlyOwner {
require( _newOwner != owner );
require( _newOwner != address(0x0) );
OwnershipTransferProposed(owner, _newOwner);
newOwner = _newOwner;
}
function acceptOwnership() {
require(msg.sender == newOwner);
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
// ----------------------------------------------------------------------------
//
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
//
// ----------------------------------------------------------------------------
contract ERC20Interface {
// Events ---------------------------
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
// Functions ------------------------
function totalSupply() constant returns (uint);
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);
}
// ----------------------------------------------------------------------------
//
// ERC Token Standard #20
//
// ----------------------------------------------------------------------------
contract ERC20Token is ERC20Interface, Owned {
using SafeMath3 for uint;
uint public tokensIssuedTotal = 0;
mapping(address => uint) balances;
mapping(address => mapping (address => uint)) allowed;
// Functions ------------------------
/* Total token supply */
function totalSupply() constant returns (uint) {
return tokensIssuedTotal;
}
/* Get the account balance for an address */
function balanceOf(address _owner) constant returns (uint balance) {
return balances[_owner];
}
/* Transfer the balance from owner's account to another account */
function transfer(address _to, uint _amount) returns (bool success) {
// amount sent cannot exceed balance
require( balances[msg.sender] >= _amount );
// update balances
balances[msg.sender] = balances[msg.sender].sub(_amount);
balances[_to] = balances[_to].add(_amount);
// log event
Transfer(msg.sender, _to, _amount);
return true;
}
/* Allow _spender to withdraw from your account up to _amount */
function approve(address _spender, uint _amount) returns (bool success) {
// approval amount cannot exceed the balance
require ( balances[msg.sender] >= _amount );
// update allowed amount
allowed[msg.sender][_spender] = _amount;
// log event
Approval(msg.sender, _spender, _amount);
return true;
}
/* Spender of tokens transfers tokens from the owner's balance */
/* Must be pre-approved by owner */
function transferFrom(address _from, address _to, uint _amount) returns (bool success) {
// balance checks
require( balances[_from] >= _amount );
require( allowed[_from][msg.sender] >= _amount );
// update balances and allowed amount
balances[_from] = balances[_from].sub(_amount);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_amount);
balances[_to] = balances[_to].add(_amount);
// log event
Transfer(_from, _to, _amount);
return true;
}
/* Returns the amount of tokens approved by the owner */
/* that can be transferred by spender */
function allowance(address _owner, address _spender) constant returns (uint remaining) {
return allowed[_owner][_spender];
}
}
// ----------------------------------------------------------------------------
//
// IDH public token sale
//
// ----------------------------------------------------------------------------
contract IndaHashToken is ERC20Token {
/* Utility variable */
uint constant E6 = 10**6;
/* Basic token data */
string public constant name = "indaHash Coin";
string public constant symbol = "IDH";
uint8 public constant decimals = 6;
/* Wallet addresses - initially set to owner at deployment */
address public wallet;
address public adminWallet;
/* ICO dates */
uint public constant DATE_PRESALE_START = 1510153200; // 08-Nov-2017 15:00 UTC
uint public constant DATE_PRESALE_END = 1510758000; // 15-Nov-2017 15:00 UTC
uint public constant DATE_ICO_START = 1511967600; // 29-Nov-2017 15:00 UTC
uint public constant DATE_ICO_END = 1513782000; // 20-Dec-2017 15:00 UTC
/* ICO tokens per ETH */
uint public tokensPerEth = 3200 * E6; // rate during last ICO week
uint public constant BONUS_PRESALE = 40;
uint public constant BONUS_ICO_WEEK_ONE = 20;
uint public constant BONUS_ICO_WEEK_TWO = 10;
/* Other ICO parameters */
uint public constant TOKEN_SUPPLY_TOTAL = 400 * E6 * E6; // 400 mm tokens
uint public constant TOKEN_SUPPLY_ICO = 320 * E6 * E6; // 320 mm tokens
uint public constant TOKEN_SUPPLY_MKT = 80 * E6 * E6; // 80 mm tokens
uint public constant PRESALE_ETH_CAP = 15000 ether;
uint public constant MIN_FUNDING_GOAL = 40 * E6 * E6; // 40 mm tokens
uint public constant MIN_CONTRIBUTION = 1 ether / 2; // 0.5 Ether
uint public constant MAX_CONTRIBUTION = 300 ether;
uint public constant COOLDOWN_PERIOD = 2 days;
uint public constant CLAWBACK_PERIOD = 90 days;
/* Crowdsale variables */
uint public icoEtherReceived = 0; // Ether actually received by the contract
uint public tokensIssuedIco = 0;
uint public tokensIssuedMkt = 0;
uint public tokensClaimedAirdrop = 0;
/* Keep track of Ether contributed and tokens received during Crowdsale */
mapping(address => uint) public icoEtherContributed;
mapping(address => uint) public icoTokensReceived;
/* Keep track of participants who
/* - have received their airdropped tokens after a successful ICO */
/* - or have reclaimed their contributions in case of failed Crowdsale */
/* - are locked */
mapping(address => bool) public airdropClaimed;
mapping(address => bool) public refundClaimed;
mapping(address => bool) public locked;
// Events ---------------------------
event WalletUpdated(address _newWallet);
event AdminWalletUpdated(address _newAdminWallet);
event TokensPerEthUpdated(uint _tokensPerEth);
event TokensMinted(address indexed _owner, uint _tokens, uint _balance);
event TokensIssued(address indexed _owner, uint _tokens, uint _balance, uint _etherContributed);
event Refund(address indexed _owner, uint _amount, uint _tokens);
event Airdrop(address indexed _owner, uint _amount, uint _balance);
event LockRemoved(address indexed _participant);
// Basic Functions ------------------
/* Initialize (owner is set to msg.sender by Owned.Owned() */
function IndaHashToken() {
require( TOKEN_SUPPLY_ICO + TOKEN_SUPPLY_MKT == TOKEN_SUPPLY_TOTAL );
wallet = owner;
adminWallet = owner;
}
/* Fallback */
function () payable {
buyTokens();
}
// Information functions ------------
/* What time is it? */
function atNow() constant returns (uint) {
return now;
}
/* Has the minimum threshold been reached? */
function icoThresholdReached() constant returns (bool thresholdReached) {
if (tokensIssuedIco < MIN_FUNDING_GOAL) return false;
return true;
}
/* Are tokens transferable? */
function isTransferable() constant returns (bool transferable) {
if ( !icoThresholdReached() ) return false;
if ( atNow() < DATE_ICO_END + COOLDOWN_PERIOD ) return false;
return true;
}
// Lock functions -------------------
/* Manage locked */
function removeLock(address _participant) {
require( msg.sender == adminWallet || msg.sender == owner );
locked[_participant] = false;
LockRemoved(_participant);
}
function removeLockMultiple(address[] _participants) {
require( msg.sender == adminWallet || msg.sender == owner );
for (uint i = 0; i < _participants.length; i++) {
locked[_participants[i]] = false;
LockRemoved(_participants[i]);
}
}
// Owner Functions ------------------
/* Change the crowdsale wallet address */
function setWallet(address _wallet) onlyOwner {
require( _wallet != address(0x0) );
wallet = _wallet;
WalletUpdated(wallet);
}
/* Change the admin wallet address */
function setAdminWallet(address _wallet) onlyOwner {
require( _wallet != address(0x0) );
adminWallet = _wallet;
AdminWalletUpdated(adminWallet);
}
/* Change tokensPerEth before ICO start */
function updateTokensPerEth(uint _tokensPerEth) onlyOwner {
require( atNow() < DATE_PRESALE_START );
tokensPerEth = _tokensPerEth;
TokensPerEthUpdated(_tokensPerEth);
}
/* Minting of marketing tokens by owner */
function mintMarketing(address _participant, uint _tokens) onlyOwner {
// check amount
require( _tokens <= TOKEN_SUPPLY_MKT.sub(tokensIssuedMkt) );
// update balances
balances[_participant] = balances[_participant].add(_tokens);
tokensIssuedMkt = tokensIssuedMkt.add(_tokens);
tokensIssuedTotal = tokensIssuedTotal.add(_tokens);
// locked
locked[_participant] = true;
// log the miniting
Transfer(0x0, _participant, _tokens);
TokensMinted(_participant, _tokens, balances[_participant]);
}
/* Owner clawback of remaining funds after clawback period */
/* (for use in case of a failed Crwodsale) */
function ownerClawback() external onlyOwner {
require( atNow() > DATE_ICO_END + CLAWBACK_PERIOD );
wallet.transfer(this.balance);
}
/* Transfer out any accidentally sent ERC20 tokens */
function transferAnyERC20Token(address tokenAddress, uint amount) onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, amount);
}
// Private functions ----------------
/* Accept ETH during crowdsale (called by default function) */
function buyTokens() private {
uint ts = atNow();
bool isPresale = false;
bool isIco = false;
uint tokens = 0;
// minimum contribution
require( msg.value >= MIN_CONTRIBUTION );
// one address transfer hard cap
require( icoEtherContributed[msg.sender].add(msg.value) <= MAX_CONTRIBUTION );
// check dates for presale or ICO
if (ts > DATE_PRESALE_START && ts < DATE_PRESALE_END) isPresale = true;
if (ts > DATE_ICO_START && ts < DATE_ICO_END) isIco = true;
require( isPresale || isIco );
// presale cap in Ether
if (isPresale) require( icoEtherReceived.add(msg.value) <= PRESALE_ETH_CAP );
// get baseline number of tokens
tokens = tokensPerEth.mul(msg.value) / 1 ether;
// apply bonuses (none for last week)
if (isPresale) {
tokens = tokens.mul(100 + BONUS_PRESALE) / 100;
} else if (ts < DATE_ICO_START + 7 days) {
// first week ico bonus
tokens = tokens.mul(100 + BONUS_ICO_WEEK_ONE) / 100;
} else if (ts < DATE_ICO_START + 14 days) {
// second week ico bonus
tokens = tokens.mul(100 + BONUS_ICO_WEEK_TWO) / 100;
}
// ICO token volume cap
require( tokensIssuedIco.add(tokens) <= TOKEN_SUPPLY_ICO );
// register tokens
balances[msg.sender] = balances[msg.sender].add(tokens);
icoTokensReceived[msg.sender] = icoTokensReceived[msg.sender].add(tokens);
tokensIssuedIco = tokensIssuedIco.add(tokens);
tokensIssuedTotal = tokensIssuedTotal.add(tokens);
// register Ether
icoEtherReceived = icoEtherReceived.add(msg.value);
icoEtherContributed[msg.sender] = icoEtherContributed[msg.sender].add(msg.value);
// locked
locked[msg.sender] = true;
// log token issuance
Transfer(0x0, msg.sender, tokens);
TokensIssued(msg.sender, tokens, balances[msg.sender], msg.value);
// transfer Ether if we're over the threshold
if ( icoThresholdReached() ) wallet.transfer(this.balance);
}
// ERC20 functions ------------------
/* Override "transfer" (ERC20) */
function transfer(address _to, uint _amount) returns (bool success) {
require( isTransferable() );
require( locked[msg.sender] == false );
require( locked[_to] == false );
return super.transfer(_to, _amount);
}
/* Override "transferFrom" (ERC20) */
function transferFrom(address _from, address _to, uint _amount) returns (bool success) {
require( isTransferable() );
require( locked[_from] == false );
require( locked[_to] == false );
return super.transferFrom(_from, _to, _amount);
}
// External functions ---------------
/* Reclaiming of funds by contributors in case of a failed crowdsale */
/* (it will fail if account is empty after ownerClawback) */
/* While there could not have been any token transfers yet, a contributor */
/* may have received minted tokens, so the token balance after a refund */
/* may still be positive */
function reclaimFunds() external {
uint tokens; // tokens to destroy
uint amount; // refund amount
// ico is finished and was not successful
require( atNow() > DATE_ICO_END && !icoThresholdReached() );
// check if refund has already been claimed
require( !refundClaimed[msg.sender] );
// check if there is anything to refund
require( icoEtherContributed[msg.sender] > 0 );
// update variables affected by refund
tokens = icoTokensReceived[msg.sender];
amount = icoEtherContributed[msg.sender];
balances[msg.sender] = balances[msg.sender].sub(tokens);
tokensIssuedTotal = tokensIssuedTotal.sub(tokens);
refundClaimed[msg.sender] = true;
// transfer out refund
msg.sender.transfer(amount);
// log
Transfer(msg.sender, 0x0, tokens);
Refund(msg.sender, amount, tokens);
}
/* Claiming of "airdropped" tokens in case of successful crowdsale */
/* Can be done by token holder, or by adminWallet */
function claimAirdrop() external {
doAirdrop(msg.sender);
}
function adminClaimAirdrop(address _participant) external {
require( msg.sender == adminWallet );
doAirdrop(_participant);
}
function adminClaimAirdropMultiple(address[] _addresses) external {
require( msg.sender == adminWallet );
for (uint i = 0; i < _addresses.length; i++) doAirdrop(_addresses[i]);
}
function doAirdrop(address _participant) internal {
uint airdrop = computeAirdrop(_participant);
require( airdrop > 0 );
// update balances and token issue volume
airdropClaimed[_participant] = true;
balances[_participant] = balances[_participant].add(airdrop);
tokensIssuedTotal = tokensIssuedTotal.add(airdrop);
tokensClaimedAirdrop = tokensClaimedAirdrop.add(airdrop);
// log
Airdrop(_participant, airdrop, balances[_participant]);
Transfer(0x0, _participant, airdrop);
}
/* Function to estimate airdrop amount. For some accounts, the value of */
/* tokens received by calling claimAirdrop() may be less than gas costs */
/* If an account has tokens from the ico, the amount after the airdrop */
/* will be newBalance = tokens * TOKEN_SUPPLY_ICO / tokensIssuedIco */
function computeAirdrop(address _participant) constant returns (uint airdrop) {
// return 0 if it's too early or ico was not successful
if ( atNow() < DATE_ICO_END || !icoThresholdReached() ) return 0;
// return 0 is the airdrop was already claimed
if( airdropClaimed[_participant] ) return 0;
// return 0 if the account does not hold any crowdsale tokens
if( icoTokensReceived[_participant] == 0 ) return 0;
// airdrop amount
uint tokens = icoTokensReceived[_participant];
uint newBalance = tokens.mul(TOKEN_SUPPLY_ICO) / tokensIssuedIco;
airdrop = newBalance - tokens;
}
/* Multiple token transfers from one address to save gas */
/* (longer _amounts array not accepted = sanity check) */
function transferMultiple(address[] _addresses, uint[] _amounts) external {
require( isTransferable() );
require( locked[msg.sender] == false );
require( _addresses.length == _amounts.length );
for (uint i = 0; i < _addresses.length; i++) {
if (locked[_addresses[i]] == false) super.transfer(_addresses[i], _amounts[i]);
}
}
}