Skip to main content

Module pswap

Module pswap 

Source
Expand description

Re-export the entire miden_client crate so external projects can use a single dependency. PSWAP chain tracking — follows partial-swap orders across fills so the creator can always see the current tip and reclaim the unfilled balance.

Flow:

  1. Create → persist a PswapLineageRecord + asset-pair tag subscription.
  2. Sync → PswapChainObserver collects PSWAP-attachment notes; discovery::discover_pswap_rounds correlates them with tracked-note consumption events and emits one PswapLineageRoundUpdate per round.
  3. Reclaim → Client::build_pswap_cancel_by_order.

Protocol invariants (≤1 payback + ≤1 remainder per round, attachment word layout, deterministic reconstruction) live on miden_standards::note::PswapNote.

§Trust model

Observed notes are matched to an order by the order_id on their attachment, which the sender controls — so the (order_id, depth) bucket is untrusted. Anyone who knows one of our live order ids (public orders expose it on-chain) can publish a note carrying that id and our tag. We never trust such a note on its face: for each candidate we reconstruct the note it should be from our stored depth-0 note (payback_note / remainder_note) and accept it only if the reconstructed id matches the observed id. A forger can’t produce a matching id without actually emitting a genuine payback/remainder of our order (which pays our creator), so this is an authenticity check, not a checksum. Candidates that fail are skipped — they can’t advance the tip, change a round’s classification, or be inserted as consumable notes. Classification runs only on the surviving genuine notes, never on the raw observed count.

Structs§

PswapChainObserver
Per-sync collector of PSWAP-attachment notes seen this sync.
PswapLineageRecord
Persistent record of one PSWAP order’s chain state. The order id and creator are mirrored here so the common read paths — keying, filtering — stay lookup-free. Only the remaining amounts are stored; the asset pair’s faucets, the script/recipient, and the note_type all live on the depth-0 note, fetched on demand from output_notes by original_note_id (see store::get_original_pswap) when reconstruction, a depth-0 reclaim, or asset-pair-tag derivation needs them.
PswapTransactionObserver
Registers a PswapLineageRecord + asset-pair tag subscription for every depth-0 PSWAP this wallet emits. Creator-agnostic (service wallets are tracked too; reclaim surfaces CreatorNotLocal later).

Enums§

PswapLineageError
Failures raised by the PSWAP chain-tracking subsystem.
PswapLineageState
Lifecycle state of a PSWAP order. Discriminants are part of the serialized encoding — do not renumber.