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:
Unshield: Convert cUSDC → USDC (unwrap with public decryption)
Swap: Trade USDC → DAI on Uniswap
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 and Unshield processes.
How Swaps Work
When you initiate a swap, the contract performs three operations automatically:
Unshield: Your confidential tokens (e.g., cUSDC) are burned, and the underlying tokens (USDC) are decrypted and withdrawn from the wrapper contract
Swap: The unwrapped tokens are traded on Uniswap V2 for the destination token (e.g., USDC → DAI) using the routing path you specify
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.

Atomic Safety and Automatic Refunds
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.
Last updated