Unverified Commit b8ab7635 by Hadrien Croubois Committed by GitHub

Add IERC20Metadata with name, symbol and decimals (#2561)

Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
parent 78a98211
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
## Unreleased ## Unreleased
* `IERC20Metadata`: Add a new extended interface that includes the optional `name()`, `symbol()` and `decimals()` functions. ([#2561](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2561))
## Unreleased
* Now targeting the 0.8.x line of Solidity compilers. For 0.6.x (resp 0.7.x) support, use version 3.4.0 (resp 3.4.0-solc-0.7) of OpenZeppelin. * Now targeting the 0.8.x line of Solidity compilers. For 0.6.x (resp 0.7.x) support, use version 3.4.0 (resp 3.4.0-solc-0.7) of OpenZeppelin.
* `Context`: making `_msgData` return `bytes calldata` instead of `bytes memory` ([#2492](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2492)) * `Context`: making `_msgData` return `bytes calldata` instead of `bytes memory` ([#2492](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2492))
* `ERC20`: Removed the `_setDecimals` function and the storage slot associated to decimals. ([#2502](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2502)) * `ERC20`: Removed the `_setDecimals` function and the storage slot associated to decimals. ([#2502](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2502))
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./IERC20.sol"; import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol"; import "../../utils/Context.sol";
/** /**
...@@ -29,7 +30,7 @@ import "../../utils/Context.sol"; ...@@ -29,7 +30,7 @@ import "../../utils/Context.sol";
* functions have been added to mitigate the well-known issues around setting * functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}. * allowances. See {IERC20-approve}.
*/ */
contract ERC20 is Context, IERC20 { contract ERC20 is Context, IERC20, IERC20Metadata {
mapping (address => uint256) private _balances; mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances; mapping (address => mapping (address => uint256)) private _allowances;
...@@ -56,7 +57,7 @@ contract ERC20 is Context, IERC20 { ...@@ -56,7 +57,7 @@ contract ERC20 is Context, IERC20 {
/** /**
* @dev Returns the name of the token. * @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; return _name;
} }
...@@ -64,7 +65,7 @@ contract ERC20 is Context, IERC20 { ...@@ -64,7 +65,7 @@ contract ERC20 is Context, IERC20 {
* @dev Returns the symbol of the token, usually a shorter version of the * @dev Returns the symbol of the token, usually a shorter version of the
* name. * name.
*/ */
function symbol() public view virtual returns (string memory) { function symbol() public view virtual override returns (string memory) {
return _symbol; return _symbol;
} }
...@@ -81,7 +82,7 @@ contract ERC20 is Context, IERC20 { ...@@ -81,7 +82,7 @@ contract ERC20 is Context, IERC20 {
* no way affects any of the arithmetic of the contract, including * no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}. * {IERC20-balanceOf} and {IERC20-transfer}.
*/ */
function decimals() public view virtual returns (uint8) { function decimals() public view virtual override returns (uint8) {
return 18; return 18;
} }
......
...@@ -10,6 +10,7 @@ TIP: For an overview of ERC20 tokens and a walk through on how to create a token ...@@ -10,6 +10,7 @@ TIP: For an overview of ERC20 tokens and a walk through on how to create a token
There a few core contracts that implement the behavior specified in the EIP: There a few core contracts that implement the behavior specified in the EIP:
* {IERC20}: the interface all ERC20 implementations should conform to. * {IERC20}: the interface all ERC20 implementations should conform to.
* {IERC20Metadata}: the extended ERC20 interface including the <<ERC20-name,`name`>>, <<ERC20-symbol,`symbol`>> and <<ERC20-decimals,`decimals`>> functions.
* {ERC20}: the implementation of the ERC20 interface, including the <<ERC20-name,`name`>>, <<ERC20-symbol,`symbol`>> and <<ERC20-decimals,`decimals`>> optional standard extension to the base interface. * {ERC20}: the implementation of the ERC20 interface, including the <<ERC20-name,`name`>>, <<ERC20-symbol,`symbol`>> and <<ERC20-decimals,`decimals`>> optional standard extension to the base interface.
Additionally there are multiple custom extensions, including: Additionally there are multiple custom extensions, including:
...@@ -36,6 +37,8 @@ NOTE: This core set of contracts is designed to be unopinionated, allowing devel ...@@ -36,6 +37,8 @@ NOTE: This core set of contracts is designed to be unopinionated, allowing devel
{{IERC20}} {{IERC20}}
{{IERC20Metadata}}
{{ERC20}} {{ERC20}}
== Extensions == Extensions
......
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment