Swaps
Last modified:
Introduction
A swap is the most common interaction with the protocol. The user selects an ERC-20 token to sell and a token to buy; the smart contract computes an output amount — minus a fee that accrues to liquidity providers — and settles both transfers atomically. No approval from a counterparty is required.
Note: Web interfaces may impose additional permission structures or routing behaviour that differs from interacting with the contracts directly. See CenturionDEX Overview for details.
Unlike an order-book exchange, swaps do not fill against discrete limit orders. Instead, they execute against a passive pool of liquidity. The pool's reserves shift with every trade, causing a continuous price adjustment rather than a step function across distinct orders.
Price Impact
On a traditional order book, a large market-buy may exhaust the cheapest limit-sell and spill into a higher one, producing a blended execution price. AMM pools exhibit an analogous effect: because the constant product formula ties the price to the reserve ratio, each unit of input moves the price further against the trader. The execution price therefore always trails the pre-trade spot price.
The magnitude of this divergence depends on how much liquidity is concentrated around the current price. Deeper liquidity at a given price point means smaller impact for the same trade size; thinner liquidity means larger impact.
Calculating price impact
For a constant-product pool with reserves x (input token) and y (output token), selling Δx returns:
Δy = y * Δx / (x + Δx)The effective execution price is Δy / Δx, while the spot price before the trade is y / x. Price impact is:
price_impact = 1 - (effective_price / spot_price)
= 1 - (x / (x + Δx))
= Δx / (x + Δx)Example: A pool holds 100 CTN and 200,000 USDC. You sell 10 CTN.
- Spot price: 200,000 / 100 = 2,000 USDC/CTN
- Output: 200,000 × 10 / (100 + 10) = 18,181.8 USDC
- Effective price: 18,181.8 / 10 = 1,818.18 USDC/CTN
- Price impact: 1 − (1,818.18 / 2,000) = 9.09 %
In v3 pools, concentrated liquidity means impact depends on how capital is distributed across ticks. Pools with deep liquidity around the current price absorb larger trades with less slippage.
The interface estimates price impact in real time and displays a warning when the figure is unusually high.1
Slippage
Even after accounting for price impact, the execution environment can shift while a transaction is pending in the mempool. Other swaps may land first, altering the reserve ratio before your transaction executes.
Slippage tolerance defines the acceptable margin of deviation. If the final output falls outside this band — say, beyond 1 % of the quoted amount — the transaction reverts and no tokens change hands. This protects against unpredictable price movement between submission and execution.
Safety checks
The protocol includes two primary on-chain safeguards against adverse execution:
-
Deadline — each swap carries a timestamp after which it automatically reverts, preventing stale transactions from executing at outdated prices after an unusually long pending period.
-
INSUFFICIENT_OUTPUT_AMOUNT— if the realised output is less than the minimum acceptable amount (derived from the quoted output minus the slippage tolerance), the transaction reverts. This caps the trader's worst-case loss at the chosen tolerance.
Footnotes
-
The interface provides informational estimates; they are not guaranteed. ↩