Skip to content

Private swap ​

Alice holds a SOL note and wants VEILIX. She could withdraw, trade in public, and deposit again, but that puts a public address on both sides of the trade. A private swap does it inside the pool instead. It spends her SOL note, trades on an exchange pool, and adds a new VEILIX note to the VEILIX tree. Nothing goes to a public address. The trade is public. Whose trade it is, is not.

One swap, step by step ​

  1. Quote. Her client asks a relayer for a swap quote. The quote gives the fee, the amount that will be sold, and the expected amount bought. The client then reads the exchange pool from the chain and prices the trade itself. A relayer cannot understate the expected output to lower her minimum. The client also checks that the relayer’s fee matches the published rates.
  2. Limit. She sets a slippage limit, 1% unless she changes it. Her minimum output is the expected output less that limit. The client refuses a trade whose price impact is above 10%: one that would get more than 10% less than the pool’s current price. A pool that thin gives a bad rate, so the app offers a smaller amount instead.
  3. Prove. Her client proves the spend with the same circuit as a withdrawal. The proof binds the pair, the amount, the fee, the minimum output, and a one-time public key and blinding for the new note.
  4. Trade. A relayer submits the swap. Inside one instruction, the program moves the input from the treasury to an escrow account, calls the exchange, takes the output back, and moves it into the other asset’s treasury. The exchange call is signed only by the escrow, which holds nothing but this swap’s input. If the output is below her minimum, the whole transaction reverts and nothing is spent.
  5. New note. The program completes the new note on chain from the real output: Poseidon(amount out, one-time public key, blinding, mint). Alice keeps the whole output, even when it beats the quote. The new note is sealed for her wallet like a deposit, so a scan finds it again. If she swapped only part of the SOL note, the rest comes back as a change note in the SOL tree.

The one-time public key is visible on chain. Spending the new note needs its private key, which only Alice’s device has, so the later spend is as unlinkable as any other.

What is live on devnet ​

The swap configuration allows one exchange program, Raydium’s CPMM (DRaycpLY18LhpbydsBWbVJtxpNv9oXPgjRSfpF2bWpYb). The live relayer trades one pair, SOL and VEILIX, through the pool 4bx7EaVuGesCyhEvaVj3WrweZiLMYwSs1KJWC8quKVgu. Both directions work. Another pair needs a pool on an allowed exchange and a relayer that lists it.

What it costs ​

The fee comes out of the input, in the input asset, before the trade. It is the same three parts as a withdrawal: the 0.15% protocol fee, the relayer’s rate of at most 0.1%, and a network fee for the SOL the relayer spends. The program applies the same cap. The exchange pool also charges its own trading fee, which is inside the price. The quote shows all of it before she confirms.

What stays public ​

Everyone can see that a swap happened, both amounts, the pool, the fee, and the time. Nobody can see which note paid for it or who holds the new note. The new note joins the other asset’s tree, so a later withdrawal of it hides among that tree’s notes. Nothing leaves to an outside address, so there is no recipient to check.

A swap trades on a public pool, so the usual trading risks apply. The price can move between the quote and the trade, a thin pool gives a poor rate, and a large trade moves the price against itself. The slippage limit caps the damage. It does not guarantee a good price.

The next page is the other way to spend a note without a Solana withdrawal: sending it to another chain.