From 706d2c1e816bb18c561e91fe53f4ea2e8330a058 Mon Sep 17 00:00:00 2001 From: Kimani Kelly Date: Sat, 4 Feb 2023 09:12:32 -0500 Subject: [PATCH 1/7] Refactoring the underlying variable Removed the public visibility from the underlying variable Refactored the underlying variable to _underlying --- contracts/token/ERC20/extensions/ERC20Wrapper.sol | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/token/ERC20/extensions/ERC20Wrapper.sol b/contracts/token/ERC20/extensions/ERC20Wrapper.sol index 8b153ffcabd..176faf938da 100644 --- a/contracts/token/ERC20/extensions/ERC20Wrapper.sol +++ b/contracts/token/ERC20/extensions/ERC20Wrapper.sol @@ -16,17 +16,17 @@ import "../utils/SafeERC20.sol"; * _Available since v4.2._ */ abstract contract ERC20Wrapper is ERC20 { - IERC20 public immutable underlying; + IERC20 immutable _underlying; constructor(IERC20 underlyingToken) { - underlying = underlyingToken; + _underlying = underlyingToken; } /** * @dev See {ERC20-decimals}. */ function decimals() public view virtual override returns (uint8) { - try IERC20Metadata(address(underlying)).decimals() returns (uint8 value) { + try IERC20Metadata(address(_underlying)).decimals() returns (uint8 value) { return value; } catch { return super.decimals(); @@ -37,7 +37,7 @@ abstract contract ERC20Wrapper is ERC20 { * @dev Allow a user to deposit underlying tokens and mint the corresponding number of wrapped tokens. */ function depositFor(address account, uint256 amount) public virtual returns (bool) { - SafeERC20.safeTransferFrom(underlying, _msgSender(), address(this), amount); + SafeERC20.safeTransferFrom(_underlying, _msgSender(), address(this), amount); _mint(account, amount); return true; } @@ -47,7 +47,7 @@ abstract contract ERC20Wrapper is ERC20 { */ function withdrawTo(address account, uint256 amount) public virtual returns (bool) { _burn(_msgSender(), amount); - SafeERC20.safeTransfer(underlying, account, amount); + SafeERC20.safeTransfer(_underlying, account, amount); return true; } @@ -56,7 +56,7 @@ abstract contract ERC20Wrapper is ERC20 { * function that can be exposed with access control if desired. */ function _recover(address account) internal virtual returns (uint256) { - uint256 value = underlying.balanceOf(address(this)) - totalSupply(); + uint256 value = _underlying.balanceOf(address(this)) - totalSupply(); _mint(account, value); return value; } From 54c7c0cf75adecee4a0262d7106b88eaf2159822 Mon Sep 17 00:00:00 2001 From: Kimani Kelly Date: Sat, 4 Feb 2023 09:23:38 -0500 Subject: [PATCH 2/7] Refactor ERC20Wrapper Implemented the underlying function to return the value of the _underlying variable --- contracts/token/ERC20/extensions/ERC20Wrapper.sol | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contracts/token/ERC20/extensions/ERC20Wrapper.sol b/contracts/token/ERC20/extensions/ERC20Wrapper.sol index 176faf938da..e1bb2ec2413 100644 --- a/contracts/token/ERC20/extensions/ERC20Wrapper.sol +++ b/contracts/token/ERC20/extensions/ERC20Wrapper.sol @@ -33,6 +33,13 @@ abstract contract ERC20Wrapper is ERC20 { } } + /** + * @dev Returns the address of the ERC-20 token deployed with ERC20Wrapper.sol + */ + function underlying() public view returns (IERC20) { + return _underlying; + } + /** * @dev Allow a user to deposit underlying tokens and mint the corresponding number of wrapped tokens. */ From dc38ed855d4136283f1234ce696a673cfd052652 Mon Sep 17 00:00:00 2001 From: Kimani Kelly Date: Sun, 5 Feb 2023 17:23:35 -0500 Subject: [PATCH 3/7] Execute the changeset command for 4.9 --- .changeset/proud-comics-deliver.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/proud-comics-deliver.md diff --git a/.changeset/proud-comics-deliver.md b/.changeset/proud-comics-deliver.md new file mode 100644 index 00000000000..04cd3d95078 --- /dev/null +++ b/.changeset/proud-comics-deliver.md @@ -0,0 +1,5 @@ +--- +'openzeppelin-solidity': minor +--- + +Bugfix for ERC20Wrapper underlying variable is public From ca302ea51acf2930f20726200d49c4891e013864 Mon Sep 17 00:00:00 2001 From: Kimani Kelly Date: Mon, 6 Feb 2023 07:25:57 -0500 Subject: [PATCH 4/7] Refactoring for PR Included the private visibility to the _underlying variable Pulled the latest changes --- contracts/token/ERC20/extensions/ERC20Wrapper.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/token/ERC20/extensions/ERC20Wrapper.sol b/contracts/token/ERC20/extensions/ERC20Wrapper.sol index e1bb2ec2413..46b615da372 100644 --- a/contracts/token/ERC20/extensions/ERC20Wrapper.sol +++ b/contracts/token/ERC20/extensions/ERC20Wrapper.sol @@ -16,7 +16,7 @@ import "../utils/SafeERC20.sol"; * _Available since v4.2._ */ abstract contract ERC20Wrapper is ERC20 { - IERC20 immutable _underlying; + IERC20 private immutable _underlying; constructor(IERC20 underlyingToken) { _underlying = underlyingToken; From d774436888425b21a1d541312cd1b70046c0437a Mon Sep 17 00:00:00 2001 From: Kimani Kelly Date: Mon, 6 Feb 2023 07:31:20 -0500 Subject: [PATCH 5/7] Refactored the changeset to describe the changes done --- .changeset/proud-comics-deliver.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/proud-comics-deliver.md b/.changeset/proud-comics-deliver.md index 04cd3d95078..4bb8f096b90 100644 --- a/.changeset/proud-comics-deliver.md +++ b/.changeset/proud-comics-deliver.md @@ -2,4 +2,4 @@ 'openzeppelin-solidity': minor --- -Bugfix for ERC20Wrapper underlying variable is public +Make the `underlying` variable private and add a public accessor. From 912723fbb205c63850dc0f1cd70d62766887365c Mon Sep 17 00:00:00 2001 From: Kimani Kelly Date: Mon, 6 Feb 2023 07:39:49 -0500 Subject: [PATCH 6/7] Include the ERC20Wrapper reference in the changeset --- .changeset/proud-comics-deliver.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/proud-comics-deliver.md b/.changeset/proud-comics-deliver.md index 4bb8f096b90..e9c1015f800 100644 --- a/.changeset/proud-comics-deliver.md +++ b/.changeset/proud-comics-deliver.md @@ -2,4 +2,4 @@ 'openzeppelin-solidity': minor --- -Make the `underlying` variable private and add a public accessor. +`ERC20Wrapper`: Make the `underlying` variable private and add a public accessor. From 55aa37559df1b3bbd99216ef09b1f06c4f93b084 Mon Sep 17 00:00:00 2001 From: Kimani Kelly Date: Mon, 6 Feb 2023 08:19:32 -0500 Subject: [PATCH 7/7] Refactored the dev comments for the underlying function --- contracts/token/ERC20/extensions/ERC20Wrapper.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/token/ERC20/extensions/ERC20Wrapper.sol b/contracts/token/ERC20/extensions/ERC20Wrapper.sol index 46b615da372..ce515693e7c 100644 --- a/contracts/token/ERC20/extensions/ERC20Wrapper.sol +++ b/contracts/token/ERC20/extensions/ERC20Wrapper.sol @@ -34,7 +34,7 @@ abstract contract ERC20Wrapper is ERC20 { } /** - * @dev Returns the address of the ERC-20 token deployed with ERC20Wrapper.sol + * @dev Returns the address of the underlying ERC-20 token that is being wrapped. */ function underlying() public view returns (IERC20) { return _underlying;