-
Notifications
You must be signed in to change notification settings - Fork 4
/
preICOToken.sol
127 lines (103 loc) · 3.44 KB
/
preICOToken.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
pragma solidity ^0.4.10;
import "./erc20token.sol";
import "./interfaces/iapplypreico.sol";
contract PreICOToken is ERC20Token {
string public constant name = "REGA Risk Sharing preICO Token";
string public constant symbol = "RST-P";
uint8 public constant decimals = 10;
address public board;
address public owner;
uint public weiForToken;
uint public notMoreThan;
uint public notLessThan;
uint public tokensLimit;
uint public totalEther = 0;
address[] public holders;
bool public closed;
IApplyPreICO public rst;
event Issuance( address _to, uint _tokens, uint _amount, uint _sentBack );
modifier ownerOnly() {
require( msg.sender == owner );
_;
}
modifier boardOnly() {
require( msg.sender == board );
_;
}
modifier opened() {
require(!closed && weiForToken > 0 && totalSupply < tokensLimit);
_;
}
function PreICOToken( address _board ) {
board = _board;
owner = msg.sender;
weiForToken = 5 * uint(10)**(18-2-decimals); // 0.05 Ether
notMoreThan = 700 * uint(10)**decimals;
notLessThan = 100 * uint(10)**decimals;
tokensLimit = 30000 * uint(10)**decimals;
closed = true;
}
function() payable opened {
issueInternal( msg.sender, msg.value, true );
}
function setNotMoreThan( uint _notMoreThan ) public boardOnly {
notMoreThan = _notMoreThan * uint(10)**decimals;
}
function setNotLessThan( uint _notLessThan ) public boardOnly {
notLessThan = _notLessThan * uint(10)**decimals;
}
function setTokensLimit( uint _limit ) public boardOnly {
tokensLimit = _limit * uint(10)**decimals;
}
function setOpen( bool _open ) public boardOnly {
closed = !_open;
}
function setRST( IApplyPreICO _rst ) public boardOnly {
closed = true;
rst = _rst;
}
function getHoldersCount() public constant returns (uint count) {
count = holders.length;
}
function issue(address to, uint256 amount) public boardOnly validAddress(to) {
issueInternal( to, amount, false );
}
function buy() public payable opened {
issueInternal( msg.sender, msg.value, true );
}
function withdraw( uint amount ) public boardOnly {
board.transfer( amount );
}
function issueInternal(address to, uint256 amount, bool returnExcess) internal {
uint tokens = amount / weiForToken;
require( weiForToken > 0 && safeAdd(totalSupply, tokens) < tokensLimit && (balanceOf[to] < notMoreThan || notMoreThan == 0) && safeAdd(balanceOf[to], tokens) >= notLessThan );
uint sendBack = 0;
if( notMoreThan > 0 && safeAdd(balanceOf[to], tokens) > notMoreThan ) {
tokens = notMoreThan - balanceOf[to];
sendBack = amount - tokens * weiForToken;
}
totalEther = safeAdd(totalEther, amount - sendBack);
balanceOf[to] = safeAdd(balanceOf[to], tokens);
totalSupply = safeAdd(totalSupply, tokens);
holders.push(to);
if( returnExcess && sendBack > 0 && sendBack < amount )
to.transfer( sendBack );
Issuance(to, tokens, amount, returnExcess ? sendBack : 0);
Transfer( this, to, tokens );
}
function moveToRST() validAddress(rst) {
sendToRstForAddress( msg.sender );
}
function sendToRST( address from ) validAddress(rst) {
sendToRstForAddress( from );
}
function sendToRstForAddress( address from ) internal {
require( closed );
uint amount = balanceOf[from];
if( amount > 0 ) {
balanceOf[from] = 0;
rst.applyTokens( from, amount );
Transfer( from, rst, amount );
}
}
}