-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy path0x96a65609a7b84e8842732deb08f56c3e21ac6f8a-CTR-Centra.sol
336 lines (276 loc) · 11.8 KB
/
0x96a65609a7b84e8842732deb08f56c3e21ac6f8a-CTR-Centra.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
pragma solidity ^0.4.13;
// ----------------------------------------------------------------------------------------------
// Developer Nechesov Andrey: Facebook.com/Nechesov
// Enjoy. (c) PRCR.org ICO Platform 2017. The PRCR Licence.
// ----------------------------------------------------------------------------------------------
// ERC Token Standard #20 Interface
// https://github.com/ethereum/EIPs/issues/20
contract ERC20Interface {
// Get the total token supply
function totalSupply() constant returns (uint256 totalSupply);
// Get the account balance of another account with address _owner
function balanceOf(address _owner) constant returns (uint256 balance);
// Send _value amount of tokens to address _to
function transfer(address _to, uint256 _value) returns (bool success);
// Send _value amount of tokens from address _from to address _to
function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
// Allow _spender to withdraw from your account, multiple times, up to the _value amount.
// If this function is called again it overwrites the current allowance with _value.
// this function is required for some DEX functionality
function approve(address _spender, uint256 _value) returns (bool success);
// Returns the amount which _spender is still allowed to withdraw from _owner
function allowance(address _owner, address _spender) constant returns (uint256 remaining);
// Triggered when tokens are transferred.
event Transfer(address indexed _from, address indexed _to, uint256 _value);
// Triggered whenever approve(address _spender, uint256 _value) is called.
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract CentraToken is ERC20Interface {
string public constant symbol = "Centra";
string public constant name = "Centra token";
uint8 public constant decimals = 18;
uint256 public constant maxTokens = 100000000*10**18;
uint256 public constant ownerSupply = maxTokens*32/100;
uint256 _totalSupply = ownerSupply;
uint256 public constant token_price = 1/400*10**18;
uint public constant ico_start = 1501891200;
uint public constant ico_finish = 1507248000;
uint public constant minValuePre = 1/10*10**18;
uint public constant minValue = 1/10*10**18;
uint public constant maxValue = 3000*10**18;
uint public constant card_gold_minamount = 30*10**18;
uint public constant card_gold_first = 1000;
mapping(address => uint) cards_gold_check;
address[] public cards_gold;
uint public constant card_black_minamount = 100*10**18;
uint public constant card_black_first = 500;
mapping(address => uint) public cards_black_check;
address[] public cards_black;
uint public constant card_titanium_minamount = 500*10**18;
uint public constant card_titanium_first = 200;
mapping(address => uint) cards_titanium_check;
address[] public cards_titanium;
uint public constant card_blue_minamount = 5/10*10**18;
uint public constant card_blue_first = 100000000;
mapping(address => uint) cards_blue_check;
address[] public cards_blue;
uint public constant card_start_minamount = 1/10*10**18;
uint public constant card_start_first = 100000000;
mapping(address => uint) cards_start_check;
address[] public cards_start;
using SafeMath for uint;
// Owner of this contract
address public owner;
// Balances for each account
mapping(address => uint256) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) allowed;
// Functions with this modifier can only be executed by the owner
modifier onlyOwner() {
if (msg.sender != owner) {
throw;
}
_;
}
// Constructor
function CentraToken() {
owner = msg.sender;
balances[owner] = ownerSupply;
}
//default function for buy tokens
function() payable {
tokens_buy();
}
function totalSupply() constant returns (uint256 totalSupply) {
totalSupply = _totalSupply;
}
//Withdraw money from contract balance to owner
function withdraw() onlyOwner returns (bool result) {
owner.send(this.balance);
return true;
}
// What is the balance of a particular account?
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
// Transfer the balance from owner's account to another account
function transfer(address _to, uint256 _amount) returns (bool success) {
if(now < ico_start) throw;
if (balances[msg.sender] >= _amount
&& _amount > 0
&& balances[_to] + _amount > balances[_to]) {
balances[msg.sender] -= _amount;
balances[_to] += _amount;
Transfer(msg.sender, _to, _amount);
return true;
} else {
return false;
}
}
// Send _value amount of tokens from address _from to address _to
// The transferFrom method is used for a withdraw workflow, allowing contracts to send
// tokens on your behalf, for example to "deposit" to a contract address and/or to charge
// fees in sub-currencies; the command should fail unless the _from account has
// deliberately authorized the sender of the message via some mechanism; we propose
// these standardized APIs for approval:
function transferFrom(
address _from,
address _to,
uint256 _amount
) returns (bool success) {
if(now < ico_start) throw;
if (balances[_from] >= _amount
&& allowed[_from][msg.sender] >= _amount
&& _amount > 0
&& balances[_to] + _amount > balances[_to]) {
balances[_from] -= _amount;
allowed[_from][msg.sender] -= _amount;
balances[_to] += _amount;
Transfer(_from, _to, _amount);
return true;
} else {
return false;
}
}
// Allow _spender to withdraw from your account, multiple times, up to the _value amount.
// If this function is called again it overwrites the current allowance with _value.
function approve(address _spender, uint256 _amount) returns (bool success) {
allowed[msg.sender][_spender] = _amount;
Approval(msg.sender, _spender, _amount);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
//get total black cards
function cards_black_total() constant returns (uint) {
return cards_black.length;
}
//get total gold cards
function cards_gold_total() constant returns (uint) {
return cards_gold.length;
}
//get total titanium cards
function cards_titanium_total() constant returns (uint) {
return cards_titanium.length;
}
//get total blue cards
function cards_blue_total() constant returns (uint) {
return cards_blue.length;
}
//get total start cards
function cards_start_total() constant returns (uint) {
return cards_start.length;
}
/**
* Buy tokens pre-sale and sale
*/
function tokens_buy() payable returns (bool) {
uint tnow = now;
if(tnow > ico_finish) throw;
if(_totalSupply >= maxTokens) throw;
if(!(msg.value >= token_price)) throw;
if(!(msg.value >= minValue)) throw;
if(msg.value > maxValue) throw;
uint tokens_buy = msg.value/token_price*10**18;
if(!(tokens_buy > 0)) throw;
if(tnow < ico_start){
if(!(msg.value >= minValuePre)) throw;
tokens_buy = tokens_buy*125/100;
}
if((ico_start + 86400*0 <= tnow)&&(tnow < ico_start + 86400*2)){
tokens_buy = tokens_buy*120/100;
}
if((ico_start + 86400*2 <= tnow)&&(tnow < ico_start + 86400*7)){
tokens_buy = tokens_buy*110/100;
}
if((ico_start + 86400*7 <= tnow)&&(tnow < ico_start + 86400*14)){
tokens_buy = tokens_buy*105/100;
}
if(_totalSupply.add(tokens_buy) > maxTokens) throw;
_totalSupply = _totalSupply.add(tokens_buy);
balances[msg.sender] = balances[msg.sender].add(tokens_buy);
if((msg.value >= card_gold_minamount)
&&(msg.value < card_black_minamount)
&&(cards_gold.length < card_gold_first)
&&(cards_gold_check[msg.sender] != 1)
) {
cards_gold.push(msg.sender);
cards_gold_check[msg.sender] = 1;
}
if((msg.value >= card_black_minamount)
&&(msg.value < card_titanium_minamount)
&&(cards_black.length < card_black_first)
&&(cards_black_check[msg.sender] != 1)
) {
cards_black.push(msg.sender);
cards_black_check[msg.sender] = 1;
}
if((msg.value >= card_titanium_minamount)
&&(cards_titanium.length < card_titanium_first)
&&(cards_titanium_check[msg.sender] != 1)
) {
cards_titanium.push(msg.sender);
cards_titanium_check[msg.sender] = 1;
}
if((msg.value >= card_blue_minamount)
&&(msg.value < card_gold_minamount)
&&(cards_blue.length < card_blue_first)
&&(cards_blue_check[msg.sender] != 1)
) {
cards_blue.push(msg.sender);
cards_blue_check[msg.sender] = 1;
}
if((msg.value >= card_start_minamount)
&&(msg.value < card_blue_minamount)
&&(cards_start.length < card_start_first)
&&(cards_start_check[msg.sender] != 1)
) {
cards_start.push(msg.sender);
cards_start_check[msg.sender] = 1;
}
return true;
}
}
/**
* Math operations with safety checks
*/
library SafeMath {
function mul(uint a, uint b) internal returns (uint) {
uint c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint a, uint b) internal returns (uint) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint a, uint b) internal returns (uint) {
assert(b <= a);
return a - b;
}
function add(uint a, uint b) internal returns (uint) {
uint c = a + b;
assert(c >= a);
return c;
}
function max64(uint64 a, uint64 b) internal constant returns (uint64) {
return a >= b ? a : b;
}
function min64(uint64 a, uint64 b) internal constant returns (uint64) {
return a < b ? a : b;
}
function max256(uint256 a, uint256 b) internal constant returns (uint256) {
return a >= b ? a : b;
}
function min256(uint256 a, uint256 b) internal constant returns (uint256) {
return a < b ? a : b;
}
function assert(bool assertion) internal {
if (!assertion) {
throw;
}
}
}