Skip to main content

Morpho Subgraph

The Morpho subgraph indexes all markets created on Morpho, and all Morpho Vaults defined through the Deployed MetaMorpho Factory.

You can easily retrieve analytics such as the daily activity of the protocol, users' positions on both Morpho & Morpho Vaults and more.

It follows the Messari Schema standard for Lending protocols. In practice, some naming can differ from the classic Morpho naming to match the Messari standard.

Morpho Subgraph Repository

Find the repository on the morpho-org Github

Morpho Subgraph Playgrounds

Explore the Playgrounds:

Questions

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


Morpho examples

1. BorrowAPY

  1. Query:
{
interestRates(
first: 100
where: { side: BORROWER }
orderBy: market__totalValueLockedUSD
orderDirection: desc
) {
id
rate
side
}
}
  1. One should get a similar as what follows:
{
"data": {
"interestRates": [
{
"id": "0x39d11026eae1c6ec02aa4c0910778664089cdd97c3fd23f68f7cd05e2e95af48-borrow-477103",
"rate": "0.205574598544752",
"side": "BORROWER"
},
{
"id": "0x39d11026eae1c6ec02aa4c0910778664089cdd97c3fd23f68f7cd05e2e95af48-borrow-477102",
"rate": "0.20816504877672",
"side": "BORROWER"
},
... // truncated
]
}
}

This provides you with the annualized rate for the market with their market id alongside.

BorrowAPY=(e(rate)1)\text{BorrowAPY} = (e^{(\text{rate})} - 1)

2. SupplyAPY

  1. Query:
{
interestRates(
first: 100
where: { side: LENDER }
orderBy: market__totalValueLockedUSD
orderDirection: desc
) {
id
rate
side
}
}
  1. One should get the following output:
{
"data": {
"interestRates": [
{
"id": "0x39d11026eae1c6ec02aa4c0910778664089cdd97c3fd23f68f7cd05e2e95af48-supply-477103",
"rate": "0.19011573722135125872777079486656",
"side": "LENDER"
},
{
"id": "0x39d11026eae1c6ec02aa4c0910778664089cdd97c3fd23f68f7cd05e2e95af48-supply-477102",
"rate": "0.1926757618149261525835489760268",
"side": "LENDER"
},
... // truncated
]
}
}

This provides you with the annualized rate for the market with their market id alongside.

SupplyAPY=(e(rate)1)\text{SupplyAPY} = (e^{(\text{rate})} - 1)

