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
u64nonceu32block-height deadline- Canonical token0 and token1 IDs
Before submission
- Resolve program IDs and asset type from the selected deployment registry.
- Read a revisioned protocol snapshot and current pool state.
- Confirm global, pool, token, and pair controls allow trading.
- Derive direction from canonical token order.
- Select a sufficient unspent input record.
- Simulate five tick crossings plus the bounded partial path.
- Set Q128.128 price limit, native base-unit minimum, and block-height deadline.
- Persist factor, confidential address, nonce, and recovery state.
- Obtain any wrapper records required by the selected asset path.
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
claim_swap_output together with the original factor, confidential address, and current signer freezelist proofs.