Skip to main content
swap consumes one dynamic input token record, moves value to public AMM custody, updates one pool, and writes a pending SwapOutput. A later claim_swap_output returns output and any original-input remainder as encrypted token records.

Inputs

  • Dynamic input token record
  • Private blinding factor
  • Public confidential address
  • Pool key and direction
  • Native base-unit input and minimum output
  • Q128.128 square-root-price limit
  • u64 nonce
  • u32 block-height deadline
  • Canonical token0 and token1 IDs
The factor is private. The confidential address, route, amounts, limit, nonce, deadline, and token IDs are public.

Before submission

  1. Resolve program IDs and asset type from the selected deployment registry.
  2. Read a revisioned protocol snapshot and current pool state.
  3. Confirm global, pool, token, and pair controls allow trading.
  4. Derive direction from canonical token order.
  5. Select a sufficient unspent input record.
  6. Simulate five tick crossings plus the bounded partial path.
  7. Set Q128.128 price limit, native base-unit minimum, and block-height deadline.
  8. Persist factor, confidential address, nonce, and recovery state.
  9. Obtain any wrapper records required by the selected asset path.
Use swap_from_wrapped in shield_swap_router.aleo when the input begins as an underlying wrapped-asset record.

Execution

The finalizer verifies controls, token order, price direction, deadline, confidential-address uniqueness, and router caller identity when applicable. It walks at most five initialized ticks. It then fills only to the nearer next tick or user limit. If fee-adjusted input is zero, execution returns all input without moving price or charging a fee. If input remains after another bounded partial result, the mapping preserves it for claim.

Pending output

Read the mapping only after the swap is accepted. Copy its exact values into claim_swap_output together with the original factor, confidential address, and current signer freezelist proofs.

Retry rules

Do not resubmit after an ambiguous response until transaction status and mapping state are known. A fresh nonce does not make duplicate economic execution safe.