StakeWise V3
  • Main Hub
  • Guides
    • Staking
    • Running a Vault
    • osToken
    • DeFi
      • SWISE-ETH Liquidity Pool
    • StakeWise V2
      • Migrate to StakeWise V3 on Ethereum
      • Migrate to StakeWise V3 on Gnosis Chain
      • Change solo withdrawal credentials to 0x01 address
        • Using Ledger Nano X
        • Using Windows
        • Using macOS
      • Exit solo validator
  • Protocol overview (in-depth)
    • Introduction
    • Vaults
    • osToken
    • Fees
    • Oracles
  • For operators
    • Operator Service
      • Running with Remote Signer
      • Running with Hashi Vault
      • Running as API service
      • Monitoring
    • Kubernetes staking setup
    • Smoothing Pool relays
    • Migrate from V2
      • Ethereum
      • Gnosis
    • DVT
      • Running operator with DVT
    • Vault incentives
    • Vault performance
  • For developers
    • Create a Vault
    • Stake
    • Unstake
    • Oracles
    • Contributions
    • Networks
      • Gnosis
      • Mainnet
      • Hoodi
      • Chiado
  • Governance
    • StakeWise DAO
    • DAO Treasury
Powered by GitBook
On this page
  • Parameters
  • Return Values
  1. For developers

Create a Vault

PreviousVault performanceNextStake

Last updated 1 year ago

Vaults are created through the EthVaultFactory contracts. The factory deploys and initializes the ERC-1967 proxy and registers the vault to the VaultsRegistry so that other contracts can verify the validity of the Vault by checking whether it's in the registry.

You can find the addresses of the factories for all the vault types .

The vault can be deployed by calling the createVault function of the EthVaultFactory contract:

function createVault(bytes params, bool isOwnMevEscrow) external payable returns (address vault)

Parameters

Name
Type
Description

params

bytes

The encoded parameters for initializing the Vault contract

isOwnMevEscrow

bool

Whether to deploy own escrow contract or connect to a smoothing pool for priority fees and MEV rewards

You must encode the params argument differently based on whether you create vault with the ERC-20 token or without.

Vault without ERC-20 token

To encode the parameters for the vault without an ERC-20 token, you have to provide the following:

  • capacity - defines at what TVL in Wei the vault stops accepting new deposits. To make it unlimited, provide the max uint256 value of 2^256 - 1.

  • feePercent - defines the percent that you want to charge from the stakes rewards. Must be provided in BPS. For example, if you want to charge 5% from the stakers rewards, you must provide 500. The max value is 10000 (100%).

You must encode the parameters to the byte string. You can use the following function for that:

import { BigNumber } from '@ethersproject/bignumber'
import { defaultAbiCoder } from '@ethersproject/abi'

// encode params for vault without ERC-20 token
function encodeEthVaultInitParams(
  capacity: BigNumber,
  feePercent: number,
  metadataIpfsHash: string
): string {
  return defaultAbiCoder.encode(
    ['tuple(uint256 capacity, uint16 feePercent, string metadataIpfsHash)'],
    [[capacity, feePercent, metadataIpfsHash]]
  )
}

Vault with ERC-20 token

In addition to the parameters provided for the vault without an ERC-20 token, you have to provide the following:

  • name - the name of the ERC-20 token. It cannot exceed 30 characters. For example, Vitalik Staked ETH.

  • symbol - the symbol of the ERC-20 token. It cannot exceed ten characters. For example, vstETH.

You must encode the parameters to the byte string. You can use the following function for that:

import { BigNumber } from '@ethersproject/bignumber'
import { defaultAbiCoder } from '@ethersproject/abi'

function encodeEthErc20VaultInitParams(
  capacity: BigNumber,
  feePercent: number,
  name: string,
  symbol: string,
  metadataIpfsHash: string
): string {
  return defaultAbiCoder.encode(
    [
      'tuple(uint256 capacity, uint16 feePercent, string name, string symbol, string metadataIpfsHash)',
    ],
    [[capacity, feePercent, name, symbol, metadataIpfsHash]]
  )
}

Return Values

Name
Type
Description

vault

address

The address of the created Vault

The security deposit of 1 gwei must be transferred with the call. This protects the Vault stakers from the inflation attack described .

metadataIpfsHash - The IPFS hash to the file that contains the name, description, and icon for the vault branding (e.g., ). It's an optional value; you can skip it by specifying an empty string ("").

here
bafkreictxn323g4ad3rumxkykqayl5kluozhcet45paen2dnvetdu4ptoe
here
Vault creation
Page cover image