AMM Example

From Seasonal Tokens
Jump to navigation Jump to search

Example: Automated Market Making (AMM) Using Polygon and the Spring Token

Automated Market Makers (AMMs) such as Uniswap do not use an order book. Instead, the price is determined entirely by the liquidity pool. This page shows a simple example using Polygon (POL) and the Spring token (SPRING) to illustrate how the price changes when you buy or sell.

The goal is to show that:

When you buy Spring, you pay a price slightly higher than the listed price. When you sell Spring, you receive a price slightly lower than the listed price.

This difference is called slippage, and it happens automatically because of the AMM formula.

1. The Constant Product Formula

AMMs maintain a constant value:

x × y = k

Where:

x = amount of POL in the pool y = amount of SPRING in the pool k = constant value that does not change

The listed price shown in the interface is only the spot price, calculated as:

Price = POL in the pool ÷ SPRING in the pool

But the moment you make a purchase or a sale, the pool balances shift, and the price moves.

2. Example Pool

For this example, suppose the liquidity pool contains:

10 000 POL 10 000 SPRING

So the listed (spot) price in the interface is:

1 SPRING = 1 POL


3. Buying SPRING With POL

Let’s say a user buys:

1 000 POL worth of SPRING

Before the purchase:

x = 10 000 y = 10 000 k = 100 000 000

The user adds 1 000 POL to the pool:

New x = 11 000

We must keep x × y = k, so:

y = k ÷ x y = 100 000 000 ÷ 11 000 y ≈ 9 090.90

This means the pool must end with:

9 090.90 SPRING

So the user receives:

10 000 − 9 090.90 = 909.10 SPRING


Effective price paid

The user spent 1 000 POL and received 909.10 SPRING.

Effective price = 1 000 / 909.10 ≈ 1.10 POL per SPRING

Even though the listed price was 1, the user paid 1.10.

This is because the buy order pushed the price upward as the pool balances changed.

4. Selling SPRING for POL

Now suppose a user sells:

1 000 SPRING to the pool

Before the sale:

x = 10 000 y = 10 000 k = 100 000 000

After the user adds 1 000 SPRING:

New y = 11 000

To keep x × y = k:

x = k ÷ y x = 100 000 000 ÷ 11 000 x ≈ 9 090.90 POL

So the user receives:

10 000 − 9 090.90 = 909.10 POL


Effective price received

The user sold 1 000 SPRING and received 909.10 POL.

Effective price = 909.10 / 1 000 = 0.909 POL per SPRING

Even though the listed price was 1, the user received only 0.909.

This is because selling pushes the price downward.

5. Why Does This Happen?

AMMs do not allow traders to buy or sell at the exact spot price unless their trade is extremely small relative to the pool.

Every trade changes the pool ratios:

Buying SPRING ↑ increases POL in the pool → decreases SPRING in the pool → price rises Selling SPRING ↓ increases SPRING in the pool → decreases POL in the pool → price falls

This is not a fee or a penalty. It is simply how the AMM formula works.

6. Summary

You never trade at the listed price. Small trades have very little price impact. Large trades move the price significantly. Bigger liquidity pools = less slippage.

AMMs reward liquidity providers for taking the opposite side of trades, and this mechanism keeps markets running without order books.