Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/tokens/ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,23 @@ abstract contract ERC20 {
return true;
}

function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;

// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
error InsufficientBalance();
error TransferToZeroAddress();

emit Transfer(msg.sender, to, amount);
function transfer(address to, uint256 amount) public returns (bool) {
if (balanceOf[msg.sender] < amount) revert InsufficientBalance();
if (to == address(0)) revert TransferToZeroAddress();

return true;
unchecked {
balanceOf[msg.sender] -= amount;
balanceOf[to] += amount;
}

emit Transfer(msg.sender, to, amount);
return true;
}


function transferFrom(
address from,
address to,
Expand Down