← Back

Mathematical Proof of the Stable swap Equation

April 19, 2026

We start with two equations. Equation 1: χDn1xi+xi=χDn+(Dn)n\quad \chi D^{n-1} \sum x_i + \prod x_i = \chi D^n + \left(\frac{D}{n}\right)^n Equation 2: χ=Axi(D/n)n\quad \chi = \frac{A \prod x_i}{(D/n)^n}


Step 1: Simplify Equation 2

Before plugging the messy χ\chi fraction into Equation 1, let’s simplify it first. The denominator is (D/n)n(D/n)^n. Distributing the exponent gives Dnnn\frac{D^n}{n^n}. Since this quantity is in the denominator of a larger fraction, we can invert it and move nnn^n to the numerator:

χ=A(xi)nnDn\chi = \frac{A \cdot (\prod x_i) \cdot n^n}{D^n}

Now we have a cleaner expression for χ\chi to use going forward.


Step 2: Plug χ\chi into the left side of Equation 1

Let’s start with the left side of Eq. 1: χD˙n1xi+xi\chi \dot D^{n-1} \sum x_i + \prod x_i. Substitute our simplified χ\chi:

[A(xi)nnDn]Dn1xi+xi\left[ \frac{A \cdot (\prod x_i) \cdot n^n}{D^n} \right] \cdot D^{n-1} \sum x_i + \prod x_i

Now group the two DD terms so we can simplify them:

Dn1Dn(A(xi)nnxi)+xi\frac{D^{n-1}}{D^n} \cdot \left( A \cdot (\prod x_i) \cdot n^n \sum x_i \right) + \prod x_i

To simplifyDn1Dn\frac{D^{n-1}}{D^n}, subtract exponents: (n1)n=1(n-1) - n = -1. That gives D1=1DD^{-1} = \frac{1}{D}. So the DD terms collapse into a single DD in the denominator.

New left side: A(xi)nnDxi+xi\frac{A \cdot (\prod x_i) \cdot n^n}{D} \sum x_i + \prod x_i


Step 3: Plug χ\chi into the right side of Equation 1

Start with the right side of Eq 1: χDn+(Dn)n\chi D^n + \left(\frac{D}{n}\right)^n. (To save a step, rewrite (D/n)n(D/n)^n as Dnnn\frac{D^n}{n^n}.

Right Side: χDn+Dnnn\chi D^n + \frac{D^n}{n^n}

Substitute our clean χ\chi:

[A(xi)nnDn]Dn+Dnnn\left[ \frac{A \cdot (\prod x_i) \cdot n^n}{D^n} \right] \cdot D^n + \frac{D^n}{n^n}

This is straightforward: the DnD^n in the denominator cancels with the DnD^n we are multiplying by.

New Right Side: A(xi)nn+DnnnA \cdot (\prod x_i) \cdot n^n + \frac{D^n}{n^n}


Step 4: Add the Equals Sign back

Let's glue our New Left Side to our New Right Side.

A(xi)nnDxi+xi=A(xi)nn+Dnnn\frac{A \cdot (\prod x_i) \cdot n^n}{D} \sum x_i + \prod x_i \quad = \quad A \cdot (\prod x_i) \cdot n^n + \frac{D^n}{n^n}

This equation is perfectly accurate! To get the final whitepaper formula, the author just cleans it up in the next two steps so there isn't a giant messy fraction on the left side.


Step 5: Clean-up (Multiply the whole equation by D)

To get rid of the DD on the bottom of the Left Side, let's multiply the entire equation by DD.

Multiply the Left Side by D:

The DD on the bottom of the first part cancels out. The second part becomes DxiD \prod x_i. Result: A(xi)nnxi+DxiA\cdot(\prod x_i) \cdot n^n \sum x_i + D \prod x_i

Multiply the Right Side by DD:

The first part just gets a DD added to the front. In the second part, Dn×DD^n \times D = Dn+1D^{n+1}. Result: AD(xi)nn+Dn+1nnA \cdot D \cdot (\prod x_i) \cdot n^n + \frac{D^{n+1}}{n^n}

Our current equation looks like this:

A(xi)nnxi+Dxi=AD(xi)nn+Dn+1nnA \cdot (\prod x_i) \cdot n^n \sum x_i + D \prod x_i \quad = \quad A \cdot D \cdot (\prod x_i) \cdot n^n + \frac{D^{n+1}}{n^n}


Step 6: Final Clean-up (Divide the whole equation by xi\prod x_i)

Notice how there is a messy (xi)(\prod x_i) floating around in almost every single term? Let's get rid of it by dividing the entire equation by xi\prod x_i.

Divide the Left Side by xi\prod x_i:

It perfectly cancels out in the first term, leaving AnnxiA n^n \sum x_i. It perfectly cancels out in the second term, leaving just DDFinal Left Side: Annxi+DA n^n \sum x_i + D

Divide the Right Side by xi\prod x_i:

It perfectly cancels out in the first term, leaving ADnnADn^n. Because the second term doesn't have a xi\prod x_i to cancel, it just drops to the bottom of the fraction, leaving Dn+1nnxi\frac{D^{n+1}}{n^n \prod x_i}Final Right Side: ADnn+Dn+1nnxiADn^n + \frac{D^{n+1}}{n^n \prod x_i}

Glue those two final results together, and you have exactly derived the holy grail Stableswap equation:

Annxi+D=ADnn+Dn+1nnxiA n^n \sum x_i + D = ADn^n + \frac{D^{n+1}}{n^n \prod x_i}