Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines ERC4626, a standard for tokenized vaults whose shares can represent a claim on yield-bearing assets.

This article translates, summarizes, and expands on the proposal below, with assistance from ChatGPT.

Overview

The standard defines a common API for tokenized vaults backed by an underlying ERC20 token.

In cryptocurrency and DeFi, a vault is a mechanism or platform that holds and manages assets while providing particular functions or services. Vaults can serve the following purposes.

  • Asset custody and management.
  • Lending markets.
  • Generating yield.
  • Trading tokenized assets.

The standard provides basic operations for depositing and withdrawing tokens from a tokenized vault and querying balances.

Motivation

Historically, tokenized vaults lacked a common implementation standard, resulting in a variety of implementations. These include lending markets, aggregators, and yield-bearing tokens.

A lending market is a marketplace where borrowers obtain funds and lenders supply funds in exchange for interest. Borrowers participate when they need funds, while individuals or protocols seeking interest on their assets participate as lenders. This makes capital available to borrowers while lenders can earn interest on the assets they supply.

An aggregator is a platform or service that consolidates multiple services or information sources in one place. For example, it can combine price data from different exchanges, offering users a unified way to access different protocols and services.

A yield-bearing token is a cryptocurrency token designed to accrue interest or yield for holders over time. Conventional tokens and cryptocurrencies do not inherently pay interest to holders. Some yield-bearing tokens periodically increase the holder's token balance as interest accrues; others accrue value through the exchange rate rather than increasing the balance. A user who deposits a particular token can earn yield based on the deposited amount.

This diversity makes integration difficult at the aggregator or plugin layer for protocols that need to support many standards. Each protocol must implement its own adapters, creating opportunities for errors and wasting development resources.

A standard for tokenized vaults simplifies integration with yield-bearing vaults and promotes more consistent, robust implementations.

Specification

All ERC4626 tokenized vaults must implement ERC20 to represent shares. Non-transferable vaults may revert on calls to transfer or transferFrom. ERC20 operations such as balanceOf, transfer, and totalSupply operate on the vault shares, which represent a claim on a fraction of its underlying holdings.

All ERC4626 tokenized vaults must implement ERC20's optional metadata extensions. Their name and symbol functions should reflect the underlying token's name and symbol in some way.

ERC4626 vaults may implement EIP-2612 to improve the user experience of approving shares in different integrations.

Definitions

asset

The underlying token managed by the vault. Examples include ERC20 representations of Bitcoin or Ethereum. Its units are defined by the corresponding ERC20 token contract.

share

A token issued by the vault. The user receives shares in exchange for the deposited assets, at the conversion ratio defined by the vault rather than necessarily one-to-one. Shares represent a claim on the vault's holdings and are used in minting, depositing, withdrawing, and redeeming operations. The amount of assets represented by a share can change, and profits generated through the vault's strategy may accrue to shareholders.

fee

A charge imposed on users by the vault, denominated in assets or shares. Fees may apply to deposits, yield, assets under management (AUM), withdrawals, or other operations specified by the vault. For example, a user may need to pay a fee when depositing assets into or withdrawing assets from the vault.

slippage

The difference between the expected transaction price and the actual price achieved, excluding fees in the context of this standard. Slippage tends to be more pronounced for large trades or in markets with limited liquidity.

Suppose a user submits a market order to purchase a token. The expected price was $100 per token, but the actual execution price was $105. The $5 difference is the slippage.

Functions

asset

yaml
- name: asset
  type: function
  stateMutability: view

  inputs: []

  outputs:
    - name: assetTokenAddress
      type: address

Returns the address of the underlying token used by the vault. The vault uses the underlying token for accounting, deposits, and withdrawals. This is a read-only function that returns an address named assetTokenAddress. That address identifies the ERC20 token contract used by the vault.

totalAssets

yaml
- name: totalAssets
  type: function
  stateMutability: view

  inputs: []

  outputs:
    - name: totalManagedAssets
      type: uint256

Returns the total amount of assets managed by the vault. The total includes compounded yield. It also includes fees charged against assets in the vault. This is a read-only function that returns an unsigned integer (uint256) named totalManagedAssets. The value represents the total amount of assets currently managed by the vault.

convertToShares

yaml
- name: convertToShares
  type: function
  stateMutability: view

  inputs:
    - name: assets
      type: uint256

  outputs:
    - name: shares
      type: uint256

Calculates how many shares the vault would exchange for a given amount of assets.

The implementation must satisfy the following conditions.

  • Excludes fees and other charges.
  • Returns the same result regardless of the caller.
  • Does not reflect slippage or other on-chain conditions of the actual exchange.
  • Rounds down fractional results.
  • The calculation should reflect the price per share that an average user can expect, rather than a user-specific price.

convertToAssets

yaml
- name: convertToAssets
  type: function
  stateMutability: view

  inputs:
    - name: shares
      type: uint256

  outputs:
    - name: assets
      type: uint256

Calculates how many assets the vault would exchange for a given amount of shares.

The implementation must satisfy the following conditions.

  • Excludes fees and other charges.
  • Returns the same result regardless of the caller.
  • Does not reflect slippage or other on-chain conditions of the actual exchange.
  • Rounds down fractional results.
  • The calculation should reflect the price per share that an average user can expect, rather than a user-specific price.

maxDeposit

yaml
- name: maxDeposit
  type: function
  stateMutability: view

  inputs:
    - name: receiver
      type: address

  outputs:
    - name: maxAssets
      type: uint256

Calculates the maximum amount of assets that may be deposited into the vault for the specified recipient (receiver). The implementation must satisfy the following conditions.

  • Assumes the user has unlimited assets and returns no more than the amount that can actually be deposited.
  • Returns 0 if deposits are disabled entirely, even temporarily.
  • Returns 2 ** 256 - 1 if deposits are unlimited.

previewDeposit

yaml
- name: previewDeposit
  type: function
  stateMutability: view

  inputs:
    - name: assets
      type: uint256

  outputs:
    - name: shares
      type: uint256

Allows on-chain or off-chain users to simulate a deposit under current on-chain conditions. The implementation must satisfy the following conditions.

  • Returns an estimate of shares no greater than the amount that deposit would return in the same transaction.
  • Does not account for limits such as those returned by maxDeposit.
  • Assumes the deposit will be accepted.
  • Includes deposit fees and may revert for conditions unrelated to the deposit limits that would also cause a deposit to revert.

deposit

yaml
- name: deposit
  type: function
  stateMutability: nonpayable

  inputs:
    - name: assets
      type: uint256
    - name: receiver
      type: address

  outputs:
    - name: shares
      type: uint256

Mints vault shares to the specified recipient (receiver) in exchange for the exact amount of assets supplied as an argument. The implementation must satisfy the following conditions.

  • Supports ERC20 approve / transferFrom as a deposit flow for the underlying asset.
  • Reverts if the entire amount of assets cannot be deposited, for example because of a deposit limit, slippage, or insufficient approval.
  • Depending on the implementation, prior approval (approve) of the vault to spend the underlying assets may be required.

maxMint

yaml
- name: maxMint
  type: function
  stateMutability: view

  inputs:
    - name: receiver
      type: address

  outputs:
    - name: maxShares
      type: uint256

Calculates the maximum number of shares that can be minted for the specified recipient (receiver). The implementation must satisfy the following conditions.

  • Assumes the user has unlimited assets and returns no more than the actual mint limit.
  • Returns 0 if minting is disabled entirely, even temporarily.
  • Returns 2 ** 256 - 1 if minting is unlimited.

previewMint

yaml
- name: previewMint
  type: function
  stateMutability: view

  inputs:
    - name: shares
      type: uint256

  outputs:
    - name: assets
      type: uint256

Allows on-chain or off-chain users to simulate minting under current on-chain conditions.

The implementation must satisfy the following conditions.

  • Returns an estimate of assets no less than the amount that mint would require in the same transaction.
  • Does not account for limits such as those returned by maxMint.
  • Assumes the mint will be accepted.
  • Includes deposit fees and may revert for conditions unrelated to mint limits that would also cause minting to revert.

