> For the complete documentation index, see [llms.txt](https://zaiffer.gitbook.io/wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zaiffer.gitbook.io/wiki/zaiffer/confidential-swap.md).

# Confidential SWAP

The `SwapV0` contract enables you to swap one confidential token for another automatically while maintaining privacy. Without the swap contract, exchanging cUSDC for cDAI would require:

1. **Unshield**: Convert cUSDC → USDC (unwrap with public decryption)
2. **Swap**: Trade USDC → DAI on Uniswap
3. **Shield**: Convert DAI → cDAI (wrap back to confidential)

This exposes your swap amount publicly during step 1, requires multiple transactions, and forces you to handle decryption manually.

Once the user has configured the slippage tolerance and SWAP deadline, the `SwapV0` contract automates all three steps in a single unshield action (two transactions: initialise, finalise unshield).

This guide assumes you're familiar with confidential tokens and the [Shield](/wiki/zaiffer/shielding-tokens-wrapping.md) and [Unshield](/wiki/zaiffer/unshielding-tokens-unwrapping.md) processes.

## How Swaps Work <a href="#how-swaps-work" id="how-swaps-work"></a>

When you initiate a swap, the contract performs three operations automatically:

1. **Unshield**: Your confidential tokens (e.g., cUSDC) are burned, and the underlying tokens (USDC) are decrypted and withdrawn from the wrapper contract
2. **Swap**: The unwrapped tokens are traded on **Uniswap V2** for the destination token (e.g., USDC → DAI) using the routing path you specify
3. **Shield**: The output tokens (DAI) are automatically wrapped back into confidential tokens (cDAI) and sent to your specified recipient address

All of this happens within a single user transaction. From your perspective, you send cTokenA and receive cTokenB; all the intermediate steps are handled automatically.

<div data-with-frame="true"><figure><img src="/files/VOuIZU08HWU9vrNdkAKt" alt=""><figcaption></figcaption></figure></div>

## Atomic Safety and Automatic Refunds <a href="#atomic-safety-and-automatic-refunds" id="atomic-safety-and-automatic-refunds"></a>

While executing the swap, the `SwapV0` contract validates the path to ensure the swap can succeed. The contract checks that:

* Wrappers exist for both input and output tokens
* The Uniswap path has liquidity
* The path configuration is valid

If any validation fails, you receive an automatic refund by Shielding the Unshielded tokens back into your original confidential token. You only lose the Shield and Unshield fees---your principal is returned to you as cTokens.

This automatic refund mechanism protects you from failed swaps while maintaining the convenience of a single transaction.

The swap contract charges only the standard Shield and Unshield fees. Those are the same fees you would pay if you performed the three steps manually. There are no additional swap-specific fees. The convenience of automation comes at no extra charge.


---

# 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://zaiffer.gitbook.io/wiki/zaiffer/confidential-swap.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.
