-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYogiToken.sol
More file actions
403 lines (315 loc) · 12.5 KB
/
Copy pathYogiToken.sol
File metadata and controls
403 lines (315 loc) · 12.5 KB
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
pragma solidity ^0.4.11;
library SafeMath {
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal constant 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 c;
}
function sub(uint256 a, uint256 b) internal constant returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract IERC20 {
function totalSupply() public constant returns (uint256);
function balanceOf(address _to) public constant returns (uint256);
function transfer(address to, uint256 value) public;
function transferFrom(address from, address to, uint256 value);
function approve(address spender, uint256 value) public;
function allowance(address owner, address spender) public constant returns (uint256);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract YogiToken is IERC20 {
using SafeMath for uint256;
enum Stage {PREICO, ICO, SUCCESS, FAILURE, REFUNDING }
// Token properties
string public name = "YOGI Token";
string public symbol = "YOG";
uint public decimals = 18;
uint public _totalSupply = 70000000e18;
uint public _icoSupply = 35000000e18;
uint public _founders = 21000000e18;
uint public _marketAllocation = 14000000e18;
uint public softCap = 15 ether;
bool public isGoalReached = false;
//total sold token
uint public totaldistribution = 0;
// 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;
// How much ETH each address has invested to this crowdsale
mapping (address => uint256) public investedAmountOf;
// How many distinct addresses have invested
uint public investorCount;
// start and end timestamps where investments are allowed (both inclusive)
uint256 public startTime;
uint256 public endTime;
//stage preICO or ICO
Stage public stage;
// Owner of Token
address public owner;
// Wallet Address of Token
address public multisig;
// how many token units a buyer gets per wei
uint public PRICE = 1000;
uint public minContribAmount = 0.1 ether; // 0.1 ether
// amount of raised money in wei
uint256 public fundRaised = 0;
// How much wei we have returned back to the contract after a failed crowdfund.
uint public loadedRefund = 0;
// How much wei we have given back to investors.
uint public weiRefunded = 0;
bool public crowdsale = true;
event TokenPurchase(address indexed purchaser, address indexed beneficiary, uint256 value, uint256 amount);
event BurnToken(uint256 value);
// Refund was processed for a contributor
event Refund(address investor, uint weiAmount);
event ResumeCrowdsale();
event PausedCrowdsale();
event MinimumGoalReached();
// modifier to allow only owner has full control on the function
modifier onlyOwner {
require(msg.sender == owner);
_;
}
modifier isCrowdsale() {
require(crowdsale);
_;
}
// Constructor
// @notice YogiToken Contract
// @return the transaction address
function YogiToken(uint256 _startTime, uint256 _endTime, address _multisig) public payable{
require(_startTime >= getNow() &&_endTime >= _startTime &&_multisig!=0x0);
startTime = _startTime;
endTime = _endTime;
multisig = _multisig;
balances[multisig] = _totalSupply;
stage = Stage.PREICO;
owner=msg.sender;
}
// Payable method
// @notice Anyone can buy the tokens on tokensale by paying ether
function () public payable isCrowdsale {
tokensale(msg.sender);
}
// @notice tokensale
// @param recipient The address of the recipient
// @return the transaction address and send the event as Transfer
function tokensale(address _to) public payable isCrowdsale {
require(_to != 0x0);
require(validPurchase());
uint256 weiAmount = msg.value;
uint tokens = weiAmount.mul(getPrice());
uint timebasedBonus = tokens.mul(getTimebasedBonusRate()).div(100);
tokens = tokens.add(timebasedBonus);
require (tokens < _icoSupply);
if(investedAmountOf[_to] == 0) {
// A new investor
investorCount++;
}
// Update investor
investedAmountOf[_to] = investedAmountOf[_to].add(weiAmount);
balances[_to] = balances[_to].add(tokens);
// Update totals
fundRaised = fundRaised.add(weiAmount);
totaldistribution = totaldistribution.add(tokens);
balances[multisig] = balances[multisig].sub(tokens);
_icoSupply = _icoSupply.sub(tokens);
TokenPurchase(msg.sender, _to, weiAmount, tokens);
forwardFunds();
if (!isGoalReached && fundRaised >= softCap) {
isGoalReached = true;
MinimumGoalReached();
}
}
// send ether to the fund collection wallet
// override to create custom fund forwarding mechanisms
function forwardFunds() internal {
multisig.transfer(msg.value);
}
// @return true if the transaction can buy tokens
function validPurchase() internal constant returns (bool) {
bool withinPeriod = getNow() >= startTime && getNow() <= endTime;
bool nonZeroPurchase = msg.value != 0;
bool minContribution = minContribAmount <= msg.value;
if (stage == Stage.PREICO) {
uint nowTime = getNow();
uint days10 = startTime + (10 days * 1000);
if (nowTime > days10) {
stage = Stage.ICO;
}
}
return withinPeriod && nonZeroPurchase && minContribution;
}
// @return true if the crowdsale has raised enough money to be successful.
function isMinimumGoalReached() public constant returns (bool reached) {
return fundRaised >= softCap;
}
function updateICOStatus() public onlyOwner {
if (hasEnded() && fundRaised >= softCap) {
stage = Stage.SUCCESS;
} else if (hasEnded()) {
stage = Stage.FAILURE;
}
}
modifier isFailure {
require (stage == Stage.FAILURE);
_;
}
modifier isRefunding {
require (stage == Stage.REFUNDING);
_;
}
// Allow load refunds back on the contract for the refunding. The team can transfer the funds back on the smart contract in the case the minimum goal was not reached.
function loadRefund() public payable isFailure {
require(msg.value != 0);
loadedRefund = loadedRefund.add(msg.value);
if (loadedRefund >= fundRaised) {
stage = Stage.REFUNDING;
}
}
// Investors can claim refund.
// Note that any refunds from indirect buyers should be handled separately, and not through this contract.
function refund() public isRefunding {
uint256 weiValue = investedAmountOf[msg.sender];
require (weiValue != 0);
msg.sender.transfer(weiValue);
investedAmountOf[msg.sender] = 0;
balances[msg.sender] = 0;
weiRefunded = weiRefunded.add(weiValue);
Refund(msg.sender, weiValue);
}
// Get the time-based bonus rate
function getTimebasedBonusRate() internal constant returns (uint256) {
uint256 bonusRate = 0;
uint nowTime = getNow();
uint days10 = startTime + (10 days * 1000);
if (nowTime <= days10) {
bonusRate = 10;
}
return bonusRate;
}
function changeStartTime(uint256 _startTime) public onlyOwner {
require(startTime > getNow());
startTime = _startTime;
}
function changeEndTime(uint256 _endTime) public onlyOwner {
require(startTime > getNow());
endTime = _endTime;
}
// Halt or Resume Crowd Sale / ICO
function pauseResumeCrowdsale(bool _crowdsale) public onlyOwner {
crowdsale = _crowdsale;
if (crowdsale)
ResumeCrowdsale();
else
PausedCrowdsale();
}
function burnToken() public onlyOwner {
require(_icoSupply >= 0 && endTime < getNow());
balances[multisig] = balances[multisig].sub(_icoSupply);
_totalSupply = _totalSupply.sub(_icoSupply);
BurnToken(_icoSupply);
_icoSupply = 0;
}
// @return total tokens supplied
function totalSupply() public constant returns (uint256) {
return _totalSupply;
}
// What is the balance of a particular account?
// @param who The address of the particular account
// @return the balanace the particular account
function balanceOf(address _to) public constant returns (uint256) {
return balances[_to];
}
// @notice send `value` token to `to` from `msg.sender`
// @param to The address of the recipient
// @param value The amount of token to be transferred
// @return the transaction address and send the event as Transfer
function transfer(address to, uint256 value) public {
require (
balances[msg.sender] >= value && value > 0
);
balances[msg.sender] = balances[msg.sender].sub(value);
balances[to] = balances[to].add(value);
Transfer(msg.sender, to, value);
}
// @notice send `value` token to `to` from `from`
// @param from The address of the sender
// @param to The address of the recipient
// @param value The amount of token to be transferred
// @return the transaction address and send the event as Transfer
function transferFrom(address from, address to, uint256 value) public {
require (
allowed[from][msg.sender] >= value && balances[from] >= value && value > 0
);
balances[from] = balances[from].sub(value);
balances[to] = balances[to].add(value);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(value);
Transfer(from, to, value);
}
// 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.
// @param spender The address of the sender
// @param value The amount to be approved
// @return the transaction address and send the event as Approval
function approve(address spender, uint256 value) public {
require (
balances[msg.sender] >= value && value > 0
);
allowed[msg.sender][spender] = value;
Approval(msg.sender, spender, value);
}
// Check the allowed value for the spender to withdraw from owner
// @param owner The address of the owner
// @param spender The address of the spender
// @return the amount which spender is still allowed to withdraw from owner
function allowance(address _owner, address spender) public constant returns (uint256) {
return allowed[_owner][spender];
}
// Get current price of a Token
// @return the price or token value for a ether
function getPrice() public constant returns (uint result) {
return PRICE;
}
// @return true if crowdsale current lot event has ended
function hasEnded() public constant returns (bool) {
return getNow() > endTime;
}
// @return current time
function getNow() public constant returns (uint) {
return (now * 1000);
}
function FoundersToken(address to, uint256 value) onlyOwner {
require (
to != 0x0 && value > 0 && _founders >= value
);
balances[multisig] = balances[multisig].sub(value);
balances[to] = balances[to].add(value);
_founders = _founders.sub(value);
Transfer(msg.sender, to, value);
}
function marketallocationTokens(address to, uint256 value) onlyOwner {
require (
to != 0x0 && value > 0 && _marketAllocation >= value
);
balances[multisig] = balances[multisig].sub(value);
balances[to] = balances[to].add(value);
_marketAllocation = _marketAllocation.sub(value);
Transfer(msg.sender, to, value);
}
}