Get Data
Before Starting
In this tutorial, you'll see three main ways to fetch data for Morpho Markets:
- API: Using the Morpho public API. This is the easiest and most direct way to get comprehensive, indexed data for most applications.
- Smart Contract: Fetching data directly onchain using read functions (or offchain via libraries like Viem). This is best for real-time, trustless data needed within other smart contracts or sensitive applications.
- SDK: Using the Morpho SDKs for pre-built abstractions that handle complex calculations (like interest accrual) and simplify development.
For each topic below, you'll find guides for each method where applicable. This structure helps you choose the best approach for your specific use case.
Basics
Markets List
Quickly retrieve a list of all markets or filter for specific ones, like those whitelisted for incentives.
query {
markets {
items {
uniqueKey
lltv
oracleAddress
irmAddress
loanAsset {
address
symbol
decimals
}
collateralAsset {
address
symbol
decimals
}
state {
borrowAssets
supplyAssets
fee
utilization
}
}
}
}
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(s) Parameters
Fetch the core, immutable parameters for one or more markets.
query {
markets(
first: 100
orderBy: SupplyAssetsUsd
orderDirection: Desc
where: { chainId_in: [1, 8453] }
) {
items {
uniqueKey
loanAsset { address }
collateralAsset { address }
lltv
irmAddress
oracleAddress
}
}
}
query {
marketByUniqueKey(
uniqueKey: "0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836"
chainId: 8453
) {
uniqueKey
loanAsset { address }
collateralAsset { address }
lltv
irmAddress
oracleAddress
}
}
Total Collateral, Borrow & Supply
Get the real-time state of liquidity and debt in a market.
query {
markets(
first: 100
orderBy: SupplyAssetsUsd
orderDirection: Desc
where: { chainId_in: [1, 8453] }
) {
items {
uniqueKey
state {
collateralAssets
collateralAssetsUsd
borrowAssets
borrowAssetsUsd
supplyAssets
supplyAssetsUsd
liquidityAssets
liquidityAssetsUsd
}
}
}
}
query {
marketByUniqueKey(
uniqueKey: "0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836"
chainId: 8453
) {
state {
collateralAssets
borrowAssets
supplyAssets
liquidityAssets
}
}
}
Market APY (Native & Rewards)
Get the real-time APY, interest rates, and accrual information for markets.
query {
markets(
first: 100
orderBy: SupplyAssetsUsd
orderDirection: Desc
where: { chainId_in: [1, 8453] }
) {
items {
uniqueKey
state {
supplyApy
borrowApy
rewards {
asset { address }
supplyApr
borrowApr
}
}
}
}
}
query {
marketByUniqueKey(
uniqueKey: "0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836"
chainId: 8453
) {
state {
supplyApy
borrowApy
rewards { supplyApr, borrowApr }
}
}
}
User Position on Market
query {
marketPositions(
first: 10,
orderBy: BorrowAssetsUsd,
orderDirection: Desc
where: {
marketUniqueKey_in: ["0x698fe98247a40c5771537b5786b2f3f9d78eb487b4ce4d75533cd0e94d88a115"]
}
) {
items {
user { address }
state {
collateral
borrowAssets
borrowAssetsUsd
}
}
}
}
Assets
Get metadata and pricing for specific tokens.
query GetAssetsWithPrice {
assets(where: { symbol_in: ["wstETH", "WETH"], chainId_in: [1] }) {
items {
symbol
address
priceUsd
chain {
id
network
}
}
}
}
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 tostartTimestamp
andendTimestamp
to return around 50 data points.
Historical APYs
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
query MarketApys($options: TimeseriesOptions) {
weeklyrlyMarketAssetsUsd: marketByUniqueKey(
uniqueKey: "0x608929d6de2a10bacf1046ff157ae38df5b9f466fb89413211efb8f63c63833a"
) {
uniqueKey
historicalState {
supplyAssetsUsd(options: $options) {
x
y
}
borrowAssetsUsd(options: $options) {
x
y
}
}
}
}
Historical Asset Price
query {
wstETHWeeklyPriceUsd: assetByAddress(
address: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
chainId: 1
) {
historicalPriceUsd(
options: {
startTimestamp: 1707749700
endTimestamp: 1708354500
interval: HOUR
}
) {
x
y
}
}
}
Advanced Queries
Oracle Data
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
}
}
}
}
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
}
}
}
Liquidations
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
}
}
}
}
}
}
Extra Queries
Vault Listing
The following query corresponds to which vault has this market in its supply queue
query {
marketByUniqueKey(
uniqueKey: "0x9103c3b4e834476c9a62ea009ba2c884ee42e94e6e314a26f04d312434191836"
chainId: 8453
) {
uniqueKey
supplyingVaults {
address
symbol
metadata {
description
}
}
}
}
Positions
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
Warnings type are those ones:
unrecognized_collateral_asset
: The collateral asset used in the market is not a part of the recognized token listunrecognized_oracle
: The oracle asset used in the market has not been added to the whitelistunrecognized_loan_asset
: The loan asset used in the market is not a part of our recognized token listbad_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
query {
markets {
items {
uniqueKey
warnings {
type
level
}
}
}
}