# Cross-pair Swaps

This page was drafted in December 2020 and is currently due for an update. The core concepts are implemented as planned and the only difference is the formula used to plot the curve: y = kp/(x+k)

# Context

An additional disadvantage of the pair-based structure is its lack of capital efficiency. Liquidity provided to one pair is restricted to usage within that pool alone. Even if an asset is staked in large quantities within the AMM, disproportionate distribution across the pairs results in some pairs having low liquidity and higher slippage.

Centaur Swap is designed to enable asset pools to trade with each other in a seamless manner. This means that once an asset pool is funded, it is effectively paired against every other existing asset pool. Based on the curve described in the previous segment, the price for each token against USDT or ETH can be calculated at any point in time, while taking into account the Current Balance of each individual pool. The price of any two tokens can then be used as a reference to determine an exchange rate for a direct swap.

## Approach

Consider a swap from Token A, which is currently in Deficit to Token B, which is currently in Surplus. Curve of Token A with its current balance at A1

Due to the Deficit of Token A, its price at point A1 is above i, the External Price and traders are incentivised to sell Token A. The intended quantity of tokens sold by the trader would increase the Current Balance to point A2 and the value would be represented by the shaded area under the curve ("|A|").

By integrating the curve $y = -kx^3 + i$, the value for |A| can be calculated

\begin{aligned} |A| &= \int_{x_1}^{x_2}(i-kx^3)dx \\ &= (ix_2 - \frac{k{x_2}^4} {4}) - (ix_1 - \frac{k{x_1}^4} {4}) \\ &=i(x_2 - x_1) - \frac{k}{4}({x_2}^4 - {x_1}^4) \end{aligned}

where the $x_1$ and $x_2$ represent the values of A1 and A2. Curve of Token B with its current balance at B1

After deriving |A|, the its value can be projected onto the curve of Token B, which is currently in Surplus at point B1. As token swaps must result in an equivalent exchange of value, the shaded area between points B1 and B2 ("|B|") will be exactly the same as |A|. With that, we can solve for B2 to calculate the new Current Balance after the trade is executed, and after dividing the quantity of Token B received by the quantity of Token A sold, we can determine the exchange rate for any two tokens liquidity pool in a manner that does not rely on pairing.