Lets assume a protocol with a token TPā. 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 USDCTPāā, and the bonding curve formula given by Uniswap is:
xā
y=K
Hence,
TPāā
USDC=K
This formula is responsible for calculating prices, and deciding how much TPā 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 TPā token and decreases the reserve of the other.
(x+Īx)ā
(yāĪy)=K
Where Īx is the amount being provided by the user for sale, and Īy is the amount the user is receiving from the DEX in exchange for Īx.
Since K is a constant, we can asume that:
xā
y=(x+Īx)ā
(yāĪy)
Before any swap is being made, we know the exact values of x, y, and Īx (given by the input). In that way, we are interested in calculating Īy, which is the amount of USDC or TPā token the user will receive:
yāĪy=x+Īxxā
yā
āĪy=(x+Īx)(yā
Īx)āāy
āĪy=x+Īxxā
yāy(x+Īx)ā
āĪy=x+Īxxā
yāyā
xāyā
Īxā
āĪy=x+Īxāyā
Īxā
Hence, after simplyfing the above equation to obtain Īy , we get the following:
Īy=(x+Īx)(yā
Īx)ā