forked from mico/idle_moloch
52 lines
1.6 KiB
Solidity
52 lines
1.6 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity 0.8.7;
|
|
|
|
/// @notice Basic ERC20 implementation.
|
|
contract TestERC20 {
|
|
string public name;
|
|
string public symbol;
|
|
uint8 public constant decimals = 18;
|
|
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, uint256 _totalSupply) {
|
|
name = _name;
|
|
symbol = _symbol;
|
|
totalSupply = _totalSupply;
|
|
balanceOf[msg.sender] = _totalSupply;
|
|
emit Transfer(address(0), msg.sender, _totalSupply);
|
|
}
|
|
|
|
function approve(address to, uint256 amount) external returns (bool) {
|
|
allowance[msg.sender][to] = amount;
|
|
emit Approval(msg.sender, to, amount);
|
|
return true;
|
|
}
|
|
|
|
function transfer(address to, uint256 amount) external returns (bool) {
|
|
balanceOf[msg.sender] -= amount;
|
|
balanceOf[to] += amount;
|
|
emit Transfer(msg.sender, to, amount);
|
|
return true;
|
|
}
|
|
|
|
function transferFrom(
|
|
address from,
|
|
address to,
|
|
uint256 amount
|
|
) external returns (bool) {
|
|
if (allowance[from][msg.sender] != type(uint256).max)
|
|
allowance[from][msg.sender] -= amount;
|
|
|
|
balanceOf[from] -= amount;
|
|
balanceOf[to] += amount;
|
|
emit Transfer(from, to, amount);
|
|
return true;
|
|
}
|
|
}
|