File size: 9,742 Bytes
dec6d5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
pragma solidity ^0.4.24;

library SafeMath {

    function mul(uint a, uint b) internal pure returns (uint) {
        uint c = a * b;
        require(a == 0 || c / a == b);
        return c;
    }

    function div(uint a, uint b) internal pure returns (uint) {
        uint c = a / b;
        return c;
    }

    function sub(uint a, uint b) internal pure returns (uint) {
        require(b <= a);
        return a - b;
    }

    function add(uint a, uint b) internal pure returns (uint) {
        uint c = a + b;
        require(c >= a);
        return c;
    }

    function max(uint a, uint b) internal pure returns (uint) {
        return a >= b ? a : b;
    }

    function min(uint a, uint b) internal pure returns (uint) {
        return a < b ? a : b;
    }

}







contract MntToken {

    
    event Transfer(address indexed from, address indexed to, uint value);
    event Approval(address indexed owner, address indexed spender, uint value);
    event Burn(address indexed from, uint value);
    event TransferLocked(address indexed from, address indexed to, uint value, uint8 locktype);
	event Purchased(address indexed recipient, uint purchase, uint amount);

    
    using SafeMath for uint;

    
    address public owner;
    bool public frozen = false; 

    
    uint8 constant public decimals = 6;
    uint public totalSupply = 100*10**(8+uint256(decimals));  
    string constant public name = "MDEX Platform Token | Mongolia National Blockchain Digital Assets Exchange Token";
    string constant public symbol = "MNT";

    mapping(address => uint) ownerance; 
    mapping(address => mapping(address => uint)) public allowance; 

    
    uint8 LOCKED_TYPE_MAX = 2; 
    uint private constant RELEASE_BASE_TIME = 1533686888; 
    address[] private lockedOwner;
    mapping(address => uint) public lockedance; 
    mapping(address => uint8) public lockedtype; 
    mapping(address => uint8) public unlockedstep; 

    uint public totalCirculating; 

    

    
    modifier isOwner() {
        require(msg.sender == owner);
        _;
    }

    modifier isNotFrozen() {
        require(!frozen);
        _;
    }

    
    modifier hasEnoughBalance(uint _amount) {
        require(ownerance[msg.sender] >= _amount);
        _;
    }

    modifier overflowDetected(address _owner, uint _amount) {
        require(ownerance[_owner] + _amount >= ownerance[_owner]);
        _;
    }

    modifier hasAllowBalance(address _owner, address _allower, uint _amount) {
        require(allowance[_owner][_allower] >= _amount);
        _;
    }

    modifier isNotEmpty(address _addr, uint _value) {
        require(_addr != address(0));
        require(_value != 0);
        _;
    }

    modifier isValidAddress {
        assert(0x0 != msg.sender);
        _;
    }

    
    modifier hasntLockedBalance(address _checker) {
        require(lockedtype[_checker] == 0);
        _;
    }

    modifier checkLockedType(uint8 _locktype) {
        require(_locktype > 0 && _locktype <= LOCKED_TYPE_MAX);
        _;
    }

    
    constructor() public {
        owner = msg.sender;
        ownerance[msg.sender] = totalSupply;
        totalCirculating = totalSupply;
        emit Transfer(address(0), msg.sender, totalSupply);
    }

    
    function approve(address _spender, uint _value)
        isNotFrozen
        isValidAddress
        public returns (bool success)
    {
        require(_value == 0 || allowance[msg.sender][_spender] == 0); 
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }

    function transferFrom(address _from, address _to, uint _value)
        isNotFrozen
        isValidAddress
        overflowDetected(_to, _value)
        public returns (bool success)
    {
        require(ownerance[_from] >= _value);
        require(allowance[_from][msg.sender] >= _value);

        ownerance[_to] = ownerance[_to].add(_value);
        ownerance[_from] = ownerance[_from].sub(_value);
        allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
        emit Transfer(_from, _to, _value);
        return true;
    }

    function balanceOf(address _owner) public
        constant returns (uint balance)
    {
        balance = ownerance[_owner] + lockedance[_owner];
        return balance;
    }


    function available(address _owner) public
        constant returns (uint)
    {
        return ownerance[_owner];
    }

    function transfer(address _to, uint _value) public
        isNotFrozen
        isValidAddress
        isNotEmpty(_to, _value)
        hasEnoughBalance(_value)
        overflowDetected(_to, _value)
        returns (bool success)
    {
        ownerance[msg.sender] = ownerance[msg.sender].sub(_value);
        ownerance[_to] = ownerance[_to].add(_value);
        emit Transfer(msg.sender, _to, _value);
        return true;
    }

    
    function transferOwner(address _newOwner)
        isOwner
        public returns (bool success)
    {
        if (_newOwner != address(0)) {
            owner = _newOwner;
        }
        return true;
    }

    function freeze()
        isOwner
        public returns (bool success)
    {
        frozen = true;
        return true;
    }

    function unfreeze()
        isOwner
        public returns (bool success)
    {
        frozen = false;
        return true;
    }

    function burn(uint _value)
        isNotFrozen
        isValidAddress
        hasEnoughBalance(_value)
        public returns (bool success)
    {
        ownerance[msg.sender] = ownerance[msg.sender].sub(_value);
        ownerance[0x0] = ownerance[0x0].add(_value);
        totalSupply = totalSupply.sub(_value);
        totalCirculating = totalCirculating.sub(_value);
        emit Burn(msg.sender, _value);
        return true;
    }

    
    function transferLocked(address _to, uint _value, uint8 _locktype) public
        isNotFrozen
        isOwner
        isValidAddress
        isNotEmpty(_to, _value)
        hasEnoughBalance(_value)
        hasntLockedBalance(_to)
        checkLockedType(_locktype)
        returns (bool success)
    {
        require(msg.sender != _to);
        ownerance[msg.sender] = ownerance[msg.sender].sub(_value);
        if (_locktype == 1) {
            lockedance[_to] = _value;
            lockedtype[_to] = _locktype;
            lockedOwner.push(_to);
            totalCirculating = totalCirculating.sub(_value);
            emit TransferLocked(msg.sender, _to, _value, _locktype);
        } else if (_locktype == 2) {
            uint _first = _value / 100 * 8; 
            ownerance[_to] = ownerance[_to].add(_first);
            lockedance[_to] = _value.sub(_first);
            lockedtype[_to] = _locktype;
            lockedOwner.push(_to);
            totalCirculating = totalCirculating.sub(_value.sub(_first));
            emit Transfer(msg.sender, _to, _first);
            emit TransferLocked(msg.sender, _to, _value.sub(_first), _locktype);
        }
        return true;
    }

    
    
    
    
    
    
    function unlock(address _locker, uint _delta, uint8 _locktype) private
        returns (bool success)
    {
        if (_locktype == 1) {
            if (_delta < 6 * 30 days) {
                return false;
            }
            uint _more1 = _delta.sub(6 * 30 days);
            uint _step1 = _more1 / 30 days;
            for(uint8 i = 0; i < 10; i++) {
                if (unlockedstep[_locker] == i && i < 9 && i <= _step1 ) {
                    ownerance[_locker] = ownerance[_locker].add(lockedance[_locker] / (10 - i));
                    lockedance[_locker] = lockedance[_locker].sub(lockedance[_locker] / (10 - i));
                    unlockedstep[_locker] = i + 1;
                } else if (i == 9 && unlockedstep[_locker] == 9 && _step1 == 9){
                    ownerance[_locker] = ownerance[_locker].add(lockedance[_locker]);
                    lockedance[_locker] = 0;
                    unlockedstep[_locker] = 0;
                    lockedtype[_locker] = 0;
                }
            }
        } else if (_locktype == 2) {
            if (_delta < 30 days) {
                return false;
            }
            uint _more2 = _delta - 30 days;
            uint _step2 = _more2 / 30 days;
            for(uint8 j = 0; j < 11; j++) {
                if (unlockedstep[_locker] == j && j < 10 && j <= _step2 ) {
                    ownerance[_locker] = ownerance[_locker].add(lockedance[_locker] / (11 - j));
                    lockedance[_locker] = lockedance[_locker].sub(lockedance[_locker] / (11 - j));
                    unlockedstep[_locker] = j + 1;
                } else if (j == 10 && unlockedstep[_locker] == 10 && _step2 == 10){
                    ownerance[_locker] = ownerance[_locker].add(lockedance[_locker]);
                    lockedance[_locker] = 0;
                    unlockedstep[_locker] = 0;
                    lockedtype[_locker] = 0;
                }
            }
        }
        return true;
    }

    function lockedCounts() public view
        returns (uint counts)
    {
        return lockedOwner.length;
    }

    function releaseLocked() public
        isNotFrozen
        returns (bool success)
    {
        require(now > RELEASE_BASE_TIME);
        uint delta = now - RELEASE_BASE_TIME;
        uint lockedAmount;
        for (uint i = 0; i < lockedOwner.length; i++) {
            if ( lockedance[lockedOwner[i]] > 0) {
                lockedAmount = lockedance[lockedOwner[i]];
                unlock(lockedOwner[i], delta, lockedtype[lockedOwner[i]]);
                totalCirculating = totalCirculating.add(lockedAmount - lockedance[lockedOwner[i]]);
            }
        }
        return true;
    }


}