@0xbow/privacy-pools-core-sdk 1.0.2 → 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 (33) hide show
  1. package/dist/esm/{fetchArtifacts.esm-D0mKkSYH.js → fetchArtifacts.esm-C_DNv-_D.js} +2 -2
  2. package/dist/esm/{fetchArtifacts.esm-D0mKkSYH.js.map → fetchArtifacts.esm-C_DNv-_D.js.map} +1 -1
  3. package/dist/esm/{fetchArtifacts.node-D2RwI1ei.js → fetchArtifacts.node-BBPNjgiT.js} +2 -2
  4. package/dist/esm/{fetchArtifacts.node-D2RwI1ei.js.map → fetchArtifacts.node-BBPNjgiT.js.map} +1 -1
  5. package/dist/esm/{index-CysEkDfm.js → index-BxzIe_IR.js} +43 -11
  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-GuREmUVE.js → fetchArtifacts.esm-l-EDo53-.js} +2 -2
  10. package/dist/node/{fetchArtifacts.esm-GuREmUVE.js.map → fetchArtifacts.esm-l-EDo53-.js.map} +1 -1
  11. package/dist/node/{fetchArtifacts.node-80qrImLq.js → fetchArtifacts.node-DYwQHSF4.js} +2 -2
  12. package/dist/node/{fetchArtifacts.node-80qrImLq.js.map → fetchArtifacts.node-DYwQHSF4.js.map} +1 -1
  13. package/dist/node/{index-bIu80opN.js → index-DGsIfUGw.js} +43 -11
  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-Ok2Ropox.js → fetchArtifacts.esm-IMTIZwq7.js} +1 -1
  18. package/dist/types/{fetchArtifacts.node-DpNFJc75.js → fetchArtifacts.node-BcXsBNCT.js} +1 -1
  19. package/dist/types/{index-xpjDqElC.js → index-DbuAhDci.js} +42 -10
  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/data.service.ts +8 -6
  25. package/src/utils/concurrency.ts +32 -0
  26. package/dist/esm/index-CysEkDfm.js.map +0 -1
  27. package/dist/node/artifacts/commitment.vkey +0 -109
  28. package/dist/node/artifacts/commitment.wasm +0 -0
  29. package/dist/node/artifacts/commitment.zkey +0 -0
  30. package/dist/node/artifacts/withdraw.vkey +0 -129
  31. package/dist/node/artifacts/withdraw.wasm +0 -0
  32. package/dist/node/artifacts/withdraw.zkey +0 -0
  33. package/dist/node/index-bIu80opN.js.map +0 -1
@@ -1,4 +1,4 @@
1
- export { n as AccountError, A as AccountService, B as BlockchainProvider, o as CircuitName, j as Circuits, C as CommitmentService, m as ContractError, k as ContractInteractionsService, D as DataService, E as ErrorCode, I as InvalidRpcUrl, P as PrivacyPoolSDK, l as ProofError, S as SDKError, W as WithdrawalService, e as bigintToHash, f as bigintToHex, i as calculateContext, a as generateDepositSecrets, g as generateMasterKeys, d as generateMerkleProof, b as generateWithdrawalSecrets, c as getCommitment, h as hashPrecommitment } from './index-CysEkDfm.js';
1
+ export { n as AccountError, A as AccountService, B as BlockchainProvider, o as CircuitName, j as Circuits, C as CommitmentService, m as ContractError, k as ContractInteractionsService, D as DataService, E as ErrorCode, I as InvalidRpcUrl, P as PrivacyPoolSDK, l as ProofError, S as SDKError, W as WithdrawalService, e as bigintToHash, f as bigintToHex, i as calculateContext, a as generateDepositSecrets, g as generateMasterKeys, d as generateMerkleProof, b as generateWithdrawalSecrets, c as getCommitment, h as hashPrecommitment } from './index-BxzIe_IR.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'assert';
package/dist/index.d.mts CHANGED
@@ -1099,13 +1099,14 @@ declare class AccountService {
1099
1099
  */
1100
1100
  getRagequitEvents(pool: PoolInfo): Promise<Map<Hash, RagequitEvent>>;
1101
1101
  /**
1102
- * Fetches events for a given set of pools
1102
+ * Fetches events for a given set of pools with concurrency control
1103
1103
  *
1104
1104
  * @param pools - The pools to fetch events for
1105
+ * @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
1105
1106
  *
1106
1107
  * @returns A map of pool scopes to their events
1107
1108
  */
1108
- getEvents(pools: PoolInfo[]): Promise<PoolEventsResult>;
1109
+ getEvents(pools: PoolInfo[], maxConcurrency?: number): Promise<PoolEventsResult>;
1109
1110
  /**
1110
1111
  * Processes deposit events for a given scope and adds them to the account
1111
1112
  * Deterministically generate deposit secrets and check if they match on-chain deposits
@@ -1155,10 +1156,11 @@ declare class AccountService {
1155
1156
  * @param dataService - The data service to use for fetching events
1156
1157
  * @param source - The source to use for initializing the account. Either a mnemonic or an existing account service instance
1157
1158
  * @param pools - The pools to fetch events for
1159
+ * @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
1158
1160
  *
1159
1161
  * @remarks
1160
1162
  * This method performs the following steps for each pool:
1161
- * 1. Fetches deposit, withdrawal, and ragequit events for each pool
1163
+ * 1. Fetches deposit, withdrawal, and ragequit events for each pool (with concurrency control)
1162
1164
  * 2. Processes deposit events and creates pool accounts
1163
1165
  * 3. Processes withdrawal events and adds commitments to pool accounts
1164
1166
  * 4. Processes ragequit events and adds ragequit to pool accounts
@@ -1174,7 +1176,7 @@ declare class AccountService {
1174
1176
  mnemonic: string;
1175
1177
  } | {
1176
1178
  service: AccountService;
1177
- }, pools: PoolInfo[]): Promise<{
1179
+ }, pools: PoolInfo[], maxConcurrency?: number): Promise<{
1178
1180
  account: AccountService;
1179
1181
  errors: PoolEventsError[];
1180
1182
  }>;
@@ -1,4 +1,4 @@
1
- import { F as FetchArtifact } from './index-bIu80opN.js';
1
+ import { F as FetchArtifact } from './index-DGsIfUGw.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'http';
@@ -32,4 +32,4 @@ async function fetchVersionedArtifact(artifactUrl) {
32
32
  }
33
33
 
34
34
  export { fetchVersionedArtifact };
35
- //# sourceMappingURL=fetchArtifacts.esm-GuREmUVE.js.map
35
+ //# sourceMappingURL=fetchArtifacts.esm-l-EDo53-.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchArtifacts.esm-GuREmUVE.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-l-EDo53-.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-bIu80opN.js';
1
+ import { F as FetchArtifact } from './index-DGsIfUGw.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'http';
@@ -45,4 +45,4 @@ async function fetchVersionedArtifact(artifactUrl) {
45
45
  }
46
46
 
47
47
  export { fetchVersionedArtifact };
48
- //# sourceMappingURL=fetchArtifacts.node-80qrImLq.js.map
48
+ //# sourceMappingURL=fetchArtifacts.node-DYwQHSF4.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchArtifacts.node-80qrImLq.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-DYwQHSF4.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;;;;"}
@@ -51070,10 +51070,10 @@ const circuitToAsset = {
51070
51070
 
51071
51071
  async function importFetchVersionedArtifact(isBrowser) {
51072
51072
  if (isBrowser) {
51073
- return import('./fetchArtifacts.esm-GuREmUVE.js');
51073
+ return import('./fetchArtifacts.esm-l-EDo53-.js');
51074
51074
  }
51075
51075
  else {
51076
- return import('./fetchArtifacts.node-80qrImLq.js');
51076
+ return import('./fetchArtifacts.node-DYwQHSF4.js');
51077
51077
  }
51078
51078
  }
51079
51079
 
@@ -76371,6 +76371,31 @@ class Logger {
76371
76371
  }
76372
76372
  }
76373
76373
 
76374
+ /**
76375
+ * Executes an array of promise-returning functions with a maximum concurrency limit.
76376
+ * This prevents overwhelming RPC endpoints with too many concurrent requests.
76377
+ *
76378
+ * @param tasks - Array of functions that return promises
76379
+ * @param maxConcurrency - Maximum number of concurrent executions (default: 5)
76380
+ * @returns Promise that resolves to an array of settled results
76381
+ *
76382
+ * @example
76383
+ * ```typescript
76384
+ * const tasks = pools.map(pool => () => fetchPoolData(pool));
76385
+ * const results = await batchWithConcurrency(tasks, 5);
76386
+ * ```
76387
+ */
76388
+ async function batchWithConcurrency(tasks, maxConcurrency = 5) {
76389
+ const results = [];
76390
+ // Process tasks in batches
76391
+ for (let i = 0; i < tasks.length; i += maxConcurrency) {
76392
+ const batch = tasks.slice(i, i + maxConcurrency);
76393
+ const batchResults = await Promise.allSettled(batch.map(task => task()));
76394
+ results.push(...batchResults);
76395
+ }
76396
+ return results;
76397
+ }
76398
+
76374
76399
  class DataError extends SDKError {
76375
76400
  constructor(message, code = ErrorCode.NETWORK_ERROR, details) {
76376
76401
  super(message, code, details);
@@ -76814,15 +76839,17 @@ class AccountService {
76814
76839
  }
76815
76840
  }
76816
76841
  /**
76817
- * Fetches events for a given set of pools
76842
+ * Fetches events for a given set of pools with concurrency control
76818
76843
  *
76819
76844
  * @param pools - The pools to fetch events for
76845
+ * @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
76820
76846
  *
76821
76847
  * @returns A map of pool scopes to their events
76822
76848
  */
76823
- async getEvents(pools) {
76849
+ async getEvents(pools, maxConcurrency = 5) {
76824
76850
  const events = new Map();
76825
- const poolEventResults = await Promise.allSettled(pools.map(async (pool) => {
76851
+ // Create tasks for batched execution
76852
+ const tasks = pools.map((pool) => async () => {
76826
76853
  this.logger.info(`Fetching events for pool`, {
76827
76854
  poolAddress: pool.address,
76828
76855
  poolChainId: pool.chainId,
@@ -76839,7 +76866,9 @@ class AccountService {
76839
76866
  withdrawalEvents,
76840
76867
  ragequitEvents,
76841
76868
  };
76842
- }));
76869
+ });
76870
+ // Execute with concurrency control
76871
+ const poolEventResults = await batchWithConcurrency(tasks, maxConcurrency);
76843
76872
  for (const result of poolEventResults) {
76844
76873
  if (result.status === "fulfilled") {
76845
76874
  const { scope, depositEvents, withdrawalEvents, ragequitEvents } = result.value;
@@ -76978,10 +77007,11 @@ class AccountService {
76978
77007
  * @param dataService - The data service to use for fetching events
76979
77008
  * @param source - The source to use for initializing the account. Either a mnemonic or an existing account service instance
76980
77009
  * @param pools - The pools to fetch events for
77010
+ * @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
76981
77011
  *
76982
77012
  * @remarks
76983
77013
  * This method performs the following steps for each pool:
76984
- * 1. Fetches deposit, withdrawal, and ragequit events for each pool
77014
+ * 1. Fetches deposit, withdrawal, and ragequit events for each pool (with concurrency control)
76985
77015
  * 2. Processes deposit events and creates pool accounts
76986
77016
  * 3. Processes withdrawal events and adds commitments to pool accounts
76987
77017
  * 4. Processes ragequit events and adds ragequit to pool accounts
@@ -76993,7 +77023,7 @@ class AccountService {
76993
77023
  *
76994
77024
  * @throws {AccountError} If account state reconstruction fails or if duplicate pools are found
76995
77025
  */
76996
- static async initializeWithEvents(dataService, source, pools) {
77026
+ static async initializeWithEvents(dataService, source, pools, maxConcurrency = 5) {
76997
77027
  // Log the start of the history retrieval process
76998
77028
  const logger = new Logger({ prefix: "Account" });
76999
77029
  logger.info(`Fetching events for pools`, { poolLength: pools.length });
@@ -77009,7 +77039,7 @@ class AccountService {
77009
77039
  const account = new AccountService(dataService, "mnemonic" in source
77010
77040
  ? { mnemonic: source.mnemonic }
77011
77041
  : { account: source.service.account });
77012
- const events = await account.getEvents(pools);
77042
+ const events = await account.getEvents(pools, maxConcurrency);
77013
77043
  for (const [scope, result] of events.entries()) {
77014
77044
  if ("reason" in result) {
77015
77045
  errors.push(result);
@@ -77220,7 +77250,9 @@ class DataService {
77220
77250
  throw new Error(`Missing RPC URL for chain ${config.chainId}`);
77221
77251
  }
77222
77252
  const client = createPublicClient({
77223
- transport: http(config.rpcUrl),
77253
+ transport: http(config.rpcUrl, {
77254
+ timeout: 20_000,
77255
+ }),
77224
77256
  });
77225
77257
  this.clients.set(config.chainId, client);
77226
77258
  }
@@ -77396,4 +77428,4 @@ class DataService {
77396
77428
  }
77397
77429
 
77398
77430
  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 };
77399
- //# sourceMappingURL=index-bIu80opN.js.map
77431
+ //# sourceMappingURL=index-DGsIfUGw.js.map