Mera
ExecutionInstant confidential swapsClear from encrypted balances in one 150ms slot.Hidden-size limit ordersLock encrypted size in a private escrow PDA.Sealed RFQ block tradesRequest signed quotes without leaking size.
Vault & AuditShielded vault & keysDeposit SOL, SPL, or Token-2022 into a Ring.Viewing key verifierDecrypt and prove a single settled fill.
Docs/Guides
3 min read

Instant Confidential Swaps

Quote, sign, and settle single-slot confidential swaps from a shielded balance in /trade or via @mera/sdk.

An instant confidential swap converts one shielded asset into another inside the active Ring in a single Solana transaction (settle_confidential_swap). Neither your input size nor your post-trade balance appears in plaintext on the public ledger.

Prerequisites

  • A connected Solana wallet (or MeraSigner in Node.js) with access to the target Ring.
  • At least one unspent CommitmentNote in the input mint covering your swap size. If your shielded balance is zero, deposit first in Shielding Assets.

Executing a swap in /trade

  1. Open Terminal and confirm your active Ring in the top bar.
  2. Select the Swap tab and pick a pair (SOL / USDC, wBTC / USDC, wETH / USDC, or JitoSOL / SOL) and side (sell base for quote, or buy base with quote).
  3. Enter your input amount. Mera calls POST /v1/swap/quote and returns a sealed quote valid for 25 seconds, showing executionPrice, outputAmount, minOutputAmount (bounded by slippageBps, default 50 bps), feeAmount (0.10% default), and the expiry countdown.
  4. Press Execute Swap before the countdown expires. Mera calls POST /v1/swap/build to assemble the unsigned v0 transaction, your wallet signs first as taker and fee payer, and POST /v1/transactions/submit attaches the maker co-signature and relays the transaction.
  5. Once confirmed, the terminal displays the settlement status, measured finality in milliseconds, updated shielded balances, and a Copy TVK button in the recent fills table.

Executing a swap with @mera/sdk

mera.executeSwap runs quoteSwap, buildSwap, signs the v0 transaction with your signer, and submits it in one call:

ts
import { createMeraClient, keypairSigner } from '@mera/sdk'

const mera = createMeraClient({
  apiUrl: 'http://127.0.0.1:36102',
  signer: keypairSigner(myKeypair),
})

const { quote, submission } = await mera.executeSwap({
  ringId: 'ring-default',
  pairId: 'SOL-USDC',
  side: 'sell',
  inputAmount: '2000000000', // 2 SOL (9 decimals)
  slippageBps: 50,           // 0.50% max slippage (1..500)
})

console.log('Quote ID:', quote.quoteId)
console.log('Net output (base units):', quote.outputAmount)
console.log('Protocol fee (base units):', quote.feeAmount, `(${quote.feeBps} bps)`)
console.log('Signature:', submission.signature)
console.log('Slot:', submission.slot, 'Finality:', submission.finalityMs, 'ms')
console.log('TVK:', submission.tvk)

If you want to inspect the quote before signing, call mera.api.quoteSwap(...), verify quote.executionPrice and quote.minOutputAmount, then call mera.api.buildSwap({ wallet, quoteId: quote.quoteId }) and submit the signed transaction via mera.api.submitTransaction(...).

Fee and output math

  • grossOutput is computed from inputAmount and executionPrice.
  • feeAmount = floor(grossOutput * feeBps / 10_000) is transferred on chain from the Ring's output ShieldedVault to ProtocolConfig.fee_recipient (Token & Fee Flow).
  • outputAmount = grossOutput - feeAmount is credited to your new output CommitmentNote PDA.
  • minOutputAmount = outputAmount - floor(outputAmount * slippageBps / 10_000).

Handling errors

CodeHTTPCause and action
QUOTE_EXPIRED409More than 25 seconds elapsed between quote and build, or the quote was already used. Request a fresh quote.
INSUFFICIENT_SHIELDED_BALANCE400No single unspent CommitmentNote in the Ring covers inputAmount. Shield more tokens in /balance.
PAIR_NOT_SUPPORTED400pairId is not in the active pairs list (GET /v1/pairs).
RING_ACCESS_DENIED / RING_FROZEN403Wallet is not allowlisted in this Custom Ring, or the Ring or member is frozen.
UPSTREAM_UNAVAILABLE502Maker shielded output inventory is temporarily below the requested size. Retry shortly or reduce size.