-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73b1083
commit 0207992
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/interfaces/IERC20.sol"; | ||
|
||
contract ERC20Base is IERC20 { | ||
string public name = "ERC20Token"; | ||
string public symbol = "ERC"; | ||
uint8 public decimals = 18; | ||
|
||
uint256 public totalSupply; | ||
mapping(address => uint256) public balanceOf; | ||
mapping(address => mapping(address => uint256)) public allowance; | ||
|
||
function approve(address spender, uint256 amount) public returns (bool) { | ||
_approve(msg.sender, spender, amount); | ||
return true; | ||
} | ||
|
||
function _approve(address owner, address spender, uint256 amount) internal virtual { | ||
require(owner != address(0), "ERC20: approve from the zero address"); | ||
require(spender != address(0), "ERC20: approve to the zero address"); | ||
|
||
allowance[owner][spender] = amount; | ||
emit Approval(owner, spender, amount); | ||
} | ||
|
||
function transfer(address to, uint256 amount) public virtual returns (bool) { | ||
_transfer(msg.sender, to, amount); | ||
return true; | ||
} | ||
|
||
function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) { | ||
_transfer(from, to, amount); | ||
_approve(from, msg.sender, allowance[from][msg.sender] - amount); | ||
return true; | ||
} | ||
|
||
function _transfer(address sender, address recipient, uint256 amount) internal { | ||
require(sender != address(0), "ERC20: transfer from the zero address"); | ||
require(recipient != address(0), "ERC20: transfer to the zero address"); | ||
require(balanceOf[sender] >= amount, "ERC20: insufficient balance"); | ||
|
||
balanceOf[sender] -= amount; | ||
balanceOf[recipient] += amount; | ||
|
||
emit Transfer(sender, recipient, amount); | ||
} | ||
} |