-
Notifications
You must be signed in to change notification settings - Fork 1
/
token.sol
336 lines (292 loc) · 9.74 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
pragma solidity ^0.4.18;
import "browser/IERC20Token.sol";
contract JS {
string public symbol = "JS";
string public name = "JS Tunisian Community"
uint8 public decimals = 18;
uint256 public _totalSupply = 170000000;
uint256 _ICOprices = 0;
uint256 _BUYPrices = 0;
uint256 _SELLPrices = 0;
address _fundsReceiverAddress = 0;
address owner = 0;
bool setupDone = false;
bool isICOrunning = false;
bool isBUYrunning = false;
bool isSELLrunning = false;
// Events
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event Burn(address indexed _owner, uint256 _value);
// Mappings
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) internal allowed;
// Constructor
function JS(address adr) public {
owner = adr;
_fundsReceiverAddress=owner;
_totalSupply=_totalSupply*1000000000000000000;
balances[owner] = _totalSupply;
Transfer(this, owner, _totalSupply);
}
// Set ICO Price
function setIcoPrices(uint256 ICOprices) public {
if (msg.sender == owner){
_ICOprices = ICOprices;
}
else {
revert();
}
}
// Set buy price
function setBUYPrices(uint256 BUYPrices) public {
if (msg.sender == owner){
_BUYPrices = BUYPrices;
}
else {
revert();
}
}
// Set sell price
function setSELLPrices(uint256 SELLPrices) public {
if (msg.sender == owner){
_SELLPrices = SELLPrices;
}
else {
revert();
}
}
// Payable function, it will be called when the contract receives an amount of ether
function() public payable
{
if (isICOrunning && !isBUYrunning)
{
uint256 _amount = ((msg.value * _ICOprices)/1000000000000000000);
if ((balanceOf(this) < _amount) && _amount > 0) revert();
if(!_fundsReceiverAddress.send(msg.value)) revert();
balances[msg.sender] += _amount;
balances[this] -= _amount;
Transfer(this, msg.sender, _amount);
}
else if (!isICOrunning && isBUYrunning)
{
uint256 _amount2 = ((msg.value * _BUYPrices)/1000000000000000000);
if ((balanceOf(this) < _amount2) && _amount2 > 0) revert();
if(!_fundsReceiverAddress.send(msg.value)) revert();
balances[msg.sender] += _amount2;
balances[this] -= _amount2;
Transfer(this, msg.sender, _amount2);
}
}
// Sell function
function sell(uint256 amount) public payable{
amount = amount*1000000000000000000;
if((balanceOf(msg.sender)>=amount && isSELLrunning && isICOrunning && isBUYrunning) ||
(balanceOf(msg.sender)>=amount && isSELLrunning && !isICOrunning && !isBUYrunning)||
(balanceOf(msg.sender)>=amount && isSELLrunning && !isICOrunning && isBUYrunning)||
(balanceOf(msg.sender)>=amount && isSELLrunning && isICOrunning && !isBUYrunning))
{
balances[this] += amount; // adds the amount to owner's balance
balances[msg.sender] -= amount;// subtracts the amount from seller's balance
require(msg.sender.send((amount * 1000000000000000000) /_SELLPrices));
Transfer(msg.sender, this, amount); // executes an event reflecting on the change
}
else{
revert();
}
}
// sendEtherToOwner Sends ether to owner
function sendEtherToOwner(uint256 amount) public payable{
if (msg.sender == owner){
owner.send(amount);
}
else{
revert();
}
}
// startICO Starts the ICO
function startICO() public returns (bool success)
{
if (msg.sender == owner && !isICOrunning )
{
isICOrunning = true;
}
else
{
revert();
}
return true;
}
// Start selling the token
function StartSELL() public returns (bool success)
{
if (msg.sender == owner && !isSELLrunning )
{
isSELLrunning = true;
}
else
{
revert();
}
return true;
}
// startBUY Starts Buying the token
function startBUY() public returns (bool success)
{
if (msg.sender == owner && !isBUYrunning)
{
isBUYrunning = true;
}
else
{
revert();
}
return true;
}
// stopICO Stops the ICO
function stopICO() public returns (bool success)
{
if (msg.sender == owner && isICOrunning)
{
isICOrunning = false;
}
else
{
revert();
}
return true;
}
// stopSELL Stops selling the token
function stopSELL() public returns (bool success)
{
if (msg.sender == owner && isSELLrunning)
{
isSELLrunning = false;
}
else
{
revert();
}
return true;
}
// stopBUY stops buying the token
function stopBUY() public returns (bool success)
{
if (msg.sender == owner && isBUYrunning)
{
isBUYrunning = false;
}
else
{
revert();
}
return true;
}
// sendContractTokens Sends tokens from the contract adress to the owner
function sendContractTokens(uint256 amount)
{
if (msg.sender == owner){
if ((balanceOf(this) < amount) && amount > 0) revert();
if(!_fundsReceiverAddress.send(msg.value)) revert();
balances[this] -= amount;
balances[msg.sender] += amount;
Transfer(this, msg.sender, amount);
}
else {
revert();
}
}
// mintToken mints a specific amount of the token to a target address
function mintToken(address target, uint256 mintedAmount) public {
if (msg.sender == owner){
balances[target] += mintedAmount;
_totalSupply += mintedAmount;
Transfer(0, this, mintedAmount);
Transfer(this, target, mintedAmount);
}
else{ revert();}
}
// _transfer transfers a specific amount of the token from an address to another
// can only be called by the contract
function _transfer(address _from, address _to, uint256 _value) internal {
require(balances[_from] >= _value);
require(balances[_to] + _value > balances[_to]);
uint previousBalances = balances[_from] + balances[_to];
balances[_from] -= _value;
balances[_to] += _value;
Transfer(_from, _to, _value);
assert(balances[_from] + balances[_to] == previousBalances);
}
// Transfer transfers a specific amount of the token from the contract to an address
function transfer(address _to, uint256 _value) public {
_transfer(msg.sender, _to, _value);
}
// TransferFrom transfers a specific amount of the token from an address to another
// returns bool
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_value <= allowed[_from][msg.sender]); // Check allowance
_transfer(_from, _to, _value);
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
}
// Approve Allows `_spender` to spend no more than `_value` tokens in your behalf
function approve(address _spender, uint256 _value) public
returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
// allowance returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
// totalSupply returns the totalsupply of the token
function totalSupply() public constant returns (uint256 totalSupplyValue) {
return _totalSupply;
}
// ICOprice returns the ICO price
function ICOprice() public constant returns (uint256 ICOprice) {
return _ICOprices;
}
// BUYprice returns the buy price
function BUYprice() public constant returns (uint256 BUYprice) {
return _BUYPrices;
}
// SELLprice returns the sell price
function SELLprice() public constant returns (uint256 SELLprice) {
return _SELLPrices;
}
// FundReceiverAddress funds the receiver address
function FundReceiverAddress() public constant returns (address FundReceiverAddress) {
return _fundsReceiverAddress;
}
// Owner returns the owner address
function Owner() public constant returns (address ownerAddress) {
return owner;
}
// IsSELLrunning checks if selling is running
// returns bool
function IsSELLrunning() public constant returns (bool isSELLrunningFalg) {
return isSELLrunning;
}
// IsICOrunning checks if ICO is running
// returns bool
function IsICOrunning() public constant returns (bool isICOrunningFalg) {
return isICOrunning;
}
// IsBUYrunning checks if buying is running
// returns bool
function IsBUYrunning() public constant returns (bool isBUYrunningFalg) {
return isBUYrunning;
}
// balanceOf returns the balance of a given address
function balanceOf(address _owner) public constant returns (uint256 balance) {
return balances[_owner];
}
// BalanceEther returns the ethereum balance of the contract
function BalanceEther() public constant returns (uint256 BalanceEther) {
return this.balance;
}
}