A Primer on Curve Lending

A Primer on Curve Lending

A Primer on Curve Lending

Mar 21, 2024

Useful Links

Summary

  • Curve Lending is a permissionless isolated lending and borrowing platform that enables users to borrow crvUSD against any supported token or any token against crvUSD.

  • The system utilizes the LLAMMA (Lending-Liquidating AMM Algorithm) mechanism from Curve's crvUSD system for automated market-making between borrowed and supplied assets, facilitating soft liquidations.

  • Lenders provide borrowable liquidity through ERC-4626 compliant vaults with additional convenience methods. The borrow interest rates are determined by a semi-log interest rate model based on the utilization ratio of each pool.

  • Lending pools are initially non-rehypothecating, meaning deposited collateral cannot be lent out. They can be permissionlessly created for any supported asset pair through the OneWayLendingFactory contract.

  • The system integrates liquidity mining incentives by allowing the deployment of liquidity gauges for pools.

Introduction

Curve Lending is a decentralized, non-custodial lending and borrowing platform built on the Ethereum blockchain. It leverages the existing infrastructure and mechanisms of Curve Finance, particularly the crvUSD stablecoin system and the LLAMMA (Lending-Liquidating AMM) algorithm. The platform allows users to create permissionless lending pools for supported asset pairs, with crvUSD initially serving as the primary collateral or borrowed token. As of mid-March 2024, the platform soft-launched with support for CRV, WETH, tBTC, and wstETH as initial markets, and plans to expand to other assets. New markets may be added permissionlessly.

Source: Curve | Curve Lending as of March 18th, 2024

Curve Lending addresses challenges and limitations in existing DeFi lending protocols by incorporating features such as the SemiLog Monetary Policy and the LLAMMA system. These features are designed to improve efficiency, mitigate risks, and enhance the user experience compared to traditional DeFi lending platforms.

This article aims to explain the inner workings of Curve Lending, its components, advantages and disadvantages, and discuss its potential impact on the DeFi lending landscape.

crvUSD: the Foundation of Curve Lending

crvUSD is a decentralized stablecoin system introduced by Curve Finance that utilizes a novel liquidation mechanism called LLAMMA (Lending-Liquidating AMM Algorithm). Unlike traditional stablecoin systems that rely on sudden, often punitive liquidations when collateral values fall below a certain threshold, crvUSD employs a more gradual and forgiving approach through LLAMMA.

The LLAMMA mechanism replaces traditional liquidations with a special-purpose AMM that encourages arbitrage to transition exposure between the collateral asset and the borrowed asset in line with market prices. It adjusts liquidity and virtual reserves based on the oracle price (P_oracle) to provide trading incentives for arbitrageurs, resulting in a more gradual and less punitive liquidation process known as "soft liquidation."

The crvUSD system also includes a Controller, which provides the interface for user interaction and manages the deposit and withdrawal of user assets. Users must specify the amount of collateral, the size of the crvUSD debt, and the number of consecutive bands (N) for depositing the collateral into LLAMMA. The choice of N affects the maximum loan-to-value ratio (LTV_max), the initial soft-liquidation price (P_ISL), and the final soft-liquidation price (P_FSL).

Source: Albert.Lin | Principles and Architecture of Curve Stablecoin

The Monetary Policy in crvUSD is governed by the Debt_Fraction (D_F), the ratio of PegKeeper's debt to the total debt. The interest rate ® is adjusted based on the deviation of the crvUSD price (P_crvUSD) from the peg price (P_P) and the deviation of D_F from the target fraction (T_F). PegKeeper is a mechanism that helps maintain the peg of crvUSD by increasing or decreasing its debt and interacting with various pools.

Source: Curve | CRV/crvUSD market bands on March 18th, 2024

By employing the LLAMMA mechanism, crvUSD promises to offer a more resilient and adaptive stablecoin system that can better withstand market volatility and protect borrowers from the harsh consequences of traditional liquidation mechanisms. For a further read on crvUSD, we recommend reading the whitepaper, the documentation, and this user guide published by 0xreview.

Curve Lending - System Overview

The Curve Lending system consists of the following key components:

Source: Curve docs | Simplified Curve Lending diagram

  • Borrowers: Users who deposit collateral assets (e.g., CRV, tBTC, wstETH) to borrow the paired asset, such as crvUSD. Borrowers are subject to the loan-to-value (LTV) ratios and interest rates determined by the SemiLog Monetary Policy.

  • Lenders: Users who supply liquidity to the lending pools by depositing their assets into the ERC-4626 compliant vaults. Lenders earn a share of the interest borrowers pay, proportional to their contribution to the pool.

  • Controller: The main contract that provides the interface for user interactions, managing the deposit and withdrawal of user assets, and the LLAMMA parameters.

  • LLAMMA: The Lending-Liquidating AMM Algorithm contract that handles the pricing and liquidation process. LLAMMA automatically adjusts the exchange rates between the borrowed and supplied assets to maintain pool balance and stability.

  • Vault: The ERC-4626 compliant contract that holds the supplied assets and manages the minting and burning of pool shares for lenders.

When interacting with Curve Lending, users have two main options: borrowing against collateral or simply supplying liquidity.

  1. Borrowing: If a user chooses to borrow, they must supply collateral as a supported asset (e.g., CRV, tBTC, or wstETH) to a lending pool. The amount of collateral required depends on the loan-to-value (LTV) ratio set for the specific pool. Once the collateral is deposited, the user can borrow a certain amount of the paired asset, such as crvUSD, based on the collateral value and the LTV ratio. Borrowers are subject to interest rates determined by the SemiLog Monetary Policy, which adjusts rates based on the pool's utilization ratio. The user interface for creating a loan allows users to view the whole market's details and the collateral distribution across bands, similar to the crvUSD system.

Source: Curve Lending | Sample user interface for creating a loan (borrow)

  1. Supplying liquidity: Users who wish to earn interest on their assets without borrowing can choose to supply liquidity to the lending pools. By depositing their assets into the ERC-4626 compliant vaults, liquidity providers contribute to the pool's available funds for borrowers. In return, they receive a share of the interest borrowers pay, proportional to their share of the pool's total liquidity. Additionally, liquidity providers may be eligible for liquidity mining incentives through CRV token rewards, increasing their potential returns. The concept of "vault shares" is introduced for suppliers, analogous to LP tokens, which track positions and handle fluctuations. Shares can be staked into gauges and unstaked for withdrawal.

Source: Curve Lending | Sample user interface for providing liquidity (supply)

The LLAMMA mechanism ensures efficient pricing and enables soft liquidations, gradually converting a borrower's collateral into the borrowed asset as the collateral value decreases. This approach helps mitigate the risks associated with sudden market fluctuations. Curve Lending also integrates liquidity mining incentives, allowing lenders to earn additional rewards through CRV tokens.

Depending on their financial goals and risk tolerance, users can simultaneously engage with Curve Lending as both borrowers and liquidity providers. The platform's permissionless nature allows users to create and participate in lending pools that suit their needs. Additionally, the platform is planned to expand to layer-2 solutions, such as Arbitrum, to reduce transaction costs further and improve user experience.

Core Features

Permissionless

Curve Lending introduces a permissionless ecosystem, enabling users to create lending pools for any supported asset pair through the OneWayLendingFactory contract. This contract allows users to deploy lending pools with customizable parameters, such as the amplification factor, fees, loan-to-value ratios, etc. The create_from_pool function facilitates the creation of a market directly from a supported Curve pool and its associated EMA oracle, while the create function allows the input of a custom oracle.

Source: Contract reader | OneWayLendingFactory contract

There are restrictions on setting an acceptable Curve pool oracle using create_from_pool. Only Curve pools using the StableSwap-ng, Tricrypto-NG, or Twocrypto-ng implementations are acceptable because they include a manipulation-resistant EMA oracle in the pool. The pool must also include both crvUSD and the collateral token.

The factory contracts are responsible for deploying new instances of the vault, controller, and AMM contracts for each pool pair, taking in various parameters such as the borrowed and collateral tokens, amplification factor, fees, and price oracles, and using these parameters to initialize the new contracts. They maintain a registry of created pool pairs and their associated metadata, allowing users to easily discover and interact with the available lending markets.

Non-Rehypothecating

In the initial phase of Curve Lending's development, the protocol focuses on offering non-rehypothecating lending pools. Non-rehypothecation means that the collateral deposited cannot be lent out or used for other purposes by the protocol or other users. There are plans to deploy a TwoWayLendingFactory that will allow the creation of markets that allow rehypothecation.

SemiLog Interest Rate Model

Curve Lending introduces a novel approach to determining borrow interest rates through its SemiLog "Monetary Policy." This policy calculates borrowing rates based on the utilization ratio of each lending pool, ensuring that rates remain competitive and attractive for both lenders and borrowers.

The SemiLog Monetary Policy is designed to balance the supplied and borrowed assets in each pool. As the utilization ratio increases, meaning more assets are being borrowed relative to the total provided assets, the borrow interest rates incrementally rise to incentivize lenders and encourage borrowers to repay their loans.

Source: Desmos | Interact with the rate model

Vault and ERC4626 Implementation

The Vault contract is an implementation of the ERC-4626 tokenized vault standard, allowing users to deposit assets and receive vault shares. The contract extends the standard ERC-4626 functionality with additional features specific to Curve Lending, such as borrowing and repayment of assets.

The vault contract manages the conversion between assets and shares, taking into account the total supply and working balances. It defines functions for depositing and withdrawing assets and minting and burning vault shares.

The vault interacts with the controller and AMM contracts to facilitate lending and borrowing operations. When a user borrows an asset, the vault transfers the borrowed amount to the user and updates the internal balances accordingly. Similarly, when a user repays a loan, the vault receives the repaid assets and updates the balances.

Liquidity Mining Incentives

Curve Lend offers CRV token rewards to incentivize liquidity providers, aligning their interests with the platform's success. The amount of CRV rewards earned is proportional to the assets supplied and the duration of participation, with liquidity gauges determining each user's share of the rewards. The Curve DAO plays a crucial role in allocating rewards among the lending pools and gauges, ensuring that the incentive structure remains aligned with the interests of all stakeholders and promoting decentralization and transparency.

The LiquidityGauge contract implements a liquidity gauging and reward distribution system. Users can deposit their LP tokens (vault shares) into the gauge and earn rewards through CRV and other reward tokens. The gauge contract uses checkpointing and integral calculations to track user balances, reward integrals, and claimed rewards, ensuring efficient and accurate reward distribution over time.

The gauge contract incorporates a voting-escrow (veCRV) boost mechanism, where users with veCRV can boost their rewards based on their veCRV balance and lock duration, encouraging long-term commitment and aligning incentives between liquidity providers and the protocol.

The gauge contract interacts with the Minter and VotingEscrow contracts to manage the minting and distribution of CRV rewards. The Minter contract is responsible for minting new CRV tokens and allocating them to the gauge contract, while the VotingEscrow contract handles the veCRV boost calculations.

LLAMMA Mechanism

Curve Lending leverages Curve's existing LLAMMA mechanism, which has been battle-tested in the crvUSD system. LLAMMA ensures efficient pricing and low slippage for users when borrowing or repaying loans.

The LLAMMA protocol automatically adjusts the exchange rates between the borrowed and supplied assets based on the current pool balances and market conditions. This ensures that the lending pools remain balanced and that users receive fair and competitive rates.

Parameterization of Lending Pools

Curve Lending provides a LLAMMA simulator tool that allows pool creators to test and analyze the potential performance of their lending pools under various scenarios, taking into account factors such as asset volatility, market trends, and user behavior. This tool enables users to experiment with different parameter combinations and observe how these settings impacted the pool's historical performance, providing valuable insights into optimal configurations and risk assessment.

Source: LLAMA Simulator | Finding Optimal AMM fee with the simulator

Amplification factor (A)

The amplification factor, denoted as "A," is a key parameter in Curve Lending's pools that influences the LLAMMA mechanism's behavior and overall stability. The amplification factor determines the size of the price bands within which the AMM provides liquidity, effectively controlling the sensitivity of the pool to price fluctuations.

A higher value of A results in narrower price bands, meaning that the AMM will maintain a more stable composition of assets within each band. This can be beneficial in terms of reducing slippage and providing a more consistent borrowing and lending experience for users. However, a higher A value also means that the pool may be less responsive to sudden market movements, potentially leading to slower adjustments in the collateral composition.

On the other hand, a lower value of A results in wider price bands, allowing for more significant changes in the AMM's asset composition as prices fluctuate. This can enable faster adaptation to market conditions but may also result in higher slippage and more frequent rebalancing of the collateral.

Source: LLAMA Simulator | Finding Optimal A with the simulator

Loan-to-Value and Liquidation Threshold Ratios

Loan-to-value (LTV) ratios and Liquidation Thresholds (LT) are critical risk management parameters in Curve Lend's lending pools, as they determine the maximum amount that users can borrow relative to the value of their collateral and when liquidation is triggered. LTV and LT ratios are typically expressed as percentages, with higher percentages indicating higher borrowing capacity and potential risk.

Curve expresses these values as the loan_discount and liquidation_discount. These optimal values can be derived from the simulator, as shown in the chart above. There should be a buffer between the liquidation discount value to the loan discount value so liquidation isn’t triggered immediately at max LTV.

Borrow Rate

Borrow rates are another important parameter in Curve Lend's lending pools, as they directly impact the cost of borrowing and the returns for lenders. Users can specify the min and max borrow rates when creating a new pool. These values are currently set to 0.5% and 50% in the current pool factory implementation. The min borrow rate is the rate charged when utilization is 0. The max borrow rate is the rate charged when utilization is 100%.

LLAMMA Protocol: Soft Liquidation Mechanism

The LLAMMA (Lending-Liquidating AMM Algorithm) is the core mechanism powering Curve Lending's soft liquidation process, ensuring efficient pricing and minimizing slippage for users when borrowing or repaying loans. LLAMMA achieves this through dynamic rebalancing of the lending pool's assets and using concentrated liquidity.

LLAMMA maintains a custom AMM (Automated Market Maker) for each lending pool that holds the supplied asset and the borrowed asset (e.g., crvUSD). The AMM is divided into multiple price bands, each with liquidity depth. As the relative value of the supplied assets and the stablecoin fluctuates, LLAMMA automatically adjusts the distribution of liquidity across these price bands to ensure optimal pricing efficiency. By concentrating liquidity around the current market price, LLAMMA minimizes slippage, allowing for larger transactions without significant price impact.

A key feature of LLAMMA is its ability to dynamically adjust the exchange rates between the supplied asset and the borrowed asset based on the current pool balances and market conditions. This ensures that the lending pool remains balanced and responsive to changes in supply and demand, continuously monitoring and adapting to these changes while adjusting exchange rates to incentivize users to maintain the pool's balance and stability.

The LLAMMA protocol has a proven track record of success, having been battle-tested in Curve Finance's crvUSD stablecoin system. In the crvUSD system, LLAMMA successfully managed the liquidation process for undercollateralized positions, ensuring the stablecoin's peg and the lending pool's solvency. The insights and lessons learned from LLAMMA's performance in crvUSD were incorporated into the design of Curve Lending.

The soft liquidation approach employed by the LLAMMA protocol offers several key benefits compared to traditional hard liquidation mechanisms:

  • Reduced liquidation losses: LLAMMA minimizes the potential for significant liquidation losses by gradually converting the supplied collateral into the borrowed stablecoin as the collateral value decreases.

  • Improved user experience: Soft liquidations are less disruptive and stressful for users, allowing them more time to adapt to changing market conditions and manage their positions.

  • Increased stability and resilience: The gradual nature of soft liquidations helps maintain the lending pool's stability and resilience, reducing the risk of cascading liquidations.

  • Enhanced capital efficiency: LLAMMA ensures that the pool maintains a healthy balance of assets and can support borrowing and lending activities without interruption.

  • Greater flexibility and control: Users can monitor their collateral ratios and proactively manage risk without fearing sudden, irreversible liquidations.

The LLAMMA mechanism relies on custom invariant and virtual balances to determine the exchange rates between the borrowed and collateral assets. The invariant is designed to maintain a balanced ratio between the assets, considering the current market prices and the desired loan-to-value ratios.

The AMM contract also implements the LLAMMA mechanism by defining a set of price bands, each representing a range of acceptable exchange rates. These price bands are similar to the concept of concentrated liquidity in Uniswap v3, allowing for better capital efficiency and lower slippage.

The AMM contract interacts with the controller contract to manage users' collateral and debt positions. When a user borrows or repays an asset, the AMM contract updates the virtual balances and exchange rates accordingly, ensuring the system remains balanced and solvent.

By offering these benefits, the soft liquidation approach employed by LLAMMA sets Curve Lending apart from other lending protocols, providing users with a more secure, efficient, and user-friendly borrowing and lending experience.

Source: Curve | Extract of crvUSD whitepaper

Smart Contract Architecture

Overview of Key Contracts

Curve Lending's smart contract ecosystem consists of several key contracts, each playing a specific role in the functioning of the platform:

Source: Curve Docs | Contract registry

  • OneWayLendingFactory: This contract serves as the main entry point for creating new lending pools. It allows users to deploy pools with customizable parameters and enforces the necessary checks and balances to ensure the system's integrity.

  • Vault: Each lending pool is represented by a Vault contract, which holds the supplied assets and manages the minting and burning of pool shares. The Vault contract is an implementation of the ERC4626 tokenized vault standard, ensuring compatibility with other DeFi protocols.

  • LLAMMA: The LLAMMA contract manages the automated market-making functionality of the lending pools. It calculates the exchange rates between the borrowed and supplied assets based on the current pool balances and the predefined parameters.

  • SemiLogMonetaryPolicy: This contract implements the SemiLog Monetary Policy, which determines the borrow interest rates based on the utilization ratio of each pool. It calculates the rates using a logarithmic formula that considers the pool creator's minimum and maximum borrow rates.

Various helper contracts support these core contracts, such as the Oracle contract for fetching asset prices, the LiquidityGauge contract for managing liquidity mining rewards, and the Factory contracts for deploying the other necessary components.

APR calculations

The rate and future_rate methods of the SemiLogMonetaryPolicy contract provide a quick way to determine current borrow APR and predicted APR given a change in either reserve asset or debt. The resulting number can be multiplied by the number of seconds in a year (365 * 86400) to determine the APR.

Source: Curve Docs | Explainer for the future_rate function

Supply APR can be further derived by multiplying the borrow APR by the debt amount, then dividing by the total supply.

Oracle for Asset Prices

Accurate and reliable price data is crucial for the proper functioning of Curve Lending. To ensure that the lending pools have access to up-to-date asset prices, lending pool creators have the flexibility to choose between using Curve pools as the default option or integrating their own custom oracle solution.

