/
stm-contract-improvements.sol
789 lines (669 loc) · 21.8 KB
/
stm-contract-improvements.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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
pragma solidity 0.4.24;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
// Gas optimization: this is cheaper than asserting 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure 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 a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* See https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender)
public view returns (uint256);
function transferFrom(address from, address to, uint256 value)
public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
/**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev Transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_value <= balances[msg.sender]);
require(_to != address(0));
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
}
/**
* @title Burnable Token
* @dev Token that can be irreversibly burned (destroyed).
*/
contract BurnableToken is BasicToken {
event Burn(address indexed burner, uint256 value);
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public {
_burn(msg.sender, _value);
}
function _burn(address _who, uint256 _value) internal {
require(_value <= balances[_who]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
balances[_who] = balances[_who].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(_who, _value);
emit Transfer(_who, address(0), _value);
}
}
/**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://github.com/ethereum/EIPs/issues/20
* Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/
contract StandardToken is ERC20, BurnableToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(
address _from,
address _to,
uint256 _value
)
public
returns (bool)
{
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
require(_to != address(0));
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(
address _owner,
address _spender
)
public
view
returns (uint256)
{
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(
address _spender,
uint256 _addedValue
)
public
returns (bool)
{
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(
address _spender,
uint256 _subtractedValue
)
public
returns (bool)
{
uint256 oldValue = allowed[msg.sender][_spender];
if (_subtractedValue >= oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
/**
* @title Standard Burnable Token
* @dev Adds burnFrom method to ERC20 implementations
*/
contract StandardBurnableToken is StandardToken {
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param _from address The address which you want to send tokens from
* @param _value uint256 The amount of token to be burned
*/
function burnFrom(address _from, uint256 _value) public {
require(_value <= allowed[_from][msg.sender]);
// Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted,
// this function needs to emit an event with the updated approval.
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
_burn(_from, _value);
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* @notice Renouncing to ownership will leave the contract without an owner.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) public onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
}
/**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/
contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner whenNotPaused public {
paused = true;
emit Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
paused = false;
emit Unpause();
}
}
/**
* @title Pausable token
* @dev StandardToken modified with pausable transfers.
**/
contract PausableToken is StandardBurnableToken, Pausable {
function transfer(
address _to,
uint256 _value
)
public
whenNotPaused
returns (bool)
{
return super.transfer(_to, _value);
}
function transferFrom(
address _from,
address _to,
uint256 _value
)
public
whenNotPaused
returns (bool)
{
return super.transferFrom(_from, _to, _value);
}
function approve(
address _spender,
uint256 _value
)
public
whenNotPaused
returns (bool)
{
return super.approve(_spender, _value);
}
function increaseApproval(
address _spender,
uint _addedValue
)
public
whenNotPaused
returns (bool success)
{
return super.increaseApproval(_spender, _addedValue);
}
function decreaseApproval(
address _spender,
uint _subtractedValue
)
public
whenNotPaused
returns (bool success)
{
return super.decreaseApproval(_spender, _subtractedValue);
}
}
contract Streamity is PausableToken {
string public constant name = "Streamity";
string public constant symbol = "STM";
uint8 public constant decimals = 18;
uint256 public constant INITIAL_SUPPLY = 180000000 * (10 ** uint256(decimals));
address public tokenOwner = 0x464398aC8B96DdAd7e22AC37147822E1c69293Cb;
address public reserveFund = 0x84726199Ac1579684d58F4A47C4c85f2C45B5a11;
address public advisersPartners = 0xa2C2f149e4b3EC671a61EAc9F12eAF2489e0Fb10;
address public teamWallet1 = 0xbBB9E0605f0BC7Af1B7238bAC2807a3A8DCb54b5;
address public teamWallet2 = 0xd69824B62D26E7f2316812b8c59F36328196Ca13;
constructor () public {
totalSupply_ = INITIAL_SUPPLY;
balances[tokenOwner] = 129780000 ether; // For distrebution
balances[address(this)] = 50220000 ether; // For freezing
emit Transfer(address(0), tokenOwner, 129780000 ether);
emit Transfer(address(0), address(this), 50220000 ether);
}
uint teamObligationPart1 = 4650000 ether;
uint advisersPartnersObligation = 3720000 ether;
function ReleaseTokenForReserveFund () public onlyOwner {
// 25 september 2018 y.
require(now >= 1537833600);
if (transfer(advisersPartners, advisersPartnersObligation)) {
advisersPartnersObligation = 0;
}
if (transfer(teamWallet1, teamObligationPart1)) {
teamObligationPart1 = 0;
}
}
uint teamObligationPart2 = 23250000 ether;
uint reserveFundObligation = 18600000 ether;
function ReleaseTokenForTeamAdvisersPartners () public onlyOwner {
// 12 march 2019
require(now >= 1552348800);
if (transfer(reserveFund, reserveFundObligation)) {
reserveFundObligation = 0;
}
if (transfer(teamWallet2, teamObligationPart2)) {
teamObligationPart2 = 0;
}
}
function sendTokens(address _to, uint _value) public onlyOwner {
require(_to != address(0));
require(_value <= balances[tokenOwner]);
balances[tokenOwner] = balances[tokenOwner].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(tokenOwner, _to, _value);
}
}
contract SalesManager is Ownable {
using SafeMath for uint;
uint public stage = 0;
uint256 public weisRaised; // how many weis was raised on crowdsale
address public tokenAddress;
uint256 public decimals = 18;
uint256 DEC = 10 ** uint256(decimals);
uint256 public buyPrice = 1000000000000000000 wei;
address public ethOwner = 0x5FB3BBF3671C78C0c8008df5F5A0CF1130469e0b;
function SalesManager() public {
tokenAddress = new Streamity();
}
event CrowdSaleFinished(string info);
struct Ico {
uint256 tokens; // Tokens in crowdsale
uint startDate; // Date when crowsale will be starting, after its starting that property will be the 0
uint endDate; // Date when crowdsale will be stop
uint8 discount; // Discount
uint8 discountFirstDayICO; // Discount. Only for first stage ico
}
Ico public ICO;
function updateStat(uint256 tokens, uint startDate, uint endDate, uint8 discount, uint8 discountFirstDayICO) public onlyOwner {
ICO = Ico(tokens, startDate, endDate, discount, discountFirstDayICO);
}
/*
* Function confirm autosell
*
*/
function confirmSell(uint256 _amount) internal view
returns(bool)
{
if (ICO.tokens < _amount) {
return false;
}
return true;
}
/*
* Make discount
*/
function countDiscount(uint256 amount) internal
returns(uint256)
{
uint256 _amount = (amount.mul(DEC)).div(buyPrice);
if (1 == stage) {
_amount = _amount.add(withDiscount(_amount, ICO.discount));
}
else if (2 == stage)
{
if (now <= ICO.startDate + 1 days)
{
if (0 == ICO.discountFirstDayICO) {
ICO.discountFirstDayICO = 20;
}
_amount = _amount.add(withDiscount(_amount, ICO.discountFirstDayICO));
}
else
{
_amount = _amount.add(withDiscount(_amount, ICO.discount));
}
}
else if (3 == stage) {
_amount = _amount.add(withDiscount(_amount, ICO.discount));
}
return _amount;
}
/**
* Function for change discount if need
*
*/
function changeDiscount(uint8 _discount) public onlyOwner
returns (bool)
{
ICO = Ico (ICO.tokens, ICO.startDate, ICO.endDate, _discount, ICO.discountFirstDayICO);
return true;
}
/**
* Expanding of the functionality
*
* @param _numerator - Numerator - value (10000)
* @param _denominator - Denominator - value (10000)
*
* example: price 1000 tokens by 1 ether = changeRate(1, 1000)
*/
function changeRate(uint256 _numerator, uint256 _denominator) public onlyOwner
returns (bool success)
{
if (_numerator == 0) _numerator = 1;
if (_denominator == 0) _denominator = 1;
buyPrice = (_numerator.mul(DEC)).div(_denominator);
return true;
}
/*
* Function show in contract what is now
*
*/
function crowdSaleStatus() internal constant
returns (string)
{
if (1 == stage) {
return "Pre-ICO";
} else if(2 == stage) {
return "ICO first stage";
} else if (3 == stage) {
return "ICO second stage";
} else if (4 >= stage) {
return "feature stage";
}
return "there is no stage at present";
}
/*
* Seles manager
*
*/
function paymentManager(address sender, uint256 value) internal
{
uint256 discountValue = countDiscount(value);
bool conf = confirmSell(discountValue);
if (conf) {
sell(sender, discountValue);
weisRaised = weisRaised.add(value);
if (now >= ICO.endDate) {
Streamity(tokenAddress).pause();
CrowdSaleFinished(crowdSaleStatus()); // if time is up
}
} else {
sell(sender, ICO.tokens); // sell tokens which has been accessible
weisRaised = weisRaised.add(value);
Streamity(tokenAddress).pause();
CrowdSaleFinished(crowdSaleStatus()); // if tokens sold
}
}
/*
* Function for selling tokens in crowd time.
*
*/
function sell(address _investor, uint256 _amount) internal
{
ICO.tokens = ICO.tokens.sub(_amount);
Streamity(tokenAddress).sendTokens(_investor, _amount);
if(!ethOwner.send(msg.value)) revert();
}
/*
* Function for start crowdsale (any)
*
* @param _tokens - How much tokens will have the crowdsale - amount humanlike value (10000)
* @param _startDate - When crowdsale will be start - unix timestamp (1512231703 )
* @param _endDate - When crowdsale will be end - humanlike value (7) same as 7 days
* @param _discount - Discount for the crowd - humanlive value (7) same as 7 %
* @param _discount - Discount for the crowds first day - humanlive value (7) same as 7 %
*/
function startCrowd(uint256 _tokens, uint _startDate, uint _endDate, uint8 _discount, uint8 _discountFirstDayICO) public onlyOwner
{
ICO = Ico (_tokens * DEC, _startDate, _startDate + _endDate * 1 days , _discount, _discountFirstDayICO);
stage = stage.add(1);
Streamity(tokenAddress).unpause();
}
/**
* Function for web3js, should be call when somebody will buy tokens from website. This function only delegator.
*
* @param _investor - address of investor (who payed)
* @param _amount - ethereum
*/
function transferWeb3js(address _investor, uint256 _amount) external onlyOwner
{
sell(_investor, _amount);
}
/**
* Function for adding discount
*
*/
function withDiscount(uint256 _amount, uint _percent) internal pure
returns (uint256)
{
return (_amount.mul(_percent)).div(100);
}
/**
* Function payments handler
*
*/
function() public payable
{
assert(msg.value >= 1 ether / 10);
require(now >= ICO.startDate);
if (Streamity(tokenAddress).paused() == false) {
paymentManager(msg.sender, msg.value);
} else {
revert();
}
}
// call any function from another contract
function callData(address contractAddress, bytes data) public onlyOwner {
if(!contractAddress.call(data)) revert();
}
function transferOwnershipToken(address newTokenOwnerAddress) public onlyOwner {
Streamity tokenContract = Streamity(tokenAddress);
tokenContract.transferOwnership(newTokenOwnerAddress);
}
function pauseToken() public onlyOwner {
Streamity tokenContract = Streamity(tokenAddress);
tokenContract.pause();
}
function unPauseToken() public onlyOwner {
Streamity tokenContract = Streamity(tokenAddress);
tokenContract.unpause();
}
function drop(address[] _destinations, uint256[] _amount) public onlyOwner
returns (uint) {
uint i = 0;
while (i < _destinations.length) {
Streamity(tokenAddress).sendTokens(_destinations[i], _amount[i]);
i += 1;
}
return(i);
}
}