@0xbow/privacy-pools-core-sdk 1.0.3 → 1.0.4

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 (29) hide show
  1. package/dist/esm/{fetchArtifacts.esm-aHubC6Nb.js → fetchArtifacts.esm-C_DNv-_D.js} +2 -2
  2. package/dist/esm/{fetchArtifacts.esm-aHubC6Nb.js.map → fetchArtifacts.esm-C_DNv-_D.js.map} +1 -1
  3. package/dist/esm/{fetchArtifacts.node-DUdhNM9Z.js → fetchArtifacts.node-BBPNjgiT.js} +2 -2
  4. package/dist/esm/{fetchArtifacts.node-DUdhNM9Z.js.map → fetchArtifacts.node-BBPNjgiT.js.map} +1 -1
  5. package/dist/esm/{index-BQLhaPQL.js → index-BxzIe_IR.js} +44 -19
  6. package/dist/esm/index-BxzIe_IR.js.map +1 -0
  7. package/dist/esm/index.mjs +1 -1
  8. package/dist/index.d.mts +6 -4
  9. package/dist/node/{fetchArtifacts.esm-CRX34p8g.js → fetchArtifacts.esm-l-EDo53-.js} +2 -2
  10. package/dist/node/{fetchArtifacts.esm-CRX34p8g.js.map → fetchArtifacts.esm-l-EDo53-.js.map} +1 -1
  11. package/dist/node/{fetchArtifacts.node-CuPs4jZ1.js → fetchArtifacts.node-DYwQHSF4.js} +2 -2
  12. package/dist/node/{fetchArtifacts.node-CuPs4jZ1.js.map → fetchArtifacts.node-DYwQHSF4.js.map} +1 -1
  13. package/dist/node/{index-DB1uYJPF.js → index-DGsIfUGw.js} +44 -19
  14. package/dist/node/index-DGsIfUGw.js.map +1 -0
  15. package/dist/node/index.mjs +1 -1
  16. package/dist/types/core/account.service.d.ts +6 -4
  17. package/dist/types/{fetchArtifacts.esm-CzBDJOwj.js → fetchArtifacts.esm-IMTIZwq7.js} +1 -1
  18. package/dist/types/{fetchArtifacts.node-CtMsXhR9.js → fetchArtifacts.node-BcXsBNCT.js} +1 -1
  19. package/dist/types/{index-BL6xN-P5.js → index-DbuAhDci.js} +43 -18
  20. package/dist/types/index.js +1 -1
  21. package/dist/types/utils/concurrency.d.ts +15 -0
  22. package/package.json +2 -1
  23. package/src/core/account.service.ts +35 -26
  24. package/src/core/contracts.service.ts +2 -6
  25. package/src/providers/blockchainProvider.ts +1 -3
  26. package/src/utils/concurrency.ts +32 -0
  27. package/dist/esm/index-BQLhaPQL.js.map +0 -1
  28. package/dist/node/index-DB1uYJPF.js.map +0 -1
  29. package/dist/types/core/test.d.ts +0 -1
@@ -1,4 +1,4 @@
1
- import { F as FetchArtifact } from './index-BQLhaPQL.js';
1
+ import { F as FetchArtifact } from './index-BxzIe_IR.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'assert';
@@ -15,4 +15,4 @@ async function fetchVersionedArtifact(artifactUrl) {
15
15
  }
16
16
 
17
17
  export { fetchVersionedArtifact };