The default oracle conveniently makes use of the Curve pool EMA oracle built into -ng pool implementations. This option requires:

  • the pool to contain crvUSD and the counterparty market asset, and

  • must be one of the manipulation-resistant oracle implementations: stableswap-ng, tricrypto-ng, or twocrypto-ng.

This oracle calculates asset prices relative to the token in pool index 0 based on the pool's trading activity without relying on external price feeds. The EMA Oracle provides several benefits, such as increased resistance to short-term price manipulations and public accessibility of the price data. However, it also has limitations, including its dependency on pool liquidity that may deteriorate its reliability in case liquidity and trade volume migrate to alternate venues.

Curve Lending also supports integrating custom oracle solutions for pool creators with specific requirements or preferences, allowing them to use their preferred price feed providers, aggregation methods, or security measures.

Access Control System

Curve Lending employs a single access control under the authority of the Curve DAO to ensure that alterations to the protocol are highly secure and transparent with a 1-week timelock on the execution of any change to the factory or individual markets. This system is designed to maintain the platform's security, integrity, and decentralization while still allowing for the necessary flexibility and upgradability.

DAO's Role in Contract Ownership and Upgradability

The Curve DAO plays a crucial role in the contract ownership and upgradability of the Curve Lending protocol. As the owner of the core contracts, the DAO is responsible for making critical decisions related to the evolution and maintenance of the platform.

The DAO is tasked with assessing the need for contract upgrades, reviewing proposed changes, and implementing them to minimize disruption to the protocol and its users. This typically involves deploying new implementations of the contracts and assigning the new implementations within the lending factory contract. This allows the protocol to maintain a consistent interface while enabling the underlying logic to be updated as needed.

The DAO can modify a small set of critical protocol parameters, such as interest rate models, AMM fees, and loan/liquidation discounts, which influence market dynamics with potential repercussions for open positions. The DAO's decision-making process is governed by a transparent and decentralized voting mechanism, where CRV token holders can propose, discuss, and vote on various protocol upgrades and parameter changes.

By entrusting the contract ownership and upgradability responsibilities to the Curve DAO, Curve Lending ensures that the protocol remains decentralized, adaptable, and responsive to the needs of its users and the broader DeFi ecosystem. This approach aligns with the core principles of decentralized finance and helps foster a sense of community ownership and participation in the platform's long-term success.

Conclusion

Curve Lending represents a significant step forward in evolving decentralized lending protocols, introducing innovative features and mechanisms that address some of the key challenges and limitations of existing DeFi lending platforms.

The protocol's permissionless lending pools, powered by the battle-tested LLAMMA mechanism, offer a more efficient, user-friendly, and resilient borrowing and lending experience. By employing a soft liquidation approach, Curve Lending minimizes the potential for significant losses due to sudden market fluctuations and provides borrowers greater flexibility and control over their positions. Curve Lending's modular and extensible architecture, combined with its robust access control system and the oversight of the Curve DAO, ensures that the protocol remains secure, transparent, and adaptable to the ever-evolving needs of the DeFi ecosystem.

However, it is essential to acknowledge that Curve Lending, like any other DeFi protocol, is not without risks. The platform's success will depend on its ability to maintain the security and stability of its smart contracts, attract sufficient liquidity, and adapt to the rapidly changing regulatory and competitive landscape of the DeFi industry. As the DeFi ecosystem continues to evolve, it will be crucial to monitor the performance and adoption of Curve Lending and assess its impact on the broader DeFi lending market. Further research and analysis will be necessary to fully understand the long-term implications of Curve Lending's innovations and their potential to drive decentralized finance's next phase of growth and maturation.

As Curve Lending continues to mature and expand, it can reshape the DeFi lending landscape and set a new standard for decentralized borrowing and lending. By addressing the limitations of traditional lending protocols and introducing a range of innovative features, Curve Lending is well-positioned to become a dominant player in the DeFi lending space and drive the next phase of growth and adoption in decentralized finance.

Resources & Further Reading

© 2023 Llama Risk. All rights reserved.