-
Notifications
You must be signed in to change notification settings - Fork 5
/
KUSDT.sol
471 lines (347 loc) · 12 KB
/
KUSDT.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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
// SPDX-License-Identifier: MIT
// Sources flattened with hardhat v2.5.0 https://hardhat.org
// File contracts/interfaces/IKToken.sol
pragma solidity ^0.8.0;
interface IKToken {
function internalTransfer(
address sender,
address recipient,
uint256 amount
) external returns (bool);
function externalTransfer(
address sender,
address recipient,
uint256 amount
) external returns (bool);
}
// File contracts/abstracts/Blacklist.sol
pragma solidity ^0.8.0;
abstract contract Blacklist {
mapping(address => bool) public blacklist;
event AddBlacklist(address indexed account, address indexed caller);
event RevokeBlacklist(address indexed account, address indexed caller);
modifier notInBlacklist(address account) {
require(!blacklist[account], "Address is in blacklist");
_;
}
modifier inBlacklist(address account) {
require(blacklist[account], "Address is not in blacklist");
_;
}
function _addBlacklist(address account) internal virtual notInBlacklist(account) {
blacklist[account] = true;
emit AddBlacklist(account, msg.sender);
}
function _revokeBlacklist(address account) internal virtual inBlacklist(account) {
blacklist[account] = false;
emit RevokeBlacklist(account, msg.sender);
}
}
// File contracts/abstracts/Pauseable.sol
pragma solidity ^0.8.0;
abstract contract Pauseable {
event Paused(address account);
event Unpaused(address account);
bool public paused;
constructor() {
paused = false;
}
modifier whenNotPaused() {
require(!paused, "Pauseable: paused");
_;
}
modifier whenPaused() {
require(paused, "Pauseable: not paused");
_;
}
function _pause() internal virtual whenNotPaused {
paused = true;
emit Paused(msg.sender);
}
function _unpause() internal virtual whenPaused {
paused = false;
emit Unpaused(msg.sender);
}
}
// File contracts/abstracts/Authorization.sol
pragma solidity ^0.8.0;
abstract contract Authorization {
address public committee;
address public admin;
event SetAdmin(address indexed oldAdmin, address indexed newAdmin, address indexed caller);
event SetCommittee(address indexed oldCommittee, address indexed newCommittee, address indexed caller);
modifier onlyAdmin() {
require(msg.sender == admin, "Restricted only admin");
_;
}
modifier onlyCommittee() {
require(msg.sender == committee, "Restricted only committee");
_;
}
modifier onlyAdminOrCommittee() {
require(msg.sender == committee || msg.sender == admin, "Restricted only committee or admin");
_;
}
function setAdmin(address _admin) external onlyCommittee {
emit SetAdmin(admin, _admin, msg.sender);
admin = _admin;
}
function setCommittee(address _committee) external onlyCommittee {
emit SetCommittee(committee, _committee, msg.sender);
committee = _committee;
}
}
// File contracts/interfaces/IKYCBitkubChain.sol
pragma solidity ^0.8.0;
interface IKYCBitkubChain {
function kycsLevel(address _addr) external view returns (uint256);
}
// File contracts/abstracts/KYCHandler.sol
pragma solidity ^0.8.0;
abstract contract KYCHandler {
IKYCBitkubChain public kyc;
uint256 public acceptedKycLevel;
bool public isActivatedOnlyKycAddress;
function _activateOnlyKycAddress() internal virtual {
isActivatedOnlyKycAddress = true;
}
function _setKYC(IKYCBitkubChain _kyc) internal virtual {
kyc = _kyc;
}
function _setAcceptedKycLevel(uint256 _kycLevel) internal virtual {
acceptedKycLevel = _kycLevel;
}
}
// File contracts/interfaces/IKAP20.sol
pragma solidity ^0.8.0;
interface IKAP20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowances(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
function adminTransfer(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// File contracts/token/KAP20.sol
pragma solidity ^0.8.0;
contract KAP20 is IKAP20, KYCHandler, Pauseable, Authorization, Blacklist {
mapping(address => uint256) _balances;
mapping(address => mapping(address => uint256)) public override allowances;
uint256 public override totalSupply;
string public override name;
string public override symbol;
uint8 public override decimals;
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals,
address _admin,
address _committee,
IKYCBitkubChain _kyc,
uint256 _acceptedKycLevel
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
kyc = _kyc;
acceptedKycLevel = _acceptedKycLevel;
admin = _admin;
committee = _committee;
}
/**
* @dev See {IKAP20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IKAP20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount)
public
virtual
override
whenNotPaused
notInBlacklist(msg.sender)
returns (bool)
{
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {IKAP20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount)
public
virtual
override
notInBlacklist(msg.sender)
returns (bool)
{
_approve(msg.sender, spender, amount);
return true;
}
function transferFrom(
address sender,
address recipient,
uint256 amount
) public virtual override whenNotPaused notInBlacklist(sender) notInBlacklist(recipient) returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = allowances[sender][msg.sender];
require(currentAllowance >= amount, "KAP20: transfer amount exceeds allowance");
unchecked {
_approve(sender, msg.sender, currentAllowance - amount);
}
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(msg.sender, spender, allowances[msg.sender][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = allowances[msg.sender][spender];
require(currentAllowance >= subtractedValue, "KAP20: decreased allowance below zero");
unchecked {
_approve(msg.sender, spender, currentAllowance - subtractedValue);
}
return true;
}
function _transfer(
address sender,
address recipient,
uint256 amount
) internal virtual {
require(sender != address(0), "KAP20: transfer from the zero address");
require(recipient != address(0), "KAP20: transfer to the zero address");
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "KAP20: transfer amount exceeds balance");
unchecked {
_balances[sender] = senderBalance - amount;
}
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "KAP20: mint to the zero address");
totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "KAP20: burn from the zero address");
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "KAP20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "KAP20: approve from the zero address");
require(spender != address(0), "KAP20: approve to the zero address");
allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function adminTransfer(
address sender,
address recipient,
uint256 amount
) public override onlyCommittee returns (bool) {
require(_balances[sender] >= amount, "KAP20: transfer amount exceed balance");
require(recipient != address(0), "KAP20: transfer to zero address");
_balances[sender] -= amount;
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
return true;
}
function pause() public onlyCommittee {
_pause();
}
function unpause() public onlyCommittee {
_unpause();
}
function addBlacklist(address account) public onlyCommittee {
_addBlacklist(account);
}
function revokeBlacklist(address account) public onlyCommittee {
_revokeBlacklist(account);
}
function activateOnlyKycAddress() public onlyCommittee {
_activateOnlyKycAddress();
}
function setKYC(IKYCBitkubChain _kyc) public onlyCommittee {
_setKYC(_kyc);
}
function setAcceptedKycLevel(uint256 _kycLevel) public onlyCommittee {
_setAcceptedKycLevel(_kycLevel);
}
}
// File contracts/KUSDT.sol
pragma solidity ^0.8.0;
contract KUSDT is KAP20, IKToken {
constructor(
address admin,
address committee,
IKYCBitkubChain kyc,
uint256 acceptedKycLevel
) KAP20("Bitkub-Peg USDT", "KUSDT", 18, admin, committee, kyc, acceptedKycLevel) {
_mint(0x6002Bd66c5DA67b812CCAaB16716dBF57BD2aA18, 3000000 ether);
}
function internalTransfer(
address sender,
address recipient,
uint256 amount
) external override whenNotPaused onlyAdmin returns (bool) {
require(
kyc.kycsLevel(sender) >= acceptedKycLevel && kyc.kycsLevel(recipient) >= acceptedKycLevel,
"Only internal purpose"
);
_transfer(sender, recipient, amount);
return true;
}
function externalTransfer(
address sender,
address recipient,
uint256 amount
) external override whenNotPaused onlyAdmin returns (bool) {
require(kyc.kycsLevel(sender) >= acceptedKycLevel, "Only internal purpose");
_transfer(sender, recipient, amount);
return true;
}
function mint(address account, uint256 amount) external virtual onlyCommittee returns (bool) {
_mint(account, amount);
return true;
}
function burn(address account, uint256 amount) external virtual onlyCommittee returns (bool) {
_burn(account, amount);
return true;
}
}