Next-generation DeFi foundational hyperstructure paradigm: lending protocol Morpho

share
Next-generation DeFi foundational hyperstructure paradigm: lending protocol Morpho

The author of this article is DeFi developer Anton Cheng

Table of Contents

Introduction

In the past year, personally, I felt that there were not many significant innovations in the DeFi world. However, it seemed to be in a very practical rebuilding phase: many high-quality teams started to rewrite and deploy many DeFi infrastructures using new engineering methods that are more secure and efficient. Many completely decentralized public goods also emerged.

Morpho is one of the most classic examples among them. Today, I will introduce how they break down complex lending agreements into simple modules, maximizing security and reusability. For those who are not familiar with DeFi or Solidity, I highly recommend using Morpho as a starting point to learn how to implement practical contracts in a concise manner.

Background: Lending Platforms

The core of lending platforms can be explained simply with two groups of people: Suppliers who want to lend assets to earn interest, and Borrowers who want to collateralize asset A, borrow asset B, pay interest to Suppliers, and have the opportunity to create a flexible composition of their asset portfolio.

Traditional lending protocols like Aave or Compound emphasize that the entire protocol is a large lending market: Suppliers only need to choose the assets they want to lend, and they can easily deposit and earn interest. Taking Aave and USDC as an example, users only need to choose to lend USDC, and after lending, they will receive an interest-bearing token called aUSDC, without needing to worry about collateral behind the scenes or the liquidation parameters of each collateral, as these so-called risk management issues are handled by DAO. This is why Aave Governance often votes to change parameters, add, or remove collateral.

Morpho's Core Concept

Morpho's fundamental logic has significant differences: it is a truly decentralized protocol where anyone can create lending markets for any token pair.

The smallest unit with which a supplier interacts with Morpho is called a "vault." The Morpho team did not introduce any official vaults but instead tried to find different individuals or entities to establish and manage various vaults to meet the needs of different suppliers. In other words, as a supplier, it is not enough to simply throw money into Morpho; you must choose the vault that suits you best from numerous vaults. This puts Morpho in an interesting position as they do not directly dictate what the users need in the market but leave these decisions to other vaults and curators.

Left: A protocol is a large market, such as Compound and Aave. Right: A protocol can create multiple unrelated Vaults and markets.

The mentioned vaults are units facing a typical supplier. In reality, a vault is composed of multiple markets. Below, we will introduce the two important components, market and vault, from the bottom up, and their relationship.

Vault consists of multiple different markets.

Morpho Market MorphoBlue / Market

At the core of the Morpho protocol is a series of independent, immutable, and ownerless markets (referred to as MorphoBlue in the contract). Once created, a market cannot be changed and allows anyone to use any ERC20 token pair and any oracle to create markets.

Creating a Market

MorphoBlue is a singleton contract, and individual markets are not newly established contracts but all exist at the same contract address. Therefore, creating a market is very cost-effective (current gas costs may be only a few dollars) and can include flash loan functionality, allowing users to borrow all the funds supplied by suppliers within one transaction.

The parameters needed to create a market are as follows:

  • collateral: Collateral ERC20
  • loan: Borrowed ERC20
  • oracle: Oracle address
  • lltv* liquidation loan to value: the ratio at which a borrower's borrowed total value/collateral total value is higher than this value will be liquidated.
  • irmModel* Interest Rate Model: contract determining the logic of interest rate changes

Of the above parameters, the first three have no restrictions as mentioned earlier; the latter two parameters are limited to using only the lltv value and irm contract approved through governance voting.

Once a market is created, it can actually function as a simple lending market: for example, a USDC-ETH market, where suppliers can directly deposit USDC to earn interest, and borrowers must deposit excess ETH as collateral, borrow, and pay interest. If any borrower's position is in a risky state, a liquidator will assist in liquidation.

Different lltv, collateral, require creating different markets.

Liquidation

Morpho's liquidation mechanism is relatively straightforward, without any auction-type design, but a simple first-come, first-served fixed price: when a borrower is underwater, a liquidator can help repay part of the debt and receive higher value collateral.

Each market has a fixed LIF Liquidation Incentive Factor, determined by lltv. The collateral that the liquidator can obtain is the value of the loan repaid * LIF:

maxLIF = 1.15, cursor = 0.3. LIF always > 1.

This design heavily relies on the fact that "each market consists of only one loan asset and collateral asset," making it feasible to sell collateral directly through pricing orders. If a protocol wants to auction a variety of collateral assets at once or allow a borrower to have many loan positions at once, it is challenging to directly liquidate through pricing based on an oracle, so it often relies on auctions, which is a more complex design.

Gasless Authentication

Here, I would like to briefly mention a very promising design: in the MorphoBlue code, there is a function called setAuthorizationWithSig, which allows an externally owned account to authorize another address to operate its position through a signature. This means developers can develop third-party contracts to provide custodial and operational services through authorization.

Conclusion: Market is the Most Simplified Basic Lending Unit

By now, you should have a basic understanding of the market, which is essentially a very small, limited-function lending market. Its functionality is limited to allowing suppliers to lend to a single collateral market and enabling borrowers to deposit one asset and borrow another.

