Token Swap
A token swap is the exchange of one cryptocurrency for another, executed either on a centralized exchange or through a DeFi protocol.
Key Takeaways
- A token swap exchanges one cryptocurrency for another, either through a centralized exchange's order book or via a decentralized exchange (DEX) that uses automated market makers or on-chain order books.
- DEX-based swaps execute through smart contracts and liquidity pools, settling atomically on-chain: the trade either fully completes or fully reverts in a single transaction.
- Swap aggregators like 1inch and Jupiter route trades across multiple DEXs to find the best price, while newer intent-based systems let solvers compete to fill orders off-chain before settling on-chain.
What Is a Token Swap?
A token swap is the exchange of one cryptocurrency token for another. At its simplest, a user sends token A into a trading venue and receives token B in return at the prevailing market rate. This is the most fundamental operation in crypto trading and the backbone of decentralized finance (DeFi).
Token swaps can happen in two contexts. On a centralized exchange (CEX) like Coinbase or Binance, the exchange matches buyers and sellers using internal order books and settles trades on its own ledger. On a DEX, the swap executes through a smart contract on a public blockchain, with no intermediary holding funds at any point. DEX swaps are trustless, permissionless, and transparent: anyone can verify the trade on-chain.
DEX trading volume has grown significantly, with monthly spot volume reaching $231 billion in January 2026 and DEX-to-CEX market share climbing above 14%. This growth reflects a broader shift toward self-custodial trading, where users retain control of their assets throughout the swap process.
How It Works
The mechanics of a token swap differ depending on whether the venue uses an automated market maker or an order book. Both models achieve the same result (exchanging one token for another) but price discovery works differently.
AMM-Based Swaps
Most DEX volume flows through automated market makers. Instead of matching individual buyers and sellers, AMMs use liquidity pools: smart contracts holding reserves of two (or more) tokens. Anyone can deposit tokens into a pool to become a liquidity provider (LP) and earn a share of trading fees.
The price of a swap is determined algorithmically by the constant product formula. For a pool containing reserves of token X and token Y:
x * y = k
where:
x = reserve of token X
y = reserve of token Y
k = constant (product of reserves)
spot price of X in terms of Y = y / xWhen a trader buys token X from the pool, the reserve of X decreases and the reserve of Y increases (the trader deposits Y). The constant k must remain unchanged, so the price shifts with every trade. Larger trades move the price more, which is why slippage increases with trade size relative to pool depth.
Uniswap v2 pioneered this model with a flat 0.3% fee per swap distributed to LPs. Uniswap v3 introduced concentrated liquidity, letting LPs allocate capital within specific price ranges for up to 4,000x capital efficiency. Uniswap v4, launched on Ethereum mainnet in January 2026, introduced a singleton contract architecture (all pools in one contract) and a hooks system for attaching custom logic to pools.
Order Book DEX Swaps
Order book DEXs work more like traditional exchanges. Market makers post limit orders (bids and asks), and incoming swap orders match against resting orders at their posted prices. This model offers tighter spreads and lower slippage for large trades when the book is deep, but requires active market makers to provide liquidity.
| Aspect | AMM | Order Book |
|---|---|---|
| Price discovery | Algorithmic (reserve ratio) | Market-driven (bids and asks) |
| Liquidity source | Passive LPs in pools | Active market makers |
| Slippage on large trades | Higher | Lower with deep books |
| Order types | Simple swaps | Limit, stop-loss, market |
| Best for | Casual swaps, long-tail tokens | Active traders, large volumes |
The Swap Lifecycle
A typical DEX swap follows five steps from quote to settlement:
- Price quote: the DEX frontend queries the smart contract to calculate the expected output amount based on current pool reserves and fees
- Slippage tolerance: the user sets a maximum acceptable price deviation (typically 0.5% for major pairs, 1-2% for low-liquidity tokens). If the price moves beyond this threshold during execution, the transaction reverts
- Token approval: for ERC-20 tokens, the user must call
approve()on the token contract, granting the DEX router permission to spend their tokens. This is a separate on-chain transaction. Best practice is to approve only the exact amount needed rather than unlimited allowances, which create security risk if the contract is compromised - Execution: the user signs and submits the swap transaction, which enters the mempool and awaits block inclusion
- Settlement: once included in a block, the smart contract atomically transfers both tokens in a single transaction. The input token moves from the user to the pool, and the output token moves from the pool to the user
// Simplified Uniswap v2 swap interface
function swapExactTokensForTokens(
uint amountIn, // tokens the user sends
uint amountOutMin, // minimum acceptable output (slippage protection)
address[] path, // routing path (e.g., [USDC, WETH, DAI])
address to, // recipient address
uint deadline // transaction expiry timestamp
) external returns (uint[] amounts);Swap Aggregators
A single DEX pool may not offer the best price for a given trade. Swap aggregators solve this by scanning every reachable liquidity source on a chain, splitting an order across the optimal combination of pools, and delivering the best net output after gas costs.
The aggregator's pathfinding algorithm considers direct routes (single pool), multi-hop routes (token A to token B to token C), and split routes (sending portions of the trade to different pools simultaneously). Gas costs are factored in: a slightly better price on a secondary DEX may not be worth the extra gas of a multi-hop route.
Major aggregators include:
- 1inch: dominant on EVM chains with roughly 59% of Ethereum aggregator volume. Its Fusion mode uses intent-based Dutch auctions for gasless execution
- Jupiter: handles approximately 95% of Solana aggregator volume, with deep integration across Solana's DEX ecosystem including Raydium and Orca
- CoW Swap: uses batch auctions that match coincidences of wants (opposing trades that cancel out), saving fees when two users want opposite swaps in the same block
Atomic Swaps
While standard token swaps happen within a single blockchain, atomic swaps enable trustless exchange across two separate blockchains using Hash Time-Locked Contracts (HTLCs). The term "atomic" means indivisible: the swap either completes for both parties or neither.
- Alice generates a random secret, computes its hash, and creates a Bitcoin HTLC locking her BTC with two spending paths: Bob can claim with the secret, or Alice can reclaim after a 48-hour timelock
- Alice shares the hash (not the secret) with Bob
- Bob verifies Alice's locked BTC on-chain, then creates an Ethereum HTLC locking his ETH with the same hash but a shorter timelock (24 hours)
- Alice claims Bob's ETH by revealing the secret on Ethereum
- Bob observes the revealed secret on-chain and uses it to claim Alice's BTC on Bitcoin
The asymmetric timelocks ensure safety: Alice's longer timeout prevents her from claiming Bob's ETH and also reclaiming her own BTC. If either party fails to act, funds are refunded automatically. Atomic swaps require multiple on-chain transactions and compatible hash functions on both chains, making them slower than single-chain DEX swaps but fully trustless across chains.
Use Cases
- Portfolio rebalancing: traders swap between tokens to adjust allocations without withdrawing to a centralized exchange, maintaining self-custody throughout
- Yield strategy entry: swapping into LP tokens, staking tokens, or yield-bearing assets as part of a yield farming strategy
- Stablecoin conversion: swapping between different stablecoins (USDC to DAI, for example) to access specific DeFi protocols or take advantage of yield differentials
- Cross-chain asset movement: using atomic swaps or cross-chain aggregators to move value between blockchains without relying on a bridge
- Dollar-cost averaging: executing periodic swaps via on-chain automation to build a position over time without manual intervention
Why It Matters
Token swaps are the foundational primitive of decentralized finance. Every DeFi activity, from providing liquidity to entering a leveraged position, begins with a swap. The ability to exchange assets without an intermediary is what makes permissionless finance possible.
For Bitcoin users, the evolution of swap infrastructure is particularly relevant. Layer 2 protocols like Spark enable fast, low-cost transfers of Bitcoin and stablecoins, creating new opportunities for swap functionality on Bitcoin's security model. As intent-based trading matures and cross-chain aggregation improves, the user experience of token swaps continues to converge toward traditional exchange simplicity while preserving the trustless guarantees of decentralized settlement.
For a deeper look at how decentralized exchange infrastructure is evolving on Bitcoin, see the BtcFi landscape overview and the guide to Bitcoin on/off-ramps.
Risks and Considerations
Slippage and Price Impact
Slippage is the difference between the expected and actual execution price. It arises from two sources: the mathematical price impact of trading against a finite pool (inherent to the constant product formula), and market movement during the delay between transaction submission and block inclusion. Larger trades in shallower pools experience worse slippage. Setting slippage tolerance too high exposes the trader to unfavorable fills; setting it too low causes transactions to revert frequently.
Impermanent Loss
Liquidity providers face impermanent loss when the price ratio of pooled tokens diverges from the ratio at deposit time. For a standard 50/50 pool, a 2x price change results in approximately 5.7% loss compared to simply holding the tokens, and a 5x change results in roughly 25.5% loss. Trading fees earned may partially offset this, but the loss is often permanent if the price does not revert before withdrawal.
Front-Running and MEV
When a swap transaction sits in the public mempool awaiting block inclusion, it is visible to bots that extract maximal extractable value (MEV). Sandwich attacks are the most common form: a bot front-runs the victim's trade (buying before them to push the price up), then back-runs it (selling after at the inflated price). Studies estimate that roughly 1.2% of Ethereum DEX trades are sandwiched, with total MEV extraction exceeding $550 million annually on Ethereum. Private transaction submission and intent-based systems like UniswapX and CoW Swap help mitigate this by routing orders off the public mempool.
Smart Contract Risk
Every DEX swap interacts with smart contracts that may contain bugs, exploits, or malicious code. Token approval vulnerabilities are a specific concern: granting unlimited ERC-20 allowances to a DEX router means a compromised or malicious contract could drain all approved tokens. Using a smart contract audit as a baseline check and approving only exact amounts reduces this risk.
This glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.