To view keyboard shortcuts, press question mark
View keyboard shortcuts
What an AMM Actually Does Behind a DEX Swap
Khalifa Bagan
@Khalifabagan
·
5h
Most people see a swap button.
They choose a token, enter an amount, check the estimated output, and confirm the transaction.
What they do not always see is the market mechanism working underneath that simple interface.
That mechanism is the Automated Market Maker, or AMM.
Why DEXs need a different market structure
Traditional exchanges commonly use order books.
A buyer places an order.
A seller places an order.
The exchange matches those orders.
A decentralized exchange can work differently.
Instead of depending on a central order book, an AMM uses liquidity pools and smart contracts to make assets available for trading.
STON.fi is built around this model as a non custodial AMM protocol on TON. Users can connect their wallets and swap through smart contracts without transferring their funds to a central custodian.
The difference is not simply where the exchange operates.
It is how liquidity is organized.
The liquidity pool is the market
Think of a liquidity pool as a smart contract holding two assets.
For example, a pool could contain Token A and Token B.
When a user swaps Token A for Token B, the quantities of both assets inside the pool change.
That changes the ratio between them.
And when the ratio changes, the price changes.
This is the core idea behind automated market making.
There is no need for another individual trader to be waiting on the opposite side of your transaction.
The liquidity is already there.
The formula behind the classic model
The classic constant product AMM can be represented as:
x × y = k
Here, x represents the quantity of one token in the pool.
y represents the quantity of the other token.
k represents the pool's constant.
When a swap happens, the quantities change while the mechanism maintains the relationship.
The formula is useful, but the bigger idea is more important.
The pool itself provides the liquidity against which users trade.
That is what allows decentralized markets to function without a traditional order book.
Why liquidity depth matters
This is where AMMs connect directly to something every trader should understand: price impact.
Imagine a small liquidity pool.
A relatively large trade enters that pool and removes a significant amount of one asset.
The balance changes substantially.
The pool price moves.
Now imagine the same trade happening against a much deeper pool.
The same transaction represents a smaller percentage of the available liquidity, so the pool can generally absorb it with less movement in price.
This is why a token's displayed price does not tell the entire story.
Liquidity matters.
A market can show an attractive price while still having insufficient depth for a large transaction.
Not every liquidity pool works the same way
Another important point is that AMMs are not limited to one pool design.
STON.fi currently supports several pool types, including Constant Product, Weighted, Stable, and WStable pools.
Constant Product pools are the classic model for general token pairs.
Stable pools are designed for assets that are expected to trade at similar prices, such as stablecoins or wrapped versions of the same asset.
Weighted pools allow custom weights between assets.
WStable combines the stable curve approach with custom weights.
The reason this matters is simple.
Different assets behave differently.
A pair of volatile assets does not necessarily need the same pricing curve as two assets designed to remain close in value.
The pool design can therefore influence how liquidity behaves during swaps.
Where liquidity providers fit in
AMMs also create another important role in the market.
Liquidity providers supply assets to the pools.
In return, they receive a share of the pool and can earn a portion of swap fees generated by activity in that pool. STON.fi documentation explains that LP positions accrue fees as users trade through the pool.
This creates a simple relationship.
Traders need liquidity.
Liquidity providers supply liquidity.
The AMM provides the mechanism connecting the two.
The bigger picture
An AMM is therefore much more than a formula.
It is a different way of organizing a market.
Instead of relying entirely on an order book and a centralized matching engine, liquidity can be placed into pools and accessed directly through smart contracts.
Once you understand that, several other DeFi concepts become easier to understand.
Liquidity.
Price impact.
Slippage.
Liquidity provision.
Swap fees.
Impermanent loss.
They are not isolated concepts.
They are connected to the way the underlying market mechanism works.
The next time you press Swap on a DEX, remember that the interface is only showing you the final step.
Behind that button is a liquidity pool.
Behind the pool is a pricing mechanism.
And behind that mechanism is the architecture that makes decentralized trading possible.
@ston_fi
