Making the Complex Simple: How Curve DEX Pools Work
Of course, it’s included in the article for which this graphic was created. However, I agree—there should be a brief version with an explanation separate from the article.This material is designed to simplify the understanding of the structure and principles of Curve pools. It is not a guide to creating pools.
Curve was the first to implement concentrated liquidity in AMMs, and CryptoSwap pools utilize concentrated liquidity that dynamically adapts to price changes.
While utilizing liquidity within a narrow range in other protocols, such as Uniswap v3, typically increases impermanent loss (IL),
in Curve, this issue is resolved thanks to its unique technologies.
Curve offers innovative solutions to optimize the provision of deep liquidity for various asset classes.
When did these solutions emerge, how do they work, and most importantly, when and for whom are they beneficial?
Contents:
StableSwap
The history of the Curve AMM began in the fall of 2019, when Mikhail Egorov set out to create a more efficient solution for stablecoin swapping.
At that time, platforms like Uniswap v1 with a constant product invariant (CP-AMM) already existed. However, this method was inefficient for stablecoins and resulted in losses due to slippage.
Curve StableSwap was the first AMM to implement concentrated liquidity.
StableSwap concentrated liquidity around a fixed price (usually 1.0), making stablecoin swaps significantly more efficient.
Users could exchange large volumes of stablecoins with minimal losses, drastically reducing slippage and improving conditions for liquidity providers. This solution marked a major leap forward in decentralized exchanges, and Curve quickly gained popularity in the DeFi world.
Curve utilizes a mechanism called the "invariant" — a rule that determines how the price of tokens in the pool changes based on the quantity of each token.
The goal is to keep prices as stable as possible, especially when the token balances in the pool are close to equal.
StableSwap uses what is known as the "constant price invariant", which means that when token amounts are nearly equal, the price remains almost unchanged (and liquidity is maximally concentrated at this point).
However, if the quantity of one token decreases significantly, a different formula — the "constant product invariant" — is applied. This ensures that some liquidity is still available while allowing the price to adjust accordingly.
The Idea
StableSwap is an algorithm that combines both formulas. When token amounts are nearly equal, the system operates as if the price remains unchanged (similar to having an infinite supply of tokens). However, when the balance is disrupted, the system switches to a Uniswap-like principle, providing liquidity but allowing the price to change.
StableSwap strives to maintain the price at around 1.0, ensuring that each token has approximately the same value. When the balance is disturbed, the system continues to offer liquidity, but the price starts to shift to restore equilibrium.
As shown in the graph above, when exchanging larger amounts of one token for another, both invariants experience slippage due to the liquidity imbalance in the pool.
However, for stablecoin swaps, StableSwap demonstrates significantly lower slippage, and the price remains stable for much longer. In contrast, with Uniswap, the price starts to decrease immediately and much more rapidly, causing greater deviations (slippage) during swaps.
Х: Price of Token 1, Y: Price of Token 2.
The graph above illustrates that the desired StableSwap invariant remains "flat" when reserves X and Y are balanced, meaning the price stays constant and close to 1.0. When the reserves move out of equilibrium, liquidity is still provided, but slippage begins to occur.
StableSwap establishes a "golden mean" between fixed prices and slippage, distributing liquidity across the widest possible price range.
CryptoSwap in Curve V2
The first iteration of Curve's AMM performed exceptionally well with pools of stablecoins and assets that had strong price correlation. When assets have an expected price, liquidity can be pre-concentrated at a specific point.
But what about tokens whose prices can fluctuate significantly and for extended periods relative to one another?
In 2020–2021, the number of new tokens increased significantly, but liquidity on alternative platforms failed to keep up with demand. This created additional challenges for existing AMM models.
On June 9, 2021, the first crypto pools of Curve's second version AMM were officially launched on the Ethereum and Polygon networks.
A month earlier, Uniswap's third version was launched, with its main idea also revolving around liquidity concentration. However, liquidity providers faced increased impermanent loss (IL) as Uniswap's invariant led to proportional increases in IL and restricted the operational price range of a position in the pool.
(Uniswap V3 uses a constant product sum invariant for each price range.)
The realization of impermanent loss during the movement of concentrated liquidity is an unavoidable mathematical phenomenon. This happens because assets that appreciate in value are removed from the selected concentration range, leaving the liquidity provider with the depreciated asset.
But what if the liquidity concentration range is adjusted only when the income from a portion of the collected fees is sufficient to cover the impermanent loss?
The Problem of Dynamic Concentrated Liquidity
Even volatile asset pairs experience periods of stable price levels. If we could automatically provide concentrated liquidity without additional losses during these periods, pools would become much more efficient in terms of slippage and capital utilization.
Mikhail Egorov and the Curve team started with this idea and developed an algorithm that delivers significantly more efficient liquidity for uncorrelated assets.
Applying StableSwap directly to volatile assets would undoubtedly create challenges. StableSwap provides concentrated liquidity around an exchange rate of 1:1 but offers very weak liquidity beyond this range. Therefore, when prices shift significantly, it provides less liquidity than a CP-AMM (Constant Product Automated Market Maker, e.g., Uniswap v2). Additionally, liquidity providers would face higher impermanent losses, as the higher-value asset would sharply decrease in their positions. For these reasons, the StableSwap Pool adopts a model distinct from StableSwap.
A StableSwap Pool must be designed to dynamically respond to market prices, unlike StableSwap, which focuses solely on the 1:1 price point. In this sense, CryptoSwap requires concentrated liquidity around the current market price, but as the price deviates sharply, its curve should immediately resemble a CP-AMM curve.
Moreover, an algorithm is needed to dynamically adjust its "internal" equilibrium price to provide concentrated liquidity tailored to real-time market conditions.
However, if re-pegging occurs every time there is any deviation, it would lead to greater losses for liquidity providers (fixation of IL). Therefore, a specific strategy is required to prevent such losses, which will be discussed in the next section.
Let’s dive into how the magic of Curve works
There are numerous materials on CryptoSwap algorithms, which require patience and a bachelor's degree in physics or mathematics (or, at the very least, a solid grasp of advanced high school mathematics) to understand. However, over 90% of users may find these materials quite challenging: 1, 2, 3, 4, 5, 6, 7.
At first glance, the mechanics of CryptoSwap might seem complex, demanding a deep understanding of mathematical and economic principles.
That's why we tried to make the visualization of the liquidity movement process in Curve pools for volatile assets as intuitive as possible.
To demonstrate this mechanism, you simply need to adjust the sliders below. The first slider represents the accumulated trading fees in the pool, while the second slider controls the market price of the asset.
CryptoSwap utilizes an internal oracle based on the Exponential Moving Average (EMA) of the asset's price. This means the algorithm gradually adjusts liquidity distribution to avoid unnecessary costs from redistributing liquidity due to constant price fluctuations without a clear trend.
When the market price significantly deviates from the current liquidity concentration point, the CryptoSwap pool provides lower liquidity than a CP-AMM. Therefore, it is necessary to recalculate the pool's equilibrium price and initiate position rebalancing.
However, re-anchoring too frequently can result in additional losses for liquidity providers (fixation of impermanent loss). To prevent this, an algorithm is implemented that allows liquidity adjustments only within defined limits—up to half of the accumulated fees.
It’s important to understand that the CP-AMM curve (e.g., as in Uniswap) remains unchanged regardless of price movements, meaning liquidity providers may experience "impermanent losses" (IL), which can only be recovered if the price returns to its original level.
In the case of CryptoSwap, the curve adapts dynamically to market conditions. To prevent the formation of losses, liquidity is shifted only when the following condition is met: 50% of the accumulated fees must be sufficient to cover the rebalancing losses.
If the accumulated fees are insufficient to continue moving liquidity, the movement stops until new fees are collected.
The CryptoSwap invariant operates as a superposition of the StableSwap and constant product (CP-AMM) invariants. As a result, the system can adapt to different conditions, effectively maintaining deep liquidity for volatile assets without increasing costs for liquidity providers.
Dynamic Fees and Loss Protection
CryptoSwap uses dynamic fees to quickly offset impermanent losses and increase profits during periods of reduced swap volumes caused by decreased liquidity concentration due to significant token imbalance. The fee amount depends on the level of imbalance in the pool: the greater the imbalance, the higher the fee, which helps compensate for risks to liquidity providers and move liquidity closer to market prices more efficiently.
The swap fee charged must be sufficient to cover IL after liquidity rebalancing. The greater the imbalance, the higher the fee.
Another way to put it is: pool fees increase depending on how far the internal oracle price is from p (the liquidity concentration point). If the internal price has "drifted" too far and re-pegging happens too quickly, it may result in significant re-pegging losses. Therefore, fees are raised to protect profitability.
As a result, we can see how the initial goals were achieved:
Interesting to note: Unlike swap fees, deposit/withdrawal fees (or rewards) are only applied when the deposit or withdrawal is unbalanced in dollar terms.
Types of AMMs
Let’s summarize and reinforce what has been discussed.
Automated Market Makers (AMMs) use various mathematical models to simplify trading, each with its own approach to liquidity, pricing, and stability.
Here are the main approaches used in AMMs:
1. Constant Product Market Maker (CPMM)
- How it works: It’s like a scale with two sides. The more of one asset there is on one side, the more expensive it becomes, and vice versa. A specific balance is always maintained.
- Example: Uniswap v2.
- Characteristics: Asset prices change depending on their quantities in the pool, maintaining a constant product. This model offers unlimited liquidity but increases slippage for large trades.
- Pros: Simple to use, suitable for any type of asset.
- Cons: For very large trades, prices can change significantly (high slippage).
2. Concentrated Liquidity (CL-AMM)
- How it works: Liquidity providers specify a price range in which they want to operate. For example, if they believe the price will stay within a certain range, they can concentrate their funds in that range.
- Example: Uniswap v3.
- Characteristics: Improves liquidity efficiency by concentrating it within the chosen price range.
- Pros: More efficient use of capital.
- Cons: Requires more attention and management, subject to impermanent loss, limited position range, and challenges with "Just-In-Time" liquidity provision (read more here).
3. Hybrid (StableSwap)
- How it works: This approach is a combination of the two previous methods, optimized for assets that are typically similar in value. It blends elements of constant product and constant sum models. Designed for assets like stablecoins, StableSwap uses a mix of algorithms to minimize slippage and maintain liquidity. In this version, fees are dynamic, with a portion directed toward pool stabilization, enabling smooth and cost-effective trades.
- Example: Curve StableSwap.
- Characteristics: Suitable for assets with similar values, minimizing slippage and improving liquidity.
- Pros: Minimal slippage, stable prices. Particularly effective for stablecoin swaps.
- Cons: More complex to set up due to advanced fee and liquidity management.
4. Hybrid (CryptoSwap)
- How it works: Another hybrid approach, specifically designed to work effectively with volatile assets. It uses a combination of algorithms to minimize slippage and impermanent loss (IL). In the NG version, CryptoSwap utilizes a portion of fees to move liquidity closer to the current market price, enhancing pool efficiency and ensuring accurate pricing.
- Example: Curve CryptoSwap.
- Characteristics: Focused on handling volatile assets, dynamically adjusting liquidity to reduce slippage.
- Pros: Accurate pricing and risk minimization when swapping volatile assets.
- Cons: More complex to understand and configure due to advanced liquidity management algorithms.
Conclusion
StableSwap
StableSwap was Curve’s first solution for pools consisting of stablecoins or highly correlated assets. Its primary goal was to minimize slippage and impermanent loss (IL) by utilizing a curve that enables efficient asset swaps at minimal cost. StableSwap ensures even liquidity distribution around a fixed price (usually 1.0), making it ideal for stablecoins.
CryptoSwap
The core logic of CryptoSwap can be summarized in two points:
- CryptoSwap provides concentrated liquidity around the equilibrium price while also offering sufficient liquidity, similar to CP-AMM, beyond a specified range of the equilibrium price.
- The pool oracle tracks the market price, but liquidity concentration is adjusted within a set boundary—up to half of the accumulated fees—to prevent losses for liquidity providers.
CryptoSwap focuses liquidity around the current equilibrium price, providing significantly higher liquidity in most cases compared to CP-AMM. This attracts more users, increases trading volumes, and enhances returns for liquidity providers.
Thus, StableSwap and CryptoSwap represent two distinct yet complementary models for managing liquidity. StableSwap excels at handling stablecoin swaps, while CryptoSwap effectively manages volatile assets, minimizing risks for liquidity providers.
Comparison with Competitors
Uniswap v3 and its analogs also aim to provide concentrated liquidity around the equilibrium price. In these systems, liquidity providers can select a price range within which they wish to supply liquidity. This creates "overall concentrated liquidity" through the active involvement of liquidity providers in deciding at which price levels liquidity should be concentrated.
However, this approach has clear drawbacks: liquidity providers not only need to understand the precise mechanics of the pool but also must continuously monitor and respond to market conditions. In contrast, CryptoSwap does not require any actions from liquidity providers, minimizing position management costs and making it suitable for a broader audience.
Additionally, LP positions in Uniswap v3 cannot be easily integrated with other protocols, as they are not fungible and are represented as NFTs due to their attached price range. This also complicates the implementation of yield farming through staking fungible LP tokens. CryptoSwap does not face these limitations, making it more compatible with the entire DeFi ecosystem.