Skip to content

Morpho Markets

How to query Morpho Data thanks to the API?

Select the query you are interested in in the list below, and paste it into the GraphQL Playground: https://api.morpho.org/graphql

By default, the Morpho API returns only the 100 first results and retrieve informations on the Ethereum network.

Basic Queries

Morpho markets

query {
  markets {
    items {
      uniqueKey
      lltv
      oracleAddress
      irmAddress
      loanAsset {
        address
        symbol
        decimals
      }
      collateralAsset {
        address
        symbol
        decimals
      }
      state {
        borrowAssets
        supplyAssets
        fee
        utilization
      }
    }
  }
}

Morpho whitelisted markets

query {
  markets(where: { whitelisted: true }) {
    items {
      uniqueKey
      whitelisted
      lltv
      oracleAddress
      irmAddress
      loanAsset {
        address
        symbol
        decimals
      }
      collateralAsset {
        address
        symbol
        decimals
      }
      state {
        borrowAssets
        supplyAssets
        fee
        utilization
      }
    }
  }
}

Market parameters

query {
  markets(
    first: 100
    orderBy: SupplyAssetsUsd
    orderDirection: Desc
    where: { chainId_in: [1, 8453] }
  ) {
    items {
      uniqueKey
      loanAsset { address }
      collateralAsset { address }
      lltv
      irmAddress
      oracleAddress
    }
  }
}

Market parameters for a specific market

query {
  marketByUniqueKey(
    uniqueKey: "0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836"
    chainId: 8453
  ) {
    uniqueKey
    loanAsset { address }
    collateralAsset { address }
    lltv
    irmAddress
    oracleAddress
  }
}

Market totals (supply, borrow, collateral)

query {
  markets(
    first: 100
    orderBy: SupplyAssetsUsd
    orderDirection: Desc
    where: { chainId_in: [1, 8453] }
  ) {
    items {
      uniqueKey
      state {
        collateralAssets
        collateralAssetsUsd
        borrowAssets
        borrowAssetsUsd
        supplyAssets
        supplyAssetsUsd
        liquidityAssets
        liquidityAssetsUsd
      }
    }
  }
}

Market totals for a specific market

query {
  marketByUniqueKey(
    uniqueKey: "0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836"
    chainId: 8453
  ) {
    state {
      collateralAssets
      borrowAssets
      supplyAssets
      liquidityAssets
    }
  }
}

Market APY (all markets)

query {
  markets(
    first: 100
    orderBy: SupplyAssetsUsd
    orderDirection: Desc
    where: { chainId_in: [1, 8453] }
  ) {
    items {
      uniqueKey
      state {
        supplyApy
        borrowApy
        rewards {
          asset { address }
          supplyApr
          borrowApr
        }
      }
    }
  }
}

Market APY for a specific market

query {
  marketByUniqueKey(
    uniqueKey: "0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836"
    chainId: 8453
  ) {
    state {
      supplyApy
      borrowApy
      rewards { supplyApr, borrowApr }
    }
  }
}

Assets current usd price and potential yield

query GetAssetsWithPrice {
  assets(where: { symbol_in: ["wstETH", "WETH"], chainId_in: [1] }) {
    items {
      symbol
      address
      priceUsd
      chain {
        id
        network
      }
    }
  }
}
  • priceUsd is the current price of the asset in USD.
  • oraclePriceUsd is a deprecated field, please use priceUsd instead.

Oracle details for all markets

query MARKETS_PARAMS {
  markets(
    first: 100
    orderBy: SupplyAssetsUsd
    orderDirection: Desc
    where: { chainId_in: [1, 8453] }
  ) {
    items {
      uniqueKey
      oracleAddress
      oracle {
        address
        type
        creationEvent {
          txHash
          timestamp
          blockNumber
        }
        data {
          ... on MorphoChainlinkOracleV2Data {
            baseFeedOne {
              address
              description
              vendor
              pair
            }
            baseFeedTwo {
              address
            }
            baseVaultConversionSample
            quoteFeedOne {
              address
            }
            quoteFeedTwo {
              address
            }
            quoteVaultConversionSample
          }
          ... on MorphoChainlinkOracleData {
            baseFeedOne {
              address
              description
              vendor
              pair
            }
            baseOracleVault {
              address
            }
          }
        }
      }
      oracleInfo {
        type
      }
    }
  }
}

Oracle details for a given market

query {
  marketByUniqueKey(
    uniqueKey: "0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836"
    chainId: 8453
  ) {
    uniqueKey
    oracleAddress
    oracle {
      address
      type
      creationEvent {
        txHash
        timestamp
        blockNumber
      }
      data {
        ... on MorphoChainlinkOracleV2Data {
          baseFeedOne {
            address
            description
            vendor
            pair
          }
          baseFeedTwo {
            address
          }
          baseVaultConversionSample
          quoteFeedOne {
            address
          }
          quoteFeedTwo {
            address
          }
          quoteVaultConversionSample
        }
        ... on MorphoChainlinkOracleData {
          baseFeedOne {
            address
            description
            vendor
            pair
          }
          baseOracleVault {
            address
          }
        }
      }
    }
    oracleInfo {
      type
    }
  }
}

Historical queries

The historicalState allows to get historical data for certain queries. The queries need to be backfilled to return proper data (i.e. the historical data needs to be indexed and stored). Some queries are not backfilled and are flagged as deprecated in the Morpho API sandbox.

How to use the historicalState variables

