JOVANA
Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
All guides

DeFi and Automated Market Makers

Decentralized finance rebuilds banks and exchanges as open programs anyone can use or stack together. At its heart sits a clever trick: a trading pool that sets its own prices with a single line of math.

A bank with no building

Think about everything a bank or a stock exchange does: it holds deposits, lets you swap one currency for another, lends money out, and matches buyers with sellers. Behind all of it sit a company, a license, a building, and a wall of trust you have no choice but to lean on. Now imagine taking each of those services and rewriting it as a public smart contract — a vending machine for finance that anyone on Earth can use, at any hour, without an account or an application.

That is decentralized finance, or DeFi: financial services built entirely out of contracts running on a chain like Ethereum, with no company sitting in the middle. Because every contract is public and can call every other contract, they snap together like building blocks — people call them money legos. A lending contract can plug into a trading contract, which plugs into a savings contract, and a newcomer can build a fresh service on top of all three without asking anyone's permission.

The problem: who do you trade with?

Take the most basic service — swapping one token for another. A traditional exchange keeps an order book: a long list of people offering to buy at this price and sell at that price, with a matching engine pairing them up. That works beautifully on a fast central server, but it falls apart on a blockchain, where every update is slow and costs a gas fee. Keeping a busy order book alive on-chain would be agonizingly expensive, and at 3 a.m. there may simply be no one on the other side willing to trade.

So DeFi threw out the order book and asked a stranger question: what if you didn't trade against a *person* at all, but against a pool of money that prices itself with a formula? No counterparty to wait for, no matching engine — just a contract that is always open and always quotes a price. This is the automated market maker, or AMM, and it is the engine under most of DeFi's trading.

The pool and one line of math

An AMM starts with a liquidity pool: a contract holding a reserve of two tokens, say ETH and a dollar stablecoin called USDC. People who want to earn fees deposit *both* tokens into the pool — they are the liquidity providers — and the pool now has, for example, 100 ETH on one side and 200,000 USDC on the other. The magic is the rule the contract uses to set its price. It keeps the product of the two reserves constant:

        x  *  y  =  k

   x = amount of token A in the pool  (e.g. ETH)
   y = amount of token B in the pool  (e.g. USDC)
   k = a constant -- it must NOT change on a swap

   Start:  x = 100 ETH , y = 200,000 USDC
           k = 100 * 200,000 = 20,000,000

   Any trade must leave x * y back at 20,000,000.
The constant-product rule: the pool's price is whatever keeps x times y equal to k.

That single equation, `x · y = k`, *is* the market maker. The contract never looks up a price anywhere — the price is simply the ratio of the two reserves, and the constant `k` is the rule that the reserves must always honor. The current price of ETH here is 200,000 / 100 = 2,000 USDC. Nobody set that number by hand; it falls straight out of how much of each token happens to be sitting in the pool.

A swap, step by step

Now watch a trade happen. You want to buy ETH, so you send some USDC into the pool. Your USDC is *added* to the `y` side, which pushes `y` up. To keep `k` unchanged, the contract must hand you back enough ETH to pull `x` down by just the right amount. You don't take ETH at a fixed price — you slide along the curve, and each ETH you remove leaves the pool with a little less of it, so the next ETH costs slightly more.

  1. You send 10,000 USDC into the pool. The USDC side rises: y goes from 200,000 to 210,000.
  2. The constant must hold: x must satisfy x * 210,000 = 20,000,000, so the new x = 20,000,000 / 210,000 ≈ 95.24 ETH.
  3. The pool used to hold 100 ETH and now holds 95.24, so it hands you the difference: ≈ 4.76 ETH.
  4. You paid 10,000 USDC for about 4.76 ETH — roughly 2,100 USDC each, a bit above the 2,000 you saw before you traded. That gap is slippage, and it grows with the size of your order.

What the providers risk

Liquidity providers earn those fees, but they take on one honest risk worth naming. As the outside market price of ETH moves, traders keep rebalancing the pool — buying the cheaper side and selling the dearer — so a provider can end up with less total value than if they had simply held the two tokens in their own wallet; this shortfall is called impermanent loss. Fees can outweigh it, which is exactly the bet a provider is making.

The takeaway

DeFi rebuilds finance as open, composable contracts — money legos anyone can use or stack. Its trading workhorse, the automated market maker, replaces a human order book with a liquidity pool priced by one rule, `x · y = k`: every swap slides along that curve, larger trades slip further, and the providers who fill the pool earn fees in return for bearing impermanent loss.

From this one primitive, the rest of the application layer grows: lending markets, stablecoins that hold a steady value, and tokens that represent anything at all. Next we'll meet the tokens themselves — the standardized units of value that flow through every pool and contract on the chain.