ERC20WrapperUpgradeable
Inherits: Initializable, ERC20Upgradeable
Extension of the ERC-20 token contract to support token wrapping. Users can deposit and withdraw "underlying tokens" and receive a matching number of "wrapped tokens". This is useful in conjunction with other modules. For example, combining this wrapping mechanism with {ERC20Votes} will allow the wrapping of an existing "basic" ERC-20 into a governance token. WARNING: Any mechanism in which the underlying token changes the {balanceOf} of an account without an explicit transfer may desynchronize this contract's supply and its underlying balance. Please exercise caution when wrapping tokens that may undercollateralize the wrapper (i.e. wrapper's total supply is higher than its underlying balance). See {_recover} for recovering value accrued to the wrapper.
State Variables
ERC20WrapperStorageLocation
bytes32 private constant ERC20WrapperStorageLocation =
0x3b5a617e0d4c238430871a64fe18212794b0c8d05a4eac064a8c9039fb5e0700;
Functions
_getERC20WrapperStorage
function _getERC20WrapperStorage() private pure returns (ERC20WrapperStorage storage $);
__ERC20Wrapper_init
function __ERC20Wrapper_init(IERC20 underlyingToken) internal onlyInitializing;
__ERC20Wrapper_init_unchained
function __ERC20Wrapper_init_unchained(IERC20 underlyingToken) internal onlyInitializing;
decimals
Returns the decimals places of the token.
function decimals() public view virtual override returns (uint8);
underlying
Returns the address of the underlying ERC-20 token that is being wrapped.
function underlying() public view returns (IERC20);
depositFor
Allow a user to deposit underlying tokens and mint the corresponding number of wrapped tokens.
function depositFor(address account, uint256 value) public virtual returns (bool);
withdrawTo
Allow a user to burn a number of wrapped tokens and withdraw the corresponding number of underlying tokens.
function withdrawTo(address account, uint256 value) public virtual returns (bool);
_recover
Mint wrapped token to cover any underlyingTokens that would have been transferred by mistake or acquired from rebasing mechanisms. Internal function that can be exposed with access control if desired.
function _recover(address account) internal virtual returns (uint256);
Errors
ERC20InvalidUnderlying
The underlying token couldn't be wrapped.
error ERC20InvalidUnderlying(address token);
Structs
ERC20WrapperStorage
Note: storage-location: erc7201:openzeppelin.storage.ERC20Wrapper
struct ERC20WrapperStorage {
IERC20 _underlying;
}