An automated market maker is a smart contract pool that swaps tokens at a price set by a formula instead of an order book.
You meet one when a token swap draws from a liquidity pool: tokens deposited by other users supply the trade. Matcha swap can compare routes across AMM pools and split a trade between them to reduce price impact.
How Does an Automated Market Maker Set a Swap Price?
An automated market maker sets a swap price from the amounts of two tokens in its pool. Uniswap v2 uses the constant product formula, x × y = k: as one token leaves and the other enters, the product of their balances stays constant during the trade, before fees.
- Liquidity providers deposit a pair of tokens.
- The pool holds the tokens available for swaps.
- The formula determines how much a trader receives.
Send token A into the pool, and the contract releases token B at the amount the formula allows. Liquidity providers earn a share of the pool’s trading fee when traders use their deposits.
Say a pool holds 10 ETH and 20,000 USDC. Its starting ratio is 2,000 USDC per ETH. Buying one whole ETH removes ETH from the pool, so each successive portion costs more. To leave 9 ETH while keeping the product at 200,000, the pool needs about 22,222 USDC. The buyer adds about 2,222 USDC, before fees.
That is the average cost of the ETH bought, not the pool’s starting price. A smaller purchase moves the price less. A pool with more liquidity also moves less for the same purchase.
How Are Price Impact and Slippage Different?
Price impact is the change your own trade makes to a pool’s price. Slippage is the difference between the quoted output and what you receive when the trade executes. A quote can account for your trade moving the price along the curve.
In the 10 ETH pool, buying one ETH pushes the price up even if no one else trades. That is price impact. If another trader changes the pool’s balances before your transaction executes, you may receive less ETH than quoted. That difference is slippage.
An aggregator can spread a larger trade across pools, giving each pool a smaller order and potentially reducing price impact. Compare the final token amount after routing and fees, then set the minimum output you are willing to accept before swapping.