Skip to content

feat: clearer error message for arithmetic underflow #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
24 changes: 16 additions & 8 deletions contracts/fun/FERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,12 @@ contract FERC20 is Context, IERC20, Ownable {
address recipient,
uint256 amount
) public override returns (bool) {
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");

_transfer(sender, recipient, amount);

_approve(
sender,
_msgSender(),
_allowances[sender][_msgSender()] - amount
);
_approve(sender, _msgSender(), currentAllowance - amount);

return true;
}
Expand All @@ -122,12 +121,15 @@ contract FERC20 is Context, IERC20, Ownable {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
require(_balances[from] >= amount, "ERC20: transfer amount exceeds balance");

if (!isExcludedFromMaxTx[from]) {
require(amount <= _maxTxAmount, "Exceeds MaxTx");
}

_balances[from] = _balances[from] - amount;
unchecked {
_balances[from] = _balances[from] - amount;
}
_balances[to] = _balances[to] + amount;

emit Transfer(from, to, amount);
Expand Down Expand Up @@ -155,12 +157,18 @@ contract FERC20 is Context, IERC20, Ownable {

function _burn(address user, uint256 amount) internal {
require(user != address(0), "Invalid address");
_balances[user] = _balances[user] - amount;
require(_balances[user] >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[user] = _balances[user] - amount;
}
}

function burnFrom(address user, uint256 amount) public onlyOwner {
require(user != address(0), "Invalid address");
_balances[user] = _balances[user] - amount;
require(_balances[user] >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[user] = _balances[user] - amount;
}
emit Transfer(user, address(0), amount);
}
}