Morpho Midnight
How to query Morpho Midnight data with the API?
Morpho Midnight can be accessed through Morpho's REST API currently under version v0. This API is still evolving, and changes to routes and responses may occur as development progresses.
Discovery & listing
List all markets
Returns all Midnight markets, optionally filtered by chain, loan token, or collateral.
GET /v0/midnight/markets
All markets:
# All markets on Ethereum mainnet
curl "https://api.morpho.org/v0/midnight/markets?chain_ids=1"Filtered by token:
# USDC markets on Ethereum with wETH as collateral
curl "https://api.morpho.org/v0/midnight/markets\
?chain_ids=1\
&loan_assets=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\
&collateral_assets=0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"Get market detail
Immutable configuration for a single market: loan token, maturity, collaterals (with LLTV, liquidation cursor, oracle), and gates. Does not include fees or total units (those live on the state endpoint).
GET /v0/midnight/markets/{market-id}
curl "https://api.morpho.org/v0/midnight/markets/0xd92de5e7fbb...7614"
// Response — immutable market definition:
{
"data": {
"chain_id": 1,
"market_id": "0xd92de5e7fbb...7614",
"loan_token": "0xa0b8...3c02", // USDC
"maturity": "1798761600", // Dec 31, 2026
"collaterals": [
{ "token": "0xC02a...6Cc2", "lltv": "860000000000000000", "liquidation_cursor": "250000000000000000", "oracle": "0x1234..." },
{ "token": "0xcbBT...1234", "lltv": "770000000000000000", "liquidation_cursor": "240000000000000000", "oracle": "0x5678..." }
],
"enter_gate": "0x0000...0000",
"liquidator_gate": "0x0000...0000"
}
}Market state & metrics
Get market state
Live market state: total units outstanding, fee configuration, and tick granularity. Separated from the market definition because these values change over time.
GET /v0/midnight/markets/{market-id}/state
curl "https://api.morpho.org/v0/midnight/markets/0xd92de5e7fbb...7614/state"
// Response:
{
"data": {
"chain_id": 1,
"market_id": "0xd92de5e7fbb...7614",
"total_units": "85000000000", // total units outstanding
"tick_granularity": 1, // valid ticks must be multiples of this
"settlement_fee_schedule": [
{ "time_to_maturity_days": 0, "fee_cbp": "0" },
{ "time_to_maturity_days": 1, "fee_cbp": "50" },
{ "time_to_maturity_days": 7, "fee_cbp": "150" },
{ "time_to_maturity_days": 30, "fee_cbp": "400" },
{ "time_to_maturity_days": 90, "fee_cbp": "800" },
{ "time_to_maturity_days": 180, "fee_cbp": "1200" },
{ "time_to_maturity_days": 360, "fee_cbp": "2000" }
],
"current_settlement_fee_cbp": "743.5", // interpolated for current TTM
"current_settlement_fee_wad": "7435000000000", // same value, WAD-scaled
"continuous_fee_rate": "158549000", // per-second, WAD-scaled
"last_indexed_block": "47457420"
}
}Order books & rates
List books (browse all markets with liquidity)
Each book includes the top 3 ask and bid levels. Sorted by maturity, best ask, or best bid.
GET /v0/midnight/books
By maturity:
curl "https://api.morpho.org/v0/midnight/books\
?chain_ids=1\
&loan_tokens=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\
&sort=maturity"By best lend rate:
# Sort by best ask (lowest price = highest lend rate)
curl "https://api.morpho.org/v0/midnight/books\
?chain_ids=1\
&loan_tokens=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\
&sort=ask"Get full book for a market
Up to 5,821 price levels (ticks) per side. Each level sums all offers at that tick.
GET /v0/midnight/books/{market-id}
curl "https://api.morpho.org/v0/midnight/books/0xd92d...7614?depth=50"
// Response:
{
"data": {
"market_id": "0xd92d...7614",
"asks": [
{ "tick": 42, "price": "952380952380952380", "units": "10000000000", "assets": "9523809523", "count": 3 },
{ "tick": 43, "price": "948000...", "units": "18500000000", "assets": "17538000000", "count": 5 }
],
"bids": [
{ "tick": 41, "price": "956937...", "units": "8000000000", "assets": "7655497000", "count": 2 }
]
}
}
// Compute rates from prices:
// lend rate (from asks): (1 / (price / 1e18) - 1) × 365×86400 / TTM
// borrow rate (from bids): (1 / (price / 1e18) - 1) × 365×86400 / TTMGet one side of the book
GET /v0/midnight/books/{market-id}/{side}
# Just the asks (lender opportunities)
curl "https://api.morpho.org/v0/midnight/books/0xd92d...7614/asks?depth=100"
# Just the bids (borrower opportunities)
curl "https://api.morpho.org/v0/midnight/books/0xd92d...7614/bids?depth=100"Quotes & execution
Get a quote (execution plan)
Given a target amount (in assets or units) and a side, the Router returns execution-ready takeable offers sorted by best price with fallback excess.
GET /v0/midnight/books/{market-id}/{side}/quote
Lend (take asks):
// "I want to lend 10,000 USDC" → take asks
curl "https://api.morpho.org/v0/midnight/books/0xd92d...7614/asks/quote\
?assets=10000000000\
&slippage=0.5"
// Response:
{
"data": {
"average_best_price": "947619047619047619",
"average_worst_price": "952380952380952380",
"available_assets": "15000000000",
"available_units": "15750000000",
"takeable_offers": [
{
"market_id": "0xd92d...7614",
"units": "5000000000",
"ratifier_data": "0x4a8b...f201",
"offer": {
"buy": false, "tick": 42,
"maker": "0xAlice...", "ratifier": "0xEcdsa...",
"group": "0xabc...", "maxAssets": "5000000000"
}
},
// … more offers, best price first, with fallback excess
]
}
}Borrow (take bids):
# "I want to borrow 5,000 USDC" → take bids
curl "https://api.morpho.org/v0/midnight/books/0xd92d...7614/bids/quote\
?assets=5000000000\
&slippage=0.5"
# Same response shape — but offers have buy=true (lenders' buy-offers)By units:
# Quote by units instead of assets
curl "https://api.morpho.org/v0/midnight/books/0xd92d...7614/asks/quote\
?units=10500000000"List takeable offers (raw)
Individual executable offers with full Offer struct + ratifier_data. Use when building custom routing or analysis.
GET /v0/midnight/books/{market-id}/{side}/takeable-offers
By market side:
curl "https://api.morpho.org/v0/midnight/books/0xd92d...7614/asks/takeable-offers"By maker:
# All active offers from a specific maker
curl "https://api.morpho.org/v0/midnight/takeable-offers\
?maker=0xMakerAddress...\
&limit=100"Position tracking
List user positions
Returns all positions for a user across markets. Includes cost_basis and effective_rate_wad inline.
GET /v0/midnight/users/{address}/positions
All positions:
curl "https://api.morpho.org/v0/midnight/users/0xAlice.../positions"
// Response:
{
"data": [
{
"market_id": "0xd92d...7614",
"type": "lend",
"credit": "10500000000",
"debt": "0",
"pending_fee": "12000",
"loss_factor": "0",
"cost_basis": "952380952380952380...",
"effective_rate_wad": "52000000000000000",
"collaterals": [],
"maturity": "1798761600"
}
]
}Lend only:
curl "https://api.morpho.org/v0/midnight/users/0xAlice.../positions?types=lend"Borrow only:
curl "https://api.morpho.org/v0/midnight/users/0xAlice.../positions?types=borrow"Get position detail
Raw position state in a specific market. Does not include cost_basis or effective_rate_wad (use the performance endpoint for those).
GET /v0/midnight/markets/{id}/users/{addr}/position
curl "https://api.morpho.org/v0/midnight/markets/0xd92d...7614/users/0xBob.../position"
// Response (borrow position):
{
"data": {
"type": "borrow",
"credit": "0",
"debt": "9000000000",
"pending_fee": "0",
"loss_factor": "0",
"collaterals": [
{ "token": "0xC02a...6Cc2", "amount": "2000000000000000000" },
{ "token": "0xcbBT...1234", "amount": "10000000000000000" }
]
}
}Get position performance
Cost basis and effective rate for P&L computation. Uses average cost accounting.
GET /v0/midnight/markets/{id}/users/{addr}/position/performance
curl "https://api.morpho.org/v0/midnight/markets/0xd92d...7614/users/0xAlice.../position/performance"
// Response:
{
"data": {
"type": "lend",
"accounting_method": "average_cost",
"cost_basis": "952380952380952380...",
"effective_rate_wad": "52000000000000000"
}
}List all positions in a market
Find all borrowers, cross-reference with oracle prices to find unhealthy positions.
GET /v0/midnight/markets/{id}/positions
# All borrowers in a market
curl "https://api.morpho.org/v0/midnight/markets/0xd92d...7614/positions?types=borrow"
# Active positions only (market not yet matured)
curl "https://api.morpho.org/v0/midnight/markets/0xd92d...7614/positions\
?types=borrow\
&active_only=true"Transaction history
User transactions
All onchain events for a user. Filter by event_types to focus on specific actions.
GET /v0/midnight/users/{address}/transactions
Lending activity:
curl "https://api.morpho.org/v0/midnight/users/0xAlice.../transactions\
?event_types=lend,exit_lend_primary,exit_lend_secondary"
# lend → entered lending position (bought units)
# exit_lend_primary → redeemed credit at/after maturity
# exit_lend_secondary → sold credit units earlyBorrowing activity:
curl "https://api.morpho.org/v0/midnight/users/0xBob.../transactions\
?event_types=borrow,exit_borrow_primary,exit_borrow_secondary,supply_collateral,withdraw_collateral"
# borrow → entered borrowing position (sold units)
# exit_borrow_primary → repaid debt
# exit_borrow_secondary → bought units to close debt early
# supply_collateral → deposited collateral
# withdraw_collateral → withdrew collateralLiquidations:
curl "https://api.morpho.org/v0/midnight/users/0xBob.../transactions\
?event_types=partial_liquidation,full_liquidation"
# Each liquidation includes: borrower, collateral, seized_assets,
# repaid_units, post_maturity_mode, bad_debt, latest_loss_factorMarket transactions
GET /v0/midnight/markets/{id}/transactions
# All activity in a market since a specific time
curl "https://api.morpho.org/v0/midnight/markets/0xd92d...7614/transactions\?created_at_gte=1719000000"Offer management
List active offer groups
Track a maker's active consumption groups and which offers belong to them.
GET /v0/midnight/users/{address}/offer-groups
curl "https://api.morpho.org/v0/midnight/users/0xMaker.../offer-groups"
# Filter by market or group ID
curl "https://api.morpho.org/v0/midnight/users/0xMaker.../offer-groups\
?market_ids=0xd92d...7614\
&groups=0xMyGroupId..."Mempool
Validate offers before publishing
Check whether the Router will index your offers. Payload is version byte + 4-byte big-endian gzip length + gzip(ABI-encoded (Offer, bytes ratifierData)[]). Optionally pass a timestamp to validate against a specific policy snapshot.
POST /v0/midnight/mempool/validate
Current policy:
curl -X POST "https://api.morpho.org/v0/midnight/mempool/validate" \
-H "Content-Type: application/json" \
-d '{
"chain_id": 1,
"payload": "0x01..."
}'
# Success (Router will index):
{ "data": { "issues": [] } }
# Issues found (Router will ignore):
{ "data": { "issues": [{ "rule": "unsupported_maturity" }] } }At a specific time:
# Validate against the policy snapshot active at a specific time
# Uses the latest 15:00 UTC boundary at or before the given timestamp
curl -X POST "https://api.morpho.org/v0/midnight/mempool/validate\
?timestamp=2026-06-28T12:00:00Z" \
-H "Content-Type: application/json" \
-d '{
"chain_id": 1,
"payload": "0x01..."
}'Reference data
Tokens
GET /v0/midnight/tokens
# All tokens used in Midnight markets on Ethereum
curl "https://api.morpho.org/v0/midnight/tokens?chain_ids=1"
# Tokens for a specific market
curl "https://api.morpho.org/v0/midnight/tokens?markets=0xd92d...7614"Oracles
GET /v0/midnight/oracles
# Oracle contracts for a market's collaterals
curl "https://api.morpho.org/v0/midnight/oracles?markets=0xd92d...7614"Supported chains
GET /v0/midnight/chains
curl "https://api.morpho.org/v0/midnight/chains"Pagination & filtering
List endpoints support cursor-based pagination. The response includes a cursor field — pass it as a query parameter to get the next page.
Pagination pattern:
# First page
curl "https://api.morpho.org/v0/midnight/markets?chain_ids=1"
// Response includes:
{ "cursor": "eyJpZCI6MTAwfQ...", "data": [...] }
# Next page — pass the cursor
curl "https://api.morpho.org/v0/midnight/markets?chain_ids=1&cursor=eyJpZCI6MTAwfQ..."
// cursor is null when there are no more pagesCommon filter parameters across endpoints:
# By chain
?chain_ids=1 # Ethereum mainnet
?chain_ids=8453 # Base
# By market
?market_ids=0xd92d... # specific market(s)
# By token (combine with chain_ids)
?loan_assets=0xa0b8... # by loan token
?collateral_assets=0xC02a... # by collateral
# By maturity
?maturities=1798761600 # exact maturity timestamp(s)
?maturity_gte=1719000000 # maturities on or after this timestamp
?maturity_lte=1798761600 # maturities on or before this timestamp
# By time (transactions, offer-groups)
?created_at_gte=1719000000 # events after this unix timestamp
?created_at_lte=1720000000 # events before this unix timestamp
?tx_hash=0xabc... # specific transaction (transactions only)
# Position filters
?types=lend # lend | borrow | collateral_only
?active_only=true # only positions in markets that haven't matured
# Offer group sorting
?sort_by=created_at # id | created_at
# Book sorting
?sort=maturity # id | ask | bid | maturity (prefix with - to reverse)