Swap Math

Our swap upgrade introduces two novel features:

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

Invariant Behavior

In our medium article, we mentioned the simple example of a pool with x=token0balance=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:

Note: Price bounds purely depends on the pool boosts which is neat

New concept: Asymmetrical tuning

Asymmetrical tuning is a novel concept in the swap space.

Last modified 2mo ago

Copy link