# Swaps

The core functionality of Ambient is to allow users to exchange one type of token for another at fair market price&#x73;*.* If liquidity exists for a given pair in the DEX contract, then users will be able to swap between tokens. The frontend web app provides an interface for general-purpose swaps.

![](/files/sE2ZzjaPbzGFjk0V3IcS)

If adequate liquidity exists in a given for the pair, a swap will most likely be executed as a *single hop*. Single hops incur lower liquidity and gas fees, so are preferred. A *multihop swap* is when swaps across multiple pools are chained, usually in the case when there's little to no liquidity in any pair between the input and output token. The on-chain contracts take a pre-determined path. Finding a cost efficient price multihop path, or *routing*. Ambient provides an off-chain API for approximately optimal routing, but alternative clients are free to implement their own routing algorithms based on publicly available on-chain data.&#x20;

The *intermediate tokens* in a multihop swap are those tokens in the middle of the path that are only temporarily held when swapping through a sequence of pairs. Unlike in other AMMs, intermediate tokens in Ambient are never transferred because settlement occurs based on the net debit agains the entire DEX protocol. This reduces both the amount of gas from unnecessary token transfers, as well as taxable/capital events on the intermediate tokens.

In addition to the input and output tokens, the user defines the following parameters on a per swap basis (with sensible defaults chosen by the front-end app):

* Quantity to swap. This either be a fixed input quantity or fixed output quantity.
* Slippage. The minimum possible output tokens or maximum possible input tokens the user is willing to accept. Past this point the swap transaction will revert.
* Settlement. Swaps can either be settled directly with ERC20 tokens or to/from the user's surplus collateral balance at the DEX. A user can mix-and-match, i.e. pay input as ERC20 token transfer and receive output as surplus collateral.&#x20;


---

# 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://docs.ambient.finance/users/swaps.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.
