Swap
- Category
- Decentralised Finance
- Level
- Foundation
Simple definition
Exchanging one token directly for another in a single on-chain action. There is no order to wait on: either the whole exchange happens or none of it does.
Professional definition
A trade executed against a pool or a routed set of pools, settled atomically in one transaction. The user specifies an exact input or an exact output, a minimum acceptable result, and a deadline; the contract either satisfies all three or reverts.
Technical definition
Atomic settlement is the defining property: there is no resting order, no partial fill in the order-book sense, and no post-trade obligation. A router may split the input across several pools and hops, so the realised rate is a composition of each pool's pricing function plus each hop's fee. Because the request sits in a public mempool first, its parameters are visible to anyone who can influence block order.
Academic definition
An atomic bilateral exchange of two fungible on-chain assets executed against algorithmic liquidity, parameterised by an exact input or output and a user-supplied acceptance bound.
Mechanism
Atomicity removes settlement risk and replaces it with ordering risk. Nothing can half-happen, so neither side needs to trust the other; but the transaction must be included in a block by someone who sees its contents first and chooses where it goes. That is why a swap needs an acceptance bound and a deadline, parameters an order-book trade has no use for.
In practice
- Who uses it
- Every user of an on-chain venue, routers and aggregators that build the transaction, and bots that rebalance positions between protocols.
- Why it matters
- It settles a trade and its custody transfer in one step, with no venue account, no withdrawal queue and no counterparty to default.
- Limitations
- The rate is only known within the acceptance bound, the network fee is paid even when the transaction reverts, and routing through several hops multiplies fees.
Common mistakes
- Approving an unlimited allowance to a router for a one-off swap.
- Swapping into a token whose contract blocks selling.
- Ignoring that a long deadline leaves a signed order usable later.
Examples
Changing money at a counter leaves two separate steps: hand over one currency, receive the other. A swap is both at once, so there is no moment at which one side has paid and the other has not.
A swap routed through two pools at 0.3 percent each pays about 0.6 percent in pool fees before any price impact. One hop at 0.3 percent with worse impact may still fill better than two cheap hops.
- route A: two hops, pool fee 0.3% each
- route B: one hop, pool fee 0.3%
- price impact: 0.2% on route A in total, 0.9% on route B
- route A total = 0.3% + 0.3% + 0.2% = 0.8%
- route B total = 0.3% + 0.9% = 1.2%
Network fees are excluded and rise with the number of hops, which can reverse the ranking for small orders.
Related terminology
- parent
- Decentralised Exchange
- related
- Decentralised Exchange Automated Market Maker Liquidity Pool Constant Product Formula Slippage Tolerance Swap Contract Gas Fee Mempool
Swap Contract
A swap contract in derivatives is an agreement to exchange cash flows over time. An on-chain swap is a single instantaneous exchange of two tokens.
Market Order
A market order walks a book and can fill in parts at several prices. A swap executes once against a curve, entirely or not at all.
Sources
IOSCO · description of on-chain trading and order routing
https://www.iosco.org/library/pubdocs/pdf/ioscopd754.pdf URL verified
BIS · section on decentralised trading mechanics
https://www.bis.org/publ/othp72.pdf URL verified
Ethereum Foundation · entries on transactions and atomicity
https://ethereum.org/glossary/ URL verified
Editorial status
Flagged by the editor as uncertain on a linguistic, mathematical or regulatory point.
