Skip to content

feat(standards): SwapNote bon builder#11

Draft
VAIBHAVJINDAL3012 wants to merge 2 commits into
nextfrom
vaibhav/swap-note-builder
Draft

feat(standards): SwapNote bon builder#11
VAIBHAVJINDAL3012 wants to merge 2 commits into
nextfrom
vaibhav/swap-note-builder

Conversation

@VAIBHAVJINDAL3012

@VAIBHAVJINDAL3012 VAIBHAVJINDAL3012 commented Jun 25, 2026

Copy link
Copy Markdown

Summary

Converts SwapNote from a unit marker + SwapNote::create factory into a struct built with a bon typestate builder (SwapNote::builder()), mirroring the merged P2idNote builder. One of three per-note PRs splitting the standard-note builder work (Swap / Burn / Mint).

  • SwapNote::builder() produces a SwapNote; call SwapNote::into_notes() to get the outgoing SWAP Note plus the payback NoteDetails.
  • The requested != offered validation is preserved via NoteError::other.
  • .generate_serial_numbers() draws the swap and payback serial numbers (payback first, preserving the previous draw order).
  • Migrated the mock-chain add_swap_note and the swap interface test.

Builder-only change; no MASM or on-chain behaviour changes.

Verification

  • cargo clippy -p miden-standards -p miden-testing --all-targets --all-features -- -D warnings - clean
  • New note::swap::tests::builder_produces_swap_and_payback_notes unit test; the tests/scripts/swap.rs + faucet suites pass and re-run in CI here.

Convert the `SwapNote` marker type into a struct built via a `bon` typestate
builder (`SwapNote::builder()`), mirroring `P2idNote`. `SwapNote::into_notes`
returns the outgoing SWAP note together with its payback `NoteDetails`. The
"requested asset must differ from offered" check now surfaces via
`NoteError::other`. Migrate the mock-chain `add_swap_note` call site.

Part of 0xMiden#2283.
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e9b439aa-1061-4a6e-8263-28918dd5d32c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch vaibhav/swap-note-builder

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@VAIBHAVJINDAL3012 VAIBHAVJINDAL3012 left a comment

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.

  1. Check on serial number
  2. Check on into_notes

Comment thread crates/miden-standards/src/note/swap.rs Outdated
let tag = Self::build_tag(self.swap_note_type, &self.offered_asset, &self.requested_asset);
let metadata = PartialNoteMetadata::new(self.sender, self.swap_note_type).with_tag(tag);
let assets = NoteAssets::new(vec![self.offered_asset])
.expect("a single offered asset never exceeds the note asset limit");

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.

dont' use expect, check from P2ID note......
Btw why do we need this function......

Comment on lines +263 to +264
let payback_serial_number = rng.draw_word();
let serial_number = rng.draw_word();

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.

How both serial numbers are same???

Check it corereclty

Propagate NoteAssets::new errors with ? instead of panicking via .expect(...), matching the error handling the original create used and keeping the (Note, NoteDetails) return. Also comment the builder test.
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.

1 participant