Skip to content

Instantly share code, notes, and snippets.

@z0r0z
Last active July 10, 2023 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z0r0z/45b80bb1c80e0929dd9c63af210398de to your computer and use it in GitHub Desktop.
Save z0r0z/45b80bb1c80e0929dd9c63af210398de to your computer and use it in GitHub Desktop.
ERC223-like token for discussion in Final standard process.
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @dev ERC223ish
/// @author z0r0z
contract ERC223ish {
event Approval(address indexed from, address indexed to, uint amt);
event Transfer(address indexed from, address indexed to, uint amt);
event Transfer(address indexed from, address indexed to, uint amt, bytes data);
// STORAGE
mapping(address from => mapping(address to => uint)) public allowance;
mapping(address from => uint) public balanceOf;
uint public totalSupply;
// METADATA
string public name = 'Test Token';
string public symbol = 'TEST';
uint public constant decimals = 18;
// CREATION
constructor() payable {
emit Transfer(address(0), msg.sender, totalSupply = balanceOf[msg.sender] = 999 ether);
}
// LOGIC
function approve(address to, uint amt)
public
payable
virtual
returns (bool)
{
allowance[msg.sender][to] = amt;
emit Approval(msg.sender, to, amt);
return true;
}
function transfer(address to, uint amt)
public
payable
virtual
returns (bool)
{
return transferFrom(msg.sender, to, amt);
}
function transfer(address to, uint amt, bytes calldata data)
public
payable
virtual
returns (bool)
{
return transferFrom(msg.sender, to, amt, data);
}
function transferFrom(address from, address to, uint amt)
public
payable
virtual
returns (bool)
{
if (msg.sender != from)
if (allowance[from][msg.sender] != type(uint).max)
allowance[from][msg.sender] -= amt;
balanceOf[from] -= amt;
unchecked {
balanceOf[to] += amt;
}
emit Transfer(from, to, amt);
return true;
}
function transferFrom(address from, address to, uint amt, bytes calldata data)
public
payable
virtual
returns (bool success)
{
if (msg.sender != from)
if (allowance[from][msg.sender] != type(uint).max)
allowance[from][msg.sender] -= amt;
balanceOf[from] -= amt;
unchecked {
balanceOf[to] += amt;
}
emit Transfer(from, to, amt, data);
(success,) = to.call(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment