Automated Market Makers
A Deep Dive into Uniswap v2


Automated Market Makers / Uniswap v2
In the fast-moving world of decentralized finance (DeFi), one innovation stands out as a true game changer: the Automated Market Maker (AMM). Instead of relying on centralized exchanges or human market makers, AMMs use algorithms and smart contracts to set prices, hold liquidity, and execute trades — all without a middleman.
Uniswap v2 is one of the most popular examples, and in this post, we’ll break down exactly how it works: from the constant product formula to real trade simulations, and finally, the risks you should know.
What is an Automated Market Maker (AMM)?
At its core, an AMM is a smart contract that:
Holds reserves of two (or more) tokens.
Calculates prices using a specific mathematical formula.
Executes trades automatically based on that formula.
Anyone can trade with the pool, and anyone can supply liquidity — making markets open, transparent, and always available.
In Uniswap v2, the formula that powers everything is:
x * y = k
Where:
x = amount of token A in the pool
y = amount of token B in the pool
k = constant value that stays the same during trades
Smart Contracts and Liquidity Pools
An AMM runs entirely on a smart contract — a self-executing program on the blockchain that can’t be altered or stopped once deployed.
A liquidity pool is simply the collection of tokens locked inside that smart contract. Liquidity providers (LPs) deposit equal value of each token — for example, if ETH is worth 2,000 USDC, an LP could deposit:
1 ETH + 2,000 USDC
5 ETH + 10,000 USDC
From there, the pool handles trades between those tokens automatically. LPs earn a portion of the 0.3% trading fee for providing liquidity.
The Constant Product Formula
The constant product formula ensures that the product of the two reserves always stays the same.
Example:
x = 10 ETH
y = 20,000 USDC
k = 10 * 20,000 = 200,000
The price of ETH in USDC is:
Price of ETH = y / x = 20,000 / 10 = 2,000 USDC
If someone buys ETH, x decreases, y increases, and the price moves accordingly — without any external price feed.
Trade Simulation
Let’s see what happens when someone buys 1 ETH from the pool.
Initial reserves:
x = 10 ETH
y = 20,000 USDC
k = 200,000
Step 1 — New ETH reserve:
x' = x - 1 = 9 ETH
Step 2 — New USDC reserve (keeping k constant):
9 * y' = 200,000
y' = 200,000 / 9 ≈ 22,222.22 USDC
Step 3 — Amount paid by trader:
22,222.22 - 20,000 = 2,222.22 USDC
Step 4 — New price:
Price of ETH = 22,222.22 / 9 ≈ 2,469.13 USDC
A single purchase increased the ETH price from 2,000 to ~2,469 USDC — a clear example of slippage.
Risks of Using AMMs
AMMs are powerful, but not risk-free. Key risks include:
Impermanent Loss – When token prices change, LPs may end up with less value than if they had just held the tokens.
Slippage – Large trades move prices significantly, especially in small pools.
Front-Running – Bots can detect large trades and execute ahead of you.
Flash Loan Exploits – Attackers can borrow huge amounts to manipulate AMM prices.
Smart Contract Bugs – If there’s a flaw in the code, funds can be stolen or locked forever.
Network & Regulatory Risks – High gas fees and changing laws can impact usability.
Final Thoughts
Uniswap v2’s AMM model is elegant: simple math and transparent code powering billions in trades without centralized control. But like any powerful tool, it comes with risks that demand respect.
If you understand the constant product formula, how trades impact price, and the ways bad actors might exploit the system, you’ll be far better prepared to use AMMs wisely — whether as a trader or a liquidity provider.

