/
VANMToken.sol
380 lines (313 loc) · 11.5 KB
/
VANMToken.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
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
pragma solidity ^0.4.24;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure 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 a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
}
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/179
*/
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender) public view returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract VANMToken is ERC20, Ownable {
using SafeMath for uint256;
//Variables
string public symbol;
string public name;
uint8 public decimals;
uint256 public _totalSupply;
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) internal allowed;
uint256 public presaleSupply;
address public presaleAddress;
uint256 public crowdsaleSupply;
address public crowdsaleAddress;
uint256 public platformSupply;
address public platformAddress;
uint256 public incentivisingSupply;
address public incentivisingAddress;
uint256 public teamSupply;
address public teamAddress;
uint256 public crowdsaleEndsAt;
uint256 public teamVestingPeriod;
bool public presaleFinalized = false;
bool public crowdsaleFinalized = false;
//Modifiers
//Only presale contract
modifier onlyPresale() {
require(msg.sender == presaleAddress);
_;
}
//Only crowdsale contract
modifier onlyCrowdsale() {
require(msg.sender == crowdsaleAddress);
_;
}
//crowdsale has to be over
modifier notBeforeCrowdsaleEnds(){
require(block.timestamp >= crowdsaleEndsAt);
_;
}
// Check if vesting period is over
modifier checkTeamVestingPeriod() {
require(block.timestamp >= teamVestingPeriod);
_;
}
//Events
event PresaleFinalized(uint tokensRemaining);
event CrowdsaleFinalized(uint tokensRemaining);
//Constructor
constructor() public {
//Basic information
symbol = "VANM";
name = "VANM";
decimals = 18;
//Total VANM supply
_totalSupply = 240000000 * 10**uint256(decimals);
// 10% of total supply for presale
presaleSupply = 24000000 * 10**uint256(decimals);
// 50% of total supply for crowdsale
crowdsaleSupply = 120000000 * 10**uint256(decimals);
// 10% of total supply for platform
platformSupply = 24000000 * 10**uint256(decimals);
// 20% of total supply for incentivising
incentivisingSupply = 48000000 * 10**uint256(decimals);
// 10% of total supply for team
teamSupply = 24000000 * 10**uint256(decimals);
platformAddress = 0x6962371D5a9A229C735D936df5CE6C690e66b718;
teamAddress = 0xB9e54846da59C27eFFf06C3C08D5d108CF81FEae;
// 01.05.2019 00:00:00 UTC
crowdsaleEndsAt = 1556668800;
// 2 years vesting period
teamVestingPeriod = crowdsaleEndsAt.add(2 * 365 * 1 days);
balances[platformAddress] = platformSupply;
emit Transfer(0x0, platformAddress, platformSupply);
balances[incentivisingAddress] = incentivisingSupply;
}
//External functions
//Set Presale Address when it's deployed
function setPresaleAddress(address _presaleAddress) external onlyOwner {
require(presaleAddress == 0x0);
presaleAddress = _presaleAddress;
balances[_presaleAddress] = balances[_presaleAddress].add(presaleSupply);
}
// Finalize presale. Leftover tokens will overflow to crowdsale.
function finalizePresale() external onlyPresale {
require(presaleFinalized == false);
uint256 amount = balanceOf(presaleAddress);
if (amount > 0) {
balances[presaleAddress] = 0;
balances[crowdsaleAddress] = balances[crowdsaleAddress].add(amount);
}
presaleFinalized = true;
emit PresaleFinalized(amount);
}
//Set Crowdsale Address when it's deployed
function setCrowdsaleAddress(address _crowdsaleAddress) external onlyOwner {
require(presaleAddress != 0x0);
require(crowdsaleAddress == 0x0);
crowdsaleAddress = _crowdsaleAddress;
balances[_crowdsaleAddress] = balances[_crowdsaleAddress].add(crowdsaleSupply);
}
// Finalize crowdsale. Leftover tokens will overflow to platform.
function finalizeCrowdsale() external onlyCrowdsale {
require(presaleFinalized == true && crowdsaleFinalized == false);
uint256 amount = balanceOf(crowdsaleAddress);
if (amount > 0) {
balances[crowdsaleAddress] = 0;
balances[platformAddress] = balances[platformAddress].add(amount);
emit Transfer(0x0, platformAddress, amount);
}
crowdsaleFinalized = true;
emit CrowdsaleFinalized(amount);
}
//Public functions
//ERC20 functions
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
function transfer(address _to, uint256 _value) public
notBeforeCrowdsaleEnds
returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
function transferFrom(address _from, address _to, uint256 _value) public
notBeforeCrowdsaleEnds
returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
//Token functions
//Incentivising function to transfer tokens
function transferFromIncentivising(address _to, uint256 _value) public
onlyOwner
returns (bool) {
require(_value <= balances[incentivisingAddress]);
balances[incentivisingAddress] = balances[incentivisingAddress].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(0x0, _to, _value);
return true;
}
//Presalefunction to transfer tokens
function transferFromPresale(address _to, uint256 _value) public
onlyPresale
returns (bool) {
require(_value <= balances[presaleAddress]);
balances[presaleAddress] = balances[presaleAddress].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(0x0, _to, _value);
return true;
}
//Crowdsalefunction to transfer tokens
function transferFromCrowdsale(address _to, uint256 _value) public
onlyCrowdsale
returns (bool) {
require(_value <= balances[crowdsaleAddress]);
balances[crowdsaleAddress] = balances[crowdsaleAddress].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(0x0, _to, _value);
return true;
}
// Release team supply after vesting period is finished.
function releaseTeamTokens() public checkTeamVestingPeriod onlyOwner returns(bool) {
require(teamSupply > 0);
balances[teamAddress] = teamSupply;
emit Transfer(0x0, teamAddress, teamSupply);
teamSupply = 0;
return true;
}
//Check remaining incentivising tokens
function checkIncentivisingBalance() public view returns (uint256) {
return balances[incentivisingAddress];
}
//Check remaining presale tokens after presale contract is deployed
function checkPresaleBalance() public view returns (uint256) {
return balances[presaleAddress];
}
//Check remaining crowdsale tokens after crowdsale contract is deployed
function checkCrowdsaleBalance() public view returns (uint256) {
return balances[crowdsaleAddress];
}
//Recover ERC20 Tokens
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20(tokenAddress).transfer(owner, tokens);
}
//Don't accept ETH
function () public payable {
revert();
}
}