@permissionless-technologies/upp-sdk 0.4.17 → 0.4.19

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.
Files changed (42) hide show
  1. package/dist/{chunk-GJXJBDE5.cjs → chunk-5H27F6W6.cjs} +14 -5
  2. package/dist/chunk-5H27F6W6.cjs.map +1 -0
  3. package/dist/{chunk-HRHGZKTJ.js → chunk-7VPW5T5R.js} +3 -3
  4. package/dist/{chunk-HRHGZKTJ.js.map → chunk-7VPW5T5R.js.map} +1 -1
  5. package/dist/{chunk-7BOX7YFZ.js → chunk-C7DUABSG.js} +14 -5
  6. package/dist/chunk-C7DUABSG.js.map +1 -0
  7. package/dist/{chunk-QOMHO6FP.cjs → chunk-M7SCH6LU.cjs} +2 -2
  8. package/dist/{chunk-QOMHO6FP.cjs.map → chunk-M7SCH6LU.cjs.map} +1 -1
  9. package/dist/{chunk-KOT5MTDL.js → chunk-QGSTHXRP.js} +2 -2
  10. package/dist/{chunk-KOT5MTDL.js.map → chunk-QGSTHXRP.js.map} +1 -1
  11. package/dist/{chunk-D3XBKPQ2.cjs → chunk-V6MW5VOF.cjs} +4 -4
  12. package/dist/{chunk-D3XBKPQ2.cjs.map → chunk-V6MW5VOF.cjs.map} +1 -1
  13. package/dist/core/index.cjs +50 -50
  14. package/dist/core/index.d.cts +2 -2
  15. package/dist/core/index.d.ts +2 -2
  16. package/dist/core/index.js +2 -2
  17. package/dist/{index-DKFupAA8.d.cts → index-DcfqeWvk.d.cts} +7 -2
  18. package/dist/{index-M91G-og3.d.ts → index-DmowSsZb.d.ts} +7 -2
  19. package/dist/{index-S2fzWmLW.d.ts → index-DsXMd8zh.d.ts} +1 -1
  20. package/dist/{index-qTwnREeK.d.cts → index-PgqOAfcc.d.cts} +1 -1
  21. package/dist/index.cjs +58 -52
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +3 -3
  24. package/dist/index.d.ts +3 -3
  25. package/dist/index.js +9 -3
  26. package/dist/index.js.map +1 -1
  27. package/dist/indexer/index.cjs +6 -6
  28. package/dist/indexer/index.d.cts +5 -5
  29. package/dist/indexer/index.d.ts +5 -5
  30. package/dist/indexer/index.js +1 -1
  31. package/dist/react/index.cjs +173 -20
  32. package/dist/react/index.cjs.map +1 -1
  33. package/dist/react/index.d.cts +60 -3
  34. package/dist/react/index.d.ts +60 -3
  35. package/dist/react/index.js +156 -4
  36. package/dist/react/index.js.map +1 -1
  37. package/dist/{transfer-BDYID3Hn.d.cts → transfer-B4q3ZTJK.d.cts} +73 -0
  38. package/dist/{transfer-DLukr6ed.d.ts → transfer-Cqg235q6.d.ts} +73 -0
  39. package/package.json +1 -1
  40. package/src/contracts/interfaces/IUniversalPrivatePool.sol +1 -0
  41. package/dist/chunk-7BOX7YFZ.js.map +0 -1
  42. package/dist/chunk-GJXJBDE5.cjs.map +0 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkQOMHO6FP_cjs = require('../chunk-QOMHO6FP.cjs');
3
+ var chunkM7SCH6LU_cjs = require('../chunk-M7SCH6LU.cjs');
4
4
  var chunkERQE57IA_cjs = require('../chunk-ERQE57IA.cjs');
5
5
  require('../chunk-G7VZBCD6.cjs');
6
6
 
@@ -8,23 +8,23 @@ require('../chunk-G7VZBCD6.cjs');
8
8
 
9
9
  Object.defineProperty(exports, "computeSearchTag", {
10
10
  enumerable: true,
11
- get: function () { return chunkQOMHO6FP_cjs.computeSearchTag; }
11
+ get: function () { return chunkM7SCH6LU_cjs.computeSearchTag; }
12
12
  });
