wDEFI Token
Woonkly DEFI
1
/**
2
*Submitted for verification at BscScan.com on 2021-05-11
3
*/
4
5
// SPDX-License-Identifier: MIT
6
pragma solidity 0.6.12;
7
8
/**
9
* @dev Wrappers over Solidity's arithmetic operations with added overflow
10
* checks.
11
*
12
* Arithmetic operations in Solidity wrap on overflow. This can easily result
13
* in bugs, because programmers usually assume that an overflow raises an
14
* error, which is the standard behavior in high level programming languages.
15
* `SafeMath` restores this intuition by reverting the transaction when an
16
* operation overflows.
17
*
18
* Using this library instead of the unchecked operations eliminates an entire
19
* class of bugs, so it's recommended to use it always.
20
*/
21
library SafeMath {
22
/**
23
* @dev Returns the addition of two unsigned integers, reverting on
24
* overflow.
25
*
26
* Counterpart to Solidity's `+` operator.
27
*
28
* Requirements:
29
*
30
* - Addition cannot overflow.
31
*/
32
function add(uint256 a, uint256 b) internal pure returns (uint256) {
33
uint256 c = a + b;
34
require(c >= a, "SafeMath: addition overflow");
35
36
return c;
37
}
38
39
/**
40
* @dev Returns the subtraction of two unsigned integers, reverting on
41
* overflow (when the result is negative).
42
*
43
* Counterpart to Solidity's `-` operator.
44
*
45
* Requirements:
46
*
47
* - Subtraction cannot overflow.
48
*/
49
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
50
return sub(a, b, "SafeMath: subtraction overflow");
51
}
52
53
/**
54
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
55
* overflow (when the result is negative).
56
*
57
* Counterpart to Solidity's `-` operator.
58
*
59
* Requirements:
60
*
61
* - Subtraction cannot overflow.
62
*/
63
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
64
require(b <= a, errorMessage);
65
uint256 c = a - b;
66
67
return c;
68
}
69
70
/**
71
* @dev Returns the multiplication of two unsigned integers, reverting on
72
* overflow.
73
*
74
* Counterpart to Solidity's `*` operator.
75
*
76
* Requirements:
77
*
78
* - Multiplication cannot overflow.
79
*/
80
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
81
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
82
// benefit is lost if 'b' is also tested.
83
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
84
if (a == 0) {
85
return 0;
86
}
87
88
uint256 c = a * b;
89
require(c / a == b, "SafeMath: multiplication overflow");
90
91
return c;
92
}
93
94
/**
95
* @dev Returns the integer division of two unsigned integers. Reverts on
96
* division by zero. The result is rounded towards zero.
97
*
98
* Counterpart to Solidity's `/` operator. Note: this function uses a
99
* `revert` opcode (which leaves remaining gas untouched) while Solidity
100
* uses an invalid opcode to revert (consuming all remaining gas).
101
*
102
* Requirements:
103
*
104
* - The divisor cannot be zero.
105
*/
106
function div(uint256 a, uint256 b) internal pure returns (uint256) {
107
return div(a, b, "SafeMath: division by zero");
108
}
109
110
/**
111
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
112
* division by zero. The result is rounded towards zero.
113
*
114
* Counterpart to Solidity's `/` operator. Note: this function uses a
115
* `revert` opcode (which leaves remaining gas untouched) while Solidity
116
* uses an invalid opcode to revert (consuming all remaining gas).
117
*
118
* Requirements:
119
*
120
* - The divisor cannot be zero.
121
*/
122
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
123
require(b > 0, errorMessage);
124
uint256 c = a / b;
125
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
126
127
return c;
128
}
129
130
/**
131
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
132
* Reverts when dividing by zero.
133
*
134
* Counterpart to Solidity's `%` operator. This function uses a `revert`
135
* opcode (which leaves remaining gas untouched) while Solidity uses an
136
* invalid opcode to revert (consuming all remaining gas).
137
*
138
* Requirements:
139
*
140
* - The divisor cannot be zero.
141
*/
142
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
143
return mod(a, b, "SafeMath: modulo by zero");
144
}
145
146
/**
147
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
148
* Reverts with custom message when dividing by zero.
149
*
150
* Counterpart to Solidity's `%` operator. This function uses a `revert`
151
* opcode (which leaves remaining gas untouched) while Solidity uses an
152
* invalid opcode to revert (consuming all remaining gas).
153
*
154
* Requirements:
155
*
156
* - The divisor cannot be zero.
157
*/
158
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
159
require(b != 0, errorMessage);
160
return a % b;
161
}
162
}
163
164
/**
165
* @title Roles
166
* @dev Library for managing addresses assigned to a Role.
167
*/
168
library Roles {
169
struct Role {
170
mapping (address => bool) bearer;
171
}
172
173
/**
174
* @dev Give an account access to this role.
175
*/
176
function add(Role storage role, address account) internal {
177
require(!has(role, account), "Roles: account already has role");
178
role.bearer[account] = true;
179
}
180
181
/**
182
* @dev Remove an account's access to this role.
183
*/
184
function remove(Role storage role, address account) internal {
185
require(has(role, account), "Roles: account does not have role");
186
role.bearer[account] = false;
187
}
188
189
/**
190
* @dev Check if an account has this role.
191
* @return bool
192
*/
193
function has(Role storage role, address account) internal view returns (bool) {
194
require(account != address(0), "Roles: account is the zero address");
195
return role.bearer[account];
196
}
197
}
198
199
/**
200
* @title MinterRole
201
* @dev Implementation of the {MinterRole} interface.
202
*/
203
contract MinterRole {
204
using Roles for Roles.Role;
205
206
event MinterAdded(address indexed account);
207
event MinterRemoved(address indexed account);
208
209
Roles.Role private _minters;
210
211
constructor () internal {
212
_addMinter(msg.sender);
213
}
214
215
modifier onlyMinter() {
216
require(isMinter(msg.sender), "MinterRole: caller does not have the Minter role");
217
_;
218
}
219
220
function isMinter(address account) public view returns (bool) {
221
return _minters.has(account);
222
}
223
224
function addMinter(address account) public onlyMinter {
225
_addMinter(account);
226
}
227
228
function removeMinter(address account) public onlyMinter {
229
_removeMinter(account);
230
}
231
232
function renounceMinter() public {
233
_removeMinter(msg.sender);
234
}
235
236
function _addMinter(address account) internal {
237
_minters.add(account);
238
emit MinterAdded(account);
239
}
240
241
function _removeMinter(address account) internal {
242
_minters.remove(account);
243
emit MinterRemoved(account);
244
}
245
}
246
247
/*
248
* @dev Provides information about the current execution context, including the
249
* sender of the transaction and its data. While these are generally available
250
* via msg.sender and msg.data, they should not be accessed in such a direct
251
* manner, since when dealing with GSN meta-transactions the account sending and
252
* paying for execution may not be the actual sender (as far as an application
253
* is concerned).
254
*
255
* This contract is only required for intermediate, library-like contracts.
256
*/
257
abstract contract Context {
258
function _msgSender() internal view virtual returns (address payable) {
259
return msg.sender;
260
}
261
262
function _msgData() internal view virtual returns (bytes memory) {
263
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
264
return msg.data;
265
}
266
}
267
268
/**
269
* @dev Contract module which provides a basic access control mechanism, where
270
* there is an account (an owner) that can be granted exclusive access to
271
* specific functions.
272
*
273
* By default, the owner account will be the one that deploys the contract. This
274
* can later be changed with {transferOwnership}.
275
*
276
* This module is used through inheritance. It will make available the modifier
277
* `onlyOwner`, which can be applied to your functions to restrict their use to
278
* the owner.
279
*/
280
abstract contract Ownable is Context {
281
address private _owner;
282
283
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
284
285
/**
286
* @dev Initializes the contract setting the deployer as the initial owner.
287
*/
288
constructor () internal {
289
address msgSender = _msgSender();
290
_owner = msgSender;
291
emit OwnershipTransferred(address(0), msgSender);
292
}
293
294
/**
295
* @dev Returns the address of the current owner.
296
*/
297
function owner() public view returns (address) {
298
return _owner;
299
}
300
301
/**
302
* @dev Throws if called by any account other than the owner.
303
*/
304
modifier onlyOwner() {
305
require(_owner == _msgSender(), "Ownable: caller is not the owner");
306
_;
307
}
308
309
/**
310
* @dev Leaves the contract without owner. It will not be possible to call
311
* `onlyOwner` functions anymore. Can only be called by the current owner.
312
*
313
* NOTE: Renouncing ownership will leave the contract without an owner,
314
* thereby removing any functionality that is only available to the owner.
315
*/
316
function renounceOwnership() public virtual onlyOwner {
317
emit OwnershipTransferred(_owner, address(0));
318
_owner = address(0);
319
}
320
321
/**
322
* @dev Transfers ownership of the contract to a new account (`newOwner`).
323
* Can only be called by the current owner.
324
*/
325
function transferOwnership(address newOwner) public virtual onlyOwner {
326
require(newOwner != address(0), "Ownable: new owner is the zero address");
327
emit OwnershipTransferred(_owner, newOwner);
328
_owner = newOwner;
329
}
330
}
331
332
interface IBEP20 {
333
/**
334
* @dev Returns the amount of tokens in existence.
335
*/
336
function totalSupply() external view returns (uint256);
337
338
/**
339
* @dev Returns the token decimals.
340
*/
341
function decimals() external view returns (uint8);
342
343
/**
344
* @dev Returns the token symbol.
345
*/
346
function symbol() external view returns (string memory);
347
348
/**
349
* @dev Returns the token name.
350
*/
351
function name() external view returns (string memory);
352
353
/**
354
* @dev Returns the bep token owner.
355
*/
356
function getOwner() external view returns (address);
357
358
/**
359
* @dev Returns the amount of tokens owned by `account`.
360
*/
361
function balanceOf(address account) external view returns (uint256);
362
363
/**
364
* @dev Moves `amount` tokens from the caller's account to `recipient`.
365
*
366
* Returns a boolean value indicating whether the operation succeeded.
367
*
368
* Emits a {Transfer} event.
369
*/
370
function transfer(address recipient, uint256 amount) external returns (bool);
371
372
/**
373
* @dev Returns the remaining number of tokens that `spender` will be
374
* allowed to spend on behalf of `owner` through {transferFrom}. This is
375
* zero by default.
376
*
377
* This value changes when {approve} or {transferFrom} are called.
378
*/
379
function allowance(address _owner, address spender) external view returns (uint256);
380
381
/**
382
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
383
*
384
* Returns a boolean value indicating whether the operation succeeded.
385
*
386
* IMPORTANT: Beware that changing an allowance with this method brings the risk
387
* that someone may use both the old and the new allowance by unfortunate
388
* transaction ordering. One possible solution to mitigate this race
389
* condition is to first reduce the spender's allowance to 0 and set the
390
* desired value afterwards:
391
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
392
*
393
* Emits an {Approval} event.
394
*/
395
function approve(address spender, uint256 amount) external returns (bool);
396
397
/**
398
* @dev Moves `amount` tokens from `sender` to `recipient` using the
399
* allowance mechanism. `amount` is then deducted from the caller's
400
* allowance.
401
*
402
* Returns a boolean value indicating whether the operation succeeded.
403
*
404
* Emits a {Transfer} event.
405
*/
406
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
407
408
/**
409
* @dev Emitted when `value` tokens are moved from one account (`from`) to
410
* another (`to`).
411
*
412
* Note that `value` may be zero.
413
*/
414
event Transfer(address indexed from, address indexed to, uint256 value);
415
416
/**
417
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
418
* a call to {approve}. `value` is the new allowance.
419
*/
420
event Approval(address indexed owner, address indexed spender, uint256 value);
421
}
422
423
/**
424
* @dev Implementation of the {IBEP20} interface.
425
*
426
* This implementation is agnostic to the way tokens are created. This means
427
* that a supply mechanism has to be added in a derived contract using {_mint}.
428
* For a generic mechanism see {BEP20PresetMinterPauser}.
429
*
430
* TIP: For a detailed writeup see our guide
431
* https://forum.zeppelin.solutions/t/how-to-implement-BEP20-supply-mechanisms/226[How
432
* to implement supply mechanisms].
433
*
434
* We have followed general OpenZeppelin guidelines: functions revert instead
435
* of returning `false` on failure. This behavior is nonetheless conventional
436
* and does not conflict with the expectations of BEP20 applications.
437
*
438
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
439
* This allows applications to reconstruct the allowance for all accounts just
440
* by listening to said events. Other implementations of the EIP may not emit
441
* these events, as it isn't required by the specification.
442
*
443
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
444
* functions have been added to mitigate the well-known issues around setting
445
* allowances. See {IBEP20-approve}.
446
*/
447
contract BEP20 is Context, IBEP20, Ownable {
448
using SafeMath for uint256;
449
450
mapping(address => uint256) private _balances;
451
452
mapping(address => mapping(address => uint256)) private _allowances;
453
454
uint256 private _totalSupply;
455
456
string private _name;
457
string private _symbol;
458
uint8 private _decimals;
459
460
/**
461
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
462
* a default value of 18.
463
*
464
* To select a different value for {decimals}, use {_setupDecimals}.
465
*
466
* All three of these values are immutable: they can only be set once during
467
* construction.
468
*/
469
constructor(string memory name, string memory symbol, uint8 decimals) public {
470
_name = name;
471
_symbol = symbol;
472
_decimals = decimals;
473
}
474
475
/**
476
* @dev Returns the bep token owner.
477
*/
478
function getOwner() external override view returns (address) {
479
return owner();
480
}
481
482
/**
483
* @dev Returns the name of the token.
484
*/
485
function name() public override view returns (string memory) {
486
return _name;
487
}
488
489
/**
490
* @dev Returns the symbol of the token, usually a shorter version of the
491
* name.
492
*/
493
function symbol() public override view returns (string memory) {
494
return _symbol;
495
}
496
497
/**
498
* @dev Returns the number of decimals used to get its user representation.
499
*/
500
function decimals() public override view returns (uint8) {
501
return _decimals;
502
}
503
504
/**
505
* @dev See {BEP20-totalSupply}.
506
*/
507
function totalSupply() public override view returns (uint256) {
508
return _totalSupply;
509
}
510
511
/**
512
* @dev See {BEP20-balanceOf}.
513
*/
514
function balanceOf(address account) public override view returns (uint256) {
515
return _balances[account];
516
}
517
518
/**
519
* @dev See {BEP20-transfer}.
520
*
521
* Requirements:
522
*
523
* - `recipient` cannot be the zero address.
524
* - the caller must have a balance of at least `amount`.
525
*/
526
function transfer(address recipient, uint256 amount) public override returns (bool) {
527
_transfer(_msgSender(), recipient, amount);
528
return true;
529
}
530
531
/**
532
* @dev See {BEP20-allowance}.
533
*/
534
function allowance(address owner, address spender) public override view returns (uint256) {
535
return _allowances[owner][spender];
536
}
537
538
/**
539
* @dev See {BEP20-approve}.
540
*
541
* Requirements:
542
*
543
* - `spender` cannot be the zero address.
544
*/
545
function approve(address spender, uint256 amount) public override returns (bool) {
546
_approve(_msgSender(), spender, amount);
547
return true;
548
}
549
550
/**
551
* @dev See {BEP20-transferFrom}.
552
*
553
* Emits an {Approval} event indicating the updated allowance. This is not
554
* required by the EIP. See the note at the beginning of {BEP20};
555
*
556
* Requirements:
557
* - `sender` and `recipient` cannot be the zero address.
558
* - `sender` must have a balance of at least `amount`.
559
* - the caller must have allowance for `sender`'s tokens of at least
560
* `amount`.
561
*/
562
function transferFrom (address sender, address recipient, uint256 amount) public override returns (bool) {
563
_transfer(sender, recipient, amount);
564
_approve(
565
sender,
566
_msgSender(),
567
_allowances[sender][_msgSender()].sub(amount, 'BEP20: transfer amount exceeds allowance')
568
);
569
return true;
570
}
571
572
/**
573
* @dev Atomically increases the allowance granted to `spender` by the caller.
574
*
575
* This is an alternative to {approve} that can be used as a mitigation for
576
* problems described in {BEP20-approve}.
577
*
578
* Emits an {Approval} event indicating the updated allowance.
579
*
580
* Requirements:
581
*
582
* - `spender` cannot be the zero address.
583
*/
584
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
585
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
586
return true;
587
}
588
589
/**
590
* @dev Atomically decreases the allowance granted to `spender` by the caller.
591
*
592
* This is an alternative to {approve} that can be used as a mitigation for
593
* problems described in {BEP20-approve}.
594
*
595
* Emits an {Approval} event indicating the updated allowance.
596
*
597
* Requirements:
598
*
599
* - `spender` cannot be the zero address.
600
* - `spender` must have allowance for the caller of at least
601
* `subtractedValue`.
602
*/
603
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
604
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, 'BEP20: decreased allowance below zero'));
605
return true;
606
}
607
608
/**
609
* @dev Creates `amount` tokens and assigns them to `msg.sender`, increasing
610
* the total supply.
611
*
612
* Requirements
613
*
614
* - `msg.sender` must be the token owner
615
*/
616
function mint(uint256 amount) public onlyOwner returns (bool) {
617
_mint(_msgSender(), amount);
618
return true;
619
}
620
621
/**
622
* @dev Moves tokens `amount` from `sender` to `recipient`.
623
*
624
* This is internal function is equivalent to {transfer}, and can be used to
625
* e.g. implement automatic token fees, slashing mechanisms, etc.
626
*
627
* Emits a {Transfer} event.
628
*
629
* Requirements:
630
*
631
* - `sender` cannot be the zero address.
632
* - `recipient` cannot be the zero address.
633
* - `sender` must have a balance of at least `amount`.
634
*/
635
function _transfer (address sender, address recipient, uint256 amount) internal {
636
require(sender != address(0), 'BEP20: transfer from the zero address');
637
require(recipient != address(0), 'BEP20: transfer to the zero address');
638
639
_balances[sender] = _balances[sender].sub(amount, 'BEP20: transfer amount exceeds balance');
640
_balances[recipient] = _balances[recipient].add(amount);
641
emit Transfer(sender, recipient, amount);
642
}
643
644
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
645
* the total supply.
646
*
647
* Emits a {Transfer} event with `from` set to the zero address.
648
*
649
* Requirements
650
*
651
* - `to` cannot be the zero address.
652
*/
653
function _mint(address account, uint256 amount) internal {
654
require(account != address(0), 'BEP20: mint to the zero address');
655
656
_totalSupply = _totalSupply.add(amount);
657
_balances[account] = _balances[account].add(amount);
658
emit Transfer(address(0), account, amount);
659
}
660
661
/**
662
* @dev Destroys `amount` tokens from `account`, reducing the
663
* total supply.
664
*
665
* Emits a {Transfer} event with `to` set to the zero address.
666
*
667
* Requirements
668
*
669
* - `account` cannot be the zero address.
670
* - `account` must have at least `amount` tokens.
671
*/
672
function _burn(address account, uint256 amount) internal {
673
require(account != address(0), 'BEP20: burn from the zero address');
674
675
_balances[account] = _balances[account].sub(amount, 'BEP20: burn amount exceeds balance');
676
_totalSupply = _totalSupply.sub(amount);
677
emit Transfer(account, address(0), amount);
678
}
679
680
/**
681
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
682
*
683
* This is internal function is equivalent to `approve`, and can be used to
684
* e.g. set automatic allowances for certain subsystems, etc.
685
*
686
* Emits an {Approval} event.
687
*
688
* Requirements:
689
*
690
* - `owner` cannot be the zero address.
691
* - `spender` cannot be the zero address.
692
*/
693
function _approve (address owner, address spender, uint256 amount) internal {
694
require(owner != address(0), 'BEP20: approve from the zero address');
695
require(spender != address(0), 'BEP20: approve to the zero address');
696
697
_allowances[owner][spender] = amount;
698
emit Approval(owner, spender, amount);
699
}
700
701
/**
702
* @dev Destroys `amount` tokens from `account`.`amount` is then deducted
703
* from the caller's allowance.
704
*
705
* See {_burn} and {_approve}.
706
*/
707
function _burnFrom(address account, uint256 amount) internal {
708
_burn(account, amount);
709
_approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, 'BEP20: burn amount exceeds allowance'));
710
}
711
}
712
713
// WDEFIToken
714
contract WDEFIToken is BEP20('Woonkly Defi', 'wDEFI', 18), MinterRole {
715
716
function approve(address owner, address spender, uint256 amount) public onlyOwner {
717
_approve(owner, spender, amount);
718
}
719
720
/// @notice Creates `_amount` token to `_to`. Must only be called by the owner.
721
function mint(address _to, uint256 _amount) public onlyMinter {
722
_mint(_to, _amount);
723
}
724
725
/// @notice Bunrs `_amount` token fromo `_from`. Must only be called by the owner.
726
function burn(address _from, uint256 _amount) public onlyOwner {
727
_burn(_from, _amount);
728
}
729
730
/// @notice Presale `_amount` token to `_to`. Must only be called by the minter.
731
function presale(address _to, uint256 _amount) public onlyMinter {
732
_transfer(address(this), _to, _amount);
733
}
734
}
Copied!
Última actualización 7mo ago