-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken.sol
384 lines (307 loc) · 11.4 KB
/
token.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
pragma solidity 0.4.18;
library SafeMath
{
function mul(uint256 a, uint256 b) internal pure returns (uint256)
{
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
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 c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256)
{
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256)
{
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract Ownable
{
address public owner;
// @dev The Ownable constructor sets the original `owner` of the contract to the sender
// account.
function Ownable() 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
{
if (newOwner != address(0))
{
owner = newOwner;
}
}
}
contract BasicToken
{
using SafeMath for uint256;
// Total number of Tokens
uint totalCoinSupply;
// allowance map
// ( owner => (spender => amount ) )
mapping (address => mapping (address => uint256)) public AllowanceLedger;
// ownership map
// ( owner => value )
mapping (address => uint256) public balanceOf;
// @dev transfer token for a specified address
// @param _to The address to transfer to.
// @param _value The amount to be transferred.
function transfer( address _recipient, uint256 _value ) public
returns( bool success )
{
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value);
balanceOf[_recipient] = balanceOf[_recipient].add(_value);
Transfer(msg.sender, _recipient, _value);
return true;
}
function transferFrom( address _owner, address _recipient, uint256 _value )
public returns( bool success )
{
var _allowance = AllowanceLedger[_owner][msg.sender];
// Check is not needed because sub(_allowance, _value) will already
// throw if this condition is not met
// require (_value <= _allowance);
balanceOf[_recipient] = balanceOf[_recipient].add(_value);
balanceOf[_owner] = balanceOf[_owner].sub(_value);
AllowanceLedger[_owner][msg.sender] = _allowance.sub(_value);
Transfer(_owner, _recipient, _value);
return true;
}
function approve( address _spender, uint256 _value )
public returns( bool success )
{
// _owner is the address of the owner who is giving approval to
// _spender, who can then transact coins on the behalf of _owner
address _owner = msg.sender;
AllowanceLedger[_owner][_spender] = _value;
// Fire off Approval event
Approval( _owner, _spender, _value);
return true;
}
function allowance( address _owner, address _spender ) public constant
returns ( uint256 remaining )
{
// returns the amount _spender can transact on behalf of _owner
return AllowanceLedger[_owner][_spender];
}
function totalSupply() public constant returns( uint256 total )
{
return totalCoinSupply;
}
// @dev Gets the balance of the specified address.
// @param _owner The address to query the the balance of.
// @return An uint256 representing the amount owned by the passed address.
function balanceOf(address _owner) public constant returns (uint256 balance)
{
return balanceOf[_owner];
}
event Transfer( address indexed _owner, address indexed _recipient, uint256 _value );
event Approval( address _owner, address _spender, uint256 _value );
}
contract RentIDToken is BasicToken, Ownable
{
using SafeMath for uint256;
// Token Cap for each rounds
uint256 public saleCap;
// Address where funds are collected.
address public wallet;
// Sale period.
uint256 public startDate;
uint256 public endDate;
// Amount of raised money in wei.
uint256 public weiRaised;
// Tokens rate formule
uint256 public tokensSold = 0;
bool public finalized = false;
// This is the 'Ticker' symbol and name for our Token.
string public constant symbol = "RENT";
string public constant name = "RentIDToken";
// This is for how your token can be fracionalized.
uint8 public decimals = 18;
// Events
event TokenPurchase(address indexed purchaser, uint256 value,
uint256 tokenAmount);
event CompanyTokenPushed(address indexed beneficiary, uint256 amount);
event Burn( address burnAddress, uint256 amount);
function RentIDToken() public
{
}
// @dev gets the sale pool balance
// @return tokens in the pool
function supply() internal constant returns (uint256)
{
return balanceOf[0xb1];
}
modifier uninitialized()
{
require(wallet == 0x0);
_;
}
// @dev gets the current time
// @return current time
function getCurrentTimestamp() public constant returns (uint256)
{
return now;
}
// @dev gets the current rate of tokens per ether contributed
// @return number of tokens per ether
function setRate(uint256 _newRate) public onlyOwner
{
rate = _newRate;
}
// @dev gets the current rate of tokens per ether contributed
// @return number of tokens per ether
function getRate() public constant returns (uint256)
{
return rate;
}
// @dev Initialize wallet parms, can only be called once
// @param _wallet - address of multisig wallet which receives contributions
// @param _start - start date of sale
// @param _end - end date of sale
// @param _saleCap - amount of coins for sale
// @param _totalSupply - total supply of coins
function initialize(address _wallet, uint256 _start, uint256 _end,
uint256 _saleCap, uint256 _totalSupply)
public onlyOwner uninitialized
{
require(_start >= getCurrentTimestamp());
require(_start < _end);
require(_wallet != 0x0);
require(_totalSupply > _saleCap);
finalized = false;
startDate = _start;
endDate = _end;
saleCap = _saleCap;
wallet = _wallet;
totalCoinSupply = _totalSupply;
// Set balance of company stock
balanceOf[wallet] = _totalSupply.sub(saleCap);
// Log transfer of tokens to company wallet
Transfer(0x0, wallet, balanceOf[wallet]);
// Set balance of sale pool
balanceOf[0xb1] = saleCap;
// Log transfer of tokens to ICO sale pool
Transfer(0x0, 0xb1, saleCap);
}
// Fallback function is entry point to buy tokens
function () public payable
{
buyTokens(msg.sender, msg.value);
}
// @dev Internal token purchase function
// @param beneficiary - The address of the purchaser
// @param value - Value of contribution, in ether
function buyTokens(address beneficiary, uint256 value) internal
{
require(beneficiary != 0x0);
require(value >= 0.1 ether);
// Calculate token amount to be purchased
uint256 weiAmount = value;
uint256 actualRate = getRate();
uint256 tokenAmount = weiAmount.mul(actualRate);
// Check our supply
// Potentially redundant as balanceOf[0xb1].sub(tokenAmount) will
// throw with insufficient supply
require(supply() >= tokenAmount);
// Check conditions for sale
require(saleActive());
// Transfer
balanceOf[0xb1] = balanceOf[0xb1].sub(tokenAmount);
balanceOf[beneficiary] = balanceOf[beneficiary].add(tokenAmount);
TokenPurchase(msg.sender, weiAmount, tokenAmount);
// Log the transfer of tokens
Transfer(0xb1, beneficiary, tokenAmount);
// Update state.
uint256 updatedWeiRaised = weiRaised.add(weiAmount);
// Get the base value of tokens
uint256 base = tokenAmount.div(1 ether);
uint256 updatedTokensSold = tokensSold.add(base);
weiRaised = updatedWeiRaised;
tokensSold = updatedTokensSold;
// Forward the funds to fund collection wallet.
wallet.transfer(msg.value);
}
// @dev Time remaining until official sale begins
// @returns time remaining, in seconds
function getTimeUntilStart() public constant returns (uint256)
{
if(getCurrentTimestamp() >= startDate)
return 0;
return startDate.sub(getCurrentTimestamp());
}
// @dev transfer tokens from one address to another
// @param _recipient - The address to receive tokens
// @param _value - number of coins to send
// @return true if no requires thrown
function transfer( address _recipient, uint256 _value ) public returns(bool)
{
// Check to see if the sale has ended
require(finalized);
// transfer
super.transfer(_recipient, _value);
return true;
}
// @dev push tokens from treasury stock to specified address
// @param beneficiary - The address to receive tokens
// @param amount - number of coins to push
// @param lockout - lockout time
function push(address beneficiary, uint256 amount) public
onlyOwner
{
require(balanceOf[wallet] >= amount);
// Transfer
balanceOf[wallet] = balanceOf[wallet].sub(amount);
balanceOf[beneficiary] = balanceOf[beneficiary].add(amount);
// Log transfer of tokens
CompanyTokenPushed(beneficiary, amount);
Transfer(wallet, beneficiary, amount);
}
// @dev Burns tokens from sale pool remaining after the sale
function finalize() public onlyOwner
{
// Can only finalize after after sale is completed
require(getCurrentTimestamp() > endDate);
// Set finalized
finalized = true;
// Burn tokens remaining
Burn(0xb1, balanceOf[0xb1]);
totalCoinSupply = totalCoinSupply.sub(balanceOf[0xb1]);
// Log transfer to burn address
Transfer(0xb1, 0x0, balanceOf[0xb1]);
balanceOf[0xb1] = 0;
}
// @dev check to see if the sale period is active
// @return true if sale active, false otherwise
function saleActive() public constant returns (bool)
{
// Ability to purchase has begun for this purchaser with either 2
// conditions: Sale has started
bool checkSaleBegun = getCurrentTimestamp() >= startDate;
// Sale of tokens can not happen after the ico date or with no
// supply in any case
bool canPurchase = checkSaleBegun &&
getCurrentTimestamp() < endDate &&
supply() > 0;
return(canPurchase);
}
}