Skip to content

Instantly share code, notes, and snippets.

@DanielVF
Last active February 7, 2023 21:25
Show Gist options
  • Save DanielVF/ab8e083539da1e162a442dbe9cef5b16 to your computer and use it in GitHub Desktop.
Save DanielVF/ab8e083539da1e162a442dbe9cef5b16 to your computer and use it in GitHub Desktop.
Event Only Cursed ERC20
pragma solidity >=0.8.17;
// Cursed ERC20 that does everything in events.
// by @danielvf, based solmate by @transmissions11
abstract contract ERC20 {
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
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;
constructor(string memory _name, string memory _symbol, uint8 _decimals) {
name = _name;
symbol = _symbol;
decimals = _decimals;
}
/*//////////////////////////////////////////////////////////////
Here begins the good stuff
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 amount) public virtual returns (bool) {
emit Approval(msg.sender, spender, allowance[msg.sender][spender]=amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
emit Transfer(
msg.sender,
(balanceOf[to]+=amount)>0?to:to,
(balanceOf[msg.sender]-=amount)>0?amount:amount
);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
emit Transfer(
(balanceOf[to]+=amount)>0?from:from,
(balanceOf[from]-=amount)>0?to:to,
(
(allowance[from][msg.sender]!=type(uint256).max)
? (allowance[from][msg.sender]=allowance[from][msg.sender]-amount)
: 0
)>0?amount:amount
);
return true;
}
}
@iFrostizz
Copy link

my eyes are bleeding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment