Get Data
Before Starting
In this tutorial, you might see different ways to fetch data for Morpho Vaults:
- API: Using the Morpho public API (see endpoint below). This is the easiest and most direct way for most applications. Note that only a subset of chains are supported.
- Typescript: Using Typescript snippet. For Developers expecting to perform offchain computation.
- Smart Contract: Fetching data directly onchain. This is best for real-time or trustless data.
- SDK: [Examples Incoming] Using the Morpho SDKs for pre-built abstractions and faster development.
For each topic below, you'll find short guides for each method (where possible). This avoids redundancy and helps you choose the best approach for your use case.
Basics
Vaults List
How to retrieve all deployed vaults?
query {
  vaults(first: 1000, where: { chainId_in: [1, 8453] }) {
    items {
      address
      symbol
      name
      whitelisted
      asset {
        id
        address
        decimals
      }
      chain {
        id
        network
      }
    }
  }
}Total Deposits & Assets
All vaults
query {
  vaults(first: 100, orderBy: TotalAssetsUsd, orderDirection: Desc) {
    items {
      address
      state {
        totalAssets
        totalAssetsUsd
        totalSupply
      }
    }
  }
}Unique vault
query {
  vaultByAddress(
    address: "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"
    chainId: 1
  ) {
    address
    state {
      totalAssets
      totalAssetsUsd
      totalSupply
    }
  }
}APY (Native + Rewards)
query {
  vaults(first: 100, orderBy: TotalAssetsUsd, orderDirection: Desc) {
    items {
      address
      asset {
        yield {
          apr
        }
      }
      state {
        apy
        netApy
        netApyWithoutRewards
        avgApy
        avgNetApy
        dailyApy
        dailyNetApy
        weeklyApy
        weeklyNetApy
        monthlyApy
        monthlyNetApy
        rewards {
          asset {
            address
            chain {
              id
            }
          }
          supplyApr
          yearlySupplyTokens
        }
        allocation {
          supplyAssets
          supplyAssetsUsd
          market {
            uniqueKey
            state {
              rewards {
                asset {
                  address
                  chain {
                    id
                  }
                }
                supplyApr
                borrowApr
              }
            }
          }
        }
      }
    }
  }
}query {
  vaultByAddress(
    address: "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"
    chainId: 1
  ) {
    address
    asset {
      yield {
        apr
      }
    }
    state {
      apy
      netApy
      netApyWithoutRewards
      avgApy
      avgNetApy
      dailyApy
      dailyNetApy
      weeklyApy
      weeklyNetApy
      monthlyApy
      monthlyNetApy
      rewards {
        asset {
          address
          chain {
            id
          }
        }
        supplyApr
        yearlySupplyTokens
      }
      allocation {
        supplyAssets
        supplyAssetsUsd
        market {
          uniqueKey
          state {
            rewards {
              asset {
                address
                chain {
                  id
                }
              }
              supplyApr
              borrowApr
            }
          }
        }
      }
    }
  }
}Markets Allocation
query {
  vaults(first: 100, orderBy: TotalAssetsUsd, orderDirection: Desc) {
    items {
      address
      state {
        allocation {
          market {
            uniqueKey
            loanAsset {
              name
            }
            collateralAsset {
              name
            }
            oracleAddress
            irmAddress
            lltv
          }
          supplyCap
          supplyAssets
          supplyAssetsUsd
        }
      }
    }
  }
}query {
  vaultByAddress(
    address: "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"
    chainId: 1
  ) {
    address
    state {
      allocation {
        market {
          uniqueKey
          loanAsset {
            name
          }
          collateralAsset {
            name
          }
          oracleAddress
          irmAddress
          lltv
        }
        supplyCap
        supplyAssets
        supplyAssetsUsd
      }
    }
  }
}Historical
APY Historical state
query VaultApys($options: TimeseriesOptions) {
  vaults(first: 10, orderBy: TotalAssetsUsd, orderDirection: Desc) {
    items {
      address
      historicalState {
        apy(options: $options) {
          x
          y
        }
        netApy(options: $options) {
          x
          y
        }
      }
    }
  }
}query VaultApys($options: TimeseriesOptions) {
  vaultByAddress(address: "0x73e65DBD630f90604062f6E02fAb9138e713edD9") {
    address
    historicalState {
      apy(options: $options) {
        x
        y
      }
      netApy(options: $options) {
        x
        y
      }
    }
  }
}with those variables
{
  "options": {
    "startTimestamp": 1740000000,
    "endTimestamp": 1742564817,
    "interval": "DAY"
  }
}Advanced
Price of a vault token
query {
  vaults(first: 100, orderBy: TotalAssetsUsd, orderDirection: Desc) {
    items {
      address
      state {
        sharePrice
        sharePriceUsd
      }
    }
  }
}query {
  vaultByAddress(
    address: "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"
    chainId: 1
  ) {
    address
    state {
      sharePrice
      sharePriceUsd
    }
  }
}Vault Configuration
query {
  vaults(first: 100, orderBy: TotalAssetsUsd, orderDirection: Desc) {
    items {
      address
      name
      whitelisted
      metadata {
        description
        forumLink
        image
        curators {
          image
          name
          url
        }
      }
      allocators {
        address
      }
      state {
        owner
        curator
        guardian
        timelock
      }
    }
  }
}query {
  vaultByAddress(
    address: "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"
    chainId: 1
  ) {
    address
    name
    whitelisted
    metadata {
      description
      forumLink
      image
      curators {
        image
        name
        url
      }
    }
    allocators {
      address
    }
    state {
      owner
      curator
      guardian
      timelock
    }
  }
}Depositors
query {
  vaultPositions(
    first: 10
    orderBy: Shares
    orderDirection: Desc
    where: {
      vaultAddress_in: [
        "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"
        "0x73e65DBD630f90604062f6E02fAb9138e713edD9"
      ]
    }
  ) {
    items {
      vault {
        address
      }
      user {
        address
      }
      state {
        shares
        assets
        assetsUsd
      }
    }
  }
}query {
  vaultPositions(
    first: 10
    orderBy: Shares
    orderDirection: Desc
    where: { vaultAddress_in: ["0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"] }
  ) {
    items {
      user {
        address
      }
      state {
        shares
        assets
        assetsUsd
      }
    }
  }
}Transaction history
query {
  transactions(
    first: 10
    orderBy: Timestamp
    orderDirection: Desc
    where: { vaultAddress_in: ["0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"] }
  ) {
    items {
      blockNumber
      hash
      type
      user {
        address
      }
    }
  }
}Vault Queues
query {
  vaults(first: 100, orderBy: TotalAssetsUsd, orderDirection: Desc) {
    items {
      address
      state {
        totalAssets
        lastTotalAssets
        allocation {
          supplyQueueIndex
          withdrawQueueIndex
          market {
            uniqueKey
          }
        }
      }
    }
  }
}query {
  vaultByAddress(
    address: "0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB"
    chainId: 1
  ) {
    address
    state {
      totalAssets
      lastTotalAssets
      allocation {
        supplyQueueIndex
        withdrawQueueIndex
        market {
          uniqueKey
        }
      }
    }
  }
}Vaults Warnings
Warnings type are:
- unrecognized_deposit_asset,
- unrecognized_vault_curator,
- not_whitelisted
Warning level is either:
- YELLOW,
- RED.
query {
  vaults {
    items {
      name
      warnings {
        type
        level
      }
    }
  }
}User all Vaults Position
query GetAllUserPositions($chainId: Int!, $userAddress: String!) {
  vaultPositions(
    where: {
      chainId_in: [$chainId]
      shares_gte: 0
      userAddress_in: [$userAddress]
    }
  ) {
    items {
      id
      assets
      vault {
        id
        address
      }
    }
  }
}Onchain & API combination - Vaults
In this tutorial, we'll explore how to compute the APY and rewards for Morpho Vaults. We'll cover both the calculation of the vault's APY based on allocated assets across markets and the computation of rewards.
First one has to get the Rate (of Native APY or Reward APR) on the markets belonging to the vault and apply the weight method to get the final values.
Native APY Computation
To compute the Annual Percentage Yield (APY) of Morpho Vaults, one has to follow a weighted approach based on the liquidity allocated in each market within the vault's withdraw queue.
1. Retrieve Liquidity: Identify the liquidity allocated in each market in the vault's withdrawal queue.
2. Get APYs: Retrieve the APY of each market thanks to this tutorial.
3. Compute the Weighted APY:
where:
- APYMarketX refers to the APY of market X.
- assetsAllocatedInMarketA is the amount of assets the vault has allocated in market X.
- totalAssetsAllocated is the sum of all assets allocated across markets.
Rewards Computation
A. Get Reward EmissionRetrieve the reward emission rate. Refer to the dedicated rewards section or the Morpho API section related to rewards.
B. Calculate Reward Value- emissionRatePerYearis the annual rate of reward emission. Potentially, there are supply, borrow, and collateral emission rates. In the case of Morpho Vaults, only the supply emission rate matters.
- priceRewardTokenUSDis the price of the reward token in USD.
- rewardTokenDecimalsis the decimal places of the reward token.
- marketTotalAssetsis the total supply of assets in the market.
- assetPriceUSDis the price of the asset in USD.
- assetDecimalsis the decimal of the asset.
