Origin paper: 《From Uniswap v3 to crvUSD LLAMMA.pdf》
The most difficult part of Curve stable coin is LLAMMA (AMM for continuous liquidation/deliquidation). LLAMMA refers to some of the principles in Uniswap v3. However, the price in the white paper is different from the mathematics in the Uniswap v3 white paper. We will unify these two projects and try to figure out how Curve CEO designed the algorithm.
Refer to Uniswap v3
The definitions of price in this article and Uniswap v3 are reciprocals of each other. Therefore, we have modified the formulas in the Uniswap v3 white paper to make them consistent with this article. In short, LLAMMA tries to make everything dynamic in Uniswap v3 to give a more preferable price for both crvUSD debtors and liquidators.
Compare the constant product formulas
Formula (2.2) from Uniswap v3 whitepaper:
Uniswap v3 Simulation of Virtual Liquidity
Formula (1) in the Curve stablecoin whitepaper :
AMM with an external price source
Here means , means .
The corresponding relationship is:
The corresponding constant product formula is:
Liquidity Calculation Formula Correspondence
Formula (6.7) from Uniswap v3 whitepaper:
Because of the reciprocal relationship between their price definitions, it corresponds to the formula:
One specific application of this formula is:
Do square expansion to get:
From the above formulas, we can easily find that when remains constant, The closer and are, the greater the corresponding liquidity .
In another word:
The liquidity cannot be infinite, and the corresponding minimum tick in Uniswap v3 will limit the size of .
From this, it can be deduced that in LLAMMA, we also need to define an indicator to measure the minimum difference between prices, and continue the analogy between Uniswap v3 and Curve.
Correspondence between the minimum price difference
It can be seen from the definition of , the closer and are, that is, the larger A is, the higher the liquidity concentration:
In Uniswap v3, only ticks with indexes that are divisible by tickSpacing can be initialized. Thus, tickSpacing determines the minimum price range for LPs to allocate their liquidty. The smaller the tickSpacing is, the tighter and more precise the price ranges. In Uniswap v3 different fee tiers determine different tickSpacing.
However, there is no need for crvUSD LLAMMA to have so many tickSpacing. Just make every since LLAMMA is just for ETH-crvUSD. Formula (6.1) from Uniswap v3:
In LLAMMA, A=100, Formula (11) from Curve stablecoin whitepaper:
Set and , we have:
We hope that LLAMMA has the following properties: when the price of ETH rises, the pool buys ETH. When ETH falls, the pool sells ETH. Given this, we define and as functions of and are steeper than linear functions, so their growth rates will be faster than . At the same time, it can be seen from the figure that the two curves and pass through two points and respectively. The and that meet the above requirements actually have many curves. The general formula is:
Let's start from the simplest case:
Substitute and into the square expansion of :
Then can be calculated as:
It is not difficult to find that is hard to comprehend and calculate under this assumption. What if and are cubic functions of :
Substitute and into the square expansion of :
It can be seen that when and are cubic functions of , the whole mathematical form is much simpler. The square root term is eliminated, and the calculation is much more convenient. If a higher order is taken, the price of AMM and will differ greatly, and thus the cost of buying ETH (when the price rises) will be much higher, which leads to a greater loss of liquidation. In summary, it is a better choice to define and as cubic functions of .
Derivation of other parameters
On the basis of assuming that and are cubic functions about , taking the special value , it is not difficult to obtain that and , then:
Given the fomula of , we can calculate and :
From this, we finally get the complete constant product formula:
Transform the above equation into a quadratic equation of :
Use the quadratic equation of one unknown to solve :
If the price moves so slowly that the oracle price is fully capable to follow it, given and , using the calculation formula of Uniswap v3, it is possible to calculate how much of ETH (if the price rises) or of USD will eventually be in the band (if price drops):
 Adams, Hayden, et al. "Uniswap v3 core." Tech. rep., Uniswap, Tech. Rep, 2021 from https://uniswap.org/whitepaper-v3.pdf
 Egorov, Michael, and Curve Finance. Curve stablecoin design. Technical report, Curve Finance, Tech. Rep, 2022 from