BaseForm

Git Source

Inherits: Initializable, ERC165, IBaseForm

Author: Zeropoint Labs.

SPDX-License-Identifier: Apache-2.0

Abstract contract to be inherited by different form implementations

State Variables

PRECISION_DECIMALS

uint256 internal constant PRECISION_DECIMALS = 27;

PRECISION

uint256 internal constant PRECISION = 10 ** PRECISION_DECIMALS;

CHAIN_ID

uint64 public immutable CHAIN_ID;

superRegistry

The superRegistry address is used to access relevant protocol addresses

ISuperRegistry public immutable superRegistry;

vault

the vault this form pertains to

address public vault;

formImplementationId

uint32 public formImplementationId;

Functions

notPaused

modifier notPaused(InitSingleVaultData memory singleVaultData_);

onlySuperRouter

modifier onlySuperRouter();

onlyCoreStateRegistry

modifier onlyCoreStateRegistry();

onlyEmergencyQueue

modifier onlyEmergencyQueue();

constructor

constructor(address superRegistry_);

initialize

sets caller as the admin of the contract.

function initialize(address superRegistry_, address vault_, uint32 formImplementationId_) external initializer;

Parameters

NameTypeDescription
superRegistry_addressISuperRegistry address deployed
vault_addressThe vault address this form pertains to
formImplementationId_uint32

receive

receive() external payable;

supportsInterface

function supportsInterface(bytes4 interfaceId_) public view virtual override(ERC165, IERC165) returns (bool);

directDepositIntoVault

process same chain id deposits

function directDepositIntoVault(
    InitSingleVaultData memory singleVaultData_,
    address srcSender_
)
    external
    payable
    override
    onlySuperRouter
    notPaused(singleVaultData_)
    returns (uint256 dstAmount);

Parameters

NameTypeDescription
singleVaultData_InitSingleVaultDataA bytes representation containing all the data required to make a form action
srcSender_addressThe address of the sender of the transaction

Returns

NameTypeDescription
dstAmountuint256The amount of tokens deposited in same chain action

directWithdrawFromVault

process withdrawal of collateral from a vault

function directWithdrawFromVault(
    InitSingleVaultData memory singleVaultData_,
    address srcSender_
)
    external
    override
    onlySuperRouter
    returns (uint256 dstAmount);

Parameters

NameTypeDescription
singleVaultData_InitSingleVaultDataA bytes representation containing all the data required to make a form action
srcSender_addressThe address of the sender of the transaction

Returns

NameTypeDescription
dstAmountuint256The amount of tokens withdrawn in same chain action

xChainDepositIntoVault

process same chain id deposits

function xChainDepositIntoVault(
    InitSingleVaultData memory singleVaultData_,
    address srcSender_,
    uint64 srcChainId_
)
    external
    override
    onlyCoreStateRegistry
    notPaused(singleVaultData_)
    returns (uint256 dstAmount);

Parameters

NameTypeDescription
singleVaultData_InitSingleVaultDataA bytes representation containing all the data required to make a form action
srcSender_addressThe address of the sender of the transaction
srcChainId_uint64The chain id of the source chain

Returns

NameTypeDescription
dstAmountuint256The amount of tokens deposited in same chain action

xChainWithdrawFromVault

process withdrawal of collateral from a vault

function xChainWithdrawFromVault(
    InitSingleVaultData memory singleVaultData_,
    address srcSender_,
    uint64 srcChainId_
)
    external
    override
    onlyCoreStateRegistry
    returns (uint256 dstAmount);

Parameters

NameTypeDescription
singleVaultData_InitSingleVaultDataA bytes representation containing all the data required to make a form action
srcSender_addressThe address of the sender of the transaction
srcChainId_uint64The chain id of the source chain

Returns

NameTypeDescription
dstAmountuint256The amount of tokens withdrawn

emergencyWithdraw

process withdrawal of shares if form is paused

function emergencyWithdraw(address refundAddress_, uint256 amount_) external override onlyEmergencyQueue;

Parameters

NameTypeDescription
refundAddress_addressThe address to refund the shares to
amount_uint256The amount of vault shares to refund

superformYieldTokenName

get Superform name of the ERC20 vault representation

function superformYieldTokenName() external view virtual override returns (string memory);

Returns

NameTypeDescription
<none>stringThe ERC20 name

superformYieldTokenSymbol

get Superform symbol of the ERC20 vault representation

function superformYieldTokenSymbol() external view virtual override returns (string memory);

Returns

