Subgraphs Documentation

This page describes the use of the Morpho Subgraphs: Access public data from Morpho Protocol (analytics, rates, APY, rewards) programmatically, useful for time-consuming on-chain data retrieval.

Morpho Subgraphs Repository

Morpho Subgraphs Playground

Introduction

The Morpho Subgraphs provide developers with a powerful way to access and retrieve data from the Morpho Protocol, using GraphQL-based subgraphs. The subgraphs enable developers to track the evolution of the supported lending protocols and their interactions with Morpho.

Getting Started

To use the Morpho Subgraphs, you need to be familiar with GraphQL and its query language. Visit the Morpho Subgraphs Playground to explore the available subgraphs and learn how to structure your queries.

Explore the Subgraphs

The subgraphs contain data related to lending protocols, event flows, P2P improvements, and more. You can access data such as pool rates, indexes, balances, and user interactions with Morpho, including supplies, borrows, repayments and withdraws.

Why using the Subgraphs?

  • Using the Morpho Subgraphs enables you to access comprehensive data from the Morpho Protocol, including information about its peer-to-peer aspect. The subgraphs provide a scalable and efficient way to retrieve information that is difficult or time-consuming to compute on-chain.

4 examples:

  • n°1: query the last deposit.

query {
  deposits(first: 1, orderBy: blockNumber, orderDirection: desc) {
    id
    hash
    account {
      id
    }
    asset {
      id
      name
      symbol
    }
    amount
    amountUSD
    timestamp
    blockNumber
  }
}
// Leading to this result:
{
  "data": {
    "deposits": [
      {
        "id": "0xdab1565cd9d12a950a260b2bee1046b09e5052681d254178674c1ac17ea5c90a70020000",
        "hash": "0xdab1565cd9d12a950a260b2bee1046b09e5052681d254178674c1ac17ea5c90a",
        "account": {
          "id": "0x2068d14ee50772dd6e89c6f64f32adad0cc936ef"
        },
        "asset": {
          "id": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
          "name": "Wrapped Ether",
          "symbol": "WETH"
        },
        "amount": "25000000000000000000",
        "amountUSD": "46180.5",
        "timestamp": "1682931707",
        "blockNumber": "17164957"
      }
    ]
  }
}
  • n°2: query the position.

query {
  accounts(first: 1) {
    id
    positions {
      market {
        id
      }
      asset {
        id
        symbol
      }
      side
      balanceOnPool
      balanceInP2P
    }
  }
}
// Leading to this result:
{
  "data": {
    "accounts": [
      {
        "id": "0x000000005ebfb5a950f8fdf3248e99614a7ff220",
        "positions": [
          {
            "market": {
              "id": "0x39aa39c021dfbae8fac545936693ac917d5e7563"
            },
            "asset": {
              "id": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
              "symbol": "USDC"
            },
            "side": "LENDER",
            "balanceOnPool": "29715338200741",
            "balanceInP2P": "0"
          },
          {
            "market": {
              "id": "0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9"
            },
            "asset": {
              "id": "0xdac17f958d2ee523a2206206994597c13d831ec7",
              "symbol": "USDT"
            },
            "side": "BORROWER",
            "balanceOnPool": "0",
            "balanceInP2P": "24918746309754"
          }
        ]
      }
    ]
  }
  • n°3: query the last liquidation

query {
  liquidates(first: 1, orderBy: blockNumber, orderDirection: desc) {
    id
    hash
    gasPrice
    gasUsed
    blockNumber
    market {
      id
      name
    }
    liquidator {
      id
    }
    liquidatee {
      id
    }
    asset {
      id
      name
      symbol
      lastPriceUSD
    }
    amount
    amountUSD
    profitUSD
  }
}
// Leading to this result:
{ "data": {
    "liquidates": [
      {
        "id": "0x38ab0c841de3c5f3758df0f73d1365ed3a24f9875b38b41a41d264e55708b8c261000000",
        "hash": "0x38ab0c841de3c5f3758df0f73d1365ed3a24f9875b38b41a41d264e55708b8c2",
        "gasPrice": null,
        "gasUsed": null,
        "blockNumber": "16804851",
        "market": {
          "id": "0x1982b2f5814301d4e9a8b0201555376e62f82428",
          "name": "Morpho Aave interest bearing STETH"
        },
        "liquidator": {
          "id": "0xd050e0a4838d74769228b49dff97241b4ef3805d"
        },
        "liquidatee": {
          "id": "0xe7cace2d0c8039e0ad5b49e95110e91b3b58b188"
        },
        "asset": {
          "id": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
          "name": "USD Coin",
          "symbol": "USDC",
          "lastPriceUSD": "1.00291125621762623294967415"
        },
        "amount": "40214350558801436473",
        "amountUSD": "57775.11468077603154058795781163777",
        "profitUSD": "3779.68039967693664156638170996419"
      }
    ]
  }
}

n°4: query the depositors/borrowers for a specific market

{
  markets(first: 1000, where: {id: "0x030ba81f1c18d280636f32af80b9aad02cf0854e"}) {
    id
    name
    positions {
      id
      account {
        id
      }
      side
      balanceOnPool
      balanceInP2P
    }
  }
}
// Leading to this result:
{
  "data": {
    "markets": [
      {
        "id": "0x030ba81f1c18d280636f32af80b9aad02cf0854e",
        "name": "Morpho Aave interest bearing WETH",
        "positions": [
          {
            "id": "0x00657209c6c9f678df9b6597ec9348da6300597e-0x030ba81f1c18d280636f32af80b9aad02cf0854e-LENDER-0",
            "account": {
              "id": "0x00657209c6c9f678df9b6597ec9348da6300597e"
            },
            "side": "LENDER",
            "balanceOnPool": "0",
            "balanceInP2P": "21812136102581728"
          },
          {
            "id": "0x013f42b94b828da22020f9e3208922acb4bd24b3-0x030ba81f1c18d280636f32af80b9aad02cf0854e-BORROWER-0",
            "account": {
              "id": "0x013f42b94b828da22020f9e3208922acb4bd24b3"
            },
            "side": "BORROWER",
            "balanceOnPool": "0",
            "balanceInP2P": "46643701229607763895"
          },
          {
            "id": "0x016b5ccd5f996d7769747d97ce026ec126a3a197-0x030ba81f1c18d280636f32af80b9aad02cf0854e-LENDER-0",
            "account": {
              "id": "0x016b5ccd5f996d7769747d97ce026ec126a3a197"
            },
            "side": "LENDER",
            "balanceOnPool": "0",
            "balanceInP2P": "590239976581260"
          },
          {
            "id": "0x017ec75cd68ac9120e11f7ff5a293f782fb823d3-0x030ba81f1c18d280636f32af80b9aad02cf0854e-LENDER-0",
            "account": {
              "id": "0x017ec75cd68ac9120e11f7ff5a293f782fb823d3"
            },
            "side": "LENDER",
            "balanceOnPool": "0",
            "balanceInP2P": "0"
          },
...

If you have any questions or need further assistance, please don't hesitate to reach out on Discord

Last updated

Logo

This documentation is provided by MorphoLabs, main contributor to Morpho DAO. For any question, reach out.