# Swap Math

If you have not checked out our intro article on medium, [please start here](https://medium.com/impossiblefinance/the-impossible-v2-swap-4441b054ad17)

Our swap upgrade introduces two novel features:&#x20;

1. The xybk invariant
2. Asymmetrical tuning

## **New Invariant: xybk**

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:

![The xybk invariant. When b=1, this simplifies to Uniswap's x \* y = k](https://2070884675-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Mblc6q3YEdwqoZdnD_v%2F-Mf9KZ-hsMJSX6xZ3u5u%2F-Mf9NVZktyjM-ZpXjX4G%2FScreen%20Shot%202021-07-21%20at%202.44.15%20PM.png?alt=media\&token=16953174-9ec0-4d3d-97f0-ab38e2e084cf)

**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&#x20;*****(1000, 1000)*****&#x20;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):

![](https://2070884675-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Mblc6q3YEdwqoZdnD_v%2F-Mf9KZ-hsMJSX6xZ3u5u%2F-Mf9T02oUWmA207mfl6V%2FScreen%20Shot%202021-07-21%20at%203.08.05%20PM.png?alt=media\&token=4a0ed559-9bf8-45ff-9f62-7a3e6b45a0b1)

**Price Behavior**

Artificial token balances in the pool ranges from:

![](https://2070884675-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Mblc6q3YEdwqoZdnD_v%2F-Mf9KZ-hsMJSX6xZ3u5u%2F-Mf9TwRKwV2u_U2CS-sj%2FScreen%20Shot%202021-07-21%20at%203.12.19%20PM.png?alt=media\&token=39e70b7d-ca35-4aa9-a0da-18598ae24c81)

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

![Note: Price bounds purely depends on the pool boosts which is neat](https://2070884675-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Mblc6q3YEdwqoZdnD_v%2F-Mf9KZ-hsMJSX6xZ3u5u%2F-Mf9UWHgQr4BoSHEkovI%2FScreen%20Shot%202021-07-21%20at%203.14.53%20PM.png?alt=media\&token=38c104a2-7853-438a-81c4-05a28b5fd3f3)

## New concept: Asymmetrical tuning

Asymmetrical tuning is a novel concept in the swap space.&#x20;
