|
| 1 | +// SPDX-License-Identifier: -- 🔮 -- |
| 2 | + |
| 3 | +pragma solidity ^0.8.0; |
| 4 | + |
| 5 | +contract Token { |
| 6 | + |
| 7 | + mapping (address => uint256) private _balances; |
| 8 | + mapping (address => mapping (address => uint256)) private _allowances; |
| 9 | + |
| 10 | + uint256 private _totalSupply; |
| 11 | + |
| 12 | + string private _name; |
| 13 | + string private _symbol; |
| 14 | + uint8 private _decimals; |
| 15 | + |
| 16 | + event Transfer(address indexed from, address indexed to, uint256 value); |
| 17 | + event Approval(address indexed owner, address indexed spender, uint256 value); |
| 18 | + |
| 19 | + constructor () { |
| 20 | + _name = "Token"; |
| 21 | + _symbol = "TKN"; |
| 22 | + _decimals = 18; |
| 23 | + |
| 24 | + _totalSupply = 1000000000000000000000000; |
| 25 | + _balances[msg.sender] = _totalSupply; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * @dev Returns the name of the token. |
| 30 | + */ |
| 31 | + function name() public view returns (string memory) { |
| 32 | + return _name; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @dev Returns the symbol of the token, usually a shorter version of the |
| 37 | + * name. |
| 38 | + */ |
| 39 | + function symbol() public view returns (string memory) { |
| 40 | + return _symbol; |
| 41 | + } |
| 42 | + |
| 43 | + function decimals() public view returns (uint8) { |
| 44 | + return _decimals; |
| 45 | + } |
| 46 | + |
| 47 | + function totalSupply() public view returns (uint256) { |
| 48 | + return _totalSupply; |
| 49 | + } |
| 50 | + |
| 51 | + function balanceOf(address account) public view returns (uint256) { |
| 52 | + return _balances[account]; |
| 53 | + } |
| 54 | + |
| 55 | + function transfer( |
| 56 | + address recipient, |
| 57 | + uint256 amount |
| 58 | + ) public returns (bool) { |
| 59 | + _transfer(_msgSender(), recipient, amount); |
| 60 | + return true; |
| 61 | + } |
| 62 | + |
| 63 | + function allowance( |
| 64 | + address owner, |
| 65 | + address spender |
| 66 | + ) public view returns (uint256) { |
| 67 | + return _allowances[owner][spender]; |
| 68 | + } |
| 69 | + |
| 70 | + function approve( |
| 71 | + address spender, |
| 72 | + uint256 amount |
| 73 | + ) public returns (bool) { |
| 74 | + _approve(_msgSender(), spender, amount); |
| 75 | + return true; |
| 76 | + } |
| 77 | + |
| 78 | + function transferFrom( |
| 79 | + address sender, |
| 80 | + address recipient, |
| 81 | + uint256 amount |
| 82 | + ) public returns (bool) { |
| 83 | + _approve( |
| 84 | + sender, |
| 85 | + _msgSender(), |
| 86 | + _allowances[sender][_msgSender()] - amount |
| 87 | + ); |
| 88 | + _transfer(sender, recipient, amount); |
| 89 | + return true; |
| 90 | + } |
| 91 | + |
| 92 | + function increaseAllowance( |
| 93 | + address spender, |
| 94 | + uint256 addedValue |
| 95 | + ) public virtual returns (bool) { |
| 96 | + _approve( |
| 97 | + _msgSender(), |
| 98 | + spender, |
| 99 | + _allowances[_msgSender()][spender] + addedValue |
| 100 | + ); |
| 101 | + return true; |
| 102 | + } |
| 103 | + |
| 104 | + function decreaseAllowance( |
| 105 | + address spender, |
| 106 | + uint256 subtractedValue |
| 107 | + ) public virtual returns (bool) { |
| 108 | + _approve( |
| 109 | + _msgSender(), spender, _allowances[_msgSender()][spender] - subtractedValue |
| 110 | + ); |
| 111 | + return true; |
| 112 | + } |
| 113 | + |
| 114 | + function _transfer( |
| 115 | + address sender, |
| 116 | + address recipient, |
| 117 | + uint256 amount |
| 118 | + ) |
| 119 | + internal |
| 120 | + virtual |
| 121 | + { |
| 122 | + require( |
| 123 | + sender != address(0), |
| 124 | + "ERC20: transfer from the zero address" |
| 125 | + ); |
| 126 | + |
| 127 | + require( |
| 128 | + recipient != address(0), |
| 129 | + "ERC20: transfer to the zero address" |
| 130 | + ); |
| 131 | + |
| 132 | + _balances[sender] = |
| 133 | + _balances[sender] - amount; |
| 134 | + |
| 135 | + _balances[recipient] = |
| 136 | + _balances[recipient] + amount; |
| 137 | + |
| 138 | + emit Transfer(sender, recipient, amount); |
| 139 | + } |
| 140 | + |
| 141 | + function _approve( |
| 142 | + address owner, |
| 143 | + address spender, |
| 144 | + uint256 amount |
| 145 | + ) |
| 146 | + internal |
| 147 | + virtual |
| 148 | + { |
| 149 | + require( |
| 150 | + owner != address(0x0), |
| 151 | + "ERC20: approve from the zero address" |
| 152 | + ); |
| 153 | + |
| 154 | + require( |
| 155 | + spender != address(0x0), |
| 156 | + "ERC20: approve to the zero address" |
| 157 | + ); |
| 158 | + |
| 159 | + _allowances[owner][spender] = amount; |
| 160 | + emit Approval(owner, spender, amount); |
| 161 | + } |
| 162 | + |
| 163 | + function _msgSender() internal view virtual returns (address payable) { |
| 164 | + return payable(msg.sender); |
| 165 | + } |
| 166 | + |
| 167 | + function _msgData() internal view virtual returns (bytes memory) { |
| 168 | + this; |
| 169 | + return msg.data; |
| 170 | + } |
| 171 | +} |
0 commit comments