0xMiden / 0xMiden/web-sdk

Expose PSWAP API on web client and React SDK (mirror of miden-client#2162)

Aperta
#151 1 commento 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
1
Fork
21
Merge medio
12h 14m
PR unite (30g)
41

Descrizione

## Summary

`miden-client#2162` ("Pswap Client") adds the Rust-side PSWAP API — `build_pswap_create`, `build_pswap_consume`, and `build_pswap_cancel` on `TransactionRequestBuilder`, plus a `miden-client pswap` CLI subcommand. The web client and React SDK in this repo don't have a PSWAP equivalent. For the v1 public-PSWAP DEX architecture (see `0xMiden/miden-client#1544`), browser-side users currently have no path to create PSWAPs.

## Description

The v1 DEX flow is "user creates a public PSWAP from a browser dApp, market-maker solvers discover it via tag subscription, race to fill it, and settle on-chain". The user-creation step has no web-side primitive today. Looking at the current state of this repo:

- `packages/react-sdk/src/hooks/useSwap.ts` — atomic SWAP only. Doc comment: *"Create an atomic swap offer"*.
- `crates/web-client/test/swap_transactions.test.ts` — exercises atomic SWAP only.
- A recursive search returns zero `pswap` hits anywhere in the repo.

So once `#2162` lands, we'll have a Rust-vs-web gap on the primary v1 user flow.

## What's needed

I'd expect this to be a fairly mechanical mirror of `#2162`'s surface:

- WASM bindings on `crates/web-client` exposing `build_pswap_create`, `build_pswap_consume`, and `build_pswap_cancel`, plus the `PswapTransactionData` shape (creator account ID, offered fungible asset, requested fungible asset, payback `NoteType`).
- A `usePswap` React hook in `packages/react-sdk` mirroring `useSwap`'s ergonomics. v1 callers will pass `NoteType.Public`; the hook should either default that way or expose it as a configurable option.
- TypeScript declarations for the new types and method signatures.
- An end-to-end web test mirroring `bin/integration-tests/src/tests/pswap_transaction.rs` (full-fill / partial-fill / cancel) on the browser side.

## Dependencies and prior art

- Depends on `0xMiden/miden-client#2162`. That PR currently has one failing integration test (`pswap_full_fill_onchain`) — resolution there will likely inform the web test too.
- PSWAP standard: `0xMiden/miden-base` commit `22d6d505` (merged `0xMiden/protocol#2636`, "PSwap Contract").
- v1 architecture context: the May 5 comment on `0xMiden/miden-client#1544`.

## Open Questions

1. **Scoping**: should this land as one PR mirroring all three methods, or split into `create` first (since it's the primary v1 user flow) and `consume` / `cancel` later?
2. **Hook surface**: extend `useSwap` with a `mode: 'atomic' | 'partial'` option, or keep them as distinct `useSwap` and `usePswap` hooks? Happy either way; the existing `useSwap` ergonomics seem worth preserving as-is so I'd lean toward a separate `usePswap`.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia esaminando l'hook esistente `useSwap` in `packages/react-sdk/src/hooks/useSwap.ts` e l'API PSWAP lato Rust nel collegamento `miden-client#2162`. Il compito prevede la creazione di binding WASM in `crates/web-client`, un nuovo hook `usePswap` che specchi `useSwap` e i corrispondenti tipi TypeScript. Esegui i test di scambio esistenti in `crates/web-client/test/swap_transactions.test.ts` per comprendere lo schema di test. Il lavoro è completato quando il client web e l'React SDK possono creare, consumare e annullare transazioni PSWAP, con test di integrazione superati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
react, rust, typescript, wasm
Ambito
api, frontend, web-dev
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.