ERC20WrapperLib
Title: ERC20WrapperLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Wrapper.sol)
Library implementing 1:1 wrapping of an underlying ERC-20. All logic lives here; the facet delegates.
WARNING: an underlying that changes balances without an explicit transfer (rebasing / fee-on-transfer) can desynchronise this wrapper's supply and its underlying balance; use recover to mint the surplus. Mints and burns call ERC20Lib directly: an ERC-20 movement-replacing extension (ERC20Pausable, ERC20Votes) does not see them, so the two are mutually exclusive (D25, #234).
Functions
erc20WrapperStorage
function erc20WrapperStorage() internal pure returns (ERC20WrapperStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | ERC20WrapperStorage |
__ERC20Wrapper_init
Initializes the wrapper with its underlying token.
Must be called inside a pre/postInitializer block. Reverts if underlying_ is the wrapper itself.
Caches the underlying's decimals() (default 18 on failure, per OZ) so decimals matches it.
function __ERC20Wrapper_init(address underlying_) internal;Parameters
| Name | Type | Description |
|---|---|---|
| underlying_ | address |
registerInterface
Registers support for the IERC20Wrapper interface via ERC-165.
function registerInterface() internal;underlying
The underlying ERC-20 token being wrapped.
function underlying() internal view returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
decimals
The wrapper's decimals — mirrors the underlying token's decimals.
function decimals() internal view returns (uint8);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint8 |
depositFor
Pulls value underlying from the caller and mints value wrapped tokens to account.
function depositFor(address account, uint256 value) internal returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| account | address | |
| value | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
withdrawTo
Burns value wrapped tokens from the caller and sends value underlying to account.
function withdrawTo(address account, uint256 value) internal returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| account | address | |
| value | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
recover
Mints wrapped tokens to account covering any underlying surplus (mis-sent / rebased in).
Internal — a facet exposing this MUST add access control. Not on the base ERC20Wrapper facet.
function recover(address account) internal returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| account | address |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
_safeTransfer
token.transfer(to, amount), reverting with SafeERC20FailedOperation. Handles no-bool tokens (USDT).
function _safeTransfer(address token, address to, uint256 amount) private;Parameters
| Name | Type | Description |
|---|---|---|
| token | address | |
| to | address | |
| amount | uint256 |
_safeTransferFrom
token.transferFrom(from, to, amount), reverting with SafeERC20FailedOperation. Handles USDT-likes.
function _safeTransferFrom(address token, address from, address to, uint256 amount) private;Parameters
| Name | Type | Description |
|---|---|---|
| token | address | |
| from | address | |
| to | address | |
| amount | uint256 |