Whitepapers, Derivations and Useful Resources
Whitepapers¶
-
Curve DAO
Whitepaper on the general structure and workingsof the Curve DAO.
-
Stableswap
Whitepaper on the Stableswap invariant.
-
Cryptoswap
Whitepaper on the Cryptoswap invariant.
-
Curve Stablecoin & LLAMMA
Whitepaper on the workings of the Curve Stablecoin and Linear-Liquidation Automated Market Maker Algorithm (LLAMMA).
StableSwap Derivations¶
The StableSwap invariant is defined as:
Where: - \(A\) is the amplification coefficient
- \(n\) is the number of coins
- \(x_i\) is the amount of the \(i\)-th coin
- \(D\) is the invariant (i.e. the total virtual balance when all coins are equal)
Newton’s Method for Solving \(D\)¶
We derive Newton's iteration for solving \(D\) given \(\{x_i\}_{i=1}^n\) and \(A\).
Start with:
Or equivalently:
Taking the derivative:
Newton Iteration¶
Using Newton’s formula:
Substituting \(f(D)\) and \(f'(D)\):
This corresponds to the newton_D
function in math.vy
.
Newton’s Method for Solving \(x_j\)¶
Now derive Newton’s iteration for solving \(x_j\), given \(\{x_i\}_{i \neq j}\), \(A\), and \(D\).
Start with the invariant:
Isolate \(x_j\):
Multiply both sides by \(x_j\):
Divide by \(A n^n\):
Bring terms to one side:
Define:
Taking the derivative:
Newton Iteration¶
Substitute in the expressions:
This corresponds to the newton_x
function in math.vy
.
Here’s a cleaned-up and well-structured version of your Cryptoswap Derivations document. The content remains mathematically equivalent, but the presentation is clearer, more readable, and easier to follow:
Cryptoswap Derivations¶
Newton Step for newton_D()
in Tricrypto and Twocrypto¶
This derivation explains the mathematical logic behind the newton_D()
function used in Curve’s tricrypto and twocrypto pools.
Invariant Function Definitions¶
We start with the core function:
Where: - \( D \): the invariant - \( S = \sum x_i \) - \( P = \prod x_i \) - \( n \): number of tokens (typically 2 or 3) - \( \gamma \): price scale parameter - \( A \): amplification coefficient
Intermediate Definitions¶
Derivative of \( K \)¶
Derivative of \( F \)¶
Taking the derivative:
Substitute \( K \) and \( K' \):
Derivation of \( \frac{F}{F'} \)¶
Divide numerator and denominator by \( D^n / n^n \):
Divide numerator and denominator by \( \frac{\hat{A} \gamma^2}{g^2 D} \):
Multiply numerator and denominator by \( D \):
Divide numerator and denominator by \( K_0 \):
Distribute:
Substitute the denominator with \(-\text{neg_fprime}\):
Newton Iteration Step¶
Final Form: Positive and Negative Contributions¶
Separate into two parts:
Positive Term \( D_+ \):
Negative Term \( D_- \):
Final Newton Step:
Useful Resources¶
Stableswap¶
- https://atulagarwal.dev/posts/curveamm/stableswap/
- https://xord.com/research/curve-stableswap-a-comprehensive-mathematical-guide/
- https://miguelmota.com/blog/understanding-stableswap-curve/
- https://hackmd.io/@alltold/curve-magic
- https://medium.com/defireturns/impermanent-loss-and-apy-for-curves-lps-f75aa2e8c9d6
Cryptoswap¶
- https://nagaking.substack.com/p/deep-dive-curve-v2-parameters
- https://0xreviews.xyz/posts/2022-02-28-curve-newton-method
- https://twitter.com/0xstan_/status/1644931391111725057?s=46&t=HudpwDodTBLJargV6p63IA
- https://medium.com/defireturns/impermanent-loss-and-apy-for-curves-lps-f75aa2e8c9d6
Curve Stablecoin (crvUSD)¶
- https://crvusd-rate.0xreviews.xyz/
- https://twitter.com/definikola/status/1674430800107044871
- https://mirror.xyz/0x290101596c9f85eB7194f6090a8c94fF5AAa32ca/esqF1zwoaZ4ZSIjt-faZZiuKwLLw34nD0SGlqD2fZ6Q
- https://mirror.xyz/albertlin.eth/H0m3nyq65anotTWhTdWDIWEfMPOofNPy-0qyARYXNF4
- https://www.curve.wiki/post/from-uniswap-v3-to-crvusd-llamma-%E8%8B%B1%E6%96%87%E7%89%88
- https://www.youtube.com/watch?v=p5G9injrXk8&t=2602s
- https://x.com/0xnocta/status/1659111335542571009
- https://curve.substack.com/p/august-15-2023-all-or-nothing?utm_campaign=post&utm_medium=web&triedRedirect=true
- https://curve.substack.com/p/crvusd-faq
- https://community.chaoslabs.xyz/crv-usd/risk/overview