Skip to content

Basic Queries

Markets List

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

Market(s) Parameters

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

Total Collateral - Borrow - Supply

API - All Markets
query {
  markets(
    first: 100
    orderBy: SupplyAssetsUsd
    orderDirection: Desc
    where: { chainId_in: [1, 8453] }
  ) {
    items {
      id
      uniqueKey
      loanAsset {
        address
        symbol
        decimals
        chain {
          network
        }
      }
      collateralAsset {
        address
        symbol
        decimals
      }
      lltv
      irmAddress
      oracle {
        address
      }
      state {
        collateralAssets
        collateralAssetsUsd
        borrowAssets
        borrowAssetsUsd
        borrowShares
        supplyAssets
        supplyAssetsUsd
        supplyShares
        liquidityAssets
        liquidityAssetsUsd
      }
    }
  }
}

APY - native & Rewards

API - All Markets
query {
  markets(
    first: 100
    orderBy: SupplyAssetsUsd
    orderDirection: Desc
    where: { chainId_in: [1, 8453] }
  ) {
    items {
      uniqueKey
      oracleAddress
      state {
        supplyApy
        netSupplyApy
        borrowApy
        netBorrowApy
        rewards {
          asset {
            address
          }
          supplyApr
          borrowApr
        }
        apyAtTarget
      }
    }
  }
}

Assets

API
query GetAssetsWithPrice {
  assets(where: { symbol_in: ["sUSDS"], chainId_in: [1, 8453] }) {
    items {
      symbol
      address
      priceUsd
      chain {
        id
        network
        currency
      }
      yield {
        apr
      }
    }
  }
}

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.

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.

Historical APYs

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

with the following variables

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

Historical Market States

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

Historical Asset Price

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

Advanced Queries

Oracle Data

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

Vault Listing

The following query corresponds to which vault has this market in its supply queue

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

Liquidations

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

Positions

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

Warnings

Warningss type are those ones:

  • unrecognized_collateral_asset: The collateral asset used in the market is not a part of the recognized token list
  • unrecognized_oracle : The oracle asset used in the market has not been added to the whitelist
  • unrecognized_loan_asset: The loan asset used in the market is not a part of our recognized token list
  • bad_debt_unrealized & RED level: This market has significant unrealized bad debt (>25 BPS total supply)
  • bad_debt_unrealized & YELLOW level: This market has some unrealized bad debt (>$10k)
  • bad_debt_realized: This market has some realized bad debt (>10 BPS of total supply)

Warning level is either:

  • YELLOW
  • RED
API
query {
  markets {
    items {
      uniqueKey
      warnings {
        type
        level
      }
    }
  }
}