DepositVault

Git Source

Inherits: IDepositVault, AccessControl, ReentrancyGuard, Constants

Author: luoyhang003

This contract manages deposits of underlying assets in exchange for vault tokens.

It mints vault tokens to whitelisted users based on the asset’s oracle price and applies fees and caps. Supports deposit/mint functions, preview simulations, and admin control over assets.

State Variables

VAULT_ADMIN_ROLE

Role allowed to set new AssetsRouter

Only addresses with this role can call setAssetsRouter

Calculated as keccak256("VAULT_ADMIN_ROLE").

bytes32 public constant VAULT_ADMIN_ROLE = keccak256("VAULT_ADMIN_ROLE");

VAULT_OPERATOR_ROLE

Role allowed to manage underlying assets

Only addresses with this role can call addUnderlyingAsset and removeUnderlyingAsset

Calculated as keccak256("VAULT_OPERATOR_ROLE").

bytes32 public constant VAULT_OPERATOR_ROLE = keccak256("VAULT_OPERATOR_ROLE");

vaultToken

ERC20 vault token.

Minted when users deposit assets or mint shares.

Token public immutable vaultToken;

accessRegistry

Access registry for fetching whitelist and blacklist.

IAccessRegistry public accessRegistry;

oracleRegistry

Oracle registry for fetching asset and vault token prices.

IOracleRegistry public oracleRegistry;

paramRegistry

Parameter registry for fee rates, deposit caps, etc.

IParamRegistry public paramRegistry;

assetsRouter

Router to forward deposited assets into underlying strategies.

IAssetsRouter public assetsRouter;

underlyingAssets

List of all supported underlying assets.

address[] public underlyingAssets;

isUnderlyingAsset

Mapping of supported assets.

mapping(address => bool) public isUnderlyingAsset;

tokenDecimals

Cached decimals for supported tokens.

mapping(address => uint8) public tokenDecimals;

tokenDeposited

Tracks deposited amount per underlying asset (net of fees).

mapping(address => uint256) public tokenDeposited;

Functions

constructor

Deploys the DepositVault contract.

Ensures addresses are valid and assets have valid oracles/decimals. Grants infinite approval of assets to the router.

constructor(
    address _defaultAdmin,
    address _adminRole,
    address _operatorRole,
    address _vaultToken,
    address _accessRegistry,
    address _oracleRegistry,
    address _paramRegistry,
    address _assetsRouter,
    address[] memory _underlyingAssets
);

Parameters

NameTypeDescription
_defaultAdminaddressAddress to receive the DEFAULT_ADMIN_ROLE.
_adminRoleaddressAddress granted the VAULT_ADMIN_ROLE.
_operatorRoleaddressAddress granted the VAULT_OPERATOR_ROLE.
_vaultTokenaddressAddress of the vault token contract.
_accessRegistryaddressAddress of the access registry contract.
_oracleRegistryaddressAddress of the oracle registry contract.
_paramRegistryaddressAddress of the parameter registry contract.
_assetsRouteraddressAddress of the assets router contract.
_underlyingAssetsaddress[]Initial list of supported assets.

deposit

Deposit an underlying asset and receive vault shares.

Equivalent to depositFor with msg.sender as receiver.

function deposit(address _asset, uint256 _amount) external returns (uint256 shares_);

Parameters

NameTypeDescription
_assetaddressAddress of the asset to deposit.
_amountuint256Amount of asset to deposit.

Returns

NameTypeDescription
shares_uint256Number of shares minted.

depositFor

Deposit an underlying asset on behalf of another account.

Reverts if receiver is zero address.

function depositFor(address _asset, uint256 _amount, address _receiver) external returns (uint256 shares_);

Parameters

NameTypeDescription
_assetaddressAddress of the asset to deposit.
_amountuint256Amount of asset to deposit.
_receiveraddressRecipient of the minted shares.

Returns

NameTypeDescription
shares_uint256Number of shares minted.

mint

Mint a specific number of shares by depositing assets.

Equivalent to mintFor with msg.sender as receiver.

function mint(address _asset, uint256 _shares) external returns (uint256 assets_);

Parameters

NameTypeDescription
_assetaddressAddress of the asset to deposit.
_sharesuint256Number of shares to mint.

Returns

NameTypeDescription
assets_uint256Amount of assets required.

mintFor

Mint a specific number of shares on behalf of another account.

Reverts if receiver is zero address.

function mintFor(address _asset, uint256 _shares, address _receiver) external returns (uint256 assets_);

Parameters

NameTypeDescription
_assetaddressAddress of the asset to deposit.
_sharesuint256Number of shares to mint.
_receiveraddressRecipient of the minted shares.

Returns

NameTypeDescription
assets_uint256Amount of assets required.

exchangePrice

Returns the cutoff vault token price (e.g. for settlement).

Fetches the cutoff price directly from the oracle registry.

function exchangePrice() external view returns (uint256 price_);

Returns

NameTypeDescription
price_uint256Current vault token cutoff price.

convertToShares

Converts underlying assets to equivalent vault shares.

Normalizes _amount to 18 decimals before conversion. Uses floor rounding to avoid overestimating shares.

function convertToShares(address _asset, uint256 _amount)
    public
    view
    returns (uint256 shares_, uint256 underlyingPrice_, uint256 vaultTokenPrice_);

Parameters

NameTypeDescription
_assetaddressAddress of the underlying asset.
_amountuint256Amount of underlying asset.

Returns

NameTypeDescription
shares_uint256Equivalent vault shares.
underlyingPrice_uint256Price of the underlying asset.
vaultTokenPrice_uint256Price of the vault token.

convertToAssets

Converts vault shares to equivalent underlying assets.

Denormalizes values back from 18 decimals to asset decimals. Uses floor rounding to avoid overestimating asset returns.

function convertToAssets(address _asset, uint256 _shares)
    public
    view
    returns (uint256 assets_, uint256 underlyingPrice_, uint256 vaultTokenPrice_);

Parameters

NameTypeDescription
_assetaddressAddress of the underlying asset.
_sharesuint256Number of vault shares.

Returns

NameTypeDescription
assets_uint256Equivalent underlying asset amount.
underlyingPrice_uint256Price of the underlying asset.
vaultTokenPrice_uint256Price of the vault token.

previewDeposit

Previews deposit outcome including shares, fee, and prices.

Simulates deposit logic without state changes. Performs fee deduction, cap checks, and price fetches.

function previewDeposit(address _asset, uint256 _amount)
    public
    view
    returns (uint256 shares_, uint256 fee_, uint256 underlyingPrice_, uint256 vaultTokenPrice_);

Parameters

NameTypeDescription
_assetaddressAddress of the underlying asset.
_amountuint256Deposit amount.

Returns

NameTypeDescription
shares_uint256Number of shares minted.
fee_uint256Fee charged on deposit.
underlyingPrice_uint256Price of the underlying asset.
vaultTokenPrice_uint256Price of the vault token.

previewMint

Previews mint outcome including assets, fee, and prices.

Simulates mint logic without state changes. Performs fee addition, cap checks, and price fetches.

function previewMint(address _asset, uint256 _shares)
    public
    view
    returns (uint256 assets_, uint256 fee_, uint256 underlyingPrice_, uint256 vaultTokenPrice_);

Parameters

NameTypeDescription
_assetaddressAddress of the underlying asset.
_sharesuint256Number of shares to mint.

Returns

NameTypeDescription
assets_uint256Required underlying assets.
fee_uint256Fee charged on mint.
underlyingPrice_uint256Price of the underlying asset.
vaultTokenPrice_uint256Price of the vault token.

getUnderlyings

Returns list of all supported underlying assets.

Returns storage array directly; use cautiously in gas-sensitive contexts.

function getUnderlyings() external view returns (address[] memory underlyings);

Returns

NameTypeDescription
underlyingsaddress[]Array of supported assets.

addUnderlyingAsset

Adds a new underlying asset to the vault.

Only callable by operator role. Requires valid oracle and decimals <= 18. Grants infinite approval to router.

function addUnderlyingAsset(address _asset) external onlyRole(VAULT_OPERATOR_ROLE);

Parameters

NameTypeDescription
_assetaddressAddress of the asset to add.

removeUnderlyingAsset

Removes an underlying asset from the vault.

Only callable by operator role. Resets approval to zero and updates storage.

function removeUnderlyingAsset(address _asset) external onlyRole(VAULT_OPERATOR_ROLE);

Parameters

NameTypeDescription
_assetaddressAddress of the asset to remove.

forceRouteAssets

Forcefully routes a specified amount of an asset through the assets router.

This function can only be called by an account with the {VAULT_OPERATOR_ROLE}. It is typically used in exceptional or administrative cases where assets must be manually routed to the designated destination, bypassing standard user-driven flows. Reverts if the asset address is zero or the amount is zero.

function forceRouteAssets(address _asset, uint256 _amount) external onlyRole(VAULT_OPERATOR_ROLE);

Parameters

NameTypeDescription
_assetaddressThe address of the underlying asset to be routed.
_amountuint256The amount of the underlying asset to be routed.

setAssetsRouter

Updates the asset router contract.

Only callable by admin role. Revokes approvals for old router and re-approves new one.

function setAssetsRouter(address _assetsRouter) external onlyRole(VAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
_assetsRouteraddressNew router address.

_depositFor

Internal deposit logic used by deposit and depositFor.

Applies fee, checks caps, transfers funds, and mints shares.

function _depositFor(address _asset, uint256 _amount, address _receiver)
    internal
    nonReentrant
    returns (uint256 shares_);

Parameters

NameTypeDescription
_assetaddressAddress of asset to deposit.
_amountuint256Deposit amount.
_receiveraddressRecipient of vault shares.

Returns

NameTypeDescription
shares_uint256Number of shares minted.

_mintFor

Internal mint logic used by mint and mintFor.

Applies fee, checks caps, transfers funds, and mints shares.

function _mintFor(address _asset, uint256 _shares, address _receiver) internal nonReentrant returns (uint256 assets_);

Parameters

NameTypeDescription
_assetaddressAddress of asset to deposit.
_sharesuint256Number of shares to mint.
_receiveraddressRecipient of vault shares.

Returns

NameTypeDescription
assets_uint256Amount of assets transferred.

_normalize

Normalizes token amounts to base decimals (18).

Expands or compresses numbers depending on asset decimals.

function _normalize(uint256 _amount, uint256 _decimals) internal pure returns (uint256 normalized_);

Parameters

NameTypeDescription
_amountuint256Token amount in original decimals.
_decimalsuint256Decimals of the token.

Returns

NameTypeDescription
normalized_uint256Amount scaled to 18 decimals.

_denormalize

Denormalizes token amounts from base decimals (18) to asset decimals.

Reverses normalization logic.

function _denormalize(uint256 _amount, uint256 _decimals) internal pure returns (uint256 denormalized_);

Parameters

NameTypeDescription
_amountuint256Amount in 18 decimals.
_decimalsuint256Decimals of the asset.

Returns

NameTypeDescription
denormalized_uint256Amount scaled back to asset decimals.