-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmentorhack.sol
224 lines (191 loc) · 6.81 KB
/
mentorhack.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
pragma solidity ^0.4.0;
//import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
// библиотека для математических вычислений
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) {
uint256 c = a / b;
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 permissions
{
address owner = msg.sender;
address admin;
function changeOwner(address newOwner) onlyOwner //Смена владельца
{
owner = newOwner;
}
modifier onlyOwner() // Модификатор доступа "только владелец"
{
require(msg.sender == owner);
_;
}
modifier onlyAdmin() // Модификатор доступа "администратор и владелец"
{
require(msg.sender == admin || msg.sender == owner);
_;
}
function addAdmin(address _admin) // Смена (или) добавление администратора
{
admin = _admin;
}
}
// Главный контракт
contract MentorCoin is permissions
{
using SafeMath for uint256;
string public constant name = "MentorCoin";
string public constant symbol = "MNT";
uint8 public constant decimals = 0;
bool public canTransfer = true ;
uint internal totalSupply = 13372280;
mapping (address => uint256) balances;
mapping (address => mapping (address => uint256)) allowed;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
function balanceOf(address _owner) constant returns (uint256 balance) // проверка баланса
{
return balances[_owner];
}
function transfer(address _to, uint256 _value) returns (bool success) // перевод токенов
{
assert(canTransfer == true);
if (balances[msg.sender]>=_value && _value >0 && balances[_to].add(_value) >= balances[_to])
{
balances[msg.sender]= balances[msg.sender].sub(_value);
balances[_to]= balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
else {return false;}
}
function startTransfer() onlyOwner // возможность переводить
{
canTransfer = true;
}
function stopTransfer() onlyOwner // остановка любых операций перевода
{
canTransfer = false;
}
function burn(address who, uint value) onlyAdmin // сжигаем токены с адреса
{
if (value<=balances[who])
{
balances[who] = balances[who].sub(value);
}
else{}
}
function transferFrom(address _from, address _to, uint _value) returns (bool success) // перевод с адреса на адрес
{
if( allowed[_from][msg.sender] >= _value &&
balances[_from] >= _value
&& balances[_to].add(_value) >= balances[_to])
{
allowed[_from][msg.sender]= allowed[_from][msg.sender].sub(_value);
balances[_from]= balances[_from].sub(_value);
balances[_to]= balances[_to].add(_value);
Transfer(_from, _to, _value);
return true;
}
return false;
}
function approve(address _spender, uint _value) returns (bool success) // получение доступа для снятия со счета
{
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint remaining) // просмотр разрешенных для снятия токенов
{
return allowed[_owner][_spender];
}
function mint(address _to, uint256 _value) onlyOwner // выпуск новых токенов
{
assert(totalSupply.add(_value) >= totalSupply && balances[_to].add(_value) >= balances[_to]);
balances[_to]= balances[_to].add(_value);
totalSupply= totalSupply.add(_value);
}
}
// Контракт для реализации продажи токенов
contract sales is zharcoin
{
uint coef = 1000000000000;
uint stage1 = 1509753600;
uint stage2 = 1510012800;
uint stage3 = 1510704000;
uint public bonus = 0;
bool public canSale = true;
uint public coinCount = totalSupply;
function() external payable // fallback функция
{
if(coinCount>0){
if(canSale==true){
owner.transfer(msg.value);
uint buy = msg.value.div(coef);
if(bonus == 0 && buy < totalSupply && buy<coinCount)
{
totalSupply= totalSupply.sub(buy);
coinCount = coinCount.sub(buy);
balances[msg.sender]= balances[msg.sender].add(buy);
}
else if(buy < totalSupply && buy< coinCount)
{
totalSupply= totalSupply.sub((buy.add(buy.div(bonus))));
coinCount= coinCount.sub((buy.add(buy.div(bonus))));
balances[msg.sender]= balances[msg.sender].add((buy.add(buy.div(bonus))));
}
else {msg.sender.transfer(msg.value);}
}
else{}
}}
function changeCoef(uint newCoef) onlyAdmin //коэффициент для смены стоимости токена
{
coef = newCoef;
}
function isSale(uint _stage1, uint bonus1, uint _stage2, uint bonus2, uint _stage3) onlyAdmin // распродажа токенов в несколько этапов
{
stage1 = _stage1;
stage2 = _stage2;
stage3 = _stage3;
if(now >= stage1 && now <= stage2)
{
bonus = bonus1;
}
if(now >= stage2 && now <= stage3)
{
bonus = bonus2;
}
}
function getRate() public constant returns(uint) // возврат текущего курса токена к эфиру
{
return 1000000000000000000/coef;
}
function chngCoinNumber(uint num, uint _bonus) onlyAdmin // смена количества распродаваемых токенов
{
coinCount = num;
bonus = _bonus;
}
function startSale() onlyOwner // начало продаж
{
canSale = true;
}
function stopSale() onlyOwner // остановка продаж
{
canSale = false;
}
}