The Math behind UniswapV2

Liquidity Pools: A Quick Intro & Comparison to Forex
In the realm of decentralized finance (DeFi), liquidity pools function as the crypto equivalent of traditional foreign exchange markets, but with a twist. Picture a large shared pot where users deposit pairs of cryptocurrencies. This pot is the liquidity pool, allowing traders to swap one crypto for another directly, without any middlemen.
Compare this to traditional Forex, where banks and financial institutions act as intermediaries, facilitating currency exchange. In Forex, liquidity hinges on the market's size and the number of participants. Liquidity pools, on the other hand, are fueled by the users themselves, creating a more open and accessible system.
In essence, liquidity pools are the driving force behind DeFi, providing a decentralized alternative to traditional foreign exchange markets. They enable peer-to-peer trading, fostering transparency and accessibility in the crypto world.
The AMM bonding curve
In decentralized finance (DeFi) protocols like UniswapV2, bonding curves represent the relationship between the asset reserves in a liquidity pool.
The curve is typically represented as: x * y = k where x and y are the reserves of two assets in the liquidity pool and k is a constant representing the product of the reserves.
Understanding Constant Product AMMs
Let's explore constant product AMMs, a decentralized exchange model, and the concept of liquidity within them.
The core equation behind a constant product AMM is:
x * y = L ^ 2- x = quantity of token X
- y = quantity of token Y
- L = liquidity
Illustrative Example
Consider an AMM with the following parameters:
For example, let x = 100 ETH and y = 200 DAI. Then k = 100 × 200 = 20,000, so L = √20,000 ≈ 141.42.
Swap Δx = 10 ETH:
new x = 110
new y = k / 110 ≈ 181.82
Δy received ≈ 18.18 DAI (ignoring fees)
This illustrates how prices adjust to keep x × y = k in a constant product AMM.