Morpho Integration
What is Morpho?
Morpho is a lending protocol optimizer. It offers MetaMorpho vaults — curated lending pools that automatically allocate capital to the best-performing lending markets.
Think of it as a "yield fund" for lending: instead of manually choosing which lending pool to use, Morpho's vault curators optimize for the best risk-adjusted returns.
How NMT Integrates
| Layer | Component |
|---|---|
| Contract | MorphoModule.sol — deposit, withdraw (ERC-4626 standard) |
| Backend | workers/src/defi/services/morpho/ — indexes vaults and APYs |
| Frontend | lib/defi/morpho/ — vault interaction encoding |
| Data source | The Graph (subgraph) + headless Chrome scraping |
ERC-4626 Vault Standard
Morpho vaults follow the ERC-4626 standard, which defines a common interface for yield-bearing vaults:
| Function | Purpose |
|---|---|
deposit(assets, receiver) |
Deposit tokens and receive vault shares |
withdraw(assets, receiver, owner) |
Burn shares and receive tokens back |
totalAssets() |
Total value locked in the vault |
convertToShares(assets) |
Preview how many shares you'd get |
convertToAssets(shares) |
Preview how many tokens shares are worth |
Data Collection
The backend collects Morpho data from two sources:
- The Graph (GraphQL subgraph) — vault metadata, TVL, historical data
- Headless Chrome — the backend uses a browser to scrape dynamic data from Morpho's web interface that isn't available via API
The headless Chrome dependency is notable because:
- It requires 2Gi of RAM allocated in Kubernetes
- It's fragile — if Morpho changes their website, the scraper breaks
- It's a known technical consideration for the infrastructure
Min TVL filter: $300,000 (only large MetaMorpho vaults are indexed)
Required secret: MORPHO_API_TOKEN for The Graph Gateway access