Skip to main content

Integrating Morpho Vaults

Overview

Morpho Vaults are ERC4626-compliant vaults that enable permissionless risk curation on top of Morpho. This guide covers integration options for Morpho Vaults, including both low-level contract interactions and available SDK utilities.

Core Integration Components

1. Contract Interface

The vaults implement the ERC4626 standard, exposing these key functions. For more details, see the contract section.

There are two ways to deposit assets into the vault:

Deposit:

  • Deposit a specific amount of assets and receive corresponding shares in return
  • Use when you want to deposit an exact amount of underlying tokens
function deposit(uint256 assets, address receiver) returns (uint256 shares)

Mint:

  • Mint a specific amount of shares by depositing the required assets
  • Use when you want to receive an exact amount of vault shares
function mint(uint256 shares, address receiver) returns (uint256 assets)

Then, there are two ways to withdraw assets from the vault:

Withdraw:

  • Withdraw a specific amount of assets by burning the required shares
  • Use when you want to withdraw an exact amount of underlying tokens
function withdraw(uint256 assets, address receiver, address owner) returns (uint256 shares)

Redeem:

  • Redeem a specific amount of shares for the corresponding assets
  • Use when you want to burn an exact amount of vault shares
function redeem(uint256 shares, address receiver, address owner) returns (uint256 assets)

2. Available SDKs

Several open-source SDKs are available for integration:

// Available SDK imports
import { MorphoBlue } from "@morpho-org/blue-sdk";
import { Bundler } from "@morpho-org/bundler-sdk-viem";
import { SimulationProvider } from "@morpho-org/simulation-sdk";

3. API

A GraphQL API endpoint is available for querying vault data.

Best Practices

Gas Optimization

  • The bundler SDK can help optimize complex transactions
  • Implement proper approval handling or leverage existing SDK utilities
  • For withdrawals, redeem may be more efficient than withdraw to avoid dust

User Experience

  • Show loading states during transactions
  • Provide clear feedback for errors
  • Display real-time position updates
  • Implement proper error handling with clear user messages
  • Add appropriate disclaimers and risk warnings

Data Management

On-chain Data (SDK via RPC)

Direct blockchain data access through SDK:

  • Vault and market configurations
  • User positions
  • Real-time vault states
  • APY calculations

Off-chain Data (Blue API)

The GraphQL API provides indexed data with ~1 minute latency:

  • Vault metadata
  • Current allocations
  • Historical performance
  • Market states
  • User rewards

Implementation Checklist

  1. Initial Setup

    • Install required SDKs
    • Configure Web3 provider (wagmi for frontend, viem/ethers for bots)
    • Set up API endpoints
      • For bots: Use GraphQL code generation
      • For interfaces: Implement Apollo Client for caching
  2. Core Integration

    • Implement deposit/withdraw flows
    • Add balance checking (getBalanceOf or fetchHolding)
    • Handle token approvals
    • Implement proper refresh mechanisms
  3. Data Display

    • Display vault APY (available via API)
    • Show user positions
    • Present allocation information
    • Include historical performance metrics

Additional Resources

Example Implementations

  • The open-source earn-basic-app repository contains example implementations of useful hooks, facilitating the deposit and withdraw into vaults. (Support only Ethereum).
  • The OnchainKit project contains example implementations of other react hooks.

Support

For technical support and integration questions, the Morpho community and developers can be reached through official communication channels.