# Swap Math

Last updated

Last updated

If you have not checked out our intro article on medium, please start here

Our swap upgrade introduces two novel features:

The xybk invariant

Asymmetrical tuning

Our novel invariant, the xybk model, allows stablecoin swaps to be performed more efficiently through artificially inflating the TVL in pools by a multiple of b times. The invariant is as below:

**Invariant Behavior**

In our medium article, we mentioned the simple example of a pool with *x*=token*0balance=100*, *y*=*token1balance=100*, *boost=10.* This pool has underlying assets of *(100, 100)* but **exhibits the same swap slippage as a ****(1000, 1000)**** v2 uniswap pool. This means swaps in both pools have the same slippage and will require the exact same amount of input to get the same output.**

For more complicated cases when the balances in the pool are not equal, we use a formula to calculate the K value for the pool. The value of K is bounded by the geometric mean sqrt(x*y) when b = 1 (the uniswap invariant) to the arithmetic mean (x+y)/2 when b = infinity. Since (x+y)/2 > sqrt(x*y) when x != y, the value of K in practice in an xybk pool will be greater than a uniswap pool with equivalent balances. We use the following formula, derived from rearranging the xybk equation, to compute the K value from the token balances in the pool (x, y):

**Price Behavior**

Artificial token balances in the pool ranges from:

Since token prices in pools are calculated as a ratio of token balances, this means prices ranges from:

New concept: Asymmetrical tuning

Asymmetrical tuning is a novel concept in the swap space.