3. Market Data

  1. Query:
{
markets(first: 1000, orderBy: totalValueLockedUSD, orderDirection: desc) {
borrowCount
borrowingPositionCount
borrowedToken {
name
symbol
}
closedPositionCount
collateralPositionCount
createdBlockNumber
createdTimestamp
cumulativeBorrowUSD
cumulativeDepositUSD
cumulativeFlashloanUSD
cumulativeLiquidateUSD
cumulativeProtocolSideRevenueUSD
cumulativeTotalRevenueUSD
cumulativeSupplySideRevenueUSD
cumulativeTransferUSD
cumulativeUniqueBorrowers
cumulativeUniqueDepositors
cumulativeUniqueFlashloaners
cumulativeUniqueLiquidatees
cumulativeUniqueLiquidators
cumulativeUniqueUsers
cumulativeUniqueTransferrers
depositCount
fee
flashloanCount
id
inputTokenBalance
inputToken {
name
}
inputTokenPriceUSD
interest
isActive
lendingPositionCount
liquidationCount
liquidationPenalty
liquidationThreshold
maximumLTV
name
openPositionCount
positionCount
relation
repayCount
reserveFactor
reserves
supplyIndex
totalBorrow
totalBorrowBalanceUSD
totalBorrowShares
totalDepositBalanceUSD
totalCollateral
totalSupply
totalSupplyShares
totalValueLockedUSD
transactionCount
transferCount
variableBorrowedTokenBalance
withdrawCount
}
}
  1. One should get the following output:
{
"data": {
"markets": [
{
"borrowCount": 387,
"borrowedToken": {
"name": "Dai Stablecoin",
"symbol": "DAI"
},
"borrowingPositionCount": 112,
"closedPositionCount": 49,
"collateralPositionCount": 90,
"createdBlockNumber": "19433342",
"createdTimestamp": "1710420443",
"cumulativeBorrowUSD": "161253233.6237656067686458053061481",
"cumulativeDepositUSD": "349103813.0727065086399682490796768",
"cumulativeFlashloanUSD": "0",
"cumulativeLiquidateUSD": "251.66748562665217990112693332",
"cumulativeProtocolSideRevenueUSD": "0",
"cumulativeSupplySideRevenueUSD": "0",
"cumulativeTotalRevenueUSD": "0",
"cumulativeTransferUSD": "0",
"cumulativeUniqueBorrowers": 112,
"cumulativeUniqueDepositors": 4,
"cumulativeUniqueFlashloaners": 0,
"cumulativeUniqueLiquidatees": 0,
"cumulativeUniqueLiquidators": 0,
"cumulativeUniqueTransferrers": 0,
"cumulativeUniqueUsers": 118,
"depositCount": 440,
"fee": "0",
"flashloanCount": 0,
"id": "0x39d11026eae1c6ec02aa4c0910778664089cdd97c3fd23f68f7cd05e2e95af48",
"inputToken": {
"name": "Staked USDe"
},
"inputTokenBalance": "134493178319142021823165948",
"inputTokenPriceUSD": "1.032767836856392329",
"interest": "976372724813410400494662",
"isActive": true,
"lendingPositionCount": 120,
"liquidationCount": 1,
"liquidationPenalty": "0.043841336116910229",
"liquidationThreshold": "0.86",
"maximumLTV": "0.86",
"name": "DAI / sUSDe",
"openPositionCount": 183,
"positionCount": 232,
"relation": null,
"repayCount": 108,
"reserveFactor": "0",
"reserves": "0",
"supplyIndex": null,
"totalBorrow": "124379528080181424932311447",
"totalBorrowBalanceUSD": "124315348.243692051317046374293348",
"totalBorrowShares": "119425240581523865658272705519676",
"totalCollateral": "158214585360882220189949364",
"totalDepositBalanceUSD": "297822714.9214187113753299380218499",
"totalSupply": "134493178319142021823165948",
"totalSupplyShares": "129733816859055910217780650076839",
"totalValueLockedUSD": "297822714.9214187113753299380218499",
"transactionCount": 1045,
"transferCount": 0,
"variableBorrowedTokenBalance": "124379528080181424932311447",
"withdrawCount": 109
},
... // truncated
]
}
}

4. Positions Data

  1. Query:
{
accounts(first: 1000) {
id
positionCount
openPositionCount
closedPositionCount
depositCount
withdrawCount
borrowCount
repayCount
positions(first: 1000) {
id
market {
id
}
asset {
id
}
hashClosed
side
type
isCollateral
balance
principal
depositCount
withdrawCount
borrowCount
repayCount
liquidationCount
shares
depositCollateralCount
withdrawCollateralCount
}
}
}
  1. One should get the following output:
{
"data": {
"accounts": [
{
"id": "0x00000000a2318f34c1967b9f73715235da1ffb0c",
"positionCount": 1,
"openPositionCount": 1,
"closedPositionCount": 0,
"depositCount": 0,
"withdrawCount": 0,
"borrowCount": 0,
"repayCount": 0,
"positions": [
{
"id": "0x00000000a2318f34c1967b9f73715235da1ffb0c-0x80935c765bbcb123bffa374ea9c3e84511f9dabd20a8977814eaa309c7e9aeba-COLLATERAL-0",
"market": {
"id": "0x80935c765bbcb123bffa374ea9c3e84511f9dabd20a8977814eaa309c7e9aeba"
},
"asset": {
"id": "0xdf2553b3ad768b5a29957a8dbe247ccd6f318b39"
},
"hashClosed": null,
"side": "COLLATERAL",
"type": null,
"isCollateral": true,
"balance": "1000000000000000",
"principal": "1000000000000000",
"depositCount": 1,
"withdrawCount": 0,
"borrowCount": 0,
"repayCount": 0,
"liquidationCount": 0,
"shares": null,
"depositCollateralCount": 1,
"withdrawCollateralCount": 0
}
]
},
... // truncated
]
}
}

