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://blue-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 {
        borrowApy
        borrowAssets
        borrowAssetsUsd
        supplyApy
        supplyAssets
        supplyAssetsUsd
        fee
        utilization
      }
    }
  }
}

Morpho whitelisted markets

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

Assets current usd price and potential yield

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

Oracle details for a given market

query {
  marketByUniqueKey(
    uniqueKey: "0xa72f4af2570dca1b356aa6c1e6a804d0d3df5b23bb092189776d0dc652feabb4"
    chainId: 1
  ) {
    oracle {
      address
      type
      data {
        ... on MorphoChainlinkOracleData {
          baseFeedOne {
            address
            description
            vendor
            pair
          }
          vault
        }
        ... on MorphoChainlinkOracleV2Data {
          baseFeedOne {
            address
            description
            vendor
            pair
          }
        }
      }
    }
  }
}

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 options

Here are the available options 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, HALF_HOUR, FIFTEEN_MINUTES, FIVE_MINUTES, MINUTE).

Inputting these options is not mandatory but it is advised to specify them to control the specific data returned.

If no options 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 markets list queries. Historical data is only available through individual market queries like market(id: "") or marketByUniqueKey(uniqueKey: "").

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 options:

{
"options": {
"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 options:

"options": {
"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: 30
    orderBy: SupplyShares
    orderDirection: Desc
    where: {
      marketUniqueKey_in: [
        "0x698fe98247a40c5771537b5786b2f3f9d78eb487b4ce4d75533cd0e94d88a115"
      ]
    }
  ) {
    items {
      supplyShares
      supplyAssets
      supplyAssetsUsd
      borrowShares
      borrowAssets
      borrowAssetsUsd
      collateral
      collateralUsd
      market {
        uniqueKey
        loanAsset {
          address
          symbol
        }
        collateralAsset {
          address
          symbol
        }
      }
      user {
        address
      }
    }
  }
}

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 {
  markets(
    where: {
      uniqueKey_in: [
        "0x5125fcd427c196c8796f1a7573109ad9884e6ece3208c25a9583b5999b4e03e4"
      ]
    }
  ) {
    items {
      id
      uniqueKey
      loanAsset {
        symbol
      }
      collateralAsset {
        symbol
      }
      supplyingVaults {
        address
      }
    }
  }
}

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
          }
        }
      }
    }
  }
}