Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ERC20Wrapper

Inherits: ERC20

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

_underlying

IERC20 private immutable _underlying;

Functions

constructor

constructor(IERC20 underlyingToken);

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);