Morpho Vaults examples

1. Global Data - Vault Specific

  1. Query:
{
metaMorphos(where: { id: "0xbeef02e5e13584ab96848af90261f0c8ee04722a" }) {
id
name
symbol
owner {
id
}
curator {
id
}
fee
feeRecipient {
id
}
guardian {
id
}
lastTotalAssets
asset {
id
}
account {
id
}
allocators {
id
account {
id
}
isCurrentAllocator
}
supplyQueue {
id
market {
id
}
}
withdrawQueue {
id
market {
id
}
}
timelock
}
}
  1. One should get a similar as what follows:
{
"data": {
"metaMorphos": [
{
"id": "0xbeef02e5e13584ab96848af90261f0c8ee04722a",
"name": "Steakhouse PYUSD",
"symbol": "steakPYUSD",
"owner": {
"id": "0x255c7705e8bb334dfcae438197f7c4297988085a"
},
"curator": null,
"fee": "50000000000000000",
"feeRecipient": {
"id": "0x255c7705e8bb334dfcae438197f7c4297988085a"
},
"guardian": null,
"lastTotalAssets": "249000000000",
"asset": {
"id": "0x6c3ea9036406852006290770bedfcaba0e23a0e8"
},
"account": {
"id": "0xbeef02e5e13584ab96848af90261f0c8ee04722a"
},
"allocators": [
{
"id": "0x0d61c8b6ca9669a36f351de3ae335e9689dd9c5bbeef02e5e13584ab96848af90261f0c8ee04722a",
"account": {
"id": "0x0d61c8b6ca9669a36f351de3ae335e9689dd9c5b"
},
"isCurrentAllocator": true
},
{
"id": "0xfeed60018f9eaa7df2b5e377b5cfcd630b537018beef02e5e13584ab96848af90261f0c8ee04722a",
"account": {
"id": "0xfeed60018f9eaa7df2b5e377b5cfcd630b537018"
},
"isCurrentAllocator": true
}
],
"supplyQueue": [
{
"id": "0xbeef02e5e13584ab96848af90261f0c8ee04722a124ddf1fa02a94085d1fcc35c46c7e180ddb8a0d3ec1181cf67a75341501c9e6",
"market": {
"id": "0x124ddf1fa02a94085d1fcc35c46c7e180ddb8a0d3ec1181cf67a75341501c9e6"
}
}
],
"withdrawQueue": [
{
"id": "0xbeef02e5e13584ab96848af90261f0c8ee04722a124ddf1fa02a94085d1fcc35c46c7e180ddb8a0d3ec1181cf67a75341501c9e6",
"market": {
"id": "0x124ddf1fa02a94085d1fcc35c46c7e180ddb8a0d3ec1181cf67a75341501c9e6"
}
},
{
"id": "0xbeef02e5e13584ab96848af90261f0c8ee04722ac576cddfd1ee8332d683417548801d6835fa15fb2332a647452248987a8eded3",
"market": {
"id": "0xc576cddfd1ee8332d683417548801d6835fa15fb2332a647452248987a8eded3"
}
},
{
"id": "0xbeef02e5e13584ab96848af90261f0c8ee04722af8c13c80ab8666c21fc5afa13105745cae7c1da13df596eb5054319f36655cc9",
"market": {
"id": "0xf8c13c80ab8666c21fc5afa13105745cae7c1da13df596eb5054319f36655cc9"
}
}
],
"timelock": "604800"
}
]
}
}

Questions

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