-
Notifications
You must be signed in to change notification settings - Fork 7
/
Token_contract.sol
338 lines (286 loc) · 11.1 KB
/
Token_contract.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
pragma solidity ^ 0.4 .8;
contract ERC20 {
uint public totalSupply;
function balanceOf(address who) constant returns(uint256);
function allowance(address owner, address spender) constant returns(uint);
function transferFrom(address from, address to, uint value) returns(bool ok);
function approve(address spender, uint value) returns(bool ok);
function transfer(address to, uint value) returns(bool ok);
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}
contract blockoptions is ERC20
{
/* Public variables of the token */
//To store name for token
string public name = "blockoptions";
//To store symbol for token
string public symbol = "BOPT";
//To store decimal places for token
uint8 public decimals = 8;
//To store current supply of BOPT
uint public totalSupply=20000000 * 100000000;
uint pre_ico_start;
uint pre_ico_end;
uint ico_start;
uint ico_end;
mapping(uint => address) investor;
mapping(uint => uint) weireceived;
mapping(uint => uint) optsSent;
event preico(uint counter,address investors,uint weiReceived,uint boptsent);
event ico(uint counter,address investors,uint weiReceived,uint boptsent);
uint counter=0;
uint profit_sent=0;
bool stopped = false;
function blockoptions() payable{
owner = msg.sender;
balances[owner] = totalSupply ; //to handle 8 decimal places
pre_ico_start = now;
pre_ico_end = pre_ico_start + 7 days;
}
//map to store BOPT balance corresponding to address
mapping(address => uint) balances;
//To store spender with allowed amount of BOPT to spend corresponding to BOPTs holder's account
mapping (address => mapping (address => uint)) allowed;
//owner variable to store contract owner account
address public owner;
//modifier to check transaction initiator is only owner
modifier onlyOwner() {
if (msg.sender == owner)
_;
}
//ownership can be transferred to provided newOwner. Function can only be initiated by contract owner's account
function transferOwnership(address newOwner) onlyOwner {
balances[newOwner] = balances[owner];
balances[owner]=0;
owner = newOwner;
}
/**
* Multiplication with safety check
*/
function Mul(uint a, uint b) internal returns (uint) {
uint c = a * b;
//check result should not be other wise until a=0
assert(a == 0 || c / a == b);
return c;
}
/**
* Division with safety check
*/
function Div(uint a, uint b) internal returns (uint) {
//overflow check; b must not be 0
assert(b > 0);
uint c = a / b;
assert(a == b * c + a % b);
return c;
}
/**
* Subtraction with safety check
*/
function Sub(uint a, uint b) internal returns (uint) {
//b must be greater that a as we need to store value in unsigned integer
assert(b <= a);
return a - b;
}
/**
* Addition with safety check
*/
function Add(uint a, uint b) internal returns (uint) {
uint c = a + b;
//result must be greater as a or b can not be negative
assert(c>=a && c>=b);
return c;
}
/**
* assert used in different Math functions
*/
function assert(bool assertion) internal {
if (!assertion) {
throw;
}
}
//Implementation for transferring BOPT to provided address
function transfer(address _to, uint _value) returns (bool){
uint check = balances[owner] - _value;
if(msg.sender == owner && now>=pre_ico_start && now<=pre_ico_end && check < 1900000000000000)
{
return false;
}
else if(msg.sender ==owner && now>=pre_ico_end && now<=(pre_ico_end + 16 days) && check < 1850000000000000)
{
return false;
}
else if(msg.sender == owner && check < 150000000000000 && now < ico_start + 180 days)
{
return false;
}
else if (msg.sender == owner && check < 100000000000000 && now < ico_start + 360 days)
{
return false;
}
else if (msg.sender == owner && check < 50000000000000 && now < ico_start + 540 days)
{
return false;
}
//Check provided BOPT should not be 0
else if (_value > 0) {
//deduct OPTS amount from transaction initiator
balances[msg.sender] = Sub(balances[msg.sender],_value);
//Add OPTS to balace of target account
balances[_to] = Add(balances[_to],_value);
//Emit event for transferring BOPT
Transfer(msg.sender, _to, _value);
return true;
}
else{
return false;
}
}
//Transfer initiated by spender
function transferFrom(address _from, address _to, uint _value) returns (bool) {
//Check provided BOPT should not be 0
if (_value > 0) {
//Get amount of BOPT for which spender is authorized
var _allowance = allowed[_from][msg.sender];
//Add amount of BOPT in trarget account's balance
balances[_to] = Add(balances[_to], _value);
//Deduct BOPT amount from _from account
balances[_from] = Sub(balances[_from], _value);
//Deduct Authorized amount for spender
allowed[_from][msg.sender] = Sub(_allowance, _value);
//Emit event for Transfer
Transfer(_from, _to, _value);
return true;
}else{
return false;
}
}
//Get BOPT balance for provided address
function balanceOf(address _owner) constant returns (uint balance) {
return balances[_owner];
}
//Add spender to authorize for spending specified amount of BOPT
function approve(address _spender, uint _value) returns (bool) {
allowed[msg.sender][_spender] = _value;
//Emit event for approval provided to spender
Approval(msg.sender, _spender, _value);
return true;
}
//Get BOPT amount that spender can spend from provided owner's account
function allowance(address _owner, address _spender) constant returns (uint remaining) {
return allowed[_owner][_spender];
}
/*
* Failsafe drain
*/
function drain() onlyOwner {
owner.send(this.balance);
}
function() payable
{
if(stopped && msg.sender != owner)
revert();
else if(msg.sender == owner)
{
profit_sent = msg.value;
}
else if(now>=pre_ico_start && now<=pre_ico_end)
{
uint check = balances[owner]-((400*msg.value)/10000000000);
if(check >= 1900000000000000)
pre_ico(msg.sender,msg.value);
}
else if (now>=ico_start && now<ico_end)
{
main_ico(msg.sender,msg.value);
}
}
function pre_ico(address sender, uint value)payable
{
counter = counter+1;
investor[counter]=sender;
weireceived[counter]=value;
optsSent[counter] = (400*value)/10000000000;
balances[owner]=balances[owner]-optsSent[counter];
balances[investor[counter]]+=optsSent[counter];
preico(counter,investor[counter],weireceived[counter],optsSent[counter]);
}
function main_ico(address sender, uint value)payable
{
if(now >= ico_start && now <= (ico_start + 7 days)) //20% discount on BOPT
{
counter = counter+1;
investor[counter]=sender;
weireceived[counter]=value;
optsSent[counter] = (250*value)/10000000000;
balances[owner]=balances[owner]-optsSent[counter];
balances[investor[counter]]+=optsSent[counter];
ico(counter,investor[counter],weireceived[counter],optsSent[counter]);
}
else if (now >= (ico_start + 7 days) && now <= (ico_start + 14 days)) //10% discount on BOPT
{
counter = counter+1;
investor[counter]=sender;
weireceived[counter]=value;
optsSent[counter] = (220*value)/10000000000;
balances[owner]=balances[owner]-optsSent[counter];
balances[investor[counter]]+=optsSent[counter];
ico(counter,investor[counter],weireceived[counter],optsSent[counter]);
}
else if (now >= (ico_start + 14 days) && now <= (ico_start + 31 days)) //no discount on BOPT
{
counter = counter+1;
investor[counter]=sender;
weireceived[counter]=value;
optsSent[counter] = (200*value)/10000000000;
balances[owner]=balances[owner]-optsSent[counter];
balances[investor[counter]]+=optsSent[counter];
ico(counter,investor[counter],weireceived[counter],optsSent[counter]);
}
}
function startICO()onlyOwner
{
ico_start = now;
ico_end=ico_start + 31 days;
pre_ico_start = 0;
pre_ico_end = 0;
}
function endICO()onlyOwner
{
stopped=true;
if(balances[owner] > 150000000000000)
{
uint burnedTokens = balances[owner]-150000000000000;
totalSupply = totalSupply-burnedTokens;
balances[owner] = 150000000000000;
}
}
struct distributionStruct
{
uint divident;
bool dividentStatus;
}
mapping(address => distributionStruct) dividentsMap;
mapping(uint => address)requestor;
event dividentSent(uint requestNumber,address to,uint divi);
uint requestCount=0;
function distribute()onlyOwner
{
for(uint i=1; i <= counter;i++)
{
dividentsMap[investor[i]].divident = (balanceOf(investor[i])*profit_sent)/(totalSupply*100000000);
dividentsMap[investor[i]].dividentStatus = true;
}
}
function requestDivident()payable
{
requestCount = requestCount + 1;
requestor[requestCount] = msg.sender;
if(dividentsMap[requestor[requestCount]].dividentStatus == true)
{
dividentSent(requestCount,requestor[requestCount],dividentsMap[requestor[requestCount]].divident);
requestor[requestCount].send(dividentsMap[requestor[requestCount]].divident);
dividentsMap[requestor[requestCount]].dividentStatus = false;
}
}
}