> For the complete documentation index, see [llms.txt](https://hinkal-team.gitbook.io/hinkal/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hinkal-team.gitbook.io/hinkal/technical-description/transactions/swaps.md).

# Swaps

Hinkal Swaps allow users to swap ERC-20 tokens discreetly. To achieve this functionality, Hinkal uses relayers and APIs from [Odos](https://odos.xyz/), [Uniswap](https://uniswap.org/), and [1inch](https://1inch.io/) (more to be added in the future).

When a user wants to swap assets, they generate a zk-proof that they are eligible to swap a given amount of the first asset in return for the incoming amount of the second asset. From the viewpoint of outsiders, the swap transaction will be submitted from the relayer's public Ethereum address to Hinkal Pool smart contract.

In the transaction, Hinkal Pool will call [Odos](https://odos.xyz/), [Uniswap](https://uniswap.org/) or [1inch](https://1inch.io/)’s Smart Contract in order to swap the assets. If, for any reason, the swap fails, then the whole transaction will be reverted, so no additional commitments and nullifiers will be created.

Since the protocol implements UTXO-based model of commitments and nullifiers, the swapped amount should be known at the time of zk-proof generation. At the time of the swap transaction submission, it is unknown how many other swap transactions will be submitted in the current block.

This factor generates unpredictable slippage from the viewpoint of the user and relayer. Slippage is relative to the transaction value, whereas gas fees are not. For example, paying $1 out of $10 in gas fees amounts to 10%, but paying $1 out of $1000 is only 0.1%.\
\
Check out Hinkal's current [fee structure](broken://pages/sgX0WvO2Y3IRFQ3g6rKh) used to fairly compensate for the costs.

To tackle the following risks:

* slippage
* gas costs
* smart-contract parameter change affecting payoffs (e.g. CRV emission rate)

the Unexpected Payoffs are compensated to the user using [<mark style="color:purple;">**stealth addresses**</mark>](https://github.com/Hinkal-Protocol/Hinkal-Protocol/blob/gitdocs/docs/technical-description/smart-contracts/unexpected-relay-costs-accounting-stealth-addresses.md) generated before the transaction is submitted.

Important to mention, relayers do not have custody of the swapped assets.

The swapping process in Hinkal is similar to deposits and withdrawals but with a few notable differences. Instead of using the `SwapperM1x2x1.circom` circuit, users initiate the `SwapperM` circuit, which handles multiple tokens. Additionally, rather than calling the `_internalTransact()` function, the protocol calls `_internalRunExternalAction()`. This forwards the swap operation to `ExternalActionSwap:runAction()`. This function performs the token swap and returns the output UTXOs, which cannot be calculated off-chain due to the real-time fluctuations in token prices.

Once the UTXOs are generated, the corresponding output commitments are created on-chain and added to Hinkal’s Merkle tree. Unlike deposits and withdrawals, where output commitments are generated off-chain as part of the ZKP process, swap-related commitments are computed directly on-chain after the swap has been completed.


---

# 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 dynamically by asking a question.

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

```
GET https://hinkal-team.gitbook.io/hinkal/technical-description/transactions/swaps.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
