MultiTokenVault
Inherits: Context, ERC165, AccessControl, RebasingERC20, IMultiTokenVault
Title: MultiTokenVault
Author: SocksNFlops
MultiTokenVault is a contract that allows users to deposit multiple tokens and mint a single token in return. Assumes all supported tokens have the same UOA.
State Variables
supportedTokens
The set of supported tokens
EnumerableSet.AddressSet internal supportedTokens
maximumCap
mapping(address => uint256) public maximumCap
Functions
constructor
Constructor
constructor(string memory name_, string memory symbol_, uint8 decimalsOffset_, address admin_)
RebasingERC20(name_, symbol_, decimalsOffset_);
Parameters
| Name | Type | Description |
|---|---|---|
name_ | string | The name of the MultiTokenVault |
symbol_ | string | The symbol of the MultiTokenVault |
decimalsOffset_ | uint8 | The decimals offset |
admin_ | address | The admin address |
enforceCaps
Enforces the maximum cap for a token
modifier enforceCaps(address token) ;
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The token to enforce the cap for |
supportsInterface
function supportsInterface(bytes4 interfaceId) public view virtual override(AccessControl, ERC165) returns (bool);
addSupportedToken
Add a supported token to the MultiTokenVault
function addSupportedToken(address token) public virtual override onlyRole(Roles.SUPPORTED_TOKEN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The address of the token to add |
removeSupportedToken
Remove a supported token from the MultiTokenVault
function removeSupportedToken(address token) public virtual override onlyRole(Roles.SUPPORTED_TOKEN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The address of the token to remove |
getSupportedTokens
Get the list of supported tokens
function getSupportedTokens() external view override returns (address[] memory);
Returns
| Name | Type | Description |
|---|---|---|
<none> | address[] | The list of supported tokens |
isTokenSupported
Check if a token is supported
function isTokenSupported(address token) public view override returns (bool isSupported);
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The address of the token to check |
Returns
| Name | Type | Description |
|---|---|---|
isSupported | bool | True if the token is supported, false otherwise |
setMaximumCap
Set the absolute maximum cap for an underlying token.
function setMaximumCap(address token, uint256 _maximumCap) external override onlyRole(Roles.SUPPORTED_TOKEN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The address of the token to set the cap for |
_maximumCap | uint256 | The new maximum cap for the token denominated in the UOA. Default is type(uint256).max. |
convertAmount
Calculates the amount of tokens minted/burned in a deposit/withdraw operation
function convertAmount(address, uint256 amount) public view virtual override returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
<none> | address | |
amount | uint256 | The amount of tokens to deposit/withdraw |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The mint/burn amount |
convertUnderlying
Calculates the amount of underlying tokens required to deposit/withdraw a given amount of tokens
function convertUnderlying(address, uint256 amount) public view virtual override returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
<none> | address | |
amount | uint256 | The amount of tokens minted/burned as a result of the deposit/withdraw operation |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The amount of underlying tokens required to deposit/withdraw the given amount of tokens |
deposit
Deposit tokens into the MultiTokenVault and mint an equivalent amount of the MultiTokenVault token.
function deposit(address token, uint256 amount) public virtual override enforceCaps(token);
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The address of the token to deposit |
amount | uint256 | The amount of tokens to deposit |
withdraw
Withdraw tokens from the MultiTokenVault and burn an equivalent amount of the MultiTokenVault token.
function withdraw(address token, uint256 amount) public virtual override;
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The address of the token to withdraw |
amount | uint256 | The amount of tokens to withdraw |
forfeit
Forfeit tokens from the MultiTokenVault. Redistributes the forfeited tokens to the existing holders.
function forfeit(uint256 amount) public virtual override;
Parameters
| Name | Type | Description |
|---|---|---|
amount | uint256 | The amount of tokens to forfeit |
burnExcessShares
Given shares and an amount, this will burn shares until the amount is reached.
This is achieved by burning all of the shares and minting the amount. Will no-op if attempting to mint more than the shares correspond to.
function burnExcessShares(uint256 shares, uint256 amount) public virtual override;
Parameters
| Name | Type | Description |
|---|---|---|
shares | uint256 | The amount of shares to burn |
amount | uint256 | The amount of tokens to mint |
_totalSupply
Calculates the total supply of the MultiTokenVault by summing up the balances of all supported tokens
function _totalSupply() internal view virtual override returns (uint256 totalSupply);
Returns
| Name | Type | Description |
|---|---|---|
totalSupply | uint256 | The total supply of the MultiTokenVault |