mint

yaml
- name: mint
  type: function
  stateMutability: nonpayable

  inputs:
    - name: shares
      type: uint256
    - name: receiver
      type: address

  outputs:
    - name: assets
      type: uint256

Mints the exact number of shares specified in the argument to the recipient (receiver).

The implementation must satisfy the following conditions.

  • Supports ERC20 approve / transferFrom as a flow for depositing the underlying asset.
  • Reverts if the requested shares cannot all be minted, for example because of a deposit limit, slippage, or insufficient token approval.
  • Depending on the implementation, prior approval (approve) of the vault to spend the underlying assets may be required.

maxWithdraw

yaml
- name: maxWithdraw
  type: function
  stateMutability: view

  inputs:
    - name: owner
      type: address

  outputs:
    - name: maxAssets
      type: uint256

Calculates the maximum amount of assets that the specified owner (owner) can withdraw from their holdings in the vault.

The implementation must satisfy the following conditions.

  • Returns no more than the actual withdrawal limit.
  • Returns 0 if withdrawals are disabled entirely, even temporarily.

previewWithdraw

yaml
- name: previewWithdraw
  type: function
  stateMutability: view

  inputs:
    - name: assets
      type: uint256

  outputs:
    - name: shares
      type: uint256

Allows on-chain or off-chain users to simulate withdrawals under current on-chain conditions.

The implementation must satisfy the following conditions.

  • Returns an estimate of shares no less than the amount that withdraw would burn in the same transaction.
  • Does not account for limits such as those returned by maxWithdraw.
  • Assumes the withdrawal will be accepted.
  • Includes withdrawal fees and may revert for conditions unrelated to withdrawal limits that would also cause a withdrawal to revert.

withdraw

yaml
- name: withdraw
  type: function
  stateMutability: nonpayable

  inputs:
    - name: assets
      type: uint256
    - name: receiver
      type: address
    - name: owner
      type: address

  outputs:
    - name: shares
      type: uint256

Burns shares from the specified owner (owner) and transfers the exact amount of underlying assets to the recipient (receiver).

The implementation must satisfy the following conditions.

  • Emits a Withdraw event.
  • Supports two withdrawal flows.
    • Burns shares directly from the owner when the owner is msg.sender.
    • Burns shares directly from the owner when msg.sender has ERC20 approval to spend the owner's shares.
  • Depending on the implementation, delegated withdrawals require prior share approval (approve); some vaults also require a separate withdrawal request.

maxRedeem

yaml
- name: maxRedeem
  type: function
  stateMutability: view

  inputs:
    - name: owner
      type: address

  outputs:
    - name: maxShares
      type: uint256

Calculates the maximum number of shares that the specified owner (owner) can redeem from their holdings in the vault. The implementation must satisfy the following conditions.

  • Returns no more than the actual redemption limit.
  • Returns 0 if redemption is disabled entirely, even temporarily.

previewRedeem

yaml
- name: previewRedeem
  type: function
  stateMutability: view

  inputs:
    - name: shares
      type: uint256

  outputs:
    - name: assets
      type: uint256

Allows on-chain or off-chain users to simulate redemption under current on-chain conditions. The implementation must satisfy the following conditions.

  • Returns an estimate of assets no greater than the amount that redeem would return in the same transaction.
  • Does not account for limits such as those returned by maxRedeem.
  • Assumes the redemption will be accepted.
  • Includes withdrawal fees and may revert for conditions unrelated to redemption limits that would also cause redemption to revert.

redeem

yaml
- name: redeem
  type: function
  stateMutability: nonpayable

  inputs:
    - name: shares
      type: uint256
    - name: receiver
      type: address
    - name: owner
      type: address

  outputs:
    - name: assets
      type: uint256

