📠Basic Mathematics
Last updated
Last updated
Lets assume a protocol with a token . 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 , and the bonding curve formula given by Uniswap is:
Hence,
This formula is responsible for calculating prices, and deciding how much token would be received in exchange for a certain amount of USDC, or vice versa.
The formula states that is a constant no matter what the reserves (x or y) are. Every swap increases the reserve of either USDC or token and decreases the reserve of the other.
Where is the amount being provided by the user for sale, and is the amount the user is receiving from the DEX in exchange for .
Since is a constant, we can asume that:
Before any swap is being made, we know the exact values of x, y, and (given by the input). In that way, we are interested in calculating , which is the amount of USDC or token the user will receive:
Hence, after simplyfing the above equation to obtain , we get the following: