Introduction to the Principles and Architecture of Curve Stablecoin

Curve Finance is a highly representative innovation in the DeFi field, whether it's in the AMM algorithm for Stablecoin Swap or the veToken economic model design, which is widely imitated by others. At the end of last year, Curve Finance proposed their stablecoin white paper, which made people curious about what new features they would offer to the DeFi ecosystem this time. During the research process, there were some insights and understanding that I hope can help everyone better understand the design of Curve stablecoins.


Types of Curve Stablecoins and Their Problem-Solving Features

Curve Finance's stablecoin design belongs to the type of over-collateralized stablecoins. This type of stablecoin is minted (or borrowed) by using other assets such as ETH as collateral, based on a specific interest rate and the value of the collateral. The most famous protocol of this type is MakerDAO's DAI. ETH is used as collateral and borrowed to obtain MakerDAO's stablecoin DAI. Here, the collateral is changed to Curve Finance to borrow Curve stablecoins.

Curve stablecoins are designed to solve the problem of price volatility that exists in many cryptocurrencies. The value of stablecoins is stable and not subject to fluctuations in market prices, making them ideal for use as a medium of exchange or a store of value. In addition, the use of over-collateralization reduces the risk of liquidation and instability caused by fluctuations in the value of the collateral. Overall, Curve stablecoins provide a more secure and stable solution for users in the DeFi ecosystem.

Liquidation Issues

Stablecoin architectures of this type always have a liquidation mechanism. Liquidation refers to the situation when the value of the collateral falls to a certain price, causing the value of the collateral to no longer support the stablecoins borrowed. At this time, the collateral (partially or wholly) will be auctioned off at a favorable price to fill the gap in borrowed stablecoins. However, the current liquidation model has several problems:

  • When a whale's assets are liquidated, many collaterals will flow into the market, causing market fluctuations.

  • In most cases, liquidators will sell the liquidated collateral to profit, causing the collateral's price to drop again, resulting in another wave of liquidation.

  • Liquidators usually sell the auctioned collateral on CEX/DEX. If the exchange lacks liquidity, it will cause bad debts for the lending platform.

  • Users who are liquidated will suffer permanent losses. Even if the collateral's price rebounds, the collateral has been liquidated and cannot be restored.

In view of these issues, Curve hopes to improve the liquidation problem in stablecoin design in the following ways:

  • Do not rely on external DEXs, as DEX liquidity is uncontrollable.

  • Reduce users' losses as much as possible when liquidation occurs.

  • Gradually liquidate users' collateral and convert it back when the price rebounds.


Curve Stablecoin Overall Architecture

The above diagram is the architecture diagram in the white paper, which can be roughly divided into two blocks.

  • The Controller and LLAMMA are mainly responsible for collateral liquidation-related work (the blue box in the above figure).

  • Monetary Policy, PegKeeper, and Stable Pool are mainly responsible for anchoring stablecoins to 1 USD-related work (the green box in the above figure).

This article will mainly focus on the introduction of Controller and LLAMMA, but there will also be a brief explanation of the Monetary Policy-related work. So let's start with today's highlight, LLAMMA!

LLAMMA (Lending-Liquidating AMM Algorithm)

LLAMMA stands for Lending-Liquidating AMM Algorithm, which, as the name suggests, is an AMM algorithm related to lending and liquidation. Curve mainly uses this algorithm to liquidate collateral.

AMM represents a Swap Pool based on the LLAMMA algorithm, which we will call the LLAMMA Pool for now. Users can deposit their collateral into the LLAMMA Pool through the Controller and mint stablecoins. The assets in the LLAMMA Pool are collateral and Curve stablecoins. In this article, we will use crvUSD to refer to Curve stablecoins and ETH as collateral for illustration purposes.

The most significant feature of the LLAMMA Pool is that when the price of collateral (ETH) falls below a specific price, the collateral in the Pool will gradually turn into crvUSD. Conversely, when the price is higher than a specific price, crvUSD will gradually turn into collateral (ETH).

It sounds quite magical! Before understanding this conversion process, we need to know what happens when users put their collateral in the Pool. The following diagram is an illustration of the interaction between various contracts, giving a clearer concept of the role played by the LLAMMA Pool in the architecture.

Dynamic Range and Oracle Price

Band

First, LLAMMA divides the collateral price range into different price segments called bands. When users deposit collateral, they need to provide:

  • The amount of collateral

  • How many bands to store the collateral in

  • How much crvUSD to mint (or borrow)

The collateral will be divided into equal and evenly divided small pieces according to the number of bands to store, and then stored in a continuous price range composed of bands based on the current price and the minted crvUSD. The following figure shows the distribution of storing 10 ETH in 5 bands after calculation, with 5 small pieces of 2 ETH each stored in 5 consecutive bands.

In addition, it should be noted that each band has an upper price (P_UP) and lower price (P_DOWN). The upper price of the previous band is also the lower price of the next band. For example, the upper price of band 0 in the above figure (3000) is also the lower price of band -1 (3000). The upper and lower prices of each band represent the start and end prices of liquidation for that band. When the price reaches the upper price, the collateral stored in that band will begin to be liquidated until the price reaches the lower price, indicating the end of liquidation (meaning that all collateral in that band has been converted to crvUSD).

Oracle Price

In LLAMMA, there is another important role, which is the Oracle Price. The Oracle Price refers to the external collateral price (which can be thought of as the current market price). LLAMMA designs the Oracle Price role to achieve the behavior of ETH <-> crvUSD conversion at a specific price for the collateral. We will explain how this is achieved in detail in the following chapters. Here, we assume that the Oracle Price is P_ORACLE, and the price in the LLAMMA Pool is assumed to be P_AMM.

Regarding the design of the Oracle, what is certain is that each time an external price is obtained, it will be processed by EMA before being used. This is to prevent users from suffering losses due to drastic fluctuations in external prices while also increasing the difficulty of manipulating the Oracle Price. As the service is not yet online, it is not certain which service will be used as the Oracle source.

How to Work in LLAMMA Pool

The figure below shows the price changes in the band range (using ETH as collateral). When the ETH price is higher than P_UP (yellow range), all assets in the band range will be converted to ETH. When the ETH price is lower than P_DOWN (green range), all assets in the band range will be converted to crvUSD. When the price is between P_UP and P_DOWN (white range), the assets will be in a partially ETH and partially crvUSD state, with the proportion of ETH and crvUSD determined by the price changes.

The purple line in the middle indicates the price changes of P_ORACLE, and the red line indicates the price changes of P_AMM. P_CD and P_CU can be thought of as two equations created to find the upper and lower prices of this band.

When P_ORACLE and P_AMM are equal, it will be the blue point in the middle of the diagram, indicating that the ETH price in the Pool is consistent with the external price.

Oracle Price Increase

From the diagram of LLAMMA pool price, it can be observed that when the price starts to rise (the orange line in the diagram), the red line (P_AMM) rises faster than the purple line (P_ORACLE). When P_AMM > P_ORACLE, an arbitrage space is created, motivating external arbitrageurs to deposit ETH into the LLAMMA Pool to exchange for more crvUSD to profit until P_AMM = P_ORACLE is balanced again. During this process, the amount of ETH in the pool gradually increases, while the amount of crvUSD gradually decreases. When it goes higher than P_UP, only ETH will remain in this range. The figure below shows the changes in the AMM price (P_AMM) during the arbitrage process (the X-axis represents the oracle price, and the Y-axis represents the AMM price. To clearly indicate the price position, the orange line of the oracle price is listed on both the X-axis and the Y-axis).

When P_AMM > P_ORACLE, arbitrageurs will start depositing ETH and taking out crvUSD, and the P_AMM line (red) will begin to move to the right until P_AMM = P_ORACLE is balanced again.
When P_AMM > P_ORACLE, arbitrageurs will start depositing ETH and taking out crvUSD, and the P_AMM line (red) will begin to move to the right until P_AMM = P_ORACLE is balanced again.

Oracle Price Decrease

Conversely, when the price starts to fall (the green line in the LLAMMA pool price diagram), it can be observed that the red line (P_AMM) falls faster than the purple line (P_ORACLE). When P_AMM < P_ORACLE, an arbitrage space is also created, motivating external arbitrageurs to deposit crvUSD to exchange for more ETH until the price is balanced again. During this process, the amount of crvUSD in the pool gradually increases, while the amount of ETH gradually decreases. When it goes lower than P_DOWN, only crvUSD will remain in this range.

When P_AMM < P_ORACLE, arbitrageurs will start depositing crvUSD and taking out ETH, and the P_AMM line (red) will begin to move to the left until P_AMM = P_ORACLE is balanced again. (X-axis: oracle price, Y-axis: AMM price, orange line: oracle price)
When P_AMM < P_ORACLE, arbitrageurs will start depositing crvUSD and taking out ETH, and the P_AMM line (red) will begin to move to the left until P_AMM = P_ORACLE is balanced again. (X-axis: oracle price, Y-axis: AMM price, orange line: oracle price)

LLAAMA Formulas

Why does P_AMM rise or fall faster than P_ORACLE? To understand this, we need to look at the formula for P_AMM. In the LLAMMA Invariant formula, I, f, and g are all related to P_ORACLE. This means that I, f, and g are not constant, but will change.

x and y refer to the USD balance and ETH balance of the band range. y_0 is the ETH balance when P_AMM = P_ORACLE = P_UP, which can be temporarily viewed as a constant (in reality, it is also a function related to P_ORACLE).

If we arrange the band range as a sequence, we will find that it is a geometric sequence. A is the number that determines the ratio of this geometric sequence, and it is decided when the contract is deployed, so A is also an invariant.

It can be seen that P_AMM is only related to the parameters f and g, and f and g are only related to the changes in P_ORACLE. When P_ORACLE rises, f value will rise (square relationship will rise faster) and g value will decrease. The rise of P_AMM will be greater than that of P_ORACLE, resulting in P_AMM > P_ORACLE. When P_ORACLE falls, f value will decrease (square relationship will decrease faster) and g value will increase. The fall of P_AMM will be greater than that of P_ORACLE, resulting in P_AMM < P_ORACLE. Even if there is no swap in the LLAMMA pool, P_AMM will change with P_ORACLE, and the magnitude of P_AMM will be greater than that of P_ORACLE, thus creating an arbitrage opportunity to balance the asset ratio of the pool.

Summary of LLAMMA

LLAMMA intentionally creates an arbitrage opportunity for external traders by utilizing the fact that P_AMM fluctuates more than P_ORACLE. When arbitrageurs attempt to rebalance the asset ratio in the pool, they are essentially performing partial liquidations of the pool's assets. The advantage of this dynamic and continuous liquidation process is that it avoids a large-scale liquidation that could cause market volatility. As prices recover, the assets will convert back to collateral without causing permanent losses to the collateral.


Stabilizer and Monetary Policy

After discussing how LLAMMA solves the collateral liquidation problem, let's briefly explain what PegKeeper and Monetary Policy are and how they work. PegKeeper and Monetary Policy are the mechanisms used by Curve Finance to anchor crvUSD to 1 USD.

When crvUSD price > 1 USD: it means there is a shortage of crvUSD in the Curve pool. PegKeeper can mint new crvUSD without collateral and deposit it into the Curve Pool to increase the supply of crvUSD in the market.

When crvUSD price < 1 USD: it means there is an excess of crvUSD in the Curve pool. PegKeeper will start withdrawing previously minted crvUSD from the Curve Pool and burning these crvUSD to reduce the supply of crvUSD in the market.

These actions are defined in the PegKeeper contract and can be called by any external caller. Calling PegKeeper to anchor crvUSD creates profits, and these profits are returned to the external caller in the form of LP tokens. For example, suppose PegKeeper initially mints 200 crvUSD, deposits it into the Curve pool, and obtains 300 LP tokens. When the price drops, only 200 LP tokens are needed to withdraw 200 crvUSD. The remaining 100 LP tokens will be owned by the external caller.

Although this mentions forming a pool with crvUSD in each Curve pool, it is more likely that the approach will be similar to the 3pool type of pool where crvUSD is pooled with other assets. This way, only one PegKeeper is needed to adjust the price of crvUSD. In addition, the Curve team can use CRV to vote on the crvUSD ↔ 3pool pool to increase rewards and incentivize people to deposit and mint crvUSD. However, these are just personal speculations, and we need to see the actual situation after launch.

Monetary Policy

What if the PegKeeper has burned all the uncollateralized crvUSD and the price of crvUSD is still below 1 USD? Curve Finance has another way to increase the crvUSD price, which is to use Monetary Policy to raise the borrowing rate.

https://www.desmos.com/calculator/cqtavnvhps?lang=en
https://www.desmos.com/calculator/cqtavnvhps?lang=en

As we can see, when the price is greater than 1, the borrowing rate is extremely small (tending to 0). When the price is less than 1, the borrowing rate increases rapidly. This will cause borrowers who have minted crvUSD to repay their debt quickly, otherwise their collateral may be liquidated. It is noticed that the price affects the borrowing rate, and it also affects the amount of borrowing. Of course, the actual rate at which the borrowing rate increases will only be known after the crvUSD is officially launched.


TL;DR

  • LLAMMA is the algorithm used by Curve to perform collateral liquidation, which - reduces losses during liquidation by distributing collateral across different price ranges.

  • It generates arbitrage opportunities by using larger amplitude of price changes than external prices to dynamically liquidate collateral. When prices drop, collateral becomes crvUSD, and when prices rise, it becomes collateral again.

  • PegKeeper mints or burns uncollateralized crvUSD to decrease or increase the crvUSD price, while Monetary Policy controls borrowing rates to anchor crvUSD at 1 USD.

The design of Curve Finance's mechanism is very sophisticated and is worth further study in terms of its implementation. When understanding the stablecoin mechanism of Curve, it is found that PACO has a deep understanding of studying Curve stablecoin. His articles and videos have been very helpful. The charts used in this article are from PACO's data, and it is highly recommended to read PACO's articles and videos for a deeper understanding. These references will be provided.

This article represents my own understanding and summary of researching Curve stablecoins, and I hope it can help readers gain some understanding of the mechanism. If there are any errors in the article, please kindly point them out and provide corrections. Discussions and exchanges of opinions are also welcomed. Finally, I would like to thank Cyan Ho for reviewing this article and providing some ideas for improvement.


Reference

Subscribe to Albert.Lin
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.