Burns the exact number of shares specified for the owner (owner) and transfers the corresponding amount of underlying assets to the recipient (receiver). The implementation must satisfy the following conditions.

  • Emits a Withdraw event.
  • Supports two redemption flows.
    • Burns shares directly from the owner when the owner is msg.sender.
    • Burns shares directly from the owner when msg.sender has ERC20 approval to spend the owner's shares.
  • Depending on the implementation, delegated redemption requires prior share approval (approve); some vaults also require a separate redemption request.

Event

Deposit

yaml
- name: Deposit
  type: event

  inputs:
    - name: sender
      indexed: true
      type: address
    - name: owner
      indexed: true
      type: address
    - name: assets
      indexed: false
      type: uint256
    - name: shares
      indexed: false
      type: uint256

Emitted when tokens are deposited into the vault through mint or deposit. It records the exchange of deposited assets for shares and the delivery of those shares to the owner.

  • sender
    • The address of the depositor (sender).
  • owner
    • The address of the share recipient.
  • assets
    • The amount of assets deposited.
  • shares
    • The amount of shares minted in exchange.

Withdraw

yaml
- name: Withdraw
  type: event

  inputs:
    - name: sender
      indexed: true
      type: address
    - name: receiver
      indexed: true
      type: address
    - name: owner
      indexed: true
      type: address
    - name: assets
      indexed: false
      type: uint256
    - name: shares
      indexed: false
      type: uint256

Emitted when shares are redeemed through the vault's redeem or withdraw functions. It records the exchange of shares owned by owner for assets and the transfer of those assets to the recipient.

  • sender
    • The address of the user initiating the withdrawal (sender).
  • receiver
    • The address receiving the assets.
  • owner
    • The address of the share owner.
  • assets
    • The amount of assets withdrawn.
  • shares
    • The amount of shares burned in exchange.

Additional considerations

Optimizing for integrators

The vault interface is designed to optimize integration into other systems and applications. It provides the functions needed to use a vault effectively while deliberately leaving implementation details unspecified. Vaults can therefore be treated as black boxes on-chain, with integrators expected to examine their implementations off-chain before use.

ERC20 compatibility

ERC20 defines the standard interface for Ethereum tokens. It is used here because its approval and balance operations apply directly to the vault shares. This allows vault shares to be used in ERC20-compatible applications.

Why the mint function is included

The mint function is included for symmetry and completeness. In many existing share-based vault use cases, users tend to specify an amount of assets to deposit through deposit, rather than an exact number of shares to mint. However, future vault strategies may use a particular share denomination that makes specifying the number of shares useful, which is why mint is included.

Using the conversion functions

The convertTo functions provide approximate estimates without accounting for operation-specific details such as fees. They are useful to frontends and applications requiring average share or asset valuations. Preview functions are available when a more precise estimate that accounts for slippage and fees is needed. Since preview functions do not account for deposit or withdrawal limits, the max functions are also provided so that integrators can combine these queries.

Backwards compatibility

ERC4626 is fully compatible with ERC20 and has no known compatibility issues with other standards. Wrapper adapters can be developed and used for production vault implementations that do not implement ERC4626.

Reference implementations

Reference implementations are available in Solmate EIP-4626 and Vyper EIP-4626, among others. These are minimal implementations of the standard that provide hooks for developers to insert their own logic.

Security considerations

In permissionless use cases, integrators may encounter malicious implementations that conform to the interface but not the specification. All integrators are encouraged to review vault implementations for risks that could cause users to lose deposited assets. When supporting direct access by externally owned accounts (EOAs), consider additional function calls that protect against slippage and unexpected deposit or withdrawal limits, since there may otherwise be no way for the caller to revert a transaction when the actual output differs from expectations.

Citation

Joey Santoro (@joeysantoro), t11s (@transmissions11), Jet Jadeja (@JetJadeja), Alberto Cuesta Cañada (@alcueca), Señor Doggo (@fubuloubu), "ERC-4626: Tokenized Vaults," Ethereum Improvement Proposals, no. 4626, December 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-4626.

Conclusion

This article covered ERC4626, a unified standard for tokenized vaults whose holders can earn yield. I hope you found it useful.

I plan to add further implementation details in the future.

If you have any questions, feel free to contact me via Twitter DM.

Twitter @cardene777