NameTypeDescription
<none>stringThe ERC20 symbol

getVaultAsset

Returns the underlying token of a vault.

function getVaultAsset() public view virtual override returns (address);

Returns

NameTypeDescription
<none>addressThe asset being deposited into the vault used for accounting, depositing, and withdrawing

getVaultName

Returns the name of the vault.

function getVaultName() public view virtual override returns (string memory);

Returns

NameTypeDescription
<none>stringThe name of the vault

getVaultSymbol

Returns the symbol of a vault.

function getVaultSymbol() public view virtual override returns (string memory);

Returns

NameTypeDescription
<none>stringThe symbol associated with a vault

getVaultDecimals

Returns the number of decimals in a vault for accounting purposes

function getVaultDecimals() public view virtual override returns (uint256);

Returns

NameTypeDescription
<none>uint256The number of decimals in the vault balance

getVaultAddress

function getVaultAddress() external view override returns (address);

getPricePerVaultShare

Returns the amount of underlying tokens each share of a vault is worth.

function getPricePerVaultShare() public view virtual override returns (uint256);

Returns

NameTypeDescription
<none>uint256The pricePerVaultShare value

getVaultShareBalance

Returns the amount of vault shares owned by the form.

function getVaultShareBalance() public view virtual override returns (uint256);

Returns

NameTypeDescription
<none>uint256The form's vault share balance

getTotalAssets

get the total amount of underlying managed in the ERC4626 vault

function getTotalAssets() public view virtual override returns (uint256);

getStateRegistryId

get the state registry id

function getStateRegistryId() external view virtual override returns (uint256);

getPreviewPricePerVaultShare

function getPreviewPricePerVaultShare() public view virtual override returns (uint256);

previewDepositTo

API may need to know state of funds deployed

function previewDepositTo(uint256 assets_) public view virtual override returns (uint256);

previewWithdrawFrom

positionBalance() -> .vaultIds&destAmounts

function previewWithdrawFrom(uint256 assets_) public view virtual override returns (uint256);

Returns

NameTypeDescription
<none>uint256how much of an asset + interest (accrued) is to withdraw from the Vault

previewRedeemFrom

API may need to know state of funds deployed

function previewRedeemFrom(uint256 shares_) public view virtual override returns (uint256);

_directDepositIntoVault

Deposits underlying tokens into a vault

function _directDepositIntoVault(
    InitSingleVaultData memory singleVaultData_,
    address srcSender_
)
    internal
    virtual
    returns (uint256 dstAmount);

_directWithdrawFromVault

Withdraws underlying tokens from a vault

function _directWithdrawFromVault(
    InitSingleVaultData memory singleVaultData_,
    address srcSender_
)
    internal
    virtual
    returns (uint256 dstAmount_);

_xChainDepositIntoVault

Deposits underlying tokens into a vault

function _xChainDepositIntoVault(
    InitSingleVaultData memory singleVaultData_,
    address srcSender_,
    uint64 srcChainId_
)
    internal
    virtual
    returns (uint256 dstAmount);

_xChainWithdrawFromVault

Withdraws underlying tokens from a vault

function _xChainWithdrawFromVault(
    InitSingleVaultData memory singleVaultData_,
    address srcSender_,
    uint64 srcChainId_
)
    internal
    virtual
    returns (uint256 dstAmount);

_emergencyWithdraw

withdraws vault shares from form during emergency

function _emergencyWithdraw(address refundAddress_, uint256 amount_) internal virtual;

_isPaused

returns if a form id is paused

function _isPaused(uint256 superformId) internal view returns (bool);

_vaultSharesAmountToUnderlyingAmount

Converts a vault share amount into an equivalent underlying asset amount

function _vaultSharesAmountToUnderlyingAmount(
    uint256 vaultSharesAmount_,
    uint256 pricePerVaultShare_
)
    internal
    view
    virtual
    returns (uint256);

_vaultSharesAmountToUnderlyingAmountRoundingUp

Converts a vault share amount into an equivalent underlying asset amount, rounding up

function _vaultSharesAmountToUnderlyingAmountRoundingUp(
    uint256 vaultSharesAmount_,
    uint256 pricePerVaultShare_
)
    internal
    view
    virtual
    returns (uint256);

_underlyingAmountToVaultSharesAmount

Converts an underlying asset amount into an equivalent vault shares amount

function _underlyingAmountToVaultSharesAmount(
    uint256 underlyingAmount_,
    uint256 pricePerVaultShare_
)
    internal
    view
    virtual
    returns (uint256);