Balancer

Search…

Balancer V2

Products

Ecosystem

Governance Initiatives

Getting Started

Community

Developers (Deprecated)

Stable Math

Overview

Stable Math is designed to allow for swaps between any assets that have the same price, or are "pegged" to the same asset. The most common examples are stablecoins that track US Dollars (DAI, USDT, USDC), and assets that track the price of Bitcoin (WBTC, renBTC, sBTC). Prices are determined by the pool balances, the *amplification parameter*, and amounts of the tokens that are being swapped.

Since most cases are neither ideal nor disasters, the Stable Math curve combines the *Constant Sum *and* Constant Product *curves and is designed to facilitate approximately 1-to-1 trades that incur large price changes only when token balances differ greatly. The *amplification parameter*,

$A$

, defines the degree to which the Stable Math curve approximates the Constant Product curve (when $A=0$

), or the Constant Sum curve (when $A\rightarrow \infty$

). StableSwap approaches Constant Product as A->0 and Constant Sum as A->∞

Invariant

Since the Stable Math equation is quite complex, determining the invariant,

$D$

, is typically done iteratively. For an example of how to do this, please refer to this function.$A \cdot n^n \cdot \sum{x_i} +D = A \cdot D \cdot n^n + { \frac{D^{n+1}}{{n}^{n}\cdot \prod{x_i} } }$

Where:

- $n$is the number of tokens
- $x_i$is is balance of token$i$
- $A$is the amplification parameter

Last modified 10mo ago

Copy link

On this page

Overview

Invariant