(The author of this article is DeFi developer Anton Cheng)
Preface
In the past year, I personally feel that there has been no special innovation in the DeFi world, but it is relatively in a very practical reconstruction period: many high-quality teams have begun to use new engineering methods to rewrite and deploy in a safer and more efficient way. In many DeFi infrastructures, there are also many completely decentralized public assets.
Morpho is the most classic example of this. Today I will introduce how they break down complex lending protocols into simple modules to maximize security and reusability. For those who are not familiar with DeFi or Solidity, I highly recommend using Morpho as a starter to learn how to implement practical contracts in a simple way.
Brief introduction: Lending platform
The core of the lending platform can be easily explained by two groups of people: Supplier wants to lend out assets to earn interest; Borrower wants to mortgage asset A and borrow asset B, and pay interest to the supplier in exchange for the flexibility to combine its own asset portfolio. opportunity.
Older lending protocols such as Aave or Compound emphasize that the entire protocol is a large lending market: suppliers only need to select the assets they want to lend, and they can easily deposit and collect 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 named aUSDC. They do not need to care about the collateral behind it, or the liquidation parameters of each collateral. Wait, because these so-called risk management are solved by DAO, which is why Aave Governance often has votes to change parameters, add or remove collateral.
Core Concepts of Morpho
The fundamental logic of Morpho is very different: it is a truly decentralized protocol on which anyone can create a lending market for any token pair.
Generally, the smallest unit that a supplier will interact with Morpho is called a "vault". The Morpho team did not launch any official vault, but instead tried to find different people or units to establish and manage different vaults to meet the needs of different suppliers. In other words: as a supplier, you don’t just decide to throw your money into Morpho. You also have to choose the one you are most comfortable with among the many vaults. This puts Morpho in an interesting position, as they are not the ones directly deciding what users want from the market, but leave these things to others (vault, curator) to decide.
Left: A protocol is a large market, such as Compound and Aave. Right: A protocol can create multiple risk-uncorrelated vaults and markets
The vault mentioned above is a unit facing a general supplier. In fact, a vault is composed of multiple markets. Below we will introduce the two important components of market and vault from bottom to top, as well as the relationship between them.
Vault consists of several different markets Morpho Market (MorphoBlue) / Market
At the bottom of the Morpho protocol, there are markets that are independent of each other, cannot be changed, and have no concept of ownership (contractually called
MorphoBlue
). Once a market is created, it cannot be changed, and anyone is allowed to use any set of ERC20 token pairs and use any oracle to create markets.
Create Market
MorphoBlue
It is a singleton contract. All individual markets are not newly created contracts, but all exist at the same contract address. Therefore, it is very cheap to create a market (current gas may only cost a few dollars), and it can have built-in flashloan functions. Allows people to borrow all the supplier's money stored in MorphoBlue in one transaction.
The parameters required to create a market are as follows:
collateral
: Collateral ERC20
loan
: ERC20 being borrowed
oracle
: Oracle address
lltv*
(liquidation loan to value): A borrower will be liquidated when the total loan value / total collateral price is higher than this ratio.
irmModel*
(Interest Rate Model): A contract that determines the logic of interest rate changes
Among the above parameters, the first three do not have any restrictions as mentioned above; the latter two parameters limit the use of only the lltv value and irm contract voted by governance.
When a market is created, it can actually function as a simple lending market: For example, in a USDC-ETH market, suppliers can directly deposit USDC to earn interest, while borrowers need to deposit excess ETH as collateral. , borrow money and pay interest. If any borrower's position is in danger, a liquidator will be available to help liquidate it.
If you want to use different lltv, collateral, you need to create different market liquidation
Morpho’s liquidation mechanism is relatively simple and does not have any auction-type design. Instead, it simply fixes the price and is the first to win: when a borrower goes underwater, the liquidator can help repay part of the debt and obtain higher-value collateral.
Each market will have a fixed LIF (Liquidation Incentive Factor), determined by lltv. The collateral that Liquidator can obtain is the loan value * LIF:
maxLIF = 1.15, cursor = 0.3. LIF must be > 1
The ability to design like this actually relies heavily on the fact that "a market consists of only one loan asset and collateral asset." It is precisely because the market is very simple, which makes it feasible to sell a single collateral at a fixed price. If a protocol wants to auction a truckload of different types of collateral at a time, or allows a borrower to have many loan positions at one time, it is actually difficult to liquidate it directly through oracle pricing, so most of them will Relying on auctions would be a more complex design.
Gasless Authentication
Here's a little bit of a potential little design: There's a feature in the MorphoBlue code called
setAuthorizationWithSig
The letter allows an EOA to authorize other addresses to operate its positions on its behalf through a signature. This means that developers can actually develop some third-party contracts and provide some hosting and operation services through authorization.
Summary: Market is the simplest basic unit of lending
Seeing this, you should already have a basic understanding of the market. It is basically a very small lending market with limited functions. Its functionality is limited to letting suppliers lend money to a single collateral market, and borrowers putting in one asset and lending out another.
This is obviously not enough, so vault and allocator are needed to help solve the problem.
P.S.
MorphoBlue
The contract only has about 500 lines of code (the liquidation mechanism that most people are most jealous of is only 50 lines). It is written very concisely and has been subject to very strict audit and formal verification. I think it can be called It is the safest code among the current mainstream DeFi Infra and is highly recommended to everyone who wants to learn contracts.
Morpho Vaults (MetaMorpho)
The market has been introduced before, but it is actually enough for users who have the clearest minds and want to spend time managing all risks by themselves. But most suppliers may not have these capabilities, so we need some aggregation tools and other roles to help us complete this task.
We can look back at what "risks" a DAO can control in past DeFi lending scenarios? In fact, after much deliberation, it is nothing more than choosing collateral and various parameters:
(1.) Collateral: What kind of collateral can be used to borrow the supplier’s money?
(2.) Borrow cap of collateral: the upper limit of how much each collateral can be borrowed
(3.) Liquidation line for each collateral: Different types of collateral, relatively stable prices should allow for higher leverage. For example, if you deposit $100 USDC, you can borrow $95 USDT, but if you deposit $100 of BTC, you may only be able to borrow $80.
In the definition of morpho, these so-called management conditions will be regarded as different markets, so whenever "risk management" is to be carried out, theoretically under the morpho structure, it needs to be transferred to another market. For example, the change of liquidation line: a USDC-DOGE-lltv-90% market means that depositing DOGE can borrow 90% of the face value of USDC. If you feel that the risk of DOGE has increased today, you need to withdraw your USDC instead. , rolled over to a new lltv-80% of the market. This is obviously not something that ordinary people would be willing to do, so there is an aggregator called vault, and two small risk control helpers, curator and allocator, are used to help depositors move their positions around. This is the Morpho Vault (contractually called MetaMorpho).
The relationship between Vault (blue) and Market (orange) Allocator
First, let’s introduce two little risk control helpers. A vault can have multiple allocators, and these allocators have the authority to transfer assets originally stored in one market to another market. In addition, they can also update the deposit queue & withdrawal queue: as the name suggests, "Which market will the deposit be deposited to first", and "Which market will the money be withdrawn from".
Risk Curator
The Risk curator is a vault controller. In addition to being able to set allocators (and also having their powers), he can also set the supply limit for each market.
Through these two roles, we can achieve the three major types of risk control mentioned above: by changing the queue and moving liquidity around, we can determine the markets, and thus decide whether to change the collateral, Or change the liquidation line for each collateral; coupled with the ability to set deposit caps for each market, we can adjust the exposure of the entire pool.
ERC4626
It is worth mentioning that each vault is specifically designed for one type of loan asset, that is, it only accepts deposits of a single asset. MetaMorpho supports the ERC4626 interface. After depositing, you will be given an ERC20 token containing an interest rate. You can then use this token to the agreement of other derivative financial products to bet on some interest rates and so on.
Performance Fee
Finally, let me mention that these risk control helpers are not charitable, so most of them require users who deposit through vaults to take a certain percentage of the interest earned as their commission. If you don’t want to pay... you can scroll down to the end to help you figure out how to avoid these fees.
challenge
This has probably finished introducing the core of Morpho. Next, I will mention a few points that are often discussed in this design.
Liquidity Fragmentation (?)
Seeing such a structure, the first instinct is liquidity segmentation: the money originally deposited in a vault will now be dispersed into different markets. Does this mean that liquidity is dispersed?
I think "yes and no": "Yes" is because if there is only one vault in the world, then liquidity will indeed be dispersed into different markets, which will cause a lot of trouble for the borrower.
But in fact, multiple different vaults can supply the same market at the same time. If there is a market that is very stable, more and more vaults may want to deposit money into this vault to earn a relatively stable interest rate. This allows borrowers to borrow liquidity from different vault users in the same market.
If we not only consider vaults, this advantage may be further expanded: for example, if there are other smart contracts or treasury that wants to make a simple interest-generating function, it may not want to use vaults, but directly deposit USDC into a market to generate interest. The simple design of interest and market allows more protocols to be willing to do this and bring in a larger amount of liquidity.
Multi-Collateral Borrowing
I think that in morpho, the UX of the borrower will become more complicated, but whether it is good or bad can be explained in different aspects:
All previous lending protocols have the power to change the conditions under which the borrower is liquidated. Part of the reason is because they allow the borrower to put in a lot of collateral at once and use a health score to evaluate how much money your total position can lend. In order to ensure the security of the protocol, when the collateral risk changes, they can change some parameters to make the borrower liquidable. Although there will be additional protection mechanisms, this is ultimately a difficult consideration.
In Morpho, the borrower's action object becomes a permanent and immutable market, which means that you don't have to worry about anyone being able to change your lending and liquidation conditions. The price is that if you plan to mortgage multiple collaterals to lend assets, you need to deposit different collaterals into different markets yourself, and at the same time maintain multiple positions and rebalance yourself. From this perspective, it will be very inconvenient.
Rehypothecation
One of Morpho’s biggest problems is the underlying collateral asset utilization. Many other lending protocols allow the collateral you deposit to be borrowed by others at the same time, allowing you to charge a little more interest. However, the underlying logic of morpho does not allow collateral to be lent, so there must be some assets that are "idle" in the contract.
Whether this matter is really important or not may be discussed in detail later when we introduce Euler V2.
Conclusion: Building Hyperstructures
I remember the first time I saw Morpho’s contract was around this time last year, and I thought this was the lending infra that I had been looking forward to seeing someone implement.
In addition to the implementation details of clean and concise contracts, I really like the spirit of not trying to do everything, but splitting each practical unit cleanly and developing contracts based on the principle of minimization. I think this is the best spirit for developing contracts, because the more complex things are, the more likely they are to have security issues, and the less likely they are to be reused by others.
In addition, Morpho's completely decentralized, immtuable, and minimal governance design is fully in line with the spirit of Hyperstructure.
What are Hyperstructures?
If you have never heard of the word hyperstructure, it is highly recommended to read Jacob’s original text. I'm here to help copy the definition.
Hyperstructures: Crypto protocols that can run for free and forever, without maintenance, interruption or intermediaries.
Several major characteristics further defined by Jacob in the article:
Unstoppable: the protocol cannot be stopped by anyone. It runs for as long as the underlying blockchain exists.
Free: there is a 0% protocol wide fee and runs exactly at gas cost.
Valuable: accrues value which is accessible and exitable by the owners.
Expansive: there are built-in incentives for participants in the protocol.
Permissionless: universally accessible and censorship resistant. Builders and users cannot be deplatformed.
Positive sum: it creates a win-win environment for participants to utilize the same infrastrastructure.
Credibly neutral: the protocol is user-agnostic.
P.S. Another highlight of the original article is the extension of the “Valuable” problem: these contracts can have ownership, or they can make ownership valuable, but they must be based on a basis that does not violate decentralization at all. A good example is a fee switch: an ownership control that turns on a fee switch is valuable, but the owner never has a long-term incentive to turn on the fee switch.
I think such protocols are very scarce in DeFi right now. Except for Uniswap, there are almost no other protocols that meet such conditions. In Morpho's design, it can be seen that they not only ensure decentralization, but also very intentionally move closer to minimized governance, ensuring that even if the owner becomes a bad person one day, the contract can be credibly neutral and continue to support The new market will continue to operate.
Morpho is a primitive, a public good, or a Hyperstructure.
Because of this, I like Morpho very much (especially
MorphoBlue
), so I spent some time a while ago to create a tool that allows everyone to supply directly to individual markets: MonarchLend.xyz. If you are very confident in managing your own positions, I recommend using this method to supply to markets directly, so that you will not be charged intermediate handling fees by the vault.
Welcome to try it out: https://www.monarchlend.xyz/
The simple and beautiful Morpho has been introduced. I hope to introduce Euler V2, which is about 100 times more complicated but still very decentralized!
This article New Generation DeFi Basics (Hyperstructure) Model: Lending Protocol Morpho first appeared on Chain News ABMedia.