Skip to main content

GovernanceWrappedERC20

Description

Wraps an existing ERC-20 token by inheriting from ERC20WrapperUpgradeable and allows to use it for voting by inheriting from ERC20VotesUpgradeable. The latter is compatible with OpenZeppelin's Votes interface. The contract also supports meta transactions. To use an amount of underlying tokens for voting, the token owner has to

  1. call approve for the tokens to be used by this contract
  2. call depositFor to wrap them, which safely transfers the underlying ERC-20 tokens to the contract and mints wrapped ERC-20 tokens. To get the ERC-20 tokens back, the owner of the wrapped tokens can call withdrawFor, which burns the wrapped ERC-20 tokens and safely transfers the underlying tokens back to the owner.

This contract intentionally has no public mint functionality because this is the responsibility of the underlying ERC-20 token contract.

Implementation

public function constructor

Calls the initialize function.

constructor(contract IERC20Upgradeable _token, string _name, string _symbol) public
InputTypeDescription
_tokencontract IERC20UpgradeableThe underlying ERC-20 token.
_namestringThe name of the wrapped token.
_symbolstringThe symbol of the wrapped token.

public function initialize

Initializes the contract.

function initialize(contract IERC20Upgradeable _token, string _name, string _symbol) public
InputTypeDescription
_tokencontract IERC20UpgradeableThe underlying ERC-20 token.
_namestringThe name of the wrapped token.
_symbolstringThe symbol of the wrapped token.

public function supportsInterface

Checks if this or the parent contract supports an interface by its ID.

function supportsInterface(bytes4 _interfaceId) public view virtual returns (bool)
InputTypeDescription
_interfaceIdbytes4The ID of the interface.
Output
0boolReturns true if the interface is supported.

public function decimals

function decimals() public view returns (uint8)

Uses the decimals of the underlying ERC-20 token.

public function depositFor

Deposits an amount of underlying token and mints the corresponding number of wrapped tokens for a receiving address.

function depositFor(address account, uint256 amount) public returns (bool)
InputTypeDescription
accountaddressThe address receiving the minted, wrapped tokens.
amountuint256The amount of tokens to deposit.

public function withdrawTo

Withdraws an amount of underlying tokens to a receiving address and burns the corresponding number of wrapped tokens.

function withdrawTo(address account, uint256 amount) public returns (bool)
InputTypeDescription
accountaddressThe address receiving the withdrawn, underlying tokens.
amountuint256The amount of underlying tokens to withdraw.

internal function _afterTokenTransfer

function _afterTokenTransfer(address from, address to, uint256 amount) internal

*Move voting power when tokens are transferred.

Emits a {IVotes-DelegateVotesChanged} event.*

internal function _mint

function _mint(address to, uint256 amount) internal

Snapshots the totalSupply after it has been increased.

internal function _burn

function _burn(address account, uint256 amount) internal

Snapshots the totalSupply after it has been decreased.

© 2024