From 76723abfd7ec429cdd3b2a0e3e09667e925309e3 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 21 Jan 2021 14:14:03 +0100 Subject: [PATCH 1/6] Removing the storage associated with decimals --- contracts/mocks/ERC20DecimalsMock.sol | 10 ++++++++-- contracts/token/ERC20/ERC20.sol | 25 ++++++------------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/contracts/mocks/ERC20DecimalsMock.sol b/contracts/mocks/ERC20DecimalsMock.sol index 141daf758ab..ef48eb1da76 100644 --- a/contracts/mocks/ERC20DecimalsMock.sol +++ b/contracts/mocks/ERC20DecimalsMock.sol @@ -5,7 +5,13 @@ pragma solidity ^0.8.0; import "../token/ERC20/ERC20.sol"; contract ERC20DecimalsMock is ERC20 { - constructor (string memory name, string memory symbol, uint8 decimals) ERC20(name, symbol) { - _setupDecimals(decimals); + uint8 immutable private _decimals; + + constructor (string memory name_, string memory symbol_, uint8 decimals_) ERC20(name_, symbol_) { + _decimals = decimals_; + } + + function decimals() public view virtual override returns (uint8) { + return _decimals; } } diff --git a/contracts/token/ERC20/ERC20.sol b/contracts/token/ERC20/ERC20.sol index 03515b92c87..05f7d91ce09 100644 --- a/contracts/token/ERC20/ERC20.sol +++ b/contracts/token/ERC20/ERC20.sol @@ -38,13 +38,12 @@ contract ERC20 is Context, IERC20 { string private _name; string private _symbol; - uint8 private _decimals; /** - * @dev Sets the values for {name} and {symbol}, initializes {decimals} with - * a default value of 18. + * @dev Sets the values for {name} and {symbol} * - * To select a different value for {decimals}, use {_setupDecimals}. + * The defaut value of {decimals} is 18, to select a different value for + * {decimals} you should overload it. * * All three of these values are immutable: they can only be set once during * construction. @@ -52,7 +51,6 @@ contract ERC20 is Context, IERC20 { constructor (string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; - _decimals = 18; } /** @@ -76,15 +74,15 @@ contract ERC20 is Context, IERC20 { * 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 - * called. + * Ether and Wei. This is the value {ERC20} uses, unless this function is + * overloaded; * * 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}. */ function decimals() public view virtual returns (uint8) { - return _decimals; + return 18; } /** @@ -283,17 +281,6 @@ contract ERC20 is Context, IERC20 { emit Approval(owner, spender, amount); } - /** - * @dev Sets {decimals} to a value other than the default one of 18. - * - * WARNING: This function should only be called from the constructor. Most - * applications that interact with token contracts will not expect - * {decimals} to ever change, and may work incorrectly if it does. - */ - function _setupDecimals(uint8 decimals_) internal virtual { - _decimals = decimals_; - } - /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. From 183abc8b3a82e2cb659ac26970c0a77042404c17 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Mon, 1 Feb 2021 17:05:21 +0100 Subject: [PATCH 2/6] changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdc5834e927..2c07bbe729a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * 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)) +* `ERC20`: Removing the `_setDecimals` functions and the storage slot associated to decimals. ([#2495](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2495)) ## 3.4.0 (2021-02-02) From 0fdada1530c6278aee11606c397d63b01b25b2cd Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 3 Feb 2021 00:26:33 +0100 Subject: [PATCH 3/6] changelog link to new issue number --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c07bbe729a..a9956d701f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ * 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)) -* `ERC20`: Removing the `_setDecimals` functions and the storage slot associated to decimals. ([#2495](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2495)) +* `ERC20`: Removing the `_setDecimals` functions and the storage slot associated to decimals. ([#2502](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2502)) ## 3.4.0 (2021-02-02) From cb2fdde4e5869a8d02dd9ec0cfbfdab34120614c Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 4 Feb 2021 19:33:01 +0100 Subject: [PATCH 4/6] Update contracts/token/ERC20/ERC20.sol Co-authored-by: Francisco Giordano --- contracts/token/ERC20/ERC20.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/token/ERC20/ERC20.sol b/contracts/token/ERC20/ERC20.sol index 05f7d91ce09..4c37a4f61a8 100644 --- a/contracts/token/ERC20/ERC20.sol +++ b/contracts/token/ERC20/ERC20.sol @@ -42,7 +42,7 @@ contract ERC20 is Context, IERC20 { /** * @dev Sets the values for {name} and {symbol} * - * The defaut value of {decimals} is 18, to select a different value for + * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All three of these values are immutable: they can only be set once during From b228f4df509c7297012f7f495befff90a3b81315 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 4 Feb 2021 19:33:09 +0100 Subject: [PATCH 5/6] Update contracts/token/ERC20/ERC20.sol Co-authored-by: Francisco Giordano --- contracts/token/ERC20/ERC20.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/token/ERC20/ERC20.sol b/contracts/token/ERC20/ERC20.sol index 4c37a4f61a8..9d0c2825ee0 100644 --- a/contracts/token/ERC20/ERC20.sol +++ b/contracts/token/ERC20/ERC20.sol @@ -40,7 +40,7 @@ contract ERC20 is Context, IERC20 { string private _symbol; /** - * @dev Sets the values for {name} and {symbol} + * @dev Sets the values for {name} and {symbol}. * * The defaut value of {decimals} is 18. To select a different value for * {decimals} you should overload it. From f850e596fcea777845b9ffd77bf9af78121737c3 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 4 Feb 2021 19:33:17 +0100 Subject: [PATCH 6/6] 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 a9956d701f7..02dddae05a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ * 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)) -* `ERC20`: Removing the `_setDecimals` functions 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.4.0 (2021-02-02)