59 lines
1.9 KiB
Solidity
59 lines
1.9 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.20;
|
|
|
|
/// @dev Minimal ERC20 for testing. No external imports so it compiles inside the
|
|
/// junction tree without needing node_modules packages.
|
|
contract MockERC20 {
|
|
string public name;
|
|
string public symbol;
|
|
uint8 public immutable decimals;
|
|
|
|
uint256 public totalSupply;
|
|
|
|
mapping(address => uint256) public balanceOf;
|
|
mapping(address => mapping(address => uint256)) public allowance;
|
|
|
|
event Transfer(address indexed from, address indexed to, uint256 amount);
|
|
event Approval(address indexed owner, address indexed spender, uint256 amount);
|
|
|
|
constructor(string memory name_, string memory symbol_, uint8 decimals_) {
|
|
name = name_;
|
|
symbol = symbol_;
|
|
decimals = decimals_;
|
|
}
|
|
|
|
function mint(address to, uint256 amount) external {
|
|
totalSupply += amount;
|
|
balanceOf[to] += amount;
|
|
emit Transfer(address(0), to, amount);
|
|
}
|
|
|
|
function approve(address spender, uint256 amount) external returns (bool) {
|
|
allowance[msg.sender][spender] = amount;
|
|
emit Approval(msg.sender, spender, amount);
|
|
return true;
|
|
}
|
|
|
|
function transfer(address to, uint256 amount) external returns (bool) {
|
|
_transfer(msg.sender, to, amount);
|
|
return true;
|
|
}
|
|
|
|
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
|
|
uint256 allowed = allowance[from][msg.sender];
|
|
if (allowed != type(uint256).max) {
|
|
require(allowed >= amount, "MockERC20: insufficient allowance");
|
|
allowance[from][msg.sender] = allowed - amount;
|
|
}
|
|
_transfer(from, to, amount);
|
|
return true;
|
|
}
|
|
|
|
function _transfer(address from, address to, uint256 amount) internal {
|
|
require(balanceOf[from] >= amount, "MockERC20: insufficient balance");
|
|
balanceOf[from] -= amount;
|
|
balanceOf[to] += amount;
|
|
emit Transfer(from, to, amount);
|
|
}
|
|
}
|