Skip to content

Commit

Permalink
mocks: add erc20 base token
Browse files Browse the repository at this point in the history
  • Loading branch information
arbazkiraak committed Nov 28, 2023
1 parent 73b1083 commit 0207992
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/mocks/tokens/base/ERC20Base.sol
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);
}
}

0 comments on commit 0207992

Please sign in to comment.