This is obviously not enough, so we need vaults and allocators to help solve these problems.

P.S. MorphoBlue contract is only about 500 lines of code (a typical liquidation mechanism that terrifies most people is only 50 lines long), written very concisely, rigorously audited, and formally verified. I believe it can be considered one of the safest codes in mainstream DeFi Infra at the moment, highly recommended for those interested in learning contracts.

Morpho Vaults MetaMorpho

After introducing the market, it should be sufficient for users who are most clear-headed and want to spend time managing all risks themselves. However, most suppliers may not have these capabilities, so we need some aggregation tools and other roles to help us complete this task.

Let's review the risks controlled by a DAO in the past DeFi lending scenarios: basically, it boils down to choosing collateral and various parameters:

1. Collateral: What kind of collateral can borrow money from suppliers

2. Collateral's borrow cap: The maximum amount each collateral can borrow

3. Liquidation line for each collateral: Different types of collateral, where the price is relatively stable, should allow higher leverage. For example, storing $100 USDC can borrow $95 USDT, but storing $100 of BTC may only be able to borrow $80.

In Morpho's definition, these so-called management conditions are seen as different markets, so whenever "risk management" needs to be carried out, theoretically under Morpho's architecture, it is necessary to switch to another market. For example, changing the liquidation line: a USDC-DOGE-lltv-90% market means storing DOGE can borrow 90% face value of USDC. If you feel that DOGE's risk has increased, you need to withdraw your USDC and transfer it to a new lltv-80% market. This is obviously not something that the average person would be willing to do, hence the existence of vault as an aggregator and risk control assistants, curator and allocator, to help depositors move their positions. This is the Morpho Vault (contract referred to as MetaMorpho).

Relationship between Vault (blue) and Market (orange)

Allocator

First, let's introduce two risk control assistants. A vault can have multiple allocators, and these allocators have the authority to transfer assets originally in one market to another market. Additionally, they can update deposit queues and withdraw queues: essentially determining where deposits go first and from which market withdrawals begin.

Risk Curator

The risk curator is the controller of a vault. Apart from being able to set allocators (who also have their powers), they can set the supply limit for each market.

Through these two roles, we can achieve the three major risk control types mentioned earlier: by changing queues and moving liquidity back and forth, we can essentially determine markets, which in turn allows us to decide whether to change collateral or liquidation lines for each collateral. Combined with setting the deposit limit for each market, we can adjust the exposure of the entire pool.

ERC4626

It is worth noting that each vault is specifically designed for a single loan asset, meaning it only accepts deposits of a single asset. MetaMorpho supports the ERC4626 interface, where upon deposit, you receive an ERC20 token containing interest rates, which can then be used in other derivative financial protocol contracts to speculate on interest rates, for example.

Performance Fee

Finally, let's mention that these risk control assistants are not charitable; therefore, they often require users who deposit through the vault to pay a certain percentage of the interest earned as their commission. If you prefer not to pay, you can scroll down to the end and I'll help you figure out how to avoid these fees 😆.

Challenges

That pretty much sums up Morpho's core concept. Next, I will bring up a few points that are often discussed about such designs.

Liquidity Fragmentation?

Looking at this structure, the first instinct is liquidity fragmentation: originally, the money deposited in a vault may now need to be dispersed among different markets. Does this mean liquidity is being fragmented?

I think it's both "yes and no": "yes" because if there is only one vault in this world, indeed liquidity is fragmented across different markets, causing many troubles for borrowers.

However, multiple different vaults can simultaneously supply to the same market. If a market is very stable, more and more vaults may want to deposit funds into this market to earn a more stable interest. This allows borrowers to borrow liquidity from different vault users within the same market.

If we consider not only vaults, this advantage may further expand: for example, if other smart contracts or treasuries want to create a simple interest-earning feature, they may not want to use vaults and instead directly deposit USDC into a market to earn interest. The concise design of the market may attract more protocols to do this, bringing in more liquidity.

Multi-Collateral Borrowing

In Morpho, I believe the borrower's user experience may become more complex, but whether it is good or bad can be explained from different perspectives:

Previously, all lending protocols had the power to change the conditions under which a borrower would be liquidated, partly because they allowed borrowers to deposit multiple collaterals and used a health score to assess how much money you could borrow with your total position. To ensure the protocol's security, they could change some parameters to make borrowers liquidatable when collateral risks change. Even though additional mechanisms protect borrowers, this is ultimately a difficult consideration.

In Morpho, a borrower's actions target permanently immutable markets, meaning you don't have to worry about anyone changing your borrowing and liquidation conditions. The trade-off is that if you plan to collateralize multiple collaterals to borrow assets, you need to deposit different collaterals into different markets, maintain multiple positions, rebalance, making it inconvenient from this perspective.

Rehypothecation

One of Morpho's biggest issues is the utilization rate of the underlying collateral assets. Many other lending protocols allow the collateral you deposit to be borrowed by others simultaneously, allowing you to earn a bit more interest. However, Morpho's bottom layer logic does not allow collateral to be borrowed, so there will always be some assets "idle" in the contract.

Whether this is truly significant may be further explored when we introduce Euler V2 in the future.