|
| 1 | +//SPDX-License-Identifier: UNLICENSED |
| 2 | + |
| 3 | +pragma solidity ^0.8.1; |
| 4 | + |
| 5 | +contract Ownable { |
| 6 | + address private _owner; |
| 7 | + |
| 8 | + constructor() { |
| 9 | + _owner = msg.sender; |
| 10 | + } |
| 11 | + |
| 12 | + modifier onlyOwner() { |
| 13 | + require(isOwner(), "Ownable: caller is not the owner"); |
| 14 | + _; |
| 15 | + } |
| 16 | + |
| 17 | + function owner() public view returns (address) { |
| 18 | + return _owner; |
| 19 | + } |
| 20 | + |
| 21 | + function isOwner() public view returns (bool) { |
| 22 | + return msg.sender == _owner; |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +library SafeMath { |
| 27 | + function mul(uint256 a, uint256 b) internal pure returns (uint256) { |
| 28 | + if (a == 0) { |
| 29 | + return 0; |
| 30 | + } |
| 31 | + |
| 32 | + uint256 c = a * b; |
| 33 | + assert(c / a == b); |
| 34 | + return c; |
| 35 | + } |
| 36 | + |
| 37 | + function div(uint256 a, uint256 b) internal pure returns (uint256) { |
| 38 | + uint256 c = a / b; |
| 39 | + return c; |
| 40 | + } |
| 41 | + |
| 42 | + function sub(uint256 a, uint256 b) internal pure returns (uint256) { |
| 43 | + assert(b <= a); |
| 44 | + return a - b; |
| 45 | + } |
| 46 | + |
| 47 | + function add(uint256 a, uint256 b) internal pure returns (uint256) { |
| 48 | + uint256 c = a + b; |
| 49 | + assert(c >= a); |
| 50 | + return c; |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +contract Pausable is Ownable { |
| 55 | + event Paused(address account); |
| 56 | + event Unpaused(address account); |
| 57 | + |
| 58 | + bool private _paused; |
| 59 | + |
| 60 | + modifier whenNotPaused() { |
| 61 | + require(!_paused, "Pausable: paused"); |
| 62 | + _; |
| 63 | + } |
| 64 | + |
| 65 | + modifier whenPaused() { |
| 66 | + require(_paused, "Pausable: not paused"); |
| 67 | + _; |
| 68 | + } |
| 69 | + |
| 70 | + function paused() public view returns (bool) |
| 71 | + { |
| 72 | + return _paused; |
| 73 | + } |
| 74 | + |
| 75 | + function pause() public onlyOwner whenNotPaused { |
| 76 | + _paused = true; |
| 77 | + emit Paused(msg.sender); |
| 78 | + } |
| 79 | + |
| 80 | + function unpause() public onlyOwner whenPaused { |
| 81 | + _paused = false; |
| 82 | + emit Unpaused(msg.sender); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +contract ERC20 is Ownable, Pausable { |
| 87 | + using SafeMath for uint; |
| 88 | + |
| 89 | + string internal _name; |
| 90 | + string internal _symbol; |
| 91 | + uint8 internal _decimals; |
| 92 | + uint256 internal _totalSupply; |
| 93 | + |
| 94 | + mapping (address => uint256) internal _balances; |
| 95 | + mapping (address => mapping (address => uint256)) internal _allowed; |
| 96 | + |
| 97 | + event Mint(address indexed minter, address indexed account, uint256 amount); |
| 98 | + event Burn(address indexed burner, address indexed account, uint256 amount); |
| 99 | + |
| 100 | + constructor (string memory nameC, string memory symbolC, uint8 decimalsC, uint256 totalSupplyC) { |
| 101 | + _symbol = symbolC; |
| 102 | + _name = nameC; |
| 103 | + _decimals = decimalsC; |
| 104 | + _totalSupply = totalSupplyC; |
| 105 | + _balances[msg.sender] = totalSupplyC; |
| 106 | + } |
| 107 | + |
| 108 | + function name() public view returns (string memory) { |
| 109 | + return _name; |
| 110 | + } |
| 111 | + |
| 112 | + function symbol() public view returns (string memory) { |
| 113 | + return _symbol; |
| 114 | + } |
| 115 | + |
| 116 | + function decimals() public view returns (uint8) { |
| 117 | + return _decimals; |
| 118 | + } |
| 119 | + |
| 120 | + function totalSupply() public view returns (uint256) { |
| 121 | + return _totalSupply; |
| 122 | + } |
| 123 | + |
| 124 | + function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { |
| 125 | + require(_to != address(0), 'ERC20: to address is not valid'); |
| 126 | + require(_value <= _balances[msg.sender], 'ERC20: insufficient balance'); |
| 127 | + |
| 128 | + _balances[msg.sender] = SafeMath.sub(_balances[msg.sender], _value); |
| 129 | + _balances[_to] = SafeMath.add(_balances[_to], _value); |
| 130 | + |
| 131 | + emit Transfer(msg.sender, _to, _value); |
| 132 | + |
| 133 | + return true; |
| 134 | + } |
| 135 | + |
| 136 | + function balanceOf(address _owner) public view returns (uint256 balance) { |
| 137 | + return _balances[_owner]; |
| 138 | + } |
| 139 | + |
| 140 | + function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) { |
| 141 | + _allowed[msg.sender][_spender] = _value; |
| 142 | + |
| 143 | + emit Approval(msg.sender, _spender, _value); |
| 144 | + |
| 145 | + return true; |
| 146 | + } |
| 147 | + |
| 148 | + function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { |
| 149 | + require(_from != address(0), 'ERC20: from address is not valid'); |
| 150 | + require(_to != address(0), 'ERC20: to address is not valid'); |
| 151 | + require(_value <= _balances[_from], 'ERC20: insufficient balance'); |
| 152 | + require(_value <= _allowed[_from][msg.sender], 'ERC20: from not allowed'); |
| 153 | + |
| 154 | + _balances[_from] = SafeMath.sub(_balances[_from], _value); |
| 155 | + _balances[_to] = SafeMath.add(_balances[_to], _value); |
| 156 | + _allowed[_from][msg.sender] = SafeMath.sub(_allowed[_from][msg.sender], _value); |
| 157 | + |
| 158 | + emit Transfer(_from, _to, _value); |
| 159 | + |
| 160 | + return true; |
| 161 | + } |
| 162 | + |
| 163 | + function allowance(address _owner, address _spender) public view whenNotPaused returns (uint256) { |
| 164 | + return _allowed[_owner][_spender]; |
| 165 | + } |
| 166 | + |
| 167 | + function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool) { |
| 168 | + _allowed[msg.sender][_spender] = SafeMath.add(_allowed[msg.sender][_spender], _addedValue); |
| 169 | + |
| 170 | + emit Approval(msg.sender, _spender, _allowed[msg.sender][_spender]); |
| 171 | + |
| 172 | + return true; |
| 173 | + } |
| 174 | + |
| 175 | + function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool) { |
| 176 | + uint oldValue = _allowed[msg.sender][_spender]; |
| 177 | + |
| 178 | + if (_subtractedValue > oldValue) { |
| 179 | + _allowed[msg.sender][_spender] = 0; |
| 180 | + } else { |
| 181 | + _allowed[msg.sender][_spender] = SafeMath.sub(oldValue, _subtractedValue); |
| 182 | + } |
| 183 | + |
| 184 | + emit Approval(msg.sender, _spender, _allowed[msg.sender][_spender]); |
| 185 | + |
| 186 | + return true; |
| 187 | + } |
| 188 | + |
| 189 | + function mintTo(address _to, uint _amount) public whenNotPaused onlyOwner { |
| 190 | + require(_to != address(0), 'ERC20: to address is not valid'); |
| 191 | + require(_amount > 0, 'ERC20: amount is not valid'); |
| 192 | + |
| 193 | + _totalSupply = _totalSupply.add(_amount); |
| 194 | + _balances[_to] = _balances[_to].add(_amount); |
| 195 | + |
| 196 | + emit Mint(msg.sender, _to, _amount); |
| 197 | + } |
| 198 | + |
| 199 | + function burnFrom(address _from, uint _amount) public whenNotPaused onlyOwner { |
| 200 | + require(_from != address(0), 'ERC20: from address is not valid'); |
| 201 | + require(_balances[_from] >= _amount, 'ERC20: insufficient balance'); |
| 202 | + |
| 203 | + _balances[_from] = _balances[_from].sub(_amount); |
| 204 | + _totalSupply = _totalSupply.sub(_amount); |
| 205 | + |
| 206 | + emit Burn(msg.sender, _from, _amount); |
| 207 | + } |
| 208 | + |
| 209 | + event Transfer(address indexed from, address indexed to, uint256 value); |
| 210 | + event Approval(address indexed owner, address indexed spender, uint256 value); |
| 211 | +} |
0 commit comments