13
13
  Object.defineProperty(exports, "makeRpcIndexer", {
14
14
  enumerable: true,
15
- get: function () { return chunkQOMHO6FP_cjs.makeRpcIndexer; }
15
+ get: function () { return chunkM7SCH6LU_cjs.makeRpcIndexer; }
16
16
  });
17
17
  Object.defineProperty(exports, "matchesSearchTag", {
18
18
  enumerable: true,
19
- get: function () { return chunkQOMHO6FP_cjs.matchesSearchTag; }
19
+ get: function () { return chunkM7SCH6LU_cjs.matchesSearchTag; }
20
20
  });
21
21
  Object.defineProperty(exports, "tryDecryptNote", {
22
22
  enumerable: true,
23
- get: function () { return chunkQOMHO6FP_cjs.tryDecryptNote; }
23
+ get: function () { return chunkM7SCH6LU_cjs.tryDecryptNote; }
24
24
  });
25
25
  Object.defineProperty(exports, "unpackNoteData", {
26
26
  enumerable: true,
27
- get: function () { return chunkQOMHO6FP_cjs.unpackNoteData; }
27
+ get: function () { return chunkM7SCH6LU_cjs.unpackNoteData; }
28
28
  });
29
29
  Object.defineProperty(exports, "createAutoAdapter", {
30
30
  enumerable: true,
@@ -1,10 +1,10 @@
1
- import { S as StorageAdapter } from '../index-qTwnREeK.cjs';
2
- export { C as CommitmentInsertedArgs, a as IndexedNote, I as Indexer, f as IndexerState, L as LiveSyncConfig, b as NoteFilters, N as NoteStatus, j as NullifiedArgs, R as RpcIndexerConfig, h as SerializedNote, i as StealthTransactArgs, e as SyncConfig, d as SyncProgress, c as SyncResult, g as SyncState } from '../index-qTwnREeK.cjs';
3
- import { _ as ___index_js } from '../index-DKFupAA8.cjs';
4
- export { m as makeRpcIndexer } from '../index-DKFupAA8.cjs';
1
+ import { S as StorageAdapter } from '../index-PgqOAfcc.cjs';
2
+ export { C as CommitmentInsertedArgs, a as IndexedNote, I as Indexer, f as IndexerState, L as LiveSyncConfig, b as NoteFilters, N as NoteStatus, j as NullifiedArgs, R as RpcIndexerConfig, h as SerializedNote, i as StealthTransactArgs, e as SyncConfig, d as SyncProgress, c as SyncResult, g as SyncState } from '../index-PgqOAfcc.cjs';
3
+ import { _ as ___index_js } from '../index-DcfqeWvk.cjs';
4
+ export { m as makeRpcIndexer } from '../index-DcfqeWvk.cjs';
5
5
  import { Hex } from 'viem';
6
6
  import { P as Point } from '../merkle-mteVOlDf.cjs';
7
- import '../transfer-BDYID3Hn.cjs';
7
+ import '../transfer-B4q3ZTJK.cjs';
8
8
  import '../keccak-m31-B_AqBbRF.cjs';
9
9
  import '@permissionless-technologies/upc-sdk';
10
10
  import 'react/jsx-runtime';
@@ -1,10 +1,10 @@
1
- import { S as StorageAdapter } from '../index-S2fzWmLW.js';
2
- export { C as CommitmentInsertedArgs, a as IndexedNote, I as Indexer, f as IndexerState, L as LiveSyncConfig, b as NoteFilters, N as NoteStatus, j as NullifiedArgs, R as RpcIndexerConfig, h as SerializedNote, i as StealthTransactArgs, e as SyncConfig, d as SyncProgress, c as SyncResult, g as SyncState } from '../index-S2fzWmLW.js';
3
- import { _ as ___index_js } from '../index-M91G-og3.js';
4
- export { m as makeRpcIndexer } from '../index-M91G-og3.js';
1
+ import { S as StorageAdapter } from '../index-DsXMd8zh.js';
2
+ export { C as CommitmentInsertedArgs, a as IndexedNote, I as Indexer, f as IndexerState, L as LiveSyncConfig, b as NoteFilters, N as NoteStatus, j as NullifiedArgs, R as RpcIndexerConfig, h as SerializedNote, i as StealthTransactArgs, e as SyncConfig, d as SyncProgress, c as SyncResult, g as SyncState } from '../index-DsXMd8zh.js';
3
+ import { _ as ___index_js } from '../index-DmowSsZb.js';
4
+ export { m as makeRpcIndexer } from '../index-DmowSsZb.js';
5
5
  import { Hex } from 'viem';
6
6
  import { P as Point } from '../merkle-mteVOlDf.js';
7
- import '../transfer-DLukr6ed.js';
7
+ import '../transfer-Cqg235q6.js';
8
8
  import '../keccak-m31-B_AqBbRF.js';
9
9
  import '@permissionless-technologies/upc-sdk';
10
10
  import 'react/jsx-runtime';
@@ -1,4 +1,4 @@
1
- export { computeSearchTag, makeRpcIndexer, matchesSearchTag, tryDecryptNote, unpackNoteData } from '../chunk-KOT5MTDL.js';
1
+ export { computeSearchTag, makeRpcIndexer, matchesSearchTag, tryDecryptNote, unpackNoteData } from '../chunk-QGSTHXRP.js';
2
2
  export { createAutoAdapter, createIndexedDBAdapter, createLocalStorageAdapter, createMemoryAdapter, indexedDBAdapter, localStorageAdapter, memoryAdapter } from '../chunk-XV72HNHN.js';
3
3
  import '../chunk-Z6ZWNWWR.js';
4
4
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkGJXJBDE5_cjs = require('../chunk-GJXJBDE5.cjs');
3
+ var chunk5H27F6W6_cjs = require('../chunk-5H27F6W6.cjs');
4
4
  var chunkXVIICZKW_cjs = require('../chunk-XVIICZKW.cjs');
5
5
  var chunkERQE57IA_cjs = require('../chunk-ERQE57IA.cjs');
6
6
  require('../chunk-UFEDJJSH.cjs');
@@ -107,7 +107,7 @@ function UPPAccountProvider({
107
107
  return;
108
108
  }
109
109
  const accountStorage = chunkERQE57IA_cjs.createAutoAdapter(`upp_account`);
110
- const adapter = new chunkGJXJBDE5_cjs.StorableAccountAdapter(accountStorage, ethAddress);
110
+ const adapter = new chunk5H27F6W6_cjs.StorableAccountAdapter(accountStorage, ethAddress);
111
111
  accountAdapterRef.current = adapter;
112
112
  const legacyKey = getStorageKey(ethAddress);
113
113
  const legacySaved = typeof window !== "undefined" ? localStorage.getItem(legacyKey) : null;
@@ -148,7 +148,7 @@ function UPPAccountProvider({
148
148
  const ownerHashHex2 = viem.toHex(account.keys.ownerHash, { size: 32 });
149
149
  const storagePrefix = `upp_${chainId}_${ownerHashHex2.slice(0, 12)}`;
150
150
  const noteStorage = chunkERQE57IA_cjs.createAutoAdapter(storagePrefix);
151
- const store = new chunkGJXJBDE5_cjs.NoteStore(noteStorage, "notes");
151
+ const store = new chunk5H27F6W6_cjs.NoteStore(noteStorage, "notes");
152
152
  noteStoreRef.current = store;
153
153
  noteStoreUnsub = store.onChange(() => {
154
154
  if (!cancelled) setNotes([...store.getNotes()]);
@@ -488,6 +488,7 @@ function UPPAccountProvider({
488
488
  { name: "takeAmount", type: "uint256", indexed: false },
489
489
  { name: "giveAmount", type: "uint256", indexed: false },
490
490
  { name: "fillerAspId", type: "uint256", indexed: false },
491
+ { name: "remainingSellAmount", type: "uint256", indexed: false },
491
492
  { name: "encryptedFillerNote", type: "bytes", indexed: false }
492
493
  ]
493
494
  },
@@ -790,7 +791,10 @@ function UPPAccountProvider({
790
791
  syncPromiseRef.current = syncPromise;
791
792
  return syncPromise;
792
793
  },
793
- [masterKeys, cryptoReady, notes, persistNotes]
794
+ // Note: `notes` is intentionally NOT in the dependency array to prevent
795
+ // sync loops. The callback reads notes from noteStoreRef.current directly.
796
+ // eslint-disable-next-line react-hooks/exhaustive-deps
797
+ [masterKeys, cryptoReady, persistNotes]
794
798
  );
795
799
  const startLiveSync = react.useCallback(
796
800
  (contractAddress, client) => {
@@ -849,7 +853,7 @@ function UPPAccountProvider({
849
853
  const stealthAddress = react.useMemo(() => {
850
854
  if (!masterKeys) return null;
851
855
  try {
852
- const { encodeStealthAddress } = (chunkGJXJBDE5_cjs.init_stealth(), chunkG7VZBCD6_cjs.__toCommonJS(chunkGJXJBDE5_cjs.stealth_exports));
856
+ const { encodeStealthAddress } = (chunk5H27F6W6_cjs.init_stealth(), chunkG7VZBCD6_cjs.__toCommonJS(chunk5H27F6W6_cjs.stealth_exports));
853
857
  return encodeStealthAddress(masterKeys.ownerHash, masterKeys.viewingHash);
854
858
  } catch {
855
859
  return null;
@@ -858,7 +862,7 @@ function UPPAccountProvider({
858
862
  const starkStealthAddress = react.useMemo(() => {
859
863
  if (!starkMasterKeys) return null;
860
864
  try {
861
- const { encodeStarkStealthAddress } = (chunkGJXJBDE5_cjs.init_stealth(), chunkG7VZBCD6_cjs.__toCommonJS(chunkGJXJBDE5_cjs.stealth_exports));
865
+ const { encodeStarkStealthAddress } = (chunk5H27F6W6_cjs.init_stealth(), chunkG7VZBCD6_cjs.__toCommonJS(chunk5H27F6W6_cjs.stealth_exports));
862
866
  return encodeStarkStealthAddress(starkMasterKeys.starkOwnerHash, starkMasterKeys.starkViewingHash);
863
867
  } catch {
864
868
  return null;
@@ -1745,7 +1749,7 @@ function usePoolTransfer(config) {
1745
1749
  changeNoteWithAmount
1746
1750
  );
1747
1751
  setProvingProgress(null);
1748
- const { proof } = await chunkGJXJBDE5_cjs.generateUPPProofAsync(
1752
+ const { proof } = await chunk5H27F6W6_cjs.generateUPPProofAsync(
1749
1753
  "transfer",
1750
1754
  circuitInputs,
1751
1755
  cfg.circuitBaseUrl ?? "/circuits/",
@@ -1928,7 +1932,7 @@ function useWithdraw(config) {
1928
1932
  aspPathIndices: Array(ASP_TREE_DEPTH2).fill("0")
1929
1933
  };
1930
1934
  setProvingProgress(null);
1931
- const { proof } = await chunkGJXJBDE5_cjs.generateUPPProofAsync(
1935
+ const { proof } = await chunk5H27F6W6_cjs.generateUPPProofAsync(
1932
1936
  "withdraw",
1933
1937
  circuitInputs,
1934
1938
  cfg.circuitBaseUrl ?? "/circuits/",
@@ -2123,7 +2127,7 @@ function useSwapOrderBook(config) {
2123
2127
  try {
2124
2128
  const logs = await config.publicClient.getLogs({
2125
2129
  address: config.poolAddress,
2126
- event: chunkGJXJBDE5_cjs.SWAP_ORDER_PLACED_EVENT,
2130
+ event: chunk5H27F6W6_cjs.SWAP_ORDER_PLACED_EVENT,
2127
2131
  fromBlock: config.fromBlock ?? 0n,
2128
2132
  toBlock: "latest"
2129
2133
  });
@@ -2139,10 +2143,10 @@ function useSwapOrderBook(config) {
2139
2143
  blockNumber: log.blockNumber ?? 0n
2140
2144
  }));
2141
2145
  if (config.sellToken && config.buyToken) {
2142
- parsedOrders = chunkGJXJBDE5_cjs.filterOrdersByTokenPair(parsedOrders, config.sellToken, config.buyToken);
2146
+ parsedOrders = chunk5H27F6W6_cjs.filterOrdersByTokenPair(parsedOrders, config.sellToken, config.buyToken);
2143
2147
  }
2144
2148
  if (config.acceptableAspIds && config.acceptableAspIds.length > 0) {
2145
- parsedOrders = chunkGJXJBDE5_cjs.filterOrdersByASP(parsedOrders, config.acceptableAspIds);
2149
+ parsedOrders = chunk5H27F6W6_cjs.filterOrdersByASP(parsedOrders, config.acceptableAspIds);
2146
2150
  }
2147
2151
  const enriched = [];
2148
2152
  for (const order of parsedOrders) {
@@ -2306,7 +2310,7 @@ function useSwap(config) {
2306
2310
  aspPathIndices: padToDepth2(aspProofData.aspPathIndices.map(String), "0", ASP_TREE_DEPTH3)
2307
2311
  };
2308
2312
  setProvingProgress(null);
2309
- const { proof } = await chunkGJXJBDE5_cjs.generateUPPProofAsync(
2313
+ const { proof } = await chunk5H27F6W6_cjs.generateUPPProofAsync(
2310
2314
  "withdraw",
2311
2315
  circuitInputs,
2312
2316
  cfg.circuitBaseUrl ?? "/circuits/",
@@ -2316,8 +2320,8 @@ function useSwap(config) {
2316
2320
  }
2317
2321
  );
2318
2322
  const formattedProof = await formatPlonkProofForContract(proof);
2319
- const cancelSecret = chunkGJXJBDE5_cjs.generateCancelSecret();
2320
- const cancelKeyHash = chunkGJXJBDE5_cjs.computeCancelKeyHash(cancelSecret);
2323
+ const cancelSecret = chunk5H27F6W6_cjs.generateCancelSecret();
2324
+ const cancelKeyHash = chunk5H27F6W6_cjs.computeCancelKeyHash(cancelSecret);
2321
2325
  const currentBlock = await cfg.publicClient.getBlockNumber();
2322
2326
  const expiry = currentBlock + expiryBlocks;
2323
2327
  return {
@@ -2366,7 +2370,7 @@ function useSwap(config) {
2366
2370
  noteOverride
2367
2371
  } = params;
2368
2372
  const cfg = configRef.current;
2369
- const giveAmount = chunkGJXJBDE5_cjs.computeGiveAmount(takeAmount, rate);
2373
+ const giveAmount = chunk5H27F6W6_cjs.computeGiveAmount(takeAmount, rate);
2370
2374
  setStage("selecting_notes");
2371
2375
  let selectedNote;
2372
2376
  if (noteOverride) {
@@ -2459,7 +2463,7 @@ function useSwap(config) {
2459
2463
  aspPathIndices: padToDepth2(aspProofData.aspPathIndices.map(String), "0", ASP_TREE_DEPTH3)
2460
2464
  };
2461
2465
  setProvingProgress(null);
2462
- const { proof } = await chunkGJXJBDE5_cjs.generateUPPProofAsync(
2466
+ const { proof } = await chunk5H27F6W6_cjs.generateUPPProofAsync(
2463
2467
  "withdraw",
2464
2468
  circuitInputs,
2465
2469
  cfg.circuitBaseUrl ?? "/circuits/",
@@ -2655,7 +2659,7 @@ function useSwap(config) {
2655
2659
  changeNoteWithAmount
2656
2660
  );
2657
2661
  setProvingProgress(null);
2658
- const { proof } = await chunkGJXJBDE5_cjs.generateUPPProofAsync(
2662
+ const { proof } = await chunk5H27F6W6_cjs.generateUPPProofAsync(
2659
2663
  "transfer",
2660
2664
  circuitInputs,
2661
2665
  cfg.circuitBaseUrl ?? "/circuits/",
@@ -2745,7 +2749,7 @@ function useProofWorker(worker) {
2745
2749
  managerRef.current = null;
2746
2750
  return;
2747
2751
  }
2748
- const manager = new chunkGJXJBDE5_cjs.ProofWorkerManager(worker);
2752
+ const manager = new chunk5H27F6W6_cjs.ProofWorkerManager(worker);
2749
2753
  managerRef.current = manager;
2750
2754
  return () => {
2751
2755
  manager.terminate();
@@ -2754,14 +2758,162 @@ function useProofWorker(worker) {
2754
2758
  }, [worker]);
2755
2759
  return managerRef.current;
2756
2760
  }
2761
+ function usePrivateBalance(config) {
2762
+ const { unspentNotes, syncNotes, isSyncing: isNoteSyncing } = useUPPAccount();
2763
+ const { poolAddress, publicClient, walletAddress, tokenList, autoSync = true, fromBlock = 0n } = config;
2764
+ const [unclaimedOrders, setUnclaimedOrders] = react.useState(/* @__PURE__ */ new Map());
2765
+ const [isOrderSyncing, setIsOrderSyncing] = react.useState(false);
2766
+ const hasAutoSynced = react.useRef(false);
2767
+ const configRef = react.useRef(config);
2768
+ configRef.current = config;
2769
+ const syncUnclaimedOrders = react.useCallback(async () => {
2770
+ if (!publicClient || !poolAddress) return;
2771
+ setIsOrderSyncing(true);
2772
+ try {
2773
+ const placedLogs = await publicClient.getLogs({
2774
+ address: poolAddress,
2775
+ event: chunk5H27F6W6_cjs.SWAP_ORDER_PLACED_EVENT,
2776
+ fromBlock,
2777
+ toBlock: "latest"
2778
+ });
2779
+ const orders = /* @__PURE__ */ new Map();
2780
+ for (const log of placedLogs) {
2781
+ const args = log.args;
2782
+ const orderId = args.orderId;
2783
+ if (walletAddress && !chunk5H27F6W6_cjs.getCancelSecret(orderId, walletAddress)) continue;
2784
+ orders.set(orderId.toLowerCase(), {
2785
+ sellToken: args.sellToken,
2786
+ sellAmount: BigInt(args.sellAmount),
2787
+ remaining: BigInt(args.sellAmount)
2788
+ });
2789
+ }
2790
+ const filledLogs = await publicClient.getLogs({
2791
+ address: poolAddress,
2792
+ event: chunk5H27F6W6_cjs.SWAP_ORDER_FILLED_EVENT,
2793
+ fromBlock,
2794
+ toBlock: "latest"
2795
+ });
2796
+ for (const log of filledLogs) {
2797
+ const args = log.args;
2798
+ const orderId = args.orderId.toLowerCase();
2799
+ const order = orders.get(orderId);
2800
+ if (order) {
2801
+ const remaining = args.remainingSellAmount;
2802
+ if (remaining !== void 0) {
2803
+ order.remaining = BigInt(remaining);
2804
+ } else {
2805
+ order.remaining -= BigInt(args.takeAmount);
2806
+ }
2807
+ }
2808
+ }
2809
+ const claimedLogs = await publicClient.getLogs({
2810
+ address: poolAddress,
2811
+ event: chunk5H27F6W6_cjs.SWAP_ORDER_CLAIMED_EVENT,
2812
+ fromBlock,
2813
+ toBlock: "latest"
2814
+ });
2815
+ for (const log of claimedLogs) {
2816
+ orders.delete(log.args.orderId.toLowerCase());
2817
+ }
2818
+ const cancelledLogs = await publicClient.getLogs({
2819
+ address: poolAddress,
2820
+ event: chunk5H27F6W6_cjs.SWAP_ORDER_CANCELLED_EVENT,
2821
+ fromBlock,
2822
+ toBlock: "latest"
2823
+ });
2824
+ for (const log of cancelledLogs) {
2825
+ orders.delete(log.args.orderId.toLowerCase());
2826
+ }
2827
+ const result = /* @__PURE__ */ new Map();
2828
+ for (const [id, order] of orders) {
2829
+ if (order.remaining > 0n) {
2830
+ result.set(id, { sellToken: order.sellToken, remaining: order.remaining });
2831
+ }
2832
+ }
2833
+ setUnclaimedOrders(result);
2834
+ } catch (e) {
2835
+ console.warn("[usePrivateBalance] Failed to sync unclaimed orders:", e);
2836
+ } finally {
2837
+ setIsOrderSyncing(false);
2838
+ }
2839
+ }, [publicClient, poolAddress, walletAddress, fromBlock]);
2840
+ const sync = react.useCallback(async () => {
2841
+ if (!publicClient || !poolAddress) return;
2842
+ await Promise.all([
2843
+ syncNotes(poolAddress, publicClient),
2844
+ syncUnclaimedOrders()
2845
+ ]);
2846
+ }, [publicClient, poolAddress, syncNotes, syncUnclaimedOrders]);
2847
+ react.useEffect(() => {
2848
+ if (!autoSync || hasAutoSynced.current || !publicClient || !poolAddress) return;
2849
+ hasAutoSynced.current = true;
2850
+ sync().catch((e) => console.error("[usePrivateBalance] Auto-sync failed:", e));
2851
+ }, [autoSync, publicClient, poolAddress]);
2852
+ react.useEffect(() => {
2853
+ hasAutoSynced.current = false;
2854
+ }, [walletAddress]);
2855
+ const balances = react.useMemo(() => {
2856
+ const byToken = /* @__PURE__ */ new Map();
2857
+ const getOrCreate = (addr) => {
2858
+ const key = addr.toLowerCase();
2859
+ let entry = byToken.get(key);
2860
+ if (!entry) {
2861
+ const info = tokenList?.find((t) => t.address.toLowerCase() === key);
2862
+ entry = {
2863
+ token: key,
2864
+ symbol: info?.symbol,
2865
+ decimals: info?.decimals,
2866
+ logoEmoji: info?.logoEmoji,
2867
+ snark: { balance: 0n, noteCount: 0 },
2868
+ stark: { balance: 0n, noteCount: 0 },
2869
+ unclaimedSnark: { balance: 0n, orderCount: 0 },
2870
+ total: 0n
2871
+ };
2872
+ byToken.set(key, entry);
2873
+ }
2874
+ return entry;
2875
+ };
2876
+ for (const note of unspentNotes) {
2877
+ if (!note.token) continue;
2878
+ const entry = getOrCreate(note.token);
2879
+ const ps = note.proofSystem ?? "snark";
2880
+ entry[ps].balance += note.amount;
2881
+ entry[ps].noteCount++;
2882
+ }
2883
+ for (const [, order] of unclaimedOrders) {
2884
+ const entry = getOrCreate(order.sellToken);
2885
+ entry.unclaimedSnark.balance += order.remaining;
2886
+ entry.unclaimedSnark.orderCount++;
2887
+ }
2888
+ if (tokenList) {
2889
+ for (const t of tokenList) {
2890
+ getOrCreate(t.address);
2891
+ }
2892
+ }
2893
+ for (const entry of byToken.values()) {
2894
+ entry.total = entry.snark.balance + entry.stark.balance + entry.unclaimedSnark.balance;
2895
+ }
2896
+ return Array.from(byToken.values()).sort((a, b) => {
2897
+ if (a.total > 0n && b.total === 0n) return -1;
2898
+ if (a.total === 0n && b.total > 0n) return 1;
2899
+ if (a.total !== b.total) return Number(b.total - a.total);
2900
+ return (a.symbol ?? "").localeCompare(b.symbol ?? "");
2901
+ });
2902
+ }, [unspentNotes, unclaimedOrders, tokenList]);
2903
+ return {
2904
+ balances,
2905
+ isSyncing: isNoteSyncing || isOrderSyncing,
2906
+ sync
2907
+ };
2908
+ }
2757
2909
 
2758
2910
  Object.defineProperty(exports, "ProofWorkerManager", {
2759
2911
  enumerable: true,
2760
- get: function () { return chunkGJXJBDE5_cjs.ProofWorkerManager; }
2912
+ get: function () { return chunk5H27F6W6_cjs.ProofWorkerManager; }
2761
2913
  });
2762
2914
  Object.defineProperty(exports, "generateUPPProofAsync", {
2763
2915
  enumerable: true,
2764
- get: function () { return chunkGJXJBDE5_cjs.generateUPPProofAsync; }
2916
+ get: function () { return chunk5H27F6W6_cjs.generateUPPProofAsync; }
2765
2917
  });
2766
2918
  Object.defineProperty(exports, "ASP_TREE_DEPTH", {
2767
2919
  enumerable: true,
@@ -2800,6 +2952,7 @@ exports.renderAvatarSVG = renderAvatarSVG;
2800
2952
  exports.storePersonalASPId = storePersonalASPId;
2801
2953
  exports.usePersonalASP = usePersonalASP;
2802
2954
  exports.usePoolTransfer = usePoolTransfer;
2955
+ exports.usePrivateBalance = usePrivateBalance;
2803
2956
  exports.useProofWorker = useProofWorker;
2804
2957
  exports.useShield = useShield;
2805
2958
  exports.useSwap = useSwap;