@miden-sdk/miden-sdk 0.15.0 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -0
- package/dist/mt/{Cargo-1zqmsGGR.js → Cargo-BbpPeJYa.js} +298 -89
- package/dist/mt/Cargo-BbpPeJYa.js.map +1 -0
- package/dist/mt/api-types.d.ts +54 -0
- package/dist/mt/assets/miden_client_web.wasm +0 -0
- package/dist/mt/crates/miden_client_web.d.ts +102 -0
- package/dist/mt/docs-entry.d.ts +3 -0
- package/dist/mt/eager.js +1 -1
- package/dist/mt/index.js +134 -1
- package/dist/mt/index.js.map +1 -1
- package/dist/mt/wasm.js +1 -1
- package/dist/mt/workerHelpers.js +1 -1
- package/dist/mt/workers/{Cargo-1zqmsGGR-COfl7R3D.js → Cargo-BbpPeJYa-BlSVzh6v.js} +298 -89
- package/dist/mt/workers/{Cargo-1zqmsGGR-COfl7R3D.js.map → Cargo-BbpPeJYa-BlSVzh6v.js.map} +1 -1
- package/dist/mt/workers/assets/miden_client_web.wasm +0 -0
- package/dist/mt/workers/web-client-methods-worker.js +300 -89
- package/dist/mt/workers/web-client-methods-worker.js.map +1 -1
- package/dist/mt/workers/web-client-methods-worker.module.js +1 -1
- package/dist/mt/workers/web-client-methods-worker.module.js.map +1 -1
- package/dist/mt/workers/workerHelpers.js +1 -1
- package/dist/st/{Cargo-qHCIdWdN.js → Cargo-Dlo4tWNG.js} +294 -87
- package/dist/st/Cargo-Dlo4tWNG.js.map +1 -0
- package/dist/st/api-types.d.ts +54 -0
- package/dist/st/assets/miden_client_web.wasm +0 -0
- package/dist/st/crates/miden_client_web.d.ts +102 -0
- package/dist/st/docs-entry.d.ts +3 -0
- package/dist/st/eager.js +1 -1
- package/dist/st/index.js +134 -1
- package/dist/st/index.js.map +1 -1
- package/dist/st/wasm.js +1 -1
- package/dist/st/workers/{Cargo-qHCIdWdN-CZmgHdJc.js → Cargo-Dlo4tWNG-BPaiqKyy.js} +294 -87
- package/dist/st/workers/Cargo-Dlo4tWNG-BPaiqKyy.js.map +1 -0
- package/dist/st/workers/assets/miden_client_web.wasm +0 -0
- package/dist/st/workers/web-client-methods-worker.js +296 -87
- package/dist/st/workers/web-client-methods-worker.js.map +1 -1
- package/dist/st/workers/web-client-methods-worker.module.js +1 -1
- package/dist/st/workers/web-client-methods-worker.module.js.map +1 -1
- package/js/client.js +2 -0
- package/js/resources/pswap.js +132 -0
- package/package.json +4 -4
- package/dist/mt/Cargo-1zqmsGGR.js.map +0 -1
- package/dist/st/Cargo-qHCIdWdN.js.map +0 -1
- package/dist/st/workers/Cargo-qHCIdWdN-CZmgHdJc.js.map +0 -1
package/README.md
CHANGED
|
@@ -452,6 +452,45 @@ const balance = await client.accounts.getBalance(wallet, dagToken);
|
|
|
452
452
|
console.log(`Balance: ${balance}`);
|
|
453
453
|
```
|
|
454
454
|
|
|
455
|
+
### Partial-Swap (PSWAP) Orders
|
|
456
|
+
|
|
457
|
+
A partial-swap note offers one asset for another and can be filled by multiple
|
|
458
|
+
counterparties over time — each partial fill pays the creator and leaves a
|
|
459
|
+
remainder note carrying the unfilled balance. The client tracks that chain as a
|
|
460
|
+
**lineage** keyed by a stable `orderId`, advancing it round by round as fills
|
|
461
|
+
are discovered on sync.
|
|
462
|
+
|
|
463
|
+
```typescript
|
|
464
|
+
// Offer 100 of token A for 25 of token B.
|
|
465
|
+
await client.transactions.pswapCreate({
|
|
466
|
+
account: wallet,
|
|
467
|
+
offer: { token: aToken, amount: 100n },
|
|
468
|
+
request: { token: bToken, amount: 25n }
|
|
469
|
+
});
|
|
470
|
+
await client.sync();
|
|
471
|
+
|
|
472
|
+
// The order is tracked as a lineage keyed by a stable order id.
|
|
473
|
+
const [lineage] = await client.pswap.lineagesFor(wallet);
|
|
474
|
+
const orderId = lineage.orderId();
|
|
475
|
+
console.log(lineage.remainingOffered().toString()); // unfilled offered balance
|
|
476
|
+
|
|
477
|
+
// A counterparty fills part of the order:
|
|
478
|
+
// client.transactions.pswapConsume({ account, note, fillAmount });
|
|
479
|
+
// On the next sync the lineage advances, and `remainingOffered()` shrinks.
|
|
480
|
+
|
|
481
|
+
// Reclaim the unfilled remainder on the current tip, by stable order id.
|
|
482
|
+
// `waitForConfirmation` blocks until the cancel commits AND a sync brings
|
|
483
|
+
// the consumed-note update down; without it, the call resolves at submit
|
|
484
|
+
// time and `pswap.lineage(orderId)` still reads `Active` until the next
|
|
485
|
+
// sync. The lineage only transitions to `Reclaimed` once the chain sees
|
|
486
|
+
// the cancel land.
|
|
487
|
+
await client.pswap.cancelByOrder({ orderId, waitForConfirmation: true });
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
`client.pswap.lineages()` returns every order this client created;
|
|
491
|
+
`client.pswap.lineage(orderId)` returns one order's lineage, or `null` if it is
|
|
492
|
+
not tracked.
|
|
493
|
+
|
|
455
494
|
### Cleanup
|
|
456
495
|
|
|
457
496
|
When you're finished using a MidenClient instance, call `terminate()` to release its Web Worker:
|