Here are the available variables when using an historicalState query:

  • startTimestamp: beginning of the historical data in UNIX timestamp format,
  • endTimestamp: end of the historical data in UNIX timestamp format,
  • interval: interval of the historical data points (YEAR, QUARTER, MONTH, WEEK, DAY, HOUR). Inputting these variables is not mandatory but it is advised to specify them to control the specific data returned.

If no variables are specified, the default values will be:

  • startTimestamp: 0,
  • endTimestamp: infinity,
  • interval: will adjust according to startTimestamp and endTimestamp to return around 50 data points.

Note that the historicalState field is not accessible through the (multiple) markets(...) and vaults(...) list queries. Historical data is only available through individual market or vault queries like market(id: ""), marketByUniqueKey, vault(id: "") or vaultByAddress.

Below you will find examples of historicalData queries.

Historical borrow and supply APY

query MarketApys($options: TimeseriesOptions) {
  weeklyHourlyMarketApys: marketByUniqueKey(
    uniqueKey: "0x608929d6de2a10bacf1046ff157ae38df5b9f466fb89413211efb8f63c63833a"
  ) {
    uniqueKey
    historicalState {
      supplyApy(options: $options) {
        x
        y
      }
      borrowApy(options: $options) {
        x
        y
      }
    }
  }
}

With the following variables:

{
"variables": {
"startTimestamp": 1707749700,
"endTimestamp": 1708354500,
"interval": HOUR,
  }
}

Historical borrow and supply assets usd

query MarketApys($options: TimeseriesOptions) {
  weeklyrlyMarketAssetsUsd: marketByUniqueKey(
    uniqueKey: "0x608929d6de2a10bacf1046ff157ae38df5b9f466fb89413211efb8f63c63833a"
  ) {
    uniqueKey
    historicalState {
      supplyAssetsUsd(options: $options) {
        x
        y
      }
      borrowAssetsUsd(options: $options) {
        x
        y
      }
    }
  }
}

With the following variables:

"variables": {
"startTimestamp": 1707749700,
"endTimestamp": 1708354500,
"interval": HOUR,
}

Asset price history

query {
  wstETHWeeklyPriceUsd: assetByAddress(
    address: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
    chainId: 1
  ) {
    historicalPriceUsd(
      options: {
        startTimestamp: 1707749700
        endTimestamp: 1708354500
        interval: HOUR
      }
    ) {
      x
      y
    }
  }
}

All queries sent for assetByAddress, marketByUniqueKey and vaultByAddress should include the chainId parameter.

Advanced Queries with more variables

Account overview

query {
  userByAddress(
    chainId: 1
    address: "0x821880a3E2bac432d67E5155e72BB655Ef65fa5E"
  ) {
    address
    marketPositions {
      market {
        uniqueKey
      }
      borrowAssets
      borrowAssetsUsd
      supplyAssets
      supplyAssetsUsd
    }
    vaultPositions {
      vault {
        address
        name
      }
      assets
      assetsUsd
      shares
    }
    transactions {
      hash
      timestamp
      type
    }
  }
}

Market(s) positions overview

query {
  marketPositions(
    first: 10
    orderBy: SupplyShares
    orderDirection: Desc
    where: {
      marketUniqueKey_in: [
        "0x698fe98247a40c5771537b5786b2f3f9d78eb487b4ce4d75533cd0e94d88a115"
      ]
    }
  ) {
    items {
      market {
        uniqueKey
        loanAsset {
          address
          symbol
        }
        collateralAsset {
          address
          symbol
        }
      }
      user {
        address
      }
      state {
        supplyShares
        supplyAssets
        supplyAssetsUsd
        borrowShares
        borrowAssets
        borrowAssetsUsd
        collateral
        collateralUsd
      }
    }
  }
}

Paging, ordering and the filtering capabilities

query {
  markets(
    first: 3
    skip: 1
    orderBy: Lltv
    orderDirection: Desc
    where: {
      collateralAssetAddress_in: ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]
    }
  ) {
    pageInfo {
      count
      countTotal
    }
    items {
      uniqueKey
      lltv
      collateralAsset {
        symbol
      }
      loanAsset {
        symbol
      }
    }
  }
}

List of vaults supplying into a market

query {
  marketByUniqueKey(
    uniqueKey: "0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836"
    chainId: 8453
  ) {
    uniqueKey
    supplyingVaults {
      address
      symbol
      metadata {
        description
      }
    }
  }
}

Liquidations that occurred on specific markets

query {
  transactions(
    where: {
      marketUniqueKey_in: [
        "0x49bb2d114be9041a787432952927f6f144f05ad3e83196a7d062f374ee11d0ee"
        "0x093d5b432aace8bf6c4d67494f4ac2542a499571ff7a1bcc9f8778f3200d457d"
      ]
      type_in: [MarketLiquidation]
    }
  ) {
    items {
      blockNumber
      hash
      type
      user {
        address
      }
      data {
        ... on MarketLiquidationTransactionData {
          seizedAssets
          repaidAssets
          seizedAssetsUsd
          repaidAssetsUsd
          badDebtAssetsUsd
          liquidator
          market {
            uniqueKey
          }
        }
      }
    }
  }
}

User positions on markets

query {
  marketPositions(
    first: 10,
    orderBy: BorrowAssetsUsd,
    orderDirection: Desc
    where: {
      marketUniqueKey_in: ["0x698fe98247a40c5771537b5786b2f3f9d78eb487b4ce4d75533cd0e94d88a115"]
    }
  ) {
    items {
      user { address }
      state {
        collateral
        borrowAssets
        borrowAssetsUsd
      }
    }
  }
}

Markets warnings

query {
  markets {
    items {
      uniqueKey
      warnings {
        type
        level
      }
    }
  }
}