Token Swap
QsnDEX provides a market swap interface that routes trades across multiple liquidity pools to find the best available price for any supported token pair.
How Swaps Work
When a user initiates a swap, the router contract determines the optimal path between the input and output tokens. This path may traverse multiple pools with different fee tiers to minimize overall cost.
Supported Fee Tiers
| Fee Tier | Typical Use Case |
|---|---|
| 0.01% | Stablecoin pairs |
| 0.05% | Correlated assets |
| 0.30% | Standard pairs |
| 1.00% | Exotic or low-liquidity pairs |
Swap Flow
- Select tokens -- Choose the input token and desired output token.
- Get quote -- The frontend requests a quote from the API, which evaluates all possible routes (including multi-hop paths across fee tiers) and returns the best price.
- Approve token -- If the input token has not been approved for the Router contract, the user must submit an approval transaction first.
- Execute swap -- The swap transaction is sent to the Router contract, which executes the trade along the determined route.
Swap Settings
Slippage Tolerance
Slippage tolerance defines the maximum acceptable difference between the quoted price and the execution price. The interface provides default slippage options as well as a custom input field for advanced users.
If the actual price moves beyond the slippage tolerance before the transaction is mined, the swap will revert.
Transaction Deadline
Each swap includes a deadline timestamp. If the transaction is not mined before the deadline expires, it will revert rather than execute at a potentially stale price.
Multi-Hop Toggle
Multi-hop routing allows swaps to pass through intermediate tokens when a direct pair does not exist or when a multi-hop route offers a better price. This can be disabled to restrict swaps to direct pairs only.
Fee-on-Transfer Token Support
QsnDEX supports deflationary and fee-on-transfer tokens. These tokens deduct a fee on every transfer, meaning the amount received by the recipient is less than the amount sent. The swap logic measures actual received balances rather than relying on nominal transfer amounts, ensuring accurate output calculations.
Price Impact Warnings
For large trades that would move the pool price significantly, the interface displays a price impact warning. This helps users understand the cost of their trade relative to the current market price and avoid unexpectedly large slippage.
Swap Confirmation
Before executing a swap, users are presented with a confirmation modal that includes a full breakdown:
- Exchange rate -- The effective rate between input and output tokens.
- Swap fee -- The total fee paid across all pools in the route.
- Route -- The path the swap will take (e.g., TokenA -> WETH -> TokenB).
- Minimum received -- The minimum output amount after accounting for slippage tolerance.
ETH Handling
Native ETH is automatically wrapped to WETH when used as a swap input, and WETH is automatically unwrapped to ETH when it is the swap output. Users do not need to manually wrap or unwrap ETH.