Layers
Program execution
shield_swap.aleo contains the AMM state machine. User functions validate inputs and construct records or a Final. Finalizers execute token futures and update public mappings.
The program imports multisig, freezelist, and a pinned IARC20 interface. A field identifier selects the concrete token program at runtime. The core accepts calls from only the hardcoded swap-router and LP-router addresses when a router bypass is required.
Successful interface dispatch does not prove that a token is safe or operationally approved. Asset support depends on the deployed token program’s code, state, transfer behavior, and authority model.
Public state and record ownership
Mappings contain pools, slots, ticks, positions, pending swap outputs, configuration, and controls. They support quoting, indexing, and independent accounting. They also expose amounts, routes, ranges, liquidity, fees, timing, and control actions. Records carry a different kind of state:- token records carry spendable value
PositionNFTcarries position authority- investigator records carry encrypted mint or swap attribution
PositionNFT alone does not contain the position’s latest public economics. Clients must reconcile both.
Swap data flow
- The client reads current pool, tick, token, and control state.
- The client preflights a revisioned protocol snapshot and the wallet selects an input token record.
- The client selects direct
swap,swap_from_wrapped, orswap_mh_from_wrappedfrom the asset registry. - The program moves input value into public custody and updates AMM mappings.
- Finalization writes
swap_outputs[swap_id]. - The client reads that exact output and constructs a core or router claim with signer freezelist proofs.
- The program returns output and refund token records.
- The wallet stores the records and reconciles the final public state.
swap_outputs entry is an unsettled user obligation until claim removes it.
Position data flow
Mint creates both a public position and aPositionNFT that binds owner and immutable withdrawal address. Mint, collect, and claim require current non-inclusion proofs. Increase, decrease, and collect consume the current ownership record and return a replacement. Burn removes the public row and consumes the final ownership record.
Custody systems must update record inventory only after transaction acceptance is known.
Production client boundary
The TypeScript harness demonstrates mapping reads, parsing, record handling, submission, and persistence. It is test-oriented. A production client still needs:- a quote engine that matches contract rounding and iteration caps
- a record store with reserved, spent, and unknown states
- a pending-claim queue
- deployment-versioned parsers
- a chain indexer or API client
- bounded retry and finality handling
- durable reconciliation and monitoring