Step 6 / Ethereum & Shared Applications
A market made of two reserves.
Calculate what leaves a pool when a trader puts something in.
Picture a market stall with two jars. One holds token A and the other holds token B. Maya wants A, so she puts B into the stall and takes some A out.
How much A can she take? A program applies a rule to the amounts already in the jars. A seller does not have to answer her at that moment because the assets are waiting in the pool.
This is the starting idea of an automated market maker, or AMM.
Start with the amounts in the pool.
An exchange with an order book matches orders from buyers and sellers. Many AMMs take another approach: a trader exchanges against assets already deposited in a contract.
That shared supply of assets is a liquidity pool. The people who deposit them are liquidity providers. The amounts currently held are the pool’s reserves, or inventory.
Use a made-up pool with 100 A and 100 B. First multiply the two amounts: 100 × 100 = 10,000. In this example, every swap must keep that product at 10,000.
Maya adds 10 B. The pool now has 110 B. To find how much A must remain, divide the fixed product by the new B amount: 10,000 ÷ 110 = about 90.91 A.
The pool began with 100 A and keeps about 90.91 A. Maya gets the difference: 100 − 90.91 = about 9.09 A. She did not receive ten A because her trade changed the amounts in the jars.
This rule is called constant product. “Product” means the result of multiplying. If x is the A reserve, y is the B reserve, and k is their fixed product, the rule is x × y = k.
The program calculates the trade from its rule and inventory. The user still relies on the tokens, code, network, and any special controls. Removing a matching desk does not remove every operator or risk.
Dashed outline: the starting 100 A × 100 B reserves.
Fee-free constant product, no intervening trades. Actual swaps include fees and rounding.
This teaching model leaves out fees and rounding. It assumes ordinary tokens, no other trades, and immediate execution. A real quote must come from the actual pool and its rules.
Before moving the slider, predict which reserve will rise and which will fall. Then compare the A received, the average price paid, and the price of the next tiny trade. The next section explains why those differ.
The average price differs from the next price.
Before Maya trades, the pool has equal reserves. The price for a very small amount of A starts near 1 B per A. But the pool cannot keep selling unlimited A at that starting price.
As Maya takes A out and puts B in, there is less A relative to B. Under this rule, each additional bit of A costs more B than the one before it.
Maya paid 10 B and received about 9.09 A. To find her average price, divide what she paid by what she received: 10 ÷ 9.09 is about 1.10 B per A. This describes the whole purchase.
Afterward, the pool has about 90.91 A and 110 B. Its price for the next tiny trade is about 110 ÷ 90.91 = 1.21 B per A. This is the marginal price: the quote at the edge of the next small trade.
The price change caused by Maya’s own purchase is called price impact. A larger purchase from the same pool usually pushes the average price further from the starting quote.
Now imagine another trader changes the reserves before Maya’s request runs. Her actual result may differ from what she expected when she submitted it. That difference is called slippage. Apps sometimes mix these labels, so check what their numbers mean.
Maya can set a minimum amount she will accept. If execution would give her too little, the request can fail. This limit does not erase her own price impact, used network fees, malicious token behavior, or every harmful choice about transaction order.
Outside prices change what traders take.
Imagine A becomes more valuable at another market while this pool still offers a lower price. A trader may buy A here with B and sell that A in the other market. Trading between markets to use a price difference is called arbitrage.
Those purchases take A out of the pool and put B in. As the reserve mix changes, the pool’s A price rises toward the outside price. The program does not need to read the news; traders change its inventory in response to the opportunity.
The model starts at 100 A and 100 B, with A priced at 1 B outside. Change the outside price to 4 B per A. Ignoring costs, arbitrage moves the pool to 50 A and 200 B.
Check both parts: 50 × 200 is still 10,000, and 200 ÷ 50 gives the new quote of 4 B per A. In real trading, fees, delays, and other risks can keep prices from matching exactly.
Notice the result for the providers. They now hold less A, the asset whose price rose, and more B. They may earn fees for making trades possible, but those fees do not guarantee that supplying the pool beats keeping the original tokens.
An AMM gives other programs a reusable way to exchange assets. Its code sets the participation and pricing rules. Next we will compare designs built for different kinds of assets, then examine the provider’s result.
Dashed outline: the starting 100 A × 100 B reserves.
The pool and outside market both begin at 1 B per A.
The idea to keep
An AMM applies a rule to assets held in a pool. The amounts in the pool affect the next price, so a trade changes conditions for the trades that follow. This affects both buyers and the people supplying the assets.
