Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.
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
68 changes: 38 additions & 30 deletions contracts/open-zeppelin/ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import "./Address.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
* This implementation is agnostic to how tokens are created. This means
* a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism, see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* TIP: For a detailed write-up, see our guide:
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226 [How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* of returning `false` on failure. This behavior is conventional
* and does not conflict with the expectations of ERC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* by listening to these events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
Expand All @@ -46,7 +46,7 @@ contract ERC20 is Context, IERC20 {
uint8 private _decimals;

/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* @dev Sets the values for {name} and {symbol}, and initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
Expand All @@ -68,8 +68,7 @@ contract ERC20 is Context, IERC20 {
}

/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
* @dev Returns the symbol of the token, usually a shorter version of the name.
*/
function symbol() public view returns (string memory) {
return _symbol;
Expand All @@ -78,13 +77,13 @@ contract ERC20 is Context, IERC20 {
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* Ether and Wei. This is the value {ERC20} uses unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* NOTE: This information is only used for _display_ purposes; it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
Expand Down Expand Up @@ -142,7 +141,7 @@ contract ERC20 is Context, IERC20 {
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20};
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
Expand All @@ -152,7 +151,11 @@ contract ERC20 is Context, IERC20 {
*/
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
_approve(
sender,
_msgSender(),
_allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")
);
return true;
}

Expand Down Expand Up @@ -188,15 +191,19 @@ contract ERC20 is Context, IERC20 {
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")
);
return true;
}

/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
* @dev Moves `amount` tokens from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
* This internal function is equivalent to {transfer}, and can be used to
* e.g., implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
Expand All @@ -217,14 +224,15 @@ contract ERC20 is Context, IERC20 {
emit Transfer(sender, recipient, amount);
}

/** @dev Creates `amount` tokens and assigns them to `account`, increasing
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
* Requirements:
*
* - `to` cannot be the zero address.
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
Expand All @@ -242,7 +250,7 @@ contract ERC20 is Context, IERC20 {
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
Expand All @@ -258,10 +266,10 @@ contract ERC20 is Context, IERC20 {
}

/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
* @dev Sets `amount` as the allowance of `spender` over the `owner`'s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
* This internal function is equivalent to `approve`, and can be used to
* e.g., set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
Expand All @@ -279,7 +287,7 @@ contract ERC20 is Context, IERC20 {
}

/**
* @dev Sets {decimals} to a value other than the default one of 18.
* @dev Sets {decimals} to a value other than the default of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
Expand All @@ -296,12 +304,12 @@ contract ERC20 is Context, IERC20 {
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks [Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
}