-
Notifications
You must be signed in to change notification settings - Fork 0
/
Buzcoin smart contract v11.sol
1555 lines (1220 loc) · 57.2 KB
/
Buzcoin smart contract v11.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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Project: BUZcoin.io (original)
// v11, 2018-04-17
// This code is the property of CryptoB2B.io
// Copying in whole or in part is prohibited.
// Authors: Ivan Fedorov and Dmitry Borodin
// Do you want the same TokenSale platform? www.cryptob2b.io
// *.sol in 1 file - https://cryptob2b.io/solidity/buzcoin/
pragma solidity ^0.4.21;
contract IFinancialStrategy{
enum State { Active, Refunding, Closed }
State public state = State.Active;
event Deposited(address indexed beneficiary, uint256 weiAmount);
event Receive(address indexed beneficiary, uint256 weiAmount);
function deposit(address _beneficiary) external payable;
function setup(address _beneficiary, uint256 _arg1, uint256 _arg2, uint8 _state) external;
function calc(uint256 _allValue) external;
function getBeneficiaryCash(address _beneficiary) external;
function getPartnerCash(uint8 _user, bool _isAdmin, address _msgsender, bool _calc, uint256 _weiTotalRaised) external;
}
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() 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 transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a / b;
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
function minus(uint256 a, uint256 b) internal pure returns (uint256) {
if (b>=a) return 0;
return a - b;
}
}
contract MigrationAgent
{
function migrateFrom(address _from, uint256 _value) public;
}
contract IToken{
function setUnpausedWallet(address _wallet, bool mode) public;
function mint(address _to, uint256 _amount) public returns (bool);
function totalSupply() public view returns (uint256);
function setPause(bool mode) public;
function setMigrationAgent(address _migrationAgent) public;
function migrateAll(address[] _holders) public;
function burn(address _beneficiary, uint256 _value) public;
function freezedTokenOf(address _beneficiary) public view returns (uint256 amount);
function defrostDate(address _beneficiary) public view returns (uint256 Date);
function freezeTokens(address _beneficiary, uint256 _amount, uint256 _when) public;
}
contract ERC223ReceivingContract {
function tokenFallback(address _from, uint _value, bytes memory _data) public;
}
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);
}
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(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
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 balance) {
return balances[_owner];
}
}
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);
}
contract StandardToken is ERC20, BasicToken {
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(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
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, uint _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, uint _subtractedValue) public returns (bool) {
uint 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;
}
}
contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
/**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount) onlyOwner public returns (bool) {
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Mint(_to, _amount);
emit Transfer(address(0), _to, _amount);
return true;
}
}
contract ICreator{
function createToken() external returns (IToken);
function createFinancialStrategy() external returns(IFinancialStrategy);
}
contract BuzFinancialStrategy is IFinancialStrategy, Ownable{
using SafeMath for uint256;
// Partner 0 Partner 1 Partner 2
uint256[3] public percent = [20, 2, 3 ];
uint256[3] public cap = [200 ether, 1800 ether, 9999999 ether]; // QUINTILLIONS
uint256[3] public debt1 = [0,0,0];
uint256[3] public debt2 = [0,0,0];
uint256[3] public total = [0,0,0]; // QUINTILLIONS
uint256[3] public took = [0,0,0];
uint256[3] public ready = [0,0,0];
address[3] public wallets= [
0x356608b672fdB01C5077d1A2cb6a7b38fDdcd8A5,
0xf1F3D1Dc1E5cEA08f127cad3B7Dbd29b299c88C8,
0x55ecFbD0111ab365b6De98A01E9305EfD4a78FAA
];
uint256 public benTook=0;
uint256 public benReady=0;
uint256 public newCash=0;
uint256 public cashHistory=0;
uint256 public prcSum=0;
address public benWallet=0;
function BuzFinancialStrategy() public {
initialize();
}
function balance() external view returns(uint256){
return address(this).balance;
}
function initialize() internal {
for (uint8 i=0; i<percent.length; i++ ) prcSum+=percent[i];
}
function deposit(address _beneficiary) external onlyOwner payable {
require(state == State.Active);
newCash = newCash.add(msg.value);
cashHistory += msg.value;
emit Deposited(_beneficiary,msg.value);
}
// 0 - destruct
// 1 - close
// 2 - restart
// 3 - refund
// 4 - test
// 5 - update Exchange
function setup(address _beneficiary, uint256 _arg1, uint256 _arg2, uint8 _state) external onlyOwner {
if (_state == 0) {
// call from Crowdsale.distructVault(true) for exit
// arg1 - nothing
// arg2 - nothing
selfdestruct(_beneficiary);
}
else if (_state == 1 || _state == 3) {
// Call from Crowdsale.finalization()
// [1] - successfull round (goalReach)
// [3] - failed round (not enough money)
// arg1 = weiTotalRaised();
// arg2 = nothing;
require(state == State.Active);
//internalCalc(_arg1);
state = State.Closed;
benWallet=_beneficiary;
}
else if (_state == 2) {
// Call from Crowdsale.initialization()
// arg1 = weiTotalRaised();
// arg2 = nothing;
require(state == State.Closed);
state = State.Active;
benWallet=_beneficiary;
}
else if (_state == 4) {
// call from Crowdsale.distructVault(false) for test
// arg1 = nothing;
// arg2 = nothing;
benWallet=_beneficiary;
}
else if (_state == 5) {
// arg1 = old ETH/USD (exchange)
// arg2 = new ETH/USD (_ETHUSD)
for (uint8 user=0; user<cap.length; user++) cap[user]=cap[user].mul(_arg1).div(_arg2);
benWallet=_beneficiary;
}
}
function calc(uint256 _allValue) external onlyOwner {
internalCalc(_allValue);
}
function internalCalc(uint256 _allValue) internal {
uint256 free=newCash+benReady;
uint256 common1=0;
uint256 common2=0;
uint256 spent=0;
uint256 plan=0;
uint8 user=0;
if (free==0) return;
for (user=0; user<percent.length; user++) {
plan=_allValue*percent[user]/100;
if (total[user]>=plan || total[user]>=cap[user]) {
debt1[user]=0;
debt2[user]=0;
continue;
}
debt1[user]=plan.minus(total[user]);
if (debt1[user]+total[user] > cap[user]) debt1[user]=cap[user].minus(total[user]);
common1+=debt1[user];
plan=free.mul(percent[user]).div(prcSum);
debt2[user]=plan;
if (debt2[user]+total[user] > cap[user]) debt2[user]=cap[user].minus(total[user]);
common2+=debt2[user];
}
if (common1>0 && common1<=free) {
for (user=0; user<percent.length; user++) {
if (debt1[user]==0) continue;
plan=free.mul(debt1[user]).div(common1);
if (plan>debt1[user]) plan=debt1[user];
ready[user]+=plan;
total[user]+=plan;
spent+=plan;
}
}
if (common2>0 && common1>free) {
for (user=0; user<percent.length; user++) {
if (debt2[user]==0) continue;
plan=free.mul(debt2[user]).div(common2);
if (plan>debt1[user]) plan=debt1[user]; // debt1, not 2
ready[user]+=plan;
total[user]+=plan;
spent+=plan;
}
}
if (spent>newCash+benReady) benReady=0;
else benReady=newCash.add(benReady).minus(spent);
newCash=0;
}
// Call from Crowdsale:
function getBeneficiaryCash(address _beneficiary) external onlyOwner {
uint256 move=benReady;
benWallet=_beneficiary;
if (move == 0) return;
emit Receive(_beneficiary, move);
benReady = 0;
benTook += move;
_beneficiary.transfer(move);
}
// Call from Crowdsale:
function getPartnerCash(uint8 _user, bool _isAdmin, address _msgsender, bool _calc, uint256 _weiTotalRaised) external onlyOwner {
require(_user<percent.length && _user<wallets.length);
if (!_isAdmin) {
for (uint8 i=0; i<wallets.length; i++) {
if (wallets[i]==_msgsender) break;
}
if (i>=wallets.length) {
return;
}
}
if (_calc) internalCalc(_weiTotalRaised);
uint256 move=ready[_user];
if (move==0) return;
emit Receive(wallets[_user], move);
ready[_user]=0;
took[_user]+=move;
wallets[_user].transfer(move);
}
}
contract ICrowdsale {
// 0 1 2 3 4 5 6
enum Roles {beneficiary, accountant, manager, observer, bounty, company, team}
address[8] public wallets;
}
contract Crowdsale is ICrowdsale{
// (A1)
// The main contract for the sale and management of rounds.
// 0000000000000000000000000000000000000000000000000000000000000000
uint256 constant USER_UNPAUSE_TOKEN_TIMEOUT = 90 days;
uint256 constant FORCED_REFUND_TIMEOUT1 = 300 days;
uint256 constant FORCED_REFUND_TIMEOUT2 = 400 days;
uint256 constant ROUND_PROLONGATE = 90 days;
uint256 constant BURN_TOKENS_TIME = 60 days;
using SafeMath for uint256;
enum TokenSaleType {round1, round2}
TokenSaleType public TokenSale = TokenSaleType.round1;
ICreator public creator;
bool isBegin=false;
IToken public token;
//Allocation public allocation;
IFinancialStrategy public financialStrategy;
bool public isFinalized;
bool public isInitialized;
bool public isPausedCrowdsale;
bool public chargeBonuses;
bool public canFirstMint=true;
struct Bonus {
uint256 value;
uint256 procent;
uint256 freezeTime;
}
struct Profit {
uint256 percent;
uint256 duration;
}
struct Freezed {
uint256 value;
uint256 dateTo;
}
Bonus[] public bonuses;
Profit[] public profits;
uint256 public startTime= 1524009600;
uint256 public endTime = 1526601599;
uint256 public renewal;
// How many tokens (excluding the bonus) are transferred to the investor in exchange for 1 ETH
// **THOUSANDS** 10^18 for human, *10**18 for Solidity, 1e18 for MyEtherWallet (MEW).
// Example: if 1ETH = 40.5 Token ==> use 40500 finney
uint256 public rate = 5000 ether; // $0.1 (ETH/USD=$500)
// ETH/USD rate in US$
// **QUINTILLIONS** 10^18 / *10**18 / 1e18. Example: ETH/USD=$1000 ==> use 1000*10**18 (Solidity) or 1000 ether or 1000e18 (MEW)
uint256 public exchange = 500 ether;
// If the round does not attain this value before the closing date, the round is recognized as a
// failure and investors take the money back (the founders will not interfere in any way).
// **QUINTILLIONS** 10^18 / *10**18 / 1e18. Example: softcap=15ETH ==> use 15*10**18 (Solidity) or 15e18 (MEW)
uint256 public softCap = 0;
// The maximum possible amount of income
// **QUINTILLIONS** 10^18 / *10**18 / 1e18. Example: hardcap=123.45ETH ==> use 123450*10**15 (Solidity) or 12345e15 (MEW)
uint256 public hardCap = 62000 ether; // $31M (ETH/USD=$500)
// If the last payment is slightly higher than the hardcap, then the usual contracts do
// not accept it, because it goes beyond the hardcap. However it is more reasonable to accept the
// last payment, very slightly raising the hardcap. The value indicates by how many ETH the
// last payment can exceed the hardcap to allow it to be paid. Immediately after this payment, the
// round closes. The funders should write here a small number, not more than 1% of the CAP.
// Can be equal to zero, to cancel.
// **QUINTILLIONS** 10^18 / *10**18 / 1e18
uint256 public overLimit = 20 ether;
// The minimum possible payment from an investor in ETH. Payments below this value will be rejected.
// **QUINTILLIONS** 10^18 / *10**18 / 1e18. Example: minPay=0.1ETH ==> use 100*10**15 (Solidity) or 100e15 (MEW)
uint256 public minPay = 20 finney;
uint256 public maxAllProfit = 38; // max time bonus=30%, max value bonus=8%, maxAll=38%
uint256 public ethWeiRaised;
uint256 public nonEthWeiRaised;
uint256 public weiRound1;
uint256 public tokenReserved;
uint256 public totalSaledToken;
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
event Finalized();
event Initialized();
function Crowdsale(ICreator _creator) public
{
creator=_creator;
// Initially, all next 7+ roles/wallets are given to the Manager. The Manager is an employee of the company
// with knowledge of IT, who publishes the contract and sets it up. However, money and tokens require
// a Beneficiary and other roles (Accountant, Team, etc.). The Manager will not have the right
// to receive them. To enable this, the Manager must either enter specific wallets here, or perform
// this via method changeWallet. In the finalization methods it is written which wallet and
// what percentage of tokens are received.
wallets = [
// Beneficiary
// Receives all the money (when finalizing Round1 & Round2)
0x55d36E21b7ee114dA69a9d79D37a894d80d8Ed09,
// Accountant
// Receives all the tokens for non-ETH investors (when finalizing Round1 & Round2)
0xaebC3c0a722A30981F8d19BDA33eFA51a89E4C6C,
// Manager
// All rights except the rights to receive tokens or money. Has the right to change any other
// wallets (Beneficiary, Accountant, ...), but only if the round has not started. Once the
// round is initialized, the Manager has lost all rights to change the wallets.
// If the TokenSale is conducted by one person, then nothing needs to be changed. Permit all 7 roles
// point to a single wallet.
msg.sender,
// Observer
// Has only the right to call paymentsInOtherCurrency (please read the document)
0x8a91aC199440Da0B45B2E278f3fE616b1bCcC494,
// Bounty - 2% tokens
0x1f85AE08D0e1313C95D6D63e9A95c4eEeaC9D9a3,
// Company - 10% tokens
0x8A6d301742133C89f08153BC9F52B585F824A18b,
// Team - 13% tokens, no freeze
0xE9B02195F38938f1462c59D7c1c2F15350ad1543
];
}
function onlyAdmin(bool forObserver) internal view {
require(wallets[uint8(Roles.manager)] == msg.sender || wallets[uint8(Roles.beneficiary)] == msg.sender ||
forObserver==true && wallets[uint8(Roles.observer)] == msg.sender);
}
// Setting the current rate ETH/USD
function changeExchange(uint256 _ETHUSD) public {
require(wallets[uint8(Roles.manager)] == msg.sender || wallets[uint8(Roles.observer)] == msg.sender);
require(_ETHUSD >= 1 ether);
softCap=softCap.mul(exchange).div(_ETHUSD); // QUINTILLIONS
hardCap=hardCap.mul(exchange).div(_ETHUSD); // QUINTILLIONS
minPay=minPay.mul(exchange).div(_ETHUSD); // QUINTILLIONS
rate=rate.mul(_ETHUSD).div(exchange); // QUINTILLIONS
for (uint16 i = 0; i < bonuses.length; i++) {
bonuses[i].value=bonuses[i].value.mul(exchange).div(_ETHUSD); // QUINTILLIONS
}
financialStrategy.setup(wallets[uint8(Roles.beneficiary)], exchange, _ETHUSD, 5);
exchange=_ETHUSD;
}
// Setting of basic parameters, analog of class constructor
// @ Do I have to use the function see your scenario
// @ When it is possible to call before Round 1/2
// @ When it is launched automatically -
// @ Who can call the function admins
function begin() public
{
onlyAdmin(true);
if (isBegin) return;
isBegin=true;
token = creator.createToken();
financialStrategy = creator.createFinancialStrategy();
token.setUnpausedWallet(wallets[uint8(Roles.accountant)], true);
token.setUnpausedWallet(wallets[uint8(Roles.manager)], true);
token.setUnpausedWallet(wallets[uint8(Roles.bounty)], true);
token.setUnpausedWallet(wallets[uint8(Roles.company)], true);
token.setUnpausedWallet(wallets[uint8(Roles.observer)], true);
bonuses.push(Bonus(20 ether, 2,0));
bonuses.push(Bonus(100 ether, 5,0));
bonuses.push(Bonus(400 ether, 8,0));
profits.push(Profit(30,900 days));
}
// Issue of tokens for the zero round, it is usually called: private pre-sale (Round 0)
// @ Do I have to use the function may be
// @ When it is possible to call before Round 1/2
// @ When it is launched automatically -
// @ Who can call the function admins
function firstMintRound0(uint256 _amount /* QUINTILLIONS! */) public {
onlyAdmin(false);
require(canFirstMint);
begin();
token.mint(wallets[uint8(Roles.manager)],_amount);
}
// info
function totalSupply() external view returns (uint256){
return token.totalSupply();
}
// Returns the name of the current round in plain text. Constant.
function getTokenSaleType() external view returns(string){
return (TokenSale == TokenSaleType.round1)?'round1':'round2';
}
// Transfers the funds of the investor to the contract of return of funds. Internal.
function forwardFunds() internal {
financialStrategy.deposit.value(msg.value)(msg.sender);
}
// Check for the possibility of buying tokens. Inside. Constant.
function validPurchase() internal view returns (bool) {
// The round started and did not end
bool withinPeriod = (now > startTime && now < endTime.add(renewal));
// Rate is greater than or equal to the minimum
bool nonZeroPurchase = msg.value >= minPay;
// hardCap is not reached, and in the event of a transaction, it will not be exceeded by more than OverLimit
bool withinCap = msg.value <= hardCap.sub(weiRaised()).add(overLimit);
// round is initialized and no "Pause of trading" is set
return withinPeriod && nonZeroPurchase && withinCap && isInitialized && !isPausedCrowdsale;
}
// Check for the ability to finalize the round. Constant.
function hasEnded() public view returns (bool) {
bool timeReached = now > endTime.add(renewal);
bool capReached = weiRaised() >= hardCap;
return (timeReached || capReached) && isInitialized;
}
// Finalize. Only available to the Manager and the Beneficiary. If the round failed, then
// anyone can call the finalization to unlock the return of funds to investors
// You must call a function to finalize each round (after the Round1 & after the Round2)
// @ Do I have to use the function yes
// @ When it is possible to call after end of Round1 & Round2
// @ When it is launched automatically no
// @ Who can call the function admins or anybody (if round is failed)
function finalize() public {
require(wallets[uint8(Roles.manager)] == msg.sender || wallets[uint8(Roles.beneficiary)] == msg.sender || !goalReached());
require(!isFinalized);
require(hasEnded() || ((wallets[uint8(Roles.manager)] == msg.sender || wallets[uint8(Roles.beneficiary)] == msg.sender) && goalReached()));
isFinalized = true;
finalization();
emit Finalized();
}
// The logic of finalization. Internal
// @ Do I have to use the function no
// @ When it is possible to call -
// @ When it is launched automatically after end of round
// @ Who can call the function -
function finalization() internal {
// If the goal of the achievement
if (goalReached()) {
financialStrategy.setup(wallets[uint8(Roles.beneficiary)], weiRaised(), 0, 1);//╨"╨>╤? ╨║╨?╨?╤'╤?╨░╨║╤'╨░ Buz ╨?╨ў╨?╤?╨?╨╕ ╨?╨ў ╨?╨?╨╖╨?╤?╨░╤%╨░╨ў╤'.
// if there is anything to give
if (tokenReserved > 0) {
token.mint(wallets[uint8(Roles.accountant)],tokenReserved);
// Reset the counter
tokenReserved = 0;
}
// If the finalization is Round 1
if (TokenSale == TokenSaleType.round1) {
// Reset settings
isInitialized = false;
isFinalized = false;
// Switch to the second round (to Round2)
TokenSale = TokenSaleType.round2;
// Reset the collection counter
weiRound1 = weiRaised();
ethWeiRaised = 0;
nonEthWeiRaised = 0;
}
else // If the second round is finalized
{
// Permission to collect tokens to those who can pick them up
chargeBonuses = true;
totalSaledToken = token.totalSupply();
//partners = true;
}
}
else // If they failed round
{
financialStrategy.setup(wallets[uint8(Roles.beneficiary)], weiRaised(), 0, 3);
}
}
// The Manager freezes the tokens for the Team.
// You must call a function to finalize Round 2 (only after the Round2)
// @ Do I have to use the function yes
// @ When it is possible to call Round2
// @ When it is launched automatically -
// @ Who can call the function admins
function finalize2() public {
onlyAdmin(false);
require(chargeBonuses);
chargeBonuses = false;
//allocation = creator.createAllocation(token, now + 1 years /* stage N1 */, now + 2 years /* stage N2 */);
//token.setUnpausedWallet(allocation, true);
// Team = %, Founders = %, Fund = % TOTAL = %
//allocation.addShare(wallets[uint8(Roles.team)], 6, 50); // only 50% - first year, stage N1 (and +50 for stage N2)
//allocation.addShare(wallets[uint8(Roles.founders)], 10, 50); // only 50% - first year, stage N1 (and +50 for stage N2)
// 2% - bounty wallet
token.mint(wallets[uint8(Roles.bounty)], totalSaledToken.mul(2).div(75));
// 10% - company
token.mint(wallets[uint8(Roles.company)], totalSaledToken.mul(10).div(75));
// 13% - team
token.mint(wallets[uint8(Roles.team)], totalSaledToken.mul(13).div(75));
}
function changeCrowdsale(address _newCrowdsale) external {
//onlyAdmin(false);
require(wallets[uint8(Roles.manager)] == msg.sender);
Ownable(token).transferOwnership(_newCrowdsale);
}
// Initializing the round. Available to the manager. After calling the function,
// the Manager loses all rights: Manager can not change the settings (setup), change
// wallets, prevent the beginning of the round, etc. You must call a function after setup
// for the initial round (before the Round1 and before the Round2)
// @ Do I have to use the function yes
// @ When it is possible to call before each round
// @ When it is launched automatically -
// @ Who can call the function admins
function initialize() public {
onlyAdmin(false);
// If not yet initialized
require(!isInitialized);
begin();
// And the specified start time has not yet come
// If initialization return an error, check the start date!
require(now <= startTime);
initialization();
emit Initialized();
renewal = 0;
isInitialized = true;
canFirstMint = false;
}
function initialization() internal {
if (financialStrategy.state() != IFinancialStrategy.State.Active){
financialStrategy.setup(wallets[uint8(Roles.beneficiary)], weiRaised(), 0, 2);
}
}
//
// @ Do I have to use the function
// @ When it is possible to call
// @ When it is launched automatically
// @ Who can call the function
function getPartnerCash(uint8 _user, bool _calc) external {
bool isAdmin=false;
for (uint8 i=0; i<wallets.length; i++) {
if (wallets[i]==msg.sender) {
isAdmin=true;
break;
}
}
financialStrategy.getPartnerCash(_user, isAdmin, msg.sender, _calc, weiTotalRaised());
}
function getBeneficiaryCash() external {
onlyAdmin(false);
// financialStrategy.calc(weiTotalRaised());
financialStrategy.getBeneficiaryCash(wallets[uint8(Roles.beneficiary)]);
}
function calcFin() external {
onlyAdmin(true);
financialStrategy.calc(weiTotalRaised());
}
function calcAndGet() public {
onlyAdmin(true);
financialStrategy.calc(weiTotalRaised());
financialStrategy.getBeneficiaryCash(wallets[uint8(Roles.beneficiary)]);
for (uint8 i=0; i<3; i++) { // <-- TODO check financialStrategy.wallets.length
financialStrategy.getPartnerCash(i, true, msg.sender, false, weiTotalRaised());
}
}
// We check whether we collected the necessary minimum funds. Constant.
function goalReached() public view returns (bool) {
return weiRaised() >= softCap;
}
// Customize. The arguments are described in the constructor above.
// @ Do I have to use the function yes
// @ When it is possible to call before each rond
// @ When it is launched automatically -
// @ Who can call the function admins
function setup(uint256 _startTime, uint256 _endTime, uint256 _softCap, uint256 _hardCap,
uint256 _rate, uint256 _exchange,
uint256 _maxAllProfit, uint256 _overLimit, uint256 _minPay,
uint256[] _durationTB , uint256[] _percentTB, uint256[] _valueVB, uint256[] _percentVB, uint256[] _freezeTimeVB) public
{
onlyAdmin(false);
require(!isInitialized);
begin();
// Date and time are correct
require(now <= _startTime);
require(_startTime < _endTime);
startTime = _startTime;
endTime = _endTime;
// The parameters are correct
require(_softCap <= _hardCap);
softCap = _softCap;
hardCap = _hardCap;
require(_rate > 0);
rate = _rate;
overLimit = _overLimit;
minPay = _minPay;
exchange = _exchange;
maxAllProfit = _maxAllProfit;
require(_valueVB.length == _percentVB.length && _valueVB.length == _freezeTimeVB.length);
bonuses.length = _valueVB.length;
for(uint256 i = 0; i < _valueVB.length; i++){
bonuses[i] = Bonus(_valueVB[i],_percentVB[i],_freezeTimeVB[i]);
}
require(_percentTB.length == _durationTB.length);
profits.length = _percentTB.length;
for( i = 0; i < _percentTB.length; i++){
profits[i] = Profit(_percentTB[i],_durationTB[i]);
}