-
Notifications
You must be signed in to change notification settings - Fork 100
/
ERC20-bool.sol
43 lines (38 loc) · 1.44 KB
/
ERC20-bool.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
pragma solidity ^0.8.0;
import "forge-std/interfaces/IERC20.sol";
import {ERC20Base} from "./base/ERC20Base.sol";
contract ERC20Bool is ERC20Base {
constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _initialSupply) {
name = _name;
symbol = _symbol;
decimals = _decimals;
totalSupply = _initialSupply;
balanceOf[msg.sender] = _initialSupply;
emit Transfer(address(0), msg.sender, _initialSupply);
}
function transfer(address to, uint256 amount) public override returns (bool) {
if (balanceOf[msg.sender] >= amount && balanceOf[to] + amount >= balanceOf[to]) {
balanceOf[to] += amount;
balanceOf[msg.sender] -= amount;
emit Transfer(msg.sender, to, amount);
return true;
} else {
return false;
}
}
function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
if (
balanceOf[from] >= amount && allowance[from][msg.sender] >= amount
&& balanceOf[to] + amount >= balanceOf[to]
) {
balanceOf[to] += amount;
balanceOf[from] -= amount;
emit Transfer(from, to, amount);
allowance[from][msg.sender] -= amount;
emit Approval(from, msg.sender, allowance[from][msg.sender]);
return true;
} else {
return false;
}
}
}