-
Notifications
You must be signed in to change notification settings - Fork 36
/
StokenERC20.sol
62 lines (55 loc) · 2.04 KB
/
StokenERC20.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
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract StokenERC20 is IERC20 {
mapping(address => uint256) public override balanceOf;
mapping(address => mapping(address => uint256)) public override allowance;
uint256 public immutable override totalSupply;
string public constant name = "STOKEN";
string public constant symbol = "SETH";
uint8 public constant decimals = 18;
constructor(uint256 _totalSupply) {
totalSupply = _totalSupply;
balanceOf[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
function transfer(address _to, uint256 _value) public override returns (bool) {
unchecked {
if (balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]) {
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
} else {
return false;
}
}
}
function transferFrom(
address _from,
address _to,
uint256 _value
) public override returns (bool) {
unchecked {
if (
balanceOf[_from] >= _value &&
allowance[_from][msg.sender] >= _value &&
balanceOf[_to] + _value >= balanceOf[_to]
) {
balanceOf[_to] += _value;
balanceOf[_from] -= _value;
emit Transfer(_from, _to, _value);
allowance[_from][msg.sender] -= _value;
emit Approval(_from, msg.sender, allowance[_from][msg.sender]);
return true;
} else {
return false;
}
}
}
function approve(address _spender, uint256 _value) public override returns (bool) {
allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
}