Skip to main content

MultiTokenVault

Git Source

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

NameTypeDescription
name_stringThe name of the MultiTokenVault
symbol_stringThe symbol of the MultiTokenVault
decimalsOffset_uint8The decimals offset
admin_addressThe admin address

enforceCaps

Enforces the maximum cap for a token

modifier enforceCaps(address token) ;

Parameters

NameTypeDescription
tokenaddressThe 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

NameTypeDescription
tokenaddressThe 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

NameTypeDescription
tokenaddressThe address of the token to remove

getSupportedTokens

Get the list of supported tokens

function getSupportedTokens() external view override returns (address[] memory);

Returns

NameTypeDescription
<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

NameTypeDescription
tokenaddressThe address of the token to check

Returns

NameTypeDescription
isSupportedboolTrue 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

NameTypeDescription
tokenaddressThe address of the token to set the cap for
_maximumCapuint256The 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

NameTypeDescription
<none>address
amountuint256The amount of tokens to deposit/withdraw

Returns

NameTypeDescription
<none>uint256The 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

NameTypeDescription
<none>address
amountuint256The amount of tokens minted/burned as a result of the deposit/withdraw operation

Returns

NameTypeDescription
<none>uint256The 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

NameTypeDescription
tokenaddressThe address of the token to deposit
amountuint256The 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

NameTypeDescription
tokenaddressThe address of the token to withdraw
amountuint256The 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

NameTypeDescription
amountuint256The 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

NameTypeDescription
sharesuint256The amount of shares to burn
amountuint256The 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

NameTypeDescription
totalSupplyuint256The total supply of the MultiTokenVault