> For the complete documentation index, see [llms.txt](https://docs.enoxswap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.enoxswap.com/getting-started/how-it-works.md). Agents can also search and read this documentation through its [MCP server](https://docs.enoxswap.com/~gitbook/mcp).

# How it works

EnoxSwap is a **DEX aggregator**. Instead of choosing one exchange and hoping it has the best rate, you let Enox check all of them.

![Swap flow](https://1273857689-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9EGjsXxqcGhGQ6XWd4Uo%2Fuploads%2Fgit-blob-1eb7e0ca8019ef683b650d2b94a59f32d6865e12%2Fswap-flow.png?alt=media)

## The five steps

1. **Enter an amount.** Pick the token you pay with and the token you want.
2. **Quote every DEX.** The aggregator contract calls `getBestPrice` and asks each active router on the chain how many tokens it would pay out for your trade (after the protocol fee).
3. **Pick the winner.** The router that returns the most tokens is selected. You can also choose a specific router manually.
4. **Approve and swap.** If you are selling a token (not the native coin) you approve it once, then `swapTokens` executes the whole trade in one transaction.
5. **Receive your tokens.** The output goes straight to your wallet. The contract measures what actually arrived and reverts if it is below your minimum.

## Architecture

![EnoxSwap architecture](https://1273857689-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9EGjsXxqcGhGQ6XWd4Uo%2Fuploads%2Fgit-blob-07ea69726306dad34bd839d4dcf7d717070be571%2Farchitecture.png?alt=media)

The EnoxSwap contract is the single on-chain entry point. It:

* keeps a list of DEX routers (Uniswap V2 style) that the owner has added,
* quotes all active routers and chooses the best one,
* takes the protocol fee from the input amount,
* forwards the rest to the chosen router,
* checks the output against your `amountOutMin` (slippage protection),
* records fees and referral rewards in a ledger that recipients claim from later.

## Safety features built into the swap

| Feature                 | What it does                                                                                                                          |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| Slippage protection     | The swap reverts if the output is below `amountOutMin`.                                                                               |
| Deadline                | The swap reverts if it is not mined before your deadline (default 20 minutes in the app).                                             |
| Reentrancy guard        | State-changing functions use `nonReentrant`.                                                                                          |
| Fee-on-transfer support | Fees are calculated on the amount the contract actually receives, so taxed tokens work when you switch on the Fee-on-Transfer option. |
| Measured output         | Output is measured from balances, not trusted from router return values.                                                              |
| Non-custodial           | Tokens pass through the contract in the same transaction and are not kept.                                                            |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.enoxswap.com/getting-started/how-it-works.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
