From 085f7bbc16cd89da85828a80090f0a393b85469c Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 4 Mar 2021 16:23:27 +0100 Subject: [PATCH 01/10] add IERC20Metadata with name, symbol and decimals --- contracts/token/ERC20/ERC20.sol | 9 ++++--- .../token/ERC20/extensions/IERC20Metadata.sol | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 contracts/token/ERC20/extensions/IERC20Metadata.sol diff --git a/contracts/token/ERC20/ERC20.sol b/contracts/token/ERC20/ERC20.sol index c92df85a10e..edb5778bd57 100644 --- a/contracts/token/ERC20/ERC20.sol +++ b/contracts/token/ERC20/ERC20.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.0; import "./IERC20.sol"; +import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** @@ -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; @@ -56,7 +57,7 @@ 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; } @@ -64,7 +65,7 @@ contract ERC20 is Context, IERC20 { * @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; } @@ -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; } diff --git a/contracts/token/ERC20/extensions/IERC20Metadata.sol b/contracts/token/ERC20/extensions/IERC20Metadata.sol new file mode 100644 index 00000000000..f666125e15f --- /dev/null +++ b/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. + */ +interface IERC20Metadata is IERC20 { + /** + * @dev Returns the name of the tokens. + */ + 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); +} From 0fcb384ca15e58fe9c12014fd1f10b41ba0f4ee4 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 4 Mar 2021 16:27:26 +0100 Subject: [PATCH 02/10] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86993639d92..ef17c3e96e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) ### How to upgrade from 3.x From c8a78660e36ac48541740c0121749f19eb062f30 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 4 Mar 2021 17:10:53 +0100 Subject: [PATCH 03/10] Update CHANGELOG.md Co-authored-by: Francisco Giordano --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef17c3e96e9..170b0273e21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +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)) + * `IERC20Metadata`: Add a new extended interface that includes the optional `name()`, `symbol()` and `decimals()` functions. ([#2561](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2561)) ### How to upgrade from 3.x From a6824873f101844d344e92c9039b6d385c4d0c0d Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 4 Mar 2021 17:11:00 +0100 Subject: [PATCH 04/10] Update contracts/token/ERC20/extensions/IERC20Metadata.sol Co-authored-by: Francisco Giordano --- contracts/token/ERC20/extensions/IERC20Metadata.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/token/ERC20/extensions/IERC20Metadata.sol b/contracts/token/ERC20/extensions/IERC20Metadata.sol index f666125e15f..a6c5cd933c9 100644 --- a/contracts/token/ERC20/extensions/IERC20Metadata.sol +++ b/contracts/token/ERC20/extensions/IERC20Metadata.sol @@ -5,7 +5,7 @@ pragma solidity ^0.8.0; import "../IERC20.sol"; /** - * @dev Interface of the ERC20 standard as defined in the EIP. + * @dev Interface for the optional metadata functions from the ERC20 standard. */ interface IERC20Metadata is IERC20 { /** From 53d5d51341477406cbee3722c210649ce15faf23 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 4 Mar 2021 17:14:00 +0100 Subject: [PATCH 05/10] address comments from PR --- contracts/token/ERC20/extensions/IERC20Metadata.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/token/ERC20/extensions/IERC20Metadata.sol b/contracts/token/ERC20/extensions/IERC20Metadata.sol index a6c5cd933c9..5bc7860695d 100644 --- a/contracts/token/ERC20/extensions/IERC20Metadata.sol +++ b/contracts/token/ERC20/extensions/IERC20Metadata.sol @@ -9,17 +9,17 @@ import "../IERC20.sol"; */ interface IERC20Metadata is IERC20 { /** - * @dev Returns the name of the tokens. + * @dev Returns the name of the token. */ function name() external view returns (string memory); /** - * @dev Returns the symbol of the tokens. + * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** - * @dev Returns the decimals places of the tokens. + * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); } From 171c135cdd8e2b6d521a164393d0c3c8d2354382 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 4 Mar 2021 17:23:23 +0100 Subject: [PATCH 06/10] Documentation update --- contracts/token/ERC20/README.adoc | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/token/ERC20/README.adoc b/contracts/token/ERC20/README.adoc index b8bfb00ca62..d63fa3f72d7 100644 --- a/contracts/token/ERC20/README.adoc +++ b/contracts/token/ERC20/README.adoc @@ -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: * {IERC20}: the interface all ERC20 implementations should conform to. +* {IERC20Metadata}: the extended ERC20 interface including the <>, <> and <> functions. * {ERC20}: the implementation of the ERC20 interface, including the <>, <> and <> optional standard extension to the base interface. Additionally there are multiple custom extensions, including: From 1e7d7a5be021724ad0386c56fe101a7a9b59561b Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 4 Mar 2021 17:51:14 +0100 Subject: [PATCH 07/10] rename to IERC20Extended --- CHANGELOG.md | 2 +- contracts/token/ERC20/ERC20.sol | 5 ++--- .../{extensions/IERC20Metadata.sol => IERC20Extended.sol} | 6 +++--- contracts/token/ERC20/README.adoc | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) rename contracts/token/ERC20/{extensions/IERC20Metadata.sol => IERC20Extended.sol} (75%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 170b0273e21..ba00aef7140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +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)) - * `IERC20Metadata`: Add a new extended interface that includes the optional `name()`, `symbol()` and `decimals()` functions. ([#2561](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2561)) + * `IERC20Extended`: Interface file for the extended ERC20 standard (that includes the optional `name()`, `symbol()` and `decimals()`). ([#2561](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2561)) ### How to upgrade from 3.x diff --git a/contracts/token/ERC20/ERC20.sol b/contracts/token/ERC20/ERC20.sol index edb5778bd57..e34b1cbdfc8 100644 --- a/contracts/token/ERC20/ERC20.sol +++ b/contracts/token/ERC20/ERC20.sol @@ -2,8 +2,7 @@ pragma solidity ^0.8.0; -import "./IERC20.sol"; -import "./extensions/IERC20Metadata.sol"; +import "./IERC20Extended.sol"; import "../../utils/Context.sol"; /** @@ -30,7 +29,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, IERC20Metadata { +contract ERC20 is Context, IERC20Extended { mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; diff --git a/contracts/token/ERC20/extensions/IERC20Metadata.sol b/contracts/token/ERC20/IERC20Extended.sol similarity index 75% rename from contracts/token/ERC20/extensions/IERC20Metadata.sol rename to contracts/token/ERC20/IERC20Extended.sol index 5bc7860695d..a49361b2701 100644 --- a/contracts/token/ERC20/extensions/IERC20Metadata.sol +++ b/contracts/token/ERC20/IERC20Extended.sol @@ -2,12 +2,12 @@ pragma solidity ^0.8.0; -import "../IERC20.sol"; +import "./IERC20.sol"; /** - * @dev Interface for the optional metadata functions from the ERC20 standard. + * @dev Interface of the extended ERC20 standard. */ -interface IERC20Metadata is IERC20 { +interface IERC20Extended is IERC20 { /** * @dev Returns the name of the token. */ diff --git a/contracts/token/ERC20/README.adoc b/contracts/token/ERC20/README.adoc index d63fa3f72d7..19aa74e45d1 100644 --- a/contracts/token/ERC20/README.adoc +++ b/contracts/token/ERC20/README.adoc @@ -10,7 +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: * {IERC20}: the interface all ERC20 implementations should conform to. -* {IERC20Metadata}: the extended ERC20 interface including the <>, <> and <> functions. +* {IERC20Extended}: the extended ERC20 interface including the <>, <> and <> functions. * {ERC20}: the implementation of the ERC20 interface, including the <>, <> and <> optional standard extension to the base interface. Additionally there are multiple custom extensions, including: From f82136df8ea355d43239a00082e951a02a14ea58 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 4 Mar 2021 17:51:14 +0100 Subject: [PATCH 08/10] Revert "rename to IERC20Extended" This reverts commit 1e7d7a5be021724ad0386c56fe101a7a9b59561b. --- CHANGELOG.md | 2 +- contracts/token/ERC20/ERC20.sol | 5 +++-- contracts/token/ERC20/README.adoc | 2 +- .../{IERC20Extended.sol => extensions/IERC20Metadata.sol} | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) rename contracts/token/ERC20/{IERC20Extended.sol => extensions/IERC20Metadata.sol} (75%) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba00aef7140..170b0273e21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +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)) - * `IERC20Extended`: Interface file for the extended ERC20 standard (that includes the optional `name()`, `symbol()` and `decimals()`). ([#2561](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2561)) + * `IERC20Metadata`: Add a new extended interface that includes the optional `name()`, `symbol()` and `decimals()` functions. ([#2561](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2561)) ### How to upgrade from 3.x diff --git a/contracts/token/ERC20/ERC20.sol b/contracts/token/ERC20/ERC20.sol index e34b1cbdfc8..edb5778bd57 100644 --- a/contracts/token/ERC20/ERC20.sol +++ b/contracts/token/ERC20/ERC20.sol @@ -2,7 +2,8 @@ pragma solidity ^0.8.0; -import "./IERC20Extended.sol"; +import "./IERC20.sol"; +import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** @@ -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, IERC20Extended { +contract ERC20 is Context, IERC20, IERC20Metadata { mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; diff --git a/contracts/token/ERC20/README.adoc b/contracts/token/ERC20/README.adoc index 19aa74e45d1..d63fa3f72d7 100644 --- a/contracts/token/ERC20/README.adoc +++ b/contracts/token/ERC20/README.adoc @@ -10,7 +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: * {IERC20}: the interface all ERC20 implementations should conform to. -* {IERC20Extended}: the extended ERC20 interface including the <>, <> and <> functions. +* {IERC20Metadata}: the extended ERC20 interface including the <>, <> and <> functions. * {ERC20}: the implementation of the ERC20 interface, including the <>, <> and <> optional standard extension to the base interface. Additionally there are multiple custom extensions, including: diff --git a/contracts/token/ERC20/IERC20Extended.sol b/contracts/token/ERC20/extensions/IERC20Metadata.sol similarity index 75% rename from contracts/token/ERC20/IERC20Extended.sol rename to contracts/token/ERC20/extensions/IERC20Metadata.sol index a49361b2701..5bc7860695d 100644 --- a/contracts/token/ERC20/IERC20Extended.sol +++ b/contracts/token/ERC20/extensions/IERC20Metadata.sol @@ -2,12 +2,12 @@ pragma solidity ^0.8.0; -import "./IERC20.sol"; +import "../IERC20.sol"; /** - * @dev Interface of the extended ERC20 standard. + * @dev Interface for the optional metadata functions from the ERC20 standard. */ -interface IERC20Extended is IERC20 { +interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ From 4206c59915a88f91808151eae2424a8e7225a8b5 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Thu, 4 Mar 2021 18:30:54 -0300 Subject: [PATCH 09/10] add new interface tod ocs --- contracts/token/ERC20/README.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/token/ERC20/README.adoc b/contracts/token/ERC20/README.adoc index d63fa3f72d7..223208c8b84 100644 --- a/contracts/token/ERC20/README.adoc +++ b/contracts/token/ERC20/README.adoc @@ -37,6 +37,8 @@ NOTE: This core set of contracts is designed to be unopinionated, allowing devel {{IERC20}} +{{IERC20Metadata}} + {{ERC20}} == Extensions From 62175c0bb87984d02cb98cf9615fb5eb7f1f5ab3 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Mon, 8 Mar 2021 16:45:45 -0300 Subject: [PATCH 10/10] separate changelog entry from 4.0 entries list --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06f817f0ea6..6473a6cb9a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 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. @@ -20,7 +24,6 @@ * `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)) * `AccessControl`: Added ERC165 interface detection. ([#2562](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2562)) * `AccessControlEnumerable`: Fixed `renounceRole` not updated underlying set. ([#2572](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2572)) - * `IERC20Metadata`: Add a new extended interface that includes the optional `name()`, `symbol()` and `decimals()` functions. ([#2561](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2561)) ### How to upgrade from 3.x