Skip to main content

How to price 1 asset of Morpho Vault

Morpho Vaults are ERC4626-compliant. ERC4626 is a standard for tokenized vaults, which allows for the creation of yield-bearing tokens. Pricing these assets correctly is crucial for their use in DeFi applications. This tutorial will guide you through the process of pricing an ERC4626-compliant asset, specifically the Re7WETH token.

Basically one may have understood that any Morpho Vault created has a token that represents the tokenized position in the vault.

Let's take into account the Re7WETH vault on Ethereum Mainnet, deployed at address: 0x78Fc2c2eD1A4cDb5402365934aE5648aDAd094d0.

The token associated is the Re7 WETH:

Vault Asset Name

Explainer

Before you start, ensure you have the following:

  • Access to the blockchain where a Morpho Vault has been deployed (e.g., via Etherscan, Basescan, ...).
  • Basic understanding of Solidity and smart contracts.
  • Familiarity with ERC20 and ERC4626 standards.

Concepts

  1. Vault Accrual of Interest: ERC4626 vaults accrue interest over time.
  2. convertToAssets Function: Converts shares to the underlying assets.
  3. totalAssets and totalSupply Functions: Provides total assets in the vault and the total supply of shares.

Methods to retrieve the underlying equivalent

There are two main methods to retrieve the price of an ERC4626 asset:

  1. Using the convertToAssets Function
  2. Using the totalAssets and totalSupply Functions

Method 1: Using convertToAssets

The convertToAssets function converts a given number of shares to the underlying assets.

Steps:

  1. Call the convertToAssets Function

    • Use 1e18 (=1000000000000000000) as input to represent 1 Re7WETH with 18 decimals.
  2. Convert the Result

    • Convert the result to get the price in terms of the underlying asset (e.g., WETH). The input is the underlying asset decimals: WETH:18 decimals, USDC:6 decimals, ...

Example:

uint256 priceInWETH = convertToAssets(1e18);
priceInWETH = priceInWETH / 1e18; // 1 Re7WETH = 1.02689... WETH at block 19981253
convertToAsset function

Method 2: Using totalAssets and totalSupply

This method involves dividing the total assets by the total supply of the shares.

Steps:

  1. Call the totalAssets Function

    • Retrieve the total assets in the vault.
  2. Call the totalSupply Function

    • Retrieve the total supply of shares.
  3. Calculate the Price

    • Divide the total assets by the total supply.
    • Calculation:
      price = totalAssets / totalSupply;

Example

uint256 totalAssets = totalAssets();
uint256 totalSupply = totalSupply();
uint256 priceInWETH = totalAssets / totalSupply; // Example result: 1.0268... WETH at block number 19981253
totalAssets & totalSupply functions

Examples in Practice

Re7WETH

Example 1: Using convertToAssets

uint256 priceInWETH = convertToAssets(1e18);
priceInWETH = priceInWETH / 1e18; // 1 Re7WETH = 1.026... WETH

Example 2: Using totalAssets and totalSupply

uint256 totalAssets = totalAssets();
uint256 totalSupply = totalSupply();
uint256 priceInWETH = totalAssets / totalSupply; // 1 Re7WETH = 1.0268... WETH

Re7USDT

For assets with different decimal places like USDT (6 decimals):

uint256 totalAssetsUSDT = totalAssets();
uint256 totalSupplyUSDT = totalSupply();
uint256 priceInUSDT = totalAssetsUSDT / totalSupplyUSDT; // 1 Re7USDT = 1.0364 USDT
priceInUSDT = priceInUSDT / 1e6; // Adjusting for 6 decimals

Conclusion

By following these methods, you can accurately price ERC4626-compliant assets such as Re7WETH, Re7USDT and any Morpho Vault token. This process ensures that you have a reliable value for these tokens, which is essential for their use as collateral and in other DeFi applications.

Feel free to reach out if you have any questions or need further assistance!