Skip to content
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

Add IERC20Metadata with name, symbol and decimals #2561

Merged
merged 11 commits into from Mar 8, 2021
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,7 @@
* Rename `UpgradeableProxy` to `ERC1967Proxy`. ([#2547](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2547))
* `ERC777`: Optimize the gas costs of the constructor. ([#2551](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2551))
* `ERC721URIStorage`: Add a new extension that implements the `_setTokenURI` behavior as it was available in 3.4.0. ([#2555](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2555))
* `ERC20Metadata`: Add a new extended interface that includes the non standard `name()`, `symbol()` and `decimals()` functions. ([#2561](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2561))
Amxx marked this conversation as resolved.
Show resolved Hide resolved

### How to upgrade from 3.x

Expand Down
9 changes: 5 additions & 4 deletions contracts/token/ERC20/ERC20.sol
Expand Up @@ -3,6 +3,7 @@
pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
Expand All @@ -29,7 +30,7 @@ import "../../utils/Context.sol";
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20 {
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping (address => uint256) private _balances;

mapping (address => mapping (address => uint256)) private _allowances;
Expand All @@ -56,15 +57,15 @@ contract ERC20 is Context, IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
function name() public view virtual override returns (string memory) {
return _name;
}

/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
function symbol() public view virtual override returns (string memory) {
return _symbol;
}

Expand All @@ -81,7 +82,7 @@ contract ERC20 is Context, IERC20 {
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
function decimals() public view virtual override returns (uint8) {
return 18;
}

Expand Down
25 changes: 25 additions & 0 deletions contracts/token/ERC20/extensions/IERC20Metadata.sol
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
* @dev Interface of the ERC20 standard as defined in the EIP.
Amxx marked this conversation as resolved.
Show resolved Hide resolved
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the tokens.
Amxx marked this conversation as resolved.
Show resolved Hide resolved
*/
function name() external view returns (string memory);

/**
* @dev Returns the symbol of the tokens.
*/
function symbol() external view returns (string memory);

/**
* @dev Returns the decimals places of the tokens.
*/
function decimals() external view returns (uint8);
}