18
- //# sourceMappingURL=fetchArtifacts.esm-aHubC6Nb.js.map
18
+ //# sourceMappingURL=fetchArtifacts.esm-C_DNv-_D.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchArtifacts.esm-aHubC6Nb.js","sources":["../../src/circuits/fetchArtifacts.esm.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAEO,eAAe,sBAAsB,CAC1C,WAAgB,EAAA;AAEhB,IAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC;AACpC,IAAA,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;AACtB,QAAA,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC;;AAEtC,IAAA,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,WAAW,EAAE;AACpC,IAAA,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC;AAC7B;;;;"}
1
+ {"version":3,"file":"fetchArtifacts.esm-C_DNv-_D.js","sources":["../../src/circuits/fetchArtifacts.esm.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAEO,eAAe,sBAAsB,CAC1C,WAAgB,EAAA;AAEhB,IAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC;AACpC,IAAA,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;AACtB,QAAA,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC;;AAEtC,IAAA,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,WAAW,EAAE;AACpC,IAAA,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC;AAC7B;;;;"}
@@ -1,4 +1,4 @@
1
- import { F as FetchArtifact } from './index-BQLhaPQL.js';
1
+ import { F as FetchArtifact } from './index-BxzIe_IR.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'assert';
@@ -28,4 +28,4 @@ async function fetchVersionedArtifact(artifactUrl) {
28
28
  }
29
29
 
30
30
  export { fetchVersionedArtifact };
31
- //# sourceMappingURL=fetchArtifacts.node-DUdhNM9Z.js.map
31
+ //# sourceMappingURL=fetchArtifacts.node-BBPNjgiT.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchArtifacts.node-DUdhNM9Z.js","sources":["../../src/circuits/fetchArtifacts.node.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAEO,eAAe,sBAAsB,CAC1C,WAAgB,EAAA;AAEhB,IAAA,IAAI;QACF,MAAM,EAAE,GAAG,CAAC,MAAM,OAAO,IAAI,CAAC,EAAE,OAAO;QACvC,MAAM,WAAW,GAAoB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;AACnE,YAAA,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,KAAI;gBAC9C,IAAI,GAAG,EAAE;oBACP,MAAM,CAAC,GAAG,CAAC;;qBACN;oBACL,OAAO,CAAC,IAAI,CAAC;;AAEjB,aAAC,CAAC;AACJ,SAAC,CAAC;AACF,QAAA,MAAM,GAAG,GAAG,MAAM,WAAW;AAC7B,QAAA,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC;;IAC1B,OAAO,KAAK,EAAE;AACd,QAAA,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;AACpB,QAAA,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC;;AAExC;;;;"}
1
+ {"version":3,"file":"fetchArtifacts.node-BBPNjgiT.js","sources":["../../src/circuits/fetchArtifacts.node.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAEO,eAAe,sBAAsB,CAC1C,WAAgB,EAAA;AAEhB,IAAA,IAAI;QACF,MAAM,EAAE,GAAG,CAAC,MAAM,OAAO,IAAI,CAAC,EAAE,OAAO;QACvC,MAAM,WAAW,GAAoB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAI;AACnE,YAAA,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,KAAI;gBAC9C,IAAI,GAAG,EAAE;oBACP,MAAM,CAAC,GAAG,CAAC;;qBACN;oBACL,OAAO,CAAC,IAAI,CAAC;;AAEjB,aAAC,CAAC;AACJ,SAAC,CAAC;AACF,QAAA,MAAM,GAAG,GAAG,MAAM,WAAW;AAC7B,QAAA,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC;;IAC1B,OAAO,KAAK,EAAE;AACd,QAAA,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;AACpB,QAAA,MAAM,IAAI,aAAa,CAAC,WAAW,CAAC;;AAExC;;;;"}
@@ -45803,10 +45803,10 @@ const circuitToAsset = {
45803
45803
 
45804
45804
  async function importFetchVersionedArtifact(isBrowser) {
45805
45805
  if (isBrowser) {
45806
- return import('./fetchArtifacts.esm-aHubC6Nb.js');
45806
+ return import('./fetchArtifacts.esm-C_DNv-_D.js');
45807
45807
  }
45808
45808
  else {
45809
- return import('./fetchArtifacts.node-DUdhNM9Z.js');
45809
+ return import('./fetchArtifacts.node-BBPNjgiT.js');
45810
45810
  }
45811
45811
  }
45812
45812
 
@@ -69321,6 +69321,31 @@ class Logger {
69321
69321
  }
69322
69322
  }
69323
69323
 
69324
+ /**
69325
+ * Executes an array of promise-returning functions with a maximum concurrency limit.
69326
+ * This prevents overwhelming RPC endpoints with too many concurrent requests.
69327
+ *
69328
+ * @param tasks - Array of functions that return promises
69329
+ * @param maxConcurrency - Maximum number of concurrent executions (default: 5)
69330
+ * @returns Promise that resolves to an array of settled results
69331
+ *
69332
+ * @example
69333
+ * ```typescript
69334
+ * const tasks = pools.map(pool => () => fetchPoolData(pool));
69335
+ * const results = await batchWithConcurrency(tasks, 5);
69336
+ * ```
69337
+ */
69338
+ async function batchWithConcurrency(tasks, maxConcurrency = 5) {
69339
+ const results = [];
69340
+ // Process tasks in batches
69341
+ for (let i = 0; i < tasks.length; i += maxConcurrency) {
69342
+ const batch = tasks.slice(i, i + maxConcurrency);
69343
+ const batchResults = await Promise.allSettled(batch.map(task => task()));
69344
+ results.push(...batchResults);
69345
+ }
69346
+ return results;
69347
+ }
69348
+
69324
69349
  class DataError extends SDKError {
69325
69350
  constructor(message, code = ErrorCode.NETWORK_ERROR, details) {
69326
69351
  super(message, code, details);
@@ -69377,7 +69402,7 @@ class AccountService {
69377
69402
  */
69378
69403
  constructor(dataService, config) {
69379
69404
  this.dataService = dataService;
69380
- this.logger = new Logger({ prefix: "Account", level: LogLevel.DEBUG });
69405
+ this.logger = new Logger({ prefix: "Account" });
69381
69406
  if ("mnemonic" in config) {
69382
69407
  this.account = this._initializeAccount(config.mnemonic);
69383
69408
  }
@@ -69592,12 +69617,6 @@ class AccountService {
69592
69617
  addPoolAccount(scope, value, nullifier, secret, label, blockNumber, txHash) {
69593
69618
  const precommitment = this._hashPrecommitment(nullifier, secret);
69594
69619
  const commitment = this._hashCommitment(value, label, precommitment);
69595
- this.logger.debug(`Commitment calculation details`, {
69596
- value,
69597
- label,
69598
- precommitment,
69599
- commitment,
69600
- });
69601
69620
  const newAccount = {
69602
69621
  label,
69603
69622
  deposit: {
@@ -69663,7 +69682,6 @@ class AccountService {
69663
69682
  blockNumber,
69664
69683
  txHash,
69665
69684
  };
69666
- this.logger.debug(`adding the following commitment`, { precommitment, hash: this._hashCommitment(value, parentCommitment.label, precommitment), });
69667
69685
  foundAccount.children.push(newCommitment);
69668
69686
  this.logger.info(`Added new commitment with value ${value} to account with label ${parentCommitment.label}`);
69669
69687
  return newCommitment;
@@ -69771,15 +69789,17 @@ class AccountService {
69771
69789
  }
69772
69790
  }
69773
69791
  /**
69774
- * Fetches events for a given set of pools
69792
+ * Fetches events for a given set of pools with concurrency control
69775
69793
  *
69776
69794
  * @param pools - The pools to fetch events for
69795
+ * @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
69777
69796
  *
69778
69797
  * @returns A map of pool scopes to their events
69779
69798
  */
69780
- async getEvents(pools) {
69799
+ async getEvents(pools, maxConcurrency = 5) {
69781
69800
  const events = new Map();
69782
- const poolEventResults = await Promise.allSettled(pools.map(async (pool) => {
69801
+ // Create tasks for batched execution
69802
+ const tasks = pools.map((pool) => async () => {
69783
69803
  this.logger.info(`Fetching events for pool`, {
69784
69804
  poolAddress: pool.address,
69785
69805
  poolChainId: pool.chainId,
@@ -69796,7 +69816,9 @@ class AccountService {
69796
69816
  withdrawalEvents,
69797
69817
  ragequitEvents,
69798
69818
  };
69799
- }));
69819
+ });
69820
+ // Execute with concurrency control
69821
+ const poolEventResults = await batchWithConcurrency(tasks, maxConcurrency);
69800
69822
  for (const result of poolEventResults) {
69801
69823
  if (result.status === "fulfilled") {
69802
69824
  const { scope, depositEvents, withdrawalEvents, ragequitEvents } = result.value;
@@ -69935,10 +69957,11 @@ class AccountService {
69935
69957
  * @param dataService - The data service to use for fetching events
69936
69958
  * @param source - The source to use for initializing the account. Either a mnemonic or an existing account service instance
69937
69959
  * @param pools - The pools to fetch events for
69960
+ * @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
69938
69961
  *
69939
69962
  * @remarks
69940
69963
  * This method performs the following steps for each pool:
69941
- * 1. Fetches deposit, withdrawal, and ragequit events for each pool
69964
+ * 1. Fetches deposit, withdrawal, and ragequit events for each pool (with concurrency control)
69942
69965
  * 2. Processes deposit events and creates pool accounts
69943
69966
  * 3. Processes withdrawal events and adds commitments to pool accounts
69944
69967
  * 4. Processes ragequit events and adds ragequit to pool accounts
@@ -69950,7 +69973,7 @@ class AccountService {
69950
69973
  *
69951
69974
  * @throws {AccountError} If account state reconstruction fails or if duplicate pools are found
69952
69975
  */
69953
- static async initializeWithEvents(dataService, source, pools) {
69976
+ static async initializeWithEvents(dataService, source, pools, maxConcurrency = 5) {
69954
69977
  // Log the start of the history retrieval process
69955
69978
  const logger = new Logger({ prefix: "Account" });
69956
69979
  logger.info(`Fetching events for pools`, { poolLength: pools.length });
@@ -69966,7 +69989,7 @@ class AccountService {
69966
69989
  const account = new AccountService(dataService, "mnemonic" in source
69967
69990
  ? { mnemonic: source.mnemonic }
69968
69991
  : { account: source.service.account });
69969
- const events = await account.getEvents(pools);
69992
+ const events = await account.getEvents(pools, maxConcurrency);
69970
69993
  for (const [scope, result] of events.entries()) {
69971
69994
  if ("reason" in result) {
69972
69995
  errors.push(result);
@@ -70177,7 +70200,9 @@ class DataService {
70177
70200
  throw new Error(`Missing RPC URL for chain ${config.chainId}`);
70178
70201
  }
70179
70202
  const client = createPublicClient({
70180
- transport: http(config.rpcUrl),
70203
+ transport: http(config.rpcUrl, {
70204
+ timeout: 20_000,
70205
+ }),
70181
70206
  });
70182
70207
  this.clients.set(config.chainId, client);
70183
70208
  }
@@ -70353,4 +70378,4 @@ class DataService {
70353
70378
  }
70354
70379
 
70355
70380
  export { AccountService as A, BlockchainProvider as B, CommitmentService as C, DataService as D, ErrorCode as E, FetchArtifact as F, InvalidRpcUrl as I, PrivacyPoolSDK as P, SDKError as S, WithdrawalService as W, generateDepositSecrets as a, generateWithdrawalSecrets as b, getCommitment as c, generateMerkleProof as d, bigintToHash as e, bigintToHex as f, generateMasterKeys as g, hashPrecommitment as h, calculateContext as i, Circuits as j, ContractInteractionsService as k, ProofError as l, ContractError as m, AccountError as n, CircuitName as o };
70356
- //# sourceMappingURL=index-BQLhaPQL.js.map
70381
+ //# sourceMappingURL=index-BxzIe_IR.js.map