-
Notifications
You must be signed in to change notification settings - Fork 3
/
IdaToken.sol
839 lines (746 loc) · 26.4 KB
/
IdaToken.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
pragma solidity ^0.4.24;
/**
* Utility library of inline functions on addresses
*/
library AddressUtils {
/**
* Returns whether the target address is a contract
* @dev This function will return false if invoked during the constructor of a contract,
* as the code is not actually created until after the constructor finishes.
* @param addr address to check
* @return whether the target address is a contract
*/
function isContract(address addr) internal view returns (bool) {
uint256 size;
// XXX Currently there is no better way to check if there is a contract in an address
// than to check the size of the code at that address.
// See https://ethereum.stackexchange.com/a/14016/36603
// for more details about how this works.
// TODO Check this again before the Serenity release, because all addresses will be
// contracts then.
// solium-disable-next-line security/no-inline-assembly
assembly { size := extcodesize(addr) }
return size > 0;
}
}
/**
* @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 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 Roles
* @author Francisco Giordano (@frangio)
* @dev Library for managing addresses assigned to a Role.
* See RBAC.sol for example usage.
*/
library Roles {
struct Role {
mapping (address => bool) bearer;
}
/**
* @dev give an address access to this role
*/
function add(Role storage role, address addr)
internal
{
role.bearer[addr] = true;
}
/**
* @dev remove an address' access to this role
*/
function remove(Role storage role, address addr)
internal
{
role.bearer[addr] = false;
}
/**
* @dev check if an address has this role
* // reverts
*/
function check(Role storage role, address addr)
view
internal
{
require(has(role, addr));
}
/**
* @dev check if an address has this role
* @return bool
*/
function has(Role storage role, address addr)
view
internal
returns (bool)
{
return role.bearer[addr];
}
}
/**
* @title RBAC (Role-Based Access Control)
* @author Matt Condon (@Shrugs)
* @dev Stores and provides setters and getters for roles and addresses.
* Supports unlimited numbers of roles and addresses.
* See //contracts/mocks/RBACMock.sol for an example of usage.
* This RBAC method uses strings to key roles. It may be beneficial
* for you to write your own implementation of this interface using Enums or similar.
*/
contract RBAC {
using Roles for Roles.Role;
mapping (string => Roles.Role) private roles;
event RoleAdded(address indexed operator, string role);
event RoleRemoved(address indexed operator, string role);
/**
* @dev reverts if addr does not have role
* @param _operator address
* @param _role the name of the role
* // reverts
*/
function checkRole(address _operator, string _role)
view
public
{
roles[_role].check(_operator);
}
/**
* @dev determine if addr has role
* @param _operator address
* @param _role the name of the role
* @return bool
*/
function hasRole(address _operator, string _role)
view
public
returns (bool)
{
return roles[_role].has(_operator);
}
/**
* @dev add a role to an address
* @param _operator address
* @param _role the name of the role
*/
function addRole(address _operator, string _role)
internal
{
roles[_role].add(_operator);
emit RoleAdded(_operator, _role);
}
/**
* @dev remove a role from an address
* @param _operator address
* @param _role the name of the role
*/
function removeRole(address _operator, string _role)
internal
{
roles[_role].remove(_operator);
emit RoleRemoved(_operator, _role);
}
/**
* @dev modifier to scope access to a single role (uses msg.sender as addr)
* @param _role the name of the role
* // reverts
*/
modifier onlyRole(string _role)
{
checkRole(msg.sender, _role);
_;
}
/**
* @dev modifier to scope access to a set of roles (uses msg.sender as addr)
* @param _roles the names of the roles to scope access to
* // reverts
*
* @TODO - when solidity supports dynamic arrays as arguments to modifiers, provide this
* see: https://github.com/ethereum/solidity/issues/2467
*/
// modifier onlyRoles(string[] _roles) {
// bool hasAnyRole = false;
// for (uint8 i = 0; i < _roles.length; i++) {
// if (hasRole(msg.sender, _roles[i])) {
// hasAnyRole = true;
// break;
// }
// }
// require(hasAnyRole);
// _;
// }
}
/**
* @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) internal balances;
uint256 internal 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 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, 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(_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) {
require(_spender != address(0));
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)
{
require(_spender != address(0));
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)
{
require(_spender != address(0));
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;
}
}
contract IdaToken is Ownable, RBAC, StandardToken {
using AddressUtils for address;
using SafeMath for uint256;
string public name = "IDA";
string public symbol = "IDA";
uint8 public decimals = 18;
// 初始发行量 100 亿
uint256 public constant INITIAL_SUPPLY = 10000000000;
// 基石轮额度 3.96 亿
uint256 public constant FOOTSTONE_ROUND_AMOUNT = 396000000;
// 私募额度 12 亿
uint256 public constant PRIVATE_SALE_AMOUNT = 1200000000;
// 2019/05/01 之前的 Owner 锁仓额度 50 亿
uint256 public constant OWNER_LOCKED_IN_COMMON = 5000000000;
// 通用额度 72.04 亿 (IDA 基金会、研发、生态建设、社区建设、运营)
uint256 public constant COMMON_PURPOSE_AMOUNT = 7204000000;
// 团队预留额度1 1.2 亿
uint256 public constant TEAM_RESERVED_AMOUNT1 = 120000000;
// 团队预留额度2 3.6 亿
uint256 public constant TEAM_RESERVED_AMOUNT2 = 360000000;
// 团队预留额度3 3.6 亿
uint256 public constant TEAM_RESERVED_AMOUNT3 = 360000000;
// 团队预留额度4 3.6 亿
uint256 public constant TEAM_RESERVED_AMOUNT4 = 360000000;
// 私募中的 Ether 兑换比率,1 Ether = 10000 IDA
uint256 public constant EXCHANGE_RATE_IN_PRIVATE_SALE = 10000;
// 2018/10/01 00:00:01 的时间戳常数
uint256 public constant TIMESTAMP_OF_20181001000001 = 1538352001;
// 2018/10/02 00:00:01 的时间戳常数
uint256 public constant TIMESTAMP_OF_20181002000001 = 1538438401;
// 2018/11/01 00:00:01 的时间戳常数
uint256 public constant TIMESTAMP_OF_20181101000001 = 1541030401;
// 2019/02/01 00:00:01 的时间戳常数
uint256 public constant TIMESTAMP_OF_20190201000001 = 1548979201;
// 2019/05/01 00:00:01 的时间戳常数
uint256 public constant TIMESTAMP_OF_20190501000001 = 1556668801;
// 2019/08/01 00:00:01 的时间戳常数
uint256 public constant TIMESTAMP_OF_20190801000001 = 1564617601;
// 2019/11/01 00:00:01 的时间戳常数
uint256 public constant TIMESTAMP_OF_20191101000001 = 1572566401;
// 2020/11/01 00:00:01 的时间戳常数
uint256 public constant TIMESTAMP_OF_20201101000001 = 1604188801;
// 2021/11/01 00:00:01 的时间戳常数
uint256 public constant TIMESTAMP_OF_20211101000001 = 1635724801;
// Role constant of Partner Whitelist
string public constant ROLE_PARTNERWHITELIST = "partnerWhitelist";
// Role constant of Privatesale Whitelist
string public constant ROLE_PRIVATESALEWHITELIST = "privateSaleWhitelist";
// 由 Owner 分发的总数额
uint256 public totalOwnerReleased;
// 所有 partner 的已分发额总数
uint256 public totalPartnersReleased;
// 所有私募代理人的已分发数额总数
uint256 public totalPrivateSalesReleased;
// 通用额度的已分发数额总数
uint256 public totalCommonReleased;
// 团队保留额度的已分发数额总数1
uint256 public totalTeamReleased1;
// 团队保留额度的已分发数额总数2
uint256 public totalTeamReleased2;
// 团队保留额度的已分发数额总数3
uint256 public totalTeamReleased3;
// 团队保留额度的已分发数额总数4
uint256 public totalTeamReleased4;
// Partner 地址数组
address[] private partners;
// Partner 地址在数组中索引
mapping (address => uint256) private partnersIndex;
// 私募代理人地址数组
address[] private privateSaleAgents;
// 私募代理人地址在数组中的索引
mapping (address => uint256) private privateSaleAgentsIndex;
// Partner 限额映射
mapping (address => uint256) private partnersAmountLimit;
// Partner 实际已转账额度映射
mapping (address => uint256) private partnersWithdrawed;
// 私募代理人实际转出(售出)的 token 数量映射
mapping (address => uint256) private privateSalesReleased;
// Owner 的钱包地址
address ownerWallet;
// Log 特定的转账函数操作
event TransferLog(address from, address to, bytes32 functionName, uint256 value);
/**
* @dev 构造函数时需传入 Owner 指定的钱包地址
* @param _ownerWallet Owner 的钱包地址
*/
constructor(address _ownerWallet) public {
ownerWallet = _ownerWallet;
totalSupply_ = INITIAL_SUPPLY * (10 ** uint256(decimals));
balances[msg.sender] = totalSupply_;
}
/**
* @dev 变更 Owner 的钱包地址
* @param _ownerWallet Owner 的钱包地址
*/
function changeOwnerWallet(address _ownerWallet) public onlyOwner {
ownerWallet = _ownerWallet;
}
/**
* @dev 添加 partner 地址到白名单并设置其限额
* @param _addr Partner 地址
* @param _amount Partner 的持有限额
*/
function addAddressToPartnerWhiteList(address _addr, uint256 _amount)
public onlyOwner
{
// 仅允许在 2018/11/01 00:00:01 之前调用
require(block.timestamp < TIMESTAMP_OF_20181101000001);
// 如 _addr 不在白名单内,则执行添加处理
if (!hasRole(_addr, ROLE_PARTNERWHITELIST)) {
addRole(_addr, ROLE_PARTNERWHITELIST);
// 把给定地址加入 partner 数组
partnersIndex[_addr] = partners.length;
partners.push(_addr);
}
// Owner 可以多次调用此函数以达到修改 partner 授权上限的效果
partnersAmountLimit[_addr] = _amount;
}
/**
* @dev 将 partner 地址从白名单移除
* @param _addr Partner 地址
*/
function removeAddressFromPartnerWhiteList(address _addr)
public onlyOwner
{
// 仅允许在 2018/11/01 00:00:01 之前调用
require(block.timestamp < TIMESTAMP_OF_20181101000001);
// 仅允许 _addr 已在白名单内时使用
require(hasRole(_addr, ROLE_PARTNERWHITELIST));
removeRole(_addr, ROLE_PARTNERWHITELIST);
partnersAmountLimit[_addr] = 0;
// 把给定地址从 partner 数组中删除
uint256 partnerIndex = partnersIndex[_addr];
uint256 lastPartnerIndex = partners.length.sub(1);
address lastPartner = partners[lastPartnerIndex];
partners[partnerIndex] = lastPartner;
delete partners[lastPartnerIndex];
partners.length--;
partnersIndex[_addr] = 0;
partnersIndex[lastPartner] = partnerIndex;
}
/**
* @dev 添加私募代理人地址到白名单并设置其限额
* @param _addr 私募代理人地址
* @param _amount 私募代理人的转账限额
*/
function addAddressToPrivateWhiteList(address _addr, uint256 _amount)
public onlyOwner
{
// 仅允许在 2018/10/02 00:00:01 之前调用
require(block.timestamp < TIMESTAMP_OF_20181002000001);
// 检查 _addr 是否已在白名单内以保证 approve 函数仅会被调用一次;
// 后续如还需要更改授权额度,
// 请直接使用安全的 increaseApproval 和 decreaseApproval 函数
require(!hasRole(_addr, ROLE_PRIVATESALEWHITELIST));
addRole(_addr, ROLE_PRIVATESALEWHITELIST);
approve(_addr, _amount);
// 把给定地址加入私募代理人数组
privateSaleAgentsIndex[_addr] = privateSaleAgents.length;
privateSaleAgents.push(_addr);
}
/**
* @dev 将私募代理人地址从白名单移除
* @param _addr 私募代理人地址
*/
function removeAddressFromPrivateWhiteList(address _addr)
public onlyOwner
{
// 仅允许在 2018/10/02 00:00:01 之前调用
require(block.timestamp < TIMESTAMP_OF_20181002000001);
// 仅允许 _addr 已在白名单内时使用
require(hasRole(_addr, ROLE_PRIVATESALEWHITELIST));
removeRole(_addr, ROLE_PRIVATESALEWHITELIST);
approve(_addr, 0);
// 把给定地址从私募代理人数组中删除
uint256 agentIndex = privateSaleAgentsIndex[_addr];
uint256 lastAgentIndex = privateSaleAgents.length.sub(1);
address lastAgent = privateSaleAgents[lastAgentIndex];
privateSaleAgents[agentIndex] = lastAgent;
delete privateSaleAgents[lastAgentIndex];
privateSaleAgents.length--;
privateSaleAgentsIndex[_addr] = 0;
privateSaleAgentsIndex[lastAgent] = agentIndex;
}
/**
* @dev 允许接受转账的 fallback 函数
*/
function() external payable {
privateSale(msg.sender);
}
/**
* @dev 私募处理
* @param _beneficiary 收取 token 地址
*/
function privateSale(address _beneficiary)
public payable onlyRole(ROLE_PRIVATESALEWHITELIST)
{
// 仅允许 EOA 购买
require(msg.sender == tx.origin);
require(!msg.sender.isContract());
// 仅允许在 2018/10/02 00:00:01 之前购买
require(block.timestamp < TIMESTAMP_OF_20181002000001);
uint256 purchaseValue = msg.value.mul(EXCHANGE_RATE_IN_PRIVATE_SALE);
transferFrom(owner, _beneficiary, purchaseValue);
}
/**
* @dev 人工私募处理
* @param _addr 收取 token 地址
* @param _amount 转账 token 数量
*/
function withdrawPrivateCoinByMan(address _addr, uint256 _amount)
public onlyRole(ROLE_PRIVATESALEWHITELIST)
{
// 仅允许在 2018/10/02 00:00:01 之前购买
require(block.timestamp < TIMESTAMP_OF_20181002000001);
// 仅允许 EOA 获得转账
require(!_addr.isContract());
transferFrom(owner, _addr, _amount);
}
/**
* @dev 私募余额提取
* @param _amount 提取 token 数量
*/
function withdrawRemainPrivateCoin(uint256 _amount) public onlyOwner {
// 仅允许在 2018/10/01 00:00:01 之后提取
require(block.timestamp >= TIMESTAMP_OF_20181001000001);
require(transfer(ownerWallet, _amount));
emit TransferLog(owner, ownerWallet, bytes32("withdrawRemainPrivateCoin"), _amount);
}
/**
* @dev 私募转账处理(从 Owner 持有的余额中转出)
* @param _to 转入地址
* @param _amount 转账数量
*/
function _privateSaleTransferFromOwner(address _to, uint256 _amount)
private returns (bool)
{
uint256 newTotalPrivateSaleAmount = totalPrivateSalesReleased.add(_amount);
// 检查私募转账总额是否超限
require(newTotalPrivateSaleAmount <= PRIVATE_SALE_AMOUNT.mul(10 ** uint256(decimals)));
bool result = super.transferFrom(owner, _to, _amount);
privateSalesReleased[msg.sender] = privateSalesReleased[msg.sender].add(_amount);
totalPrivateSalesReleased = newTotalPrivateSaleAmount;
return result;
}
/**
* @dev 合约余额提取
*/
function withdrawFunds() public onlyOwner {
ownerWallet.transfer(address(this).balance);
}
/**
* @dev 获取所有 Partner 地址
* @return 所有 Partner 地址
*/
function getPartnerAddresses() public onlyOwner view returns (address[]) {
return partners;
}
/**
* @dev 获取所有私募代理人地址
* @return 所有私募代理人地址
*/
function getPrivateSaleAgentAddresses() public onlyOwner view returns (address[]) {
return privateSaleAgents;
}
/**
* @dev 获得私募代理人地址已转出(售出)的 token 数量
* @param _addr 私募代理人地址
* @return 私募代理人地址的已转出的 token 数量
*/
function privateSaleReleased(address _addr) public view returns (uint256) {
return privateSalesReleased[_addr];
}
/**
* @dev 获得 Partner 地址的提取限额
* @param _addr Partner 的地址
* @return Partner 地址的提取限额
*/
function partnerAmountLimit(address _addr) public view returns (uint256) {
return partnersAmountLimit[_addr];
}
/**
* @dev 获得 Partner 地址的已提取 token 数量
* @param _addr Partner 的地址
* @return Partner 地址的已提取 token 数量
*/
function partnerWithdrawed(address _addr) public view returns (uint256) {
return partnersWithdrawed[_addr];
}
/**
* @dev 给 Partner 地址分发 token
* @param _addr Partner 的地址
* @param _amount 分发的 token 数量
*/
function withdrawToPartner(address _addr, uint256 _amount)
public onlyOwner
{
require(hasRole(_addr, ROLE_PARTNERWHITELIST));
// 仅允许在 2018/11/01 00:00:01 之前分发
require(block.timestamp < TIMESTAMP_OF_20181101000001);
uint256 newTotalReleased = totalPartnersReleased.add(_amount);
require(newTotalReleased <= FOOTSTONE_ROUND_AMOUNT.mul(10 ** uint256(decimals)));
uint256 newPartnerAmount = balanceOf(_addr).add(_amount);
require(newPartnerAmount <= partnersAmountLimit[_addr]);
totalPartnersReleased = newTotalReleased;
transfer(_addr, _amount);
emit TransferLog(owner, _addr, bytes32("withdrawToPartner"), _amount);
}
/**
* @dev 计算 Partner 地址的可