# 📠Basic Mathematics

Last updated

Last updated

Lets assume a protocol with a token $T_P$. On an initial cycle is going to be paired with an USD-pegged stablecoin such as **USDC**. In that way, the LP is going to be $\frac{T_P}{USDC}$, and the bonding curve formula given by Uniswap is:

$x \cdot y = K$

Hence,

$T_P \cdot USDC = K$

This formula is responsible for calculating prices, and deciding how much $T_P$ token would be received in exchange for a certain amount of USDC, or vice versa.

The formula states that $K$ is a constant no matter what the reserves (*x* or *y*) are. Every swap increases the reserve of either USDC or $T_P$ token and decreases the reserve of the other.

$(x + \Delta x) \cdot (y - \Delta y) = K$

Where $\Delta x$ is the amount being provided by the user for sale, and $\Delta y$ is the amount the user is receiving from the DEX in exchange for $\Delta x$.

Since $K$ is a constant, we can asume that:

$x \cdot y = (x + \Delta x) \cdot (y - \Delta y)$

Before any swap is being made, we know the exact values of *x*, *y*, and $\Delta x$ (given by the input). In that way, we are interested in calculating $\Delta y$, which is the amount of USDC or $T_P$ token the user will receive:

$y - \Delta y = \frac{x \cdot y}{x + \Delta x}$

$-\Delta y = \frac{(y \cdot \Delta x)}{(x + \Delta x)} - y$

$-\Delta y = \frac{x \cdot y - y(x + \Delta x) }{x+ \Delta x}$

$-\Delta y = \frac{x \cdot y - y \cdot x - y \cdot \Delta x}{x+\Delta x}$

$-\Delta y = \frac{-y \cdot \Delta x}{x+ \Delta x}$

Hence, after simplyfing the above equation to obtain $\Delta y$ , we get the following:

$\Delta y = \frac{(y \cdot \Delta x)}{(x + \Delta x)}$