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

Bugfix: ERC20Wrapper underlying variable is public #1

Merged
merged 2 commits into from
Feb 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions contracts/token/ERC20/extensions/ERC20Wrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,35 @@ 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();
}
}

/**
* @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.
*/
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;
}
Expand All @@ -47,7 +54,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;
}

Expand All @@ -56,7 +63,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;
}
Expand Down