-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy path0xcbce61316759d807c474441952ce41985bbc5a40-MOAC-MoacToken.sol
252 lines (210 loc) · 9.11 KB
/
0xcbce61316759d807c474441952ce41985bbc5a40-MOAC-MoacToken.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
pragma solidity ^0.4.11;
/**
* ERC 20 token
*
* https://github.com/ethereum/EIPs/issues/20
*/
contract MoacToken {
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
function approve(address _spender, uint256 _value) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
mapping(address => uint256) balances;
mapping(address => uint256) redeem;
mapping (address => mapping (address => uint256)) allowed;
uint256 public totalSupply;
string public name = "MoacToken Token";
string public symbol = "MOAC";
uint public decimals = 18;
uint public startBlock; //crowdsale start block (set in constructor)
uint public endBlock; //crowdsale end block (set in constructor)
address public founder = 0x0;
address public owner = 0x0;
// signer address
address public signer = 0x0;
// price is defined by levels
uint256 public levelOneTokenNum = 30000000 * 10**18; //first level
uint256 public levelTwoTokenNum = 50000000 * 10**18; //second level
uint256 public levelThreeTokenNum = 75000000 * 10**18; //third level
uint256 public levelFourTokenNum = 100000000 * 10**18; //fourth level
//max amount raised during crowdsale
uint256 public etherCap = 1000000 * 10**18;
uint public transferLockup = 370285;
uint public founderLockup = 86400;
uint256 public founderAllocation = 100 * 10**16;
bool public founderAllocated = false;
uint256 public saleTokenSupply = 0;
uint256 public saleEtherRaised = 0;
bool public halted = false;
event Donate(uint256 eth, uint256 fbt);
event AllocateFounderTokens(address indexed sender);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event print(bytes32 msg);
function MoacToken(address founderInput, address signerInput, uint startBlockInput, uint endBlockInput) {
founder = founderInput;
signer = signerInput;
startBlock = startBlockInput;
endBlock = endBlockInput;
owner = msg.sender;
}
//price based on current token supply
function price() constant returns(uint256) {
if (totalSupply<levelOneTokenNum) return 1600;
if (totalSupply>=levelOneTokenNum && totalSupply < levelTwoTokenNum) return 1000;
if (totalSupply>=levelTwoTokenNum && totalSupply < levelThreeTokenNum) return 800;
if (totalSupply>=levelThreeTokenNum && totalSupply < levelFourTokenNum) return 730;
if (totalSupply>=levelFourTokenNum) return 680;
return 1600;
}
// price() exposed for unit tests
function testPrice(uint256 currentSupply) constant returns(uint256) {
if (currentSupply<levelOneTokenNum) return 1600;
if (currentSupply>=levelOneTokenNum && currentSupply < levelTwoTokenNum) return 1000;
if (currentSupply>=levelTwoTokenNum && currentSupply < levelThreeTokenNum) return 800;
if (currentSupply>=levelThreeTokenNum && currentSupply < levelFourTokenNum) return 730;
if (currentSupply>=levelFourTokenNum) return 680;
return 1600;
}
// Donate entry point
function donate( bytes32 hash) payable {
print(hash);
if (block.number<startBlock || block.number>endBlock || (saleEtherRaised + msg.value)>etherCap || halted) throw;
uint256 tokens = (msg.value * price());
balances[msg.sender] = (balances[msg.sender] + tokens);
totalSupply = (totalSupply + tokens);
saleEtherRaised = (saleEtherRaised + msg.value);
//immediately send Ether to founder address
if (!founder.call.value(msg.value)()) throw;
Donate(msg.value, tokens);
}
/**
* Set up founder address token balance.
*/
function allocateFounderTokens() {
if (msg.sender!=founder) throw;
if (block.number <= endBlock + founderLockup) throw;
if (founderAllocated) throw;
balances[founder] = (balances[founder] + saleTokenSupply * founderAllocation / (1 ether));
totalSupply = (totalSupply + saleTokenSupply * founderAllocation / (1 ether));
founderAllocated = true;
AllocateFounderTokens(msg.sender);
}
/**
* For offline donation, executed by signer only. only available during the sale
*/
function offlineDonate(uint256 offlineTokenNum, uint256 offlineEther) {
if (msg.sender!=signer) throw;
if (block.number >= endBlock) throw; //offline can be done only before end block
//check if overflow
if( (totalSupply +offlineTokenNum) > totalSupply && (saleEtherRaised + offlineEther)>saleEtherRaised){
totalSupply = (totalSupply + offlineTokenNum);
balances[founder] = (balances[founder] + offlineTokenNum );
saleEtherRaised = (saleEtherRaised + offlineEther);
}
}
/**
* emergency adjust if incorrectly set by signer, only available during the sale
*/
function offlineAdjust(uint256 offlineTokenNum, uint256 offlineEther) {
if (msg.sender!=founder) throw;
if (block.number >= endBlock) throw; //offline can be done only before end block
//check if overflow
if( (totalSupply - offlineTokenNum) > 0 && (saleEtherRaised - offlineEther) > 0 && (balances[founder] - offlineTokenNum)>0){
totalSupply = (totalSupply - offlineTokenNum);
balances[founder] = (balances[founder] - offlineTokenNum );
saleEtherRaised = (saleEtherRaised - offlineEther);
}
}
//check for redeemed balance
function redeemBalanceOf(address _owner) constant returns (uint256 balance) {
return redeem[_owner];
}
/**
* redeem token in MOAC network
*/
function redeemToken(uint256 tokenNum) {
if (block.number <= (endBlock + transferLockup) && msg.sender!=founder) throw;
if( balances[msg.sender] < tokenNum ) throw;
balances[msg.sender] = (balances[msg.sender] - tokenNum );
redeem[msg.sender] += tokenNum;
}
/**
* restore redeemed back to user, only founder can do, if user made an error
*/
function redeemRestore(address _to, uint256 tokenNum){
if( msg.sender != founder) throw;
if( redeem[_to] < tokenNum ) throw;
redeem[_to] -= tokenNum;
balances[_to] += tokenNum;
}
/**
* Emergency Stop ICO.
*/
function halt() {
if (msg.sender!=founder) throw;
halted = true;
}
function unhalt() {
if (msg.sender!=founder) throw;
halted = false;
}
// only owner can kill
function kill() {
if (msg.sender == owner) suicide(owner);
}
/**
* Change founder address (where ICO ETH is being forwarded).
*/
function changeFounder(address newFounder) {
if (msg.sender!=founder) throw;
founder = newFounder;
}
/**
* ERC 20 Standard Token interface transfer function
*/
function transfer(address _to, uint256 _value) returns (bool success) {
if (block.number <= (endBlock + transferLockup) && msg.sender!=founder) throw;
//Default assumes totalSupply can't be over max (2^256 - 1).
if (balances[msg.sender] >= _value && (balances[_to] + _value) > balances[_to]) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
}
/**
* ERC 20 Standard Token interface transfer function
*/
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (block.number <= (endBlock + transferLockup) && msg.sender!=founder) throw;
//same as above. Replace this line with the following if you want to protect against wrapping uints.
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && (balances[_to] + _value) > balances[_to]) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
}
/**
* Do not allow direct deposits.
*
* All crowdsale depositors must have read the legal agreement.
* This is confirmed by having them signing the terms of service on the website.
* The give their crowdsale Ethereum source address on the website.
* donate() takes data as input and rejects all deposits that do not have
* signature you receive after reading terms of service.
*
*/
function() {
throw;
}
}