Ada · TOK
Run A: waiting
Run B: waiting
Learn · decentralised finance
A pool changes after each trade. A swap arriving next meets the reserves left by the trade before it.
Start with Uniswap V2: pools, swaps and LP returns if liquidity pools are new to you. This lesson uses fictional tokens and moves no funds.
An automated market maker (AMM) holds two token reserves. Buying TOK adds USDx to the pool and removes TOK. Another TOK buyer then gets fewer tokens for the same input. A TOK seller moves the reserves the other way.
Price impact is the change caused by your own trade. Slippage compares the execution with the quote you saw earlier. Other trades can move that execution in your favour or against you. Your quote already includes your trade’s price impact.
For an exact-input swap, a minimum output sets a floor on how much you receive. If the available output is smaller, the transaction reverts: its pool changes are undone. This protects the output floor; it does not guarantee execution or remove gas costs.
First execute both default queues. Ada receives TOK in run A, but her swap reverts in run B after Ben’s larger purchase. Then move Cy’s sale to the front of run B. Predict whether Ada’s available output rises or falls before you execute it.
Both runs start at 100 TOK and 100,000 USDx. These are fictional tokens. Each swap pays 0.30% of its input into the pool. No gas, external markets, token rounding or real assets are modelled; values below are rounded to six decimals.
Move a trader earlier or later, then execute one transaction at a time. Changing a queue resets that run. Quotes and minimums were fixed before either run.
Current pool reserves
100 TOK
100,000 USDx
Input: 1,000 USDx
Minimum received: 0.97 TOK
Original quote: 0.987158 TOK
Waiting to execute
Input: 5,000 USDx
Minimum received: 4.4 TOK
Original quote: 4.748297 TOK
Waiting to execute
Input: 3 TOK
Minimum received: 2,800 USDx
Original quote: 2,904.137255 USDx
Waiting to execute
Current pool reserves
100 TOK
100,000 USDx
Input: 5,000 USDx
Minimum received: 4.4 TOK
Original quote: 4.748297 TOK
Waiting to execute
Input: 1,000 USDx
Minimum received: 0.97 TOK
Original quote: 0.987158 TOK
Waiting to execute
Input: 3 TOK
Minimum received: 2,800 USDx
Original quote: 2,904.137255 USDx
Waiting to execute
Compare the same trader across runs, not different output tokens. More tokens for the same input is a better execution, not proof of investment profit.
Run A: waiting
Run B: waiting
Run A: waiting
Run B: waiting
Run A: waiting
Run B: waiting
For each transaction, use the current input reserve x and output reserve y. Multiply the input by 0.997 to account for the 0.30% swap fee, then calculate the available output:
output = y × (input × 0.997) / (x + input × 0.997)
Compare that output with the trader’s fixed minimum. If it passes, add the full input to one reserve and subtract the output from the other. The fee remains in the pool, so the reserve product grows slightly. If it fails, leave both reserves unchanged and process the next transaction.
Sources: Uniswap V2 formula and swap fees. This model omits protocol-fee ownership, integer token units and routing across pools.
The lab gives you direct control of a queue. Real transaction ordering depends on the chain and its block-building process; sending first does not universally guarantee executing first. Changes can come from ordinary demand or deliberate ordering strategies.
A tighter minimum limits adverse execution but can cause more reverts. A looser minimum permits a worse output. Neither setting guarantees a profitable trade. The comparison above measures token execution only; gas, external prices and later sale proceeds would be needed to calculate profit.