Morpho Markets for Borrow products
Integrating Morpho Markets (Borrow) into your application means implementing the infrastructure that allows users to supply collateral and borrow assets directly from isolated lending markets.
Users will pay a borrow rate on their borrowed assets and may receive incentives (rewards). A critical part of a borrow integration is facilitating the monitoring of position health to help users avoid liquidation, where their collateral can be seized to repay their debt.
Note: Borrowers will see interests accruing in their debt position, while the collateral remains idle, and do not yield.
Key Components of Borrow Integration
When building borrow products with Morpho Markets, you need to integrate three main components:
- Market Operations: Supplying collateral, borrowing, repaying, and withdrawing collateral.
- Position Health Management: Real-time tracking of Loan-to-Value (LTV), Health Factor, and liquidation risk.
- Rewards Integration: Discovery and claiming of incentives for supplying collateral or borrowing.
Integrating Borrow gives users access to:
- Isolated Risk: Each market's risk is contained. A problem in one market (e.g., a volatile collateral asset) does not affect the solvency of any other market.
- Capital Efficiency: The underlying interest rate models are designed for high utilization, which translates to better rates for both borrowers and lenders.
- Deep Liquidity via Public Allocator: While markets are isolated, the Public Allocator enables liquidity to flow between them on demand, ensuring borrowers can access deep liquidity from a single market.
Technical Components
From a technical standpoint, integrating Borrow involves:
-
Market Discovery and Display: Implementing systems to discover available markets and display their key parameters (Collateral/Loan Asset, APYs, TVL, LLTV, Oracle, IRM).
-
Transaction Handling: Building the interface and backend support, including asset approvals, transaction monitoring, and position updates. Here are the four core market operations:
supplyCollateral
borrow
repay
withdrawCollateral
-
Position Management: Creating interfaces for users to:
- View their current collateral and debt balances.
- Clearly track their Health Factor and current LTV.
- Perform any of the four core market operations.
- Claim any available rewards.
-
Liquidation Risk Transparency: Building clear and prominent displays that communicate:
- The user's current Health Factor.
- The market's Liquidation Loan-to-Value (LLTV), which is the LTV at which liquidation can occur.
- Visual warnings when a user's position health is declining.
Rewards Considerations
A complete Borrow integration should include rewards functionality. Many markets are incentivized to attract borrowers and collateral providers. Key aspects to integrate are:
- Rewards Discovery: Query the Rewards API (
https://rewards.morpho.org/v1/users/{address}/distributions
) to discover available rewards for your users. - Rewards Tracking: Display accruing, pending, and claimable rewards in your interface.
- Claiming Process: Implement the necessary functions to allow users to claim rewards from both the Morpho URD and Merkl systems.
- Multi-Token Support: Handle cases where users may receive different reward tokens from various incentive programs.
Assets Flow - Borrow
Understanding the complete flow of assets is crucial for a proper integration:
1. Supply Collateral
- A user selects a market (e.g., wstETH/WETH).
- They supply a collateral asset (wstETH) to the market. This collateral secures their future debt.
2. Borrow
- The user borrows the loan asset (WETH) from the same market.
- The amount they can borrow is limited by the value of their collateral and the market's Liquidation Loan-to-Value (LLTV).
- The user's Health Factor is established, representing their position's safety from liquidation.
3. Repay
- The user repays the loan asset (WETH), either partially or in full.
- Repaying debt reduces their LTV and increases their Health Factor, making their position safer.
- Interest continuously accrues on the outstanding debt, which must also be repaid.
4. Withdraw Collateral
- After repaying debt, the user can withdraw their collateral.
- They can only withdraw collateral if their position remains healthy (i.e., their Health Factor stays above 1). If the user has fully repaid their debt, they can withdraw all of their collateral.
Functional Integration Requirements
For a complete Borrow integration, your system needs to implement:
-
Read Operations:
- Query market parameters (LLTV, oracle, irm, etc.).
- Fetch real-time market state (APYs, total supply/borrow, utilization).
- Display user-specific position data (collateral, debt, Health Factor).
- Present available liquidity, including reallocatable liquidity from the Public Allocator.
-
Write Operations:
- Handle token approvals for supplying collateral and repaying debt.
- Execute
supplyCollateral
,borrow
,repay
, andwithdrawCollateral
. - Facilitate claiming any associated rewards.
-
Monitoring Capabilities:
- Track position Health Factor changes in real-time.
- Alert users when their position approaches the liquidation threshold.
- Update market data and interest rates dynamically.
Risk Considerations
A responsible Borrow integration must clearly communicate the following risks to the user:
- Liquidation Risk: This is the primary risk for borrowers. If a position's Health Factor drops below 1, their collateral can be seized by liquidators, resulting in a loss of funds.
- Oracle Risk: Inaccurate or manipulated price feeds from the market's oracle can lead to premature liquidations or prevent timely ones, causing bad debt.
- Smart Contract Risk: Exposure to vulnerabilities in the Morpho core contracts.
- Market Liquidity Risk: Low liquidity in a market can prevent users from borrowing or impact interest rates significantly.
- Counterparty Risk: The risk associated with the assets themselves (e.g., de-pegging of a stablecoin or centralization risk of a token).
By properly integrating these components and transparently communicating risks, your application can offer users direct access to Morpho's efficient and secure lending markets.