How AMM Algorithms Set Prices in Decentralized Finance

Posted by HELEN Nguyen
- 11 February 2026 1 Comments

How AMM Algorithms Set Prices in Decentralized Finance

When you swap ETH for USDC on a decentralized exchange like Uniswap, no human is setting the price. No trader is placing a bid. No broker is matching orders. Instead, a simple mathematical formula - hidden inside smart contracts - decides exactly how much of one token you get for another. This is the power of AMM algorithms. They’re not just a technical detail; they’re the backbone of how decentralized finance moves money without middlemen.

How AMMs Replace Order Books

Traditional stock and crypto exchanges rely on order books. Buyers list what they’re willing to pay. Sellers list what they’ll accept. The exchange matches them. It’s clear, familiar, and works well - if you have enough buyers and sellers. But in decentralized finance, there’s no central authority to match trades. So how do you trade ETH for DAI if no one’s actively offering it?

AMMs solve this by creating liquidity pools. Instead of individual buyers and sellers, you have pools of tokens - say, 100 ETH and 200,000 USDC - locked in a smart contract. Anyone can trade against this pool. The algorithm inside the contract adjusts the price automatically every time someone swaps tokens. The more you buy of one token, the more expensive it gets. The more you sell, the cheaper it becomes. It’s supply and demand, but mathematically enforced.

The Core Formula: x * y = k

The most common AMM algorithm is called the constant product market maker. Its rule is simple: for any two tokens in a pool, the product of their quantities must always stay the same. That’s x * y = k.

Let’s say you have a pool with 100 ETH and 200,000 USDC. Multiply them: 100 * 200,000 = 20,000,000. That’s your k. No matter how many trades happen, this number must stay constant.

Now, someone wants to buy 10 ETH. To keep k at 20 million, the algorithm calculates: if ETH rises to 110, then USDC must drop to 20,000,000 / 110 = 181,818.18. So the trader gets 10 ETH, but pays 200,000 - 181,818.18 = 18,181.82 USDC. That’s a price of roughly 1,818 USDC per ETH.

Wait - that’s not the market price. The market price was 2,000 USDC per ETH. So why did they pay less? Because the algorithm doesn’t just give you the current price. It gives you the price after the trade. And because the pool is finite, buying a lot pushes the price up. That’s called slippage.

Slippage Isn’t a Bug - It’s a Feature

Slippage is the difference between the price you expect and the price you get. On Uniswap V2, if you try to swap $50,000 worth of ETH, you might end up paying 2% more than the price you saw. Why? Because the algorithm forces the pool to absorb your entire trade. As you buy more ETH, the remaining ETH in the pool gets scarcer, so each unit becomes more expensive.

This isn’t a flaw - it’s how the system stays balanced. If slippage didn’t exist, traders could drain the pool. Imagine a pool with 1 ETH and 2,000 USDC. If you could buy 1 ETH for 1,000 USDC, you’d take the whole pool and walk away with 1,000 USDC profit. Slippage stops that.

But slippage becomes a problem for large trades. That’s why Uniswap V3 changed everything.

Uniswap V3: Concentrated Liquidity

Before V3, liquidity providers (LPs) had to spread their tokens evenly across all possible prices - from $100 to $10,000 per ETH. Most of that capital sat idle. V3 lets LPs choose a price range. If you think ETH will stay between $3,000 and $4,000, you put all your money there.

This is like turning a highway into a toll booth. Instead of scattering cash along a 100-mile road, you put it right at the exit ramp. The result? Up to 4,000x more capital efficiency. A pool with $1 million in V3 can match the trading depth of a $4 billion V2 pool.

But there’s a catch. If ETH crashes below $3,000, your entire ETH position turns into USDC. And if it surges past $4,000, you’re left holding only USDC. You don’t earn fees anymore. This is called impermanent loss - and it’s real. In volatile markets, LPs can lose 15-25% of their value if prices move outside their range.

Liquidity pool with ETH and USDC in glass chambers, a trader withdrawing tokens as an arbitrage bot siphons profit nearby.

Curve: The Stablecoin Specialist

If Uniswap is for volatile assets, Curve is for stablecoins. It uses a different formula: a hybrid of x + y = k and x * y = k. Why? Because stablecoins like USDC and DAI should trade at 1:1. You don’t want slippage when swapping them.

Curve’s algorithm keeps prices stable until the difference between tokens grows beyond a tiny threshold - say, 1.01:1. Then it starts to act like Uniswap. The result? A $10,000 swap between USDC and DAI might cost you 0.04% in slippage. That’s 10 to 20 times better than Uniswap.

But Curve isn’t perfect. During the UST depeg in May 2022, its 3pool saw slippage spike to 1.8% - because the algorithm assumed stability. When one stablecoin broke its peg, the system didn’t react fast enough. That’s why Curve V2 added dynamic peg monitoring and adaptive fees.

Other AMMs: Balancer, LMSR, and Beyond

Balancer lets you create pools with up to 8 tokens, each with custom weights. Want a pool that’s 80% ETH and 20% DAI? You can do it. But because the algorithm uses a geometric mean, slippage is higher than Uniswap for the same liquidity depth.

Then there’s the logarithmic market scoring rule (LMSR), used in prediction markets like Polymarket. It doesn’t just track token ratios - it tracks trader sentiment. The price reflects how confident people are in an outcome. If 70% of traders believe Team A will win, the price of “Team A Win” token rises to 0.70. It’s not about supply and demand - it’s about belief.

And then there’s TWAMM - Time-Weighted AMM. It’s not live yet, but it’s the next frontier. Instead of dumping a $1 million trade all at once, TWAMM splits it into 100 tiny trades over 30 minutes. This cuts slippage by 60-75%. It’s like using a slow drip instead of a firehose.

Who Wins? Who Loses?

Traders: Uniswap V2 is simple but expensive for big trades. Curve is cheap for stablecoins. V3 is great if you know the price range - but risky if you don’t.

Liquidity Providers: V3 offers higher yields - up to 45% APY in optimal ranges - but you need to monitor your positions constantly. Tools like Gamma.xyz help, but they’re not foolproof. Many LPs lost money during the January 2023 GBTC volatility spike because they didn’t adjust their ranges.

Bots: The real winners? Arbitrage bots. They monitor price differences between AMMs and centralized exchanges. When ETH is $2,010 on Coinbase but $2,000 on Uniswap, they buy low and sell high - pocketing 0.1-0.3% per trade. These bots execute thousands of trades per second. They’re why your $10,000 swap costs more than expected.

Uniswap V3 liquidity range as a toll booth on a price highway, with one lane empty after a price crash and LPs adjusting barriers.

The Hidden Costs: MEV and Impermanent Loss

There’s another cost no one talks about: MEV - Maximal Extractable Value. It’s the profit bots and miners make by reordering your trades. If you submit a buy order for ETH, a bot might detect it and front-run you - buying ETH before you and selling it back at a higher price. In 2023, this stole $1.2 billion from users across all DEXs.

And then there’s impermanent loss. It’s not “impermanent” if you never get your money back. If you provide liquidity during a bull run and the price moves 30% away from your range, you could lose 20% of your capital. It’s not a glitch - it’s built into the system. Most LPs don’t understand this until they’ve lost money.

The Future: Hook-Based AMMs and Adaptive Curves

Uniswap V4 (in testing) will let developers write custom pricing rules. Want a pool that only trades when volatility is low? You can code it. Want a pool that charges higher fees during a crash? Done. This opens the door to AMMs that adapt to real market conditions - not just rigid math.

Projects like SyncSwap are already testing adaptive curves that adjust slippage based on real-time volatility. In tests, they’ve hit 0.015% slippage on stablecoin swaps - nearly invisible.

The goal isn’t to replace traditional markets. It’s to make decentralized trading smoother, cheaper, and fairer. AMMs aren’t perfect. But they’re getting better - fast.

Why This Matters

AMMs didn’t just create a new kind of exchange. They created a new way to think about money. No banks. No brokers. No intermediaries. Just code, liquidity, and math. And as more people use DeFi, these algorithms will become the invisible hands behind trillions in trades.

They’re not magic. But they’re powerful. And if you’re trading on a DEX, you’re already living in a world shaped by them.

Comments

Ben Pintilie
Ben Pintilie

lol this is all just math magic lol 🤡 why do i even care if x*y=k when i just wanna swap my eth for usdc without getting rekt

February 11, 2026 at 11:37

Write a comment