Deep Dive on Meteora's Dynamic Vaults
Introduction to Dynamic Vaults
Meteora's Dynamic Vaults are a type of DeFi product that automatically optimizes yield for liquidity providers (LPs). LPs are users who provide liquidity to decentralized exchanges (DEXs) by depositing two assets into a pool. In return, they earn trading fees from the DEX.
Dynamic Vaults work by rebalancing the assets in an LP's portfolio across different lending protocols. This allows LPs to earn the highest possible yield while minimizing their risk. The rebalancing is done by an off-chain keeper, which is a program that runs on a separate computer from the DEX.
To exemplify this in simpler terms:
Imagine you have a lemonade stand. You sell lemonade for $1 a cup, and you buy lemons for $0.50 a lemon. So, every time you sell a cup of lemonade, you make a profit of $0.50.
But what if you could make more profit? What if you could buy lemons in bulk and sell them to other lemonade stands? Or what if you could lend your lemons to people who want to make lemonade but don't have any lemons of their own?
That's what Dynamic Vaults do. They automatically rebalance your assets across different lending protocols so that you can earn the highest possible yield.
Challenges faced by LPs and Protocols:
Assets kept on protocols, wallets, and treasuries are often not optimized due to the difficulty of finding the highest yield opportunities. This can lead to protocols and users losing out on potential earnings. In order to earn yield, assets need to be deposited into liquidity pools. However, many protocols and wallets do not have enough liquidity to support high-yield farming opportunities. Additionally, the cost of gas fees can make it expensive to move assets between different protocols and wallets. This can discourage users from optimizing their yield, as they may not want to eat into their profits.
As a result of these challenges, protocols and users often rely on liquidity mining (LM) rewards to attract liquidity providers. LM rewards are tokens that are given to users who deposit their assets into liquidity pools. These rewards can help to incentivize users to provide liquidity, but they are not sustainable in the long run. As the DeFi ecosystem continues to grow, it is likely that we will see new solutions emerge to address the challenges of yield optimization. These solutions will help to ensure that users and protocols can maximize the returns on their assets.
Building a yield aggregator and monitoring system that optimizes yield while keeping funds safe is a complex and time-consuming process. It requires expertise in a variety of areas, such as integration, lending protocol assessment, and risk management. Also, it is not the core competency of this category of liquidity holders.
How Meteora solves the problem
Meteora is a risk management framework that focuses on optimizing yield, mitigating lending protocol risks, and maintaining principal liquidity. It integrates with over 50 lending reserves across six protocols to enable real-time yield optimization.
Meteora's keeper program constantly searches for the best yield opportunities among the connected lending protocols and rebalances allocations to maximize returns. It also monitors lending pool utilization rates and reserves levels to ensure the safety of funds and maintain liquidity. When predetermined thresholds are reached, funds are withdrawn.
To manage risk across lending protocols, Meteora spreads out vault allocations using a security matrix that determines the maximum allocation allowed.
For advanced users, Meteora offers a user-friendly SDK and a library of pre-built modules and code samples. These resources facilitate rapid app development and plug-and-play functionality.
Bird's-eye view of the system
There are mainly 3 main components:
• Vaults
Vaults in the infrastructure layer store individual token assets such as USDC or SOL, with a focus on allocating most of these assets to different lending protocols for yield generation. A centralized vault, like the USDC vault, holds commonly used tokens from various connecting protocols, such as AMMs or wallets. Users and protocols can easily deposit liquidity into each Vault using a user-friendly interface.
• Keeper - Hermes
The off-chain keeper, Hermes, has been designed to handle intricate logic and operations, such as monitoring lending protocols and calculating the optimal allocation of liquidity across different lending platforms. Hermes performs three primary operations, ensuring efficient management of these processes.
Yield Optimizer: Hermes, the intelligent system, performs calculations to determine the optimal allocation of liquidity across lending platforms, ensuring the highest overall Annual Percentage Yield (APY) for the vault. This calculation relies on essential data from various lending platforms, including Deposit APY, utilization rate, and pool liquidity. The process repeats at regular intervals, typically every few minutes. If a discrepancy arises between the new allocation and the current one, Hermes initiates a rebalance crank, prompting deposits and withdrawals to/from the lending platforms within the vault to maintain alignment with the optimal APY.
Key Metrics Tracker: The process of calculating liquidity allocation relies on important data, including deposit APY and pool liquidity, obtained from the lending platforms. To ensure accuracy and availability, the tracker continuously monitors, tracks, and stores this information within the system. These data serve as the foundation for calculations and future reference. Additionally, the data can be accessed by potential integrators, who can display them on their user interfaces or utilize them for their own calculations and logic.
Risk Monitoring: Hermes provides a risk monitoring service that continuously monitors the utilization rates and reserve levels of lending protocols in order to protect user assets. When certain thresholds are reached, Hermes takes action to ensure the safety of funds. For instance, if the utilization rate of a lending pool exceeds 80%, Hermes initiates a transaction to withdraw all liquidity from the pool. Additionally, all deposits into the pool are temporarily halted for a period of 12 hours, allowing Hermes to conduct a thorough investigation and determine whether to resume or completely halt deposits until further notice.
• SDK Module (Integration APIs)
In order to facilitate seamless integration with the Dynamic Yield Layer, we have developed a user-friendly SDK (Software Development Kit) and are actively expanding the collection of pre-built modules and code samples. This enables DApps (Decentralized Applications) and Protocols like Automated Market Makers (AMMs) and wallets to quickly develop and integrate with the platform.
With the straightforward API calls, liquidity can easily be deposited into or withdrawn from the vaults. Moreover, the yield generated by the vaults can be distributed back to the liquidity providers (LPs) of the integrated protocols, ensuring they receive their fair share of earnings.
This section describes and defines the notations used throughout this paper:
Operator describes the authorized wallet address that is only allowed to distribute funds into predefined protocols, it is not allowed to send liquidity to other places. The operator can only claim rewards and withdraw from predefined protocols to vault reserves, it is disallowed from withdrawing to external addresses.
Strategy refers to the lending protocols that the vaults will connect or deposit into.
Strategy Handler refers to the interface built to abstract all code that links the vault to the external lending platform to simplify handling.
Rebalance Crank happens when an operator deposits to or withdraws from a lending protocol. Rebalancing is run once every few minutes, and the yield optimizer will claim yield from the various lending protocols after each run.
Operation describes a generic action of interacting with the vaults, such as user depositing, user withdrawing, operator sending rebalance crank.
Utilization rates refer to the ratio of borrowed amount to deposited amount in a lending pool. A 100% utilization rate means that all deposited funds in a pool has been lent out.
Risk Elements and Mitigation Methods
In addition to performing the algorithmic process for determining optimal yield allocations, the keeper program also takes various risks into account before finalizing the allocation. These risks can be broadly classified into two categories: operational risk and lending risk.
Operation risk:
It refers to the potential risks associated with the source code, such as updates from partner protocols or teams, as well as inadequately audited lending platforms. In less severe instances, changes in the source code can disrupt integration, resulting in users being unable to perform vault withdrawals or deposits. However, in more serious cases, there is a risk of the vault program or lending protocols being exploited, potentially resulting in the loss of tokens stored in the vaults.
To mitigate this risk, they have implemented a maximum allocation mechanism that restricts the amount the vault can deposit into each lending pool. Lending protocols start with a maximum allocation of 100%. They are assessed based on audits, open-source code, insurance funds, token pools, program multisig/verified status, non-updatable status, and integration duration with Meteora. The DAO governs these criteria.
If a lending protocol fails to meet any of the criteria, the maximum allocation allowed to that protocol will be reduced based on the following matrix:
Hermes is restricted from withdrawing funds from the lending protocols to external wallets. In the event of a hack, the hackers can only manipulate the movement of funds between the vaults and lending protocols, while the principals remain secure in both of them.
Lending Risk:
Depositors may face challenges when trying to withdraw their funds from the lending pools due to two main scenarios: when the reserves in the pools reach maximum capacity (100% utilization), with borrowed amounts equaling deposited amounts, or when the remaining reserves in the pools are insufficient compared to the total vault deposits. In both cases, depositors are unable to make immediate withdrawals upon request.
To avoid lending risks, the following mechanisms are developed to protect principals:
To manage and diversify risk, it is advisable to allocate funds across multiple lending opportunities. By stretching allocations across various lending options, risk can be effectively mitigated and managed.
Hermes closely monitors the usage levels of each lending pool and is ready to withdraw funds if they exceed the specified limit. The current limit is set at 80%, allowing participation in popular lending pools with higher usage rates, while still ensuring the ability to withdraw funds when needed.
To provide sufficient time for Hermes to respond to liquidity movements, vaults always maintain a buffer within the lending reserve. This buffer ensures that there is a cushion available, allowing Hermes to react promptly when needed.
Case Studies: Illustrating Real-World Examples
1. Solend.fi USDH Exploit Case study
In a security incident on November 2nd, 2022, an attacker used an oracle attack to manipulate the price of the USDH stablecoin on Saber. This manipulation allowed them to drain assets from Solend's isolated pools, namely Stable, Coin98, and Kamino. Unfortunately, this led to losses of $1.26 million in bad debt.
Problem:
Despite not directly supporting USDH assets, the vaults were still vulnerable to the exploit due to the involvement with UXD assets in the Stable and Coin98 pools on Solend.
Impact:
Hermes, while monitoring the utilization rates of the pools, identified that both the Stable and Coin98 pools had exceeded the threshold of 80% utilization. To ensure the safety of the assets, a withdrawal request was promptly initiated, successfully retrieving all UXD assets back to the vaults before the pools were drained.
Remarks:
This safety measure proved highly effective as it prevented the funds of their users from being locked up in Solend. By swiftly withdrawing all the UXD liquidity from Solend back to their vaults, they ensured 100% accessibility and demonstrated the success of this mechanism.
2. AMM Case Study
Currently, the vast majority of assets in AMMs are unutilized, as only a small portion of the assets is being constantly used for swaps. As a result, the yield generated is insufficient to attract LPs; continuous LM is needed to boost LP incentives instead, which is unsustainable.
On the other hand, if the AMMs are constructed on a yield layer, the liquidity from the pools can be deposited into dynamic vaults. These funds can then be allocated to different lending platforms to generate extra yield for the liquidity providers (LPs). This approach enhances the capital efficiency of the pools and reduces the dependence on liquidity mining (LM) as the sole mechanism for sustaining or expanding pool liquidity.
Take an example of a USDC and USDT AMM stable pool being set up on top of the yield infrastructure.
1. The USDC/USDT tokens deposited in the AMM pool are promptly transferred to the USDC and USDT vaults in the underlying infrastructure layer.
2. Reserves equivalent to 10% of the liquidity in the USDC and USDT vaults will be maintained to facilitate token withdrawals or swaps by the connected AMMs.
3. After setting aside the reserves, 90% of the tokens held in the USDC and USDT vaults will be allocated to different lending platforms integrated with the vaults. As an example, the USDC vault will distribute 90% of its USDC tokens across pools in platforms such as Port Finance, Solend, and Mango in order to generate yield.
4. The yield optimizer will periodically monitor and adjust the allocation ratio of liquidity across platforms such as Port Finance, Solend, Francium, Tulip, and Apricot. These adjustments will be made at regular intervals, aiming to achieve the optimal yield for the LPs (liquidity providers).
With the activation of dormant tokens within the pools, they are now actively flowing and generating returns through the Yield Layer. As a result, the pools have become highly capital efficient, maximizing the potential returns.
Meteora envisions the dynamic vaults as the infrastructure for the yield layer on Solana, offering a powerful platform for individuals to securely park and grow their assets. It serves as a reliable mechanism for generating yield and maximizing the growth potential of assets.
3. MANGO Market: 100M USD Drained in Oracle Exploit
On October 12th, 2022, a malicious actor successfully exploited an oracle price manipulation vulnerability in MANGO, resulting in the loss of more than 100 million USD in funds.
Problem:
Due to the exploit that occurred, dynamic vaults experienced a disruption in liquidity as MANGO, one of the lending platforms where Meteora allocates assets, was affected. However, the impact was mitigated since Meteora was still in the Beta testing phase and had imposed deposit limits on their users.
Impact:
Before Meteora could withdraw the funds in time, a total of 900,000 USDC was locked up in MANGO during the exploit. However, MANGO promptly reimbursed Meteora using their own treasury, allowing Meteora to successfully recover their locked funds.
Remarks:
Thanks to the availability of MANGO's insurance funds, Meteora successfully retrieved their funds. This exploit served as a valuable lesson, revealing areas within their safety mechanisms that require strengthening and improvement to enhance their ability to mitigate similar risks in the future.
A walkthrough on how to deposit into a Dynamic Vault
A picture is worth a thousand words but a video is worth many pictures. So here is a short and easy walkthrough video to deposit funds in Dynamic Vaults. I have used Meteora’s dapp to demostrate the process.
RESOURCES:
Meteora’s white paper at https://meteora.ag/WP
Thanks Meteora and SuperteamDAO for this amazing opportunity. Facing issues or have queries? Contact me at twitter @khanwaniaryan