The MadBrooks Sage

Automated Market Makers: The Math Behind Constant Product Formulas

Jul 31, 2026 · 9:11 AM CT · 7:38 · The MadBrooks Sage | Automated Market Makers | The Math Behind Constant Product Formulas | 7/31/2026

Why x × y = k became the equation that powers decentralized exchanges. We'll break down how AMMs price trades algorithmically without order books or intermediaries.

Apple Podcasts Spotify Pocket Casts RSS

Transcript

If you've ever wondered how a piece of software can quote you a price for a token without a single human being involved, without a traditional order book, and without a bank or broker in the middle, you're about to understand one of the most elegant mathematical innovations in decentralized finance.

Let's talk about automated market makers and the deceptively simple equation that changed how we think about trading: x times y equals k.

Before we get to the math, let's establish why this matters at all. Traditional exchanges, whether we're talking about the New York Stock Exchange or Coinbase's order book, work on a model that's centuries old. Buyers submit bids, sellers submit asks, and when those prices meet, trades execute. There's a central limit order book, a matching engine, and usually some institution guaranteeing liquidity. It works, but it requires infrastructure, intermediaries, and constant management.

Decentralized exchanges needed something different. You can't rely on a central order book when you're trying to build a permissionless system on a blockchain. The solution that emerged was the automated market maker, and at its heart sits this formula: x times y equals k.

Let me break down what those variables actually represent. Imagine a liquidity pool, which is really just a smart contract holding two different tokens. Let's use a classic example: Ethereum and a stablecoin like USDC. The variable x represents the quantity of Ethereum in the pool. The variable y represents the quantity of USDC in the pool. And k is the constant product of those two quantities.

The brilliance is in what stays constant and what changes. The product, k, remains fixed unless someone adds or removes liquidity from the entire pool. But x and y, the individual token quantities, change with every single trade. When someone buys Ethereum from the pool, x goes down and y must go up to maintain that constant product. When someone sells Ethereum to the pool, x goes up and y goes down.

This creates an automatic pricing mechanism. The ratio between x and y determines the price at any given moment. If the pool contains one hundred Ethereum and two hundred thousand USDC, the implied price is two thousand dollars per Ethereum. That's the ratio. No human market maker set that price. The math did.

Now here's where it gets interesting, and where the curve really matters. Because k is constant, the relationship between x and y forms a hyperbola. As you buy more and more of one token, the price doesn't increase linearly. It increases exponentially. This is called slippage, and it's a feature, not a bug.

Think about it like this. Imagine you're at a well that never runs dry, but the deeper you draw from it, the harder you have to pull. The first bucket comes up easy. The tenth bucket requires significantly more effort. The hundredth bucket might be nearly impossible. Automated market makers work the same way. Small trades barely move the price. Large trades move it substantially.

Let's walk through a real example with simple numbers. Say our pool has ten Ethereum and twenty thousand USDC. Our constant k equals two hundred thousand. Someone wants to buy one Ethereum. They're removing one Ethereum from the pool, so x becomes nine. To maintain our constant product, y must equal two hundred thousand divided by nine, which is roughly twenty-two thousand two hundred twenty-two. That means they need to put in about twenty-two hundred USDC to get one Ethereum out, even though the initial ratio suggested a price of two thousand. That extra two hundred dollars is the slippage from moving the price curve.

This might seem inefficient compared to an order book, and for very large trades, it absolutely is. But it has profound advantages. First, there's always liquidity. You can always make a trade, no matter what, as long as there are tokens in the pool. There's no waiting for a counterparty. Second, it's completely automated and permissionless. Anyone can create a pool for any token pair. Third, it's transparent. The pricing formula is right there in the smart contract code. No hidden spreads, no preferential treatment.

The people who provide liquidity to these pools, the ones who deposit both tokens to increase that k value, they earn fees from every trade. Typically something like point three percent per transaction. They're essentially becoming the market maker, earning the spread that would traditionally go to a bank or trading firm. But they also take on risk, particularly something called impermanent loss, which happens when the price ratio between the two tokens changes significantly while their funds are deposited.

Now, x times y equals k isn't the only formula in the automated market maker world. It's the constant product formula, made famous by Uniswap. But there are variations. Curve Finance uses a different formula optimized for assets that should trade very close to a one-to-one ratio, like different stablecoins or different wrapped versions of the same asset. Balancer allows pools with more than two tokens and different weighting ratios. But they all share this core insight: you can encode market-making logic into mathematics and let the algorithm handle pricing.

The philosophical shift here is worth sitting with. For most of financial history, prices have been discovered through human negotiation. Even when computers got involved, they were executing human strategies, matching human orders. Automated market makers remove humans from price discovery almost entirely. The price emerges from the mathematical relationship between supply quantities and the constant product rule. It's determined by the aggregate behavior of everyone who's traded before you, crystallized into the current state of x and y.

Is it perfect? No. The slippage on large trades is real. Arbitrage bots constantly drain small inefficiencies from these pools. There's risk for liquidity providers. And these systems are still young, still evolving, still being tested under different market conditions. But as a solution to the problem of how to create a functional exchange without traditional infrastructure, without permission, without intermediaries, it's remarkably elegant.

What started as a clever mathematical trick has grown into a fundamental building block of decentralized finance. Billions of dollars flow through these constant product pools every day. People are earning yields by providing liquidity. Traders are swapping tokens without ever touching a centralized exchange. All because someone realized you could encode the logic of a market maker into the simple relationship between three variables.

The next time you swap tokens on a decentralized exchange, you're not just using a product. You're participating in a live mathematical system, where your trade adjusts the variables, shifts the curve, and slightly changes the price for the next person. It's game theory and calculus and economics all running autonomously in a smart contract.

See you Saturday.

Remember this: the most powerful financial innovations often look simple after someone invents them, but x times y equals k turned passive mathematics into active markets.

← Flash Loans: Borrowing Millions With No Collateral (For 13…Block Reorganizations: When Blockchains Rewrite Their… →

AI generated. Not financial advice.