# Smart Routing

Smart routing is a crucial mechanism being used by DerpDEX to optimise the process of swapping tokens for users. It involves dynamically determining the most efficient path for executing a trade across multiple liquidity sources while minimising slippage and maximising trading outcomes. When a user initiate a token swap, DerpDEX checks if the token pool is available and there is sufficient liquidity to the pool. If the liquidity for the token pool is available, the swap analysis like price impact, fee and slippage to the user.

If no liquidity is found for the tokens, the combined multiple pools will be used to execute swap. Swap through multiple route won't affect the trade and routing is done by DerpDEX in the background. Instead by using router contract, DerpDEX will find the most efficient path using all the existing pools.

The smart routing optimises trading routes, splits orders if necessary, and considers gas costs. If no liquidity found, we will use 1inch DEX aggregator to find the routes from other protocols (DEX) on ZkSync Era at the end. This ensures that DerpDEX will work as expected even if it runs lows on liquidity.

Below is the flow stating how tokens are swapped from more than one pool to provide the required token to the user.

<figure><img src="/files/4NNMfNvbU4e8DupoDoyT" alt=""><figcaption><p>With CLAMM smart-router</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://derpdex.gitbook.io/home/protocol/swap/smart-routing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
