Skip to content

Pswap note v2#1

Draft
VAIBHAVJINDAL3012 wants to merge 11 commits intonextfrom
pswap-note-v2
Draft

Pswap note v2#1
VAIBHAVJINDAL3012 wants to merge 11 commits intonextfrom
pswap-note-v2

Conversation

@VAIBHAVJINDAL3012
Copy link
Copy Markdown

No description provided.

Vaibhav Jindal and others added 8 commits March 23, 2026 11:48
…MS, remove create_ wrappers, add builder finish_fn

- Rename swapp_tag -> pswap_tag and SWAPp -> PSWAP throughout
- Rename NUM_ITEMS -> NUM_STORAGE_ITEMS for clarity
- Remove create_p2id_payback_note and create_remainder_note wrappers,
  make build_ functions public instead
- Compute p2id_tag inside build_p2id_payback_note from self.storage
- Add #[builder(finish_fn(vis = "", name = build_internal))] to PswapNote
…ctly

Replace all test helper wrappers with direct calls to library functions:
- create_pswap_note -> PswapNote::create()
- create_expected_pswap_p2id_note + create_expected_pswap_remainder_note -> pswap.execute()
- build_pswap_storage -> PswapNoteStorage::from_parts()
- Remove make_pswap_tag, make_note_assets, make_note_args, compute_p2id_tag_*
- Inline calculate_output_amount as PswapNote::calculate_output_amount()
- Replace storage layout list with markdown table
- Remove trivial "Returns the X" docs on simple getters
- Add # Errors sections where relevant
- Rewrite method docs to describe intent, not implementation
- Add one-line docs on From/TryFrom conversion impls
- Tighten PswapNote struct doc
- Rename RpoRandomCoin to RandomCoin (miden-crypto 0.23 rename)
- Store full ASSET_KEY instead of prefix/suffix to preserve callback
  metadata in faucet_id_suffix_and_metadata
- Replace create_fungible_asset calls with direct ASSET_KEY + manual
  ASSET_VALUE construction, avoiding the new enable_callbacks parameter
- Update hardcoded P2ID script root to match current P2idNote::script_root()
- Replace hardcoded P2ID script root with procref.p2id::main for
  compile-time resolution
- Default to full fill when both input and inflight amounts are zero
- Replace magic address 4000 with named P2ID_RECIPIENT_STORAGE constant
- Remove step numbering from comments, fix memory layout docs
else
# Case: offered >= requested
# result = ((offered * FACTOR) / requested) * input / FACTOR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be extracted into a different procedure to avoid duplicate writing?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean when you day duplicated writing?

const SWAPP_NOTE_IDX = 0x0080
const NOTE_TYPE = 0x0084

# P2ID recipient storage (creator account ID written here for build_recipient)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be named prefix-suffix style.

Comment on lines +207 to +210
# => [METADATA_HEADER] = [hdr3, hdr2, hdr1, hdr0]
# hdr[3] = sender_id_prefix (top)
# hdr[0] = sender_suffix_and_note_type (bottom, contains note_type in bits 0-1)
# Keep hdr0 (bottom), drop hdr3/hdr2/hdr1 from top
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you link the docs where this header layout is given?

# hdr[3] = sender_id_prefix (top)
# hdr[0] = sender_suffix_and_note_type (bottom, contains note_type in bits 0-1)
# Keep hdr0 (bottom), drop hdr3/hdr2/hdr1 from top
movdn.3 drop drop drop
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is hdr0 after moving hdr3 to 3rd index and dropping 3 Felts?

# => [0, 0, 0, aux]

push.0 mem_load.P2ID_NOTE_IDX
# => [note_idx, attachment_scheme, ATTACHMENT]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc for attachment scheme in masm.

# => []

# Move input_amount from consumer's vault to P2ID note (if > 0)
mem_load.AMT_REQUESTED_IN dup push.0 neq
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the stack view here

- Rename P2ID_RECIPIENT_STORAGE to P2ID_RECIPIENT_SUFFIX/PREFIX
- Add METADATA_HEADER word layout docs with source reference
- Document attachment_scheme parameter in set_word_attachment call
- Add stack views after condition checks
…lper, simplify build_p2id_payback_note

Rename requested_key/requested_value/requested_amount to
requested_asset_key/requested_asset_value/requested_asset_amount for
clarity. Extract offered_asset_amount() helper on PswapNote to
deduplicate offered asset extraction. Simplify build_p2id_payback_note
to take fill_amount: u64 instead of aux_word: Word, constructing the
aux word internally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants