@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
- 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-BQLhaPQL.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-DB1uYJPF.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-CRX34p8g.js.map
35
+ //# sourceMappingURL=fetchArtifacts.esm-l-EDo53-.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchArtifacts.esm-CRX34p8g.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-DB1uYJPF.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-CuPs4jZ1.js.map
48
+ //# sourceMappingURL=fetchArtifacts.node-DYwQHSF4.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchArtifacts.node-CuPs4jZ1.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-CRX34p8g.js');
51073
+ return import('./fetchArtifacts.esm-l-EDo53-.js');
51074
51074
  }
51075
51075
  else {
51076
- return import('./fetchArtifacts.node-CuPs4jZ1.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);
@@ -76427,7 +76452,7 @@ class AccountService {
76427
76452
  */
76428
76453
  constructor(dataService, config) {
76429
76454
  this.dataService = dataService;
76430
- this.logger = new Logger({ prefix: "Account", level: LogLevel.DEBUG });
76455
+ this.logger = new Logger({ prefix: "Account" });
76431
76456
  if ("mnemonic" in config) {
76432
76457
  this.account = this._initializeAccount(config.mnemonic);
76433
76458
  }
@@ -76642,12 +76667,6 @@ class AccountService {
76642
76667
  addPoolAccount(scope, value, nullifier, secret, label, blockNumber, txHash) {
76643
76668
  const precommitment = this._hashPrecommitment(nullifier, secret);
76644
76669
  const commitment = this._hashCommitment(value, label, precommitment);
76645
- this.logger.debug(`Commitment calculation details`, {
76646
- value,
76647
- label,
76648
- precommitment,
76649
- commitment,
76650
- });
76651
76670
  const newAccount = {
76652
76671
  label,
76653
76672
  deposit: {
@@ -76713,7 +76732,6 @@ class AccountService {
76713
76732
  blockNumber,
76714
76733
  txHash,
76715
76734
  };
76716
- this.logger.debug(`adding the following commitment`, { precommitment, hash: this._hashCommitment(value, parentCommitment.label, precommitment), });
76717
76735
  foundAccount.children.push(newCommitment);
76718
76736
  this.logger.info(`Added new commitment with value ${value} to account with label ${parentCommitment.label}`);
76719
76737
  return newCommitment;
@@ -76821,15 +76839,17 @@ class AccountService {
76821
76839
  }
76822
76840
  }
76823
76841
  /**
76824
- * Fetches events for a given set of pools
76842
+ * Fetches events for a given set of pools with concurrency control
76825
76843
  *
76826
76844
  * @param pools - The pools to fetch events for
76845
+ * @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
76827
76846
  *
76828
76847
  * @returns A map of pool scopes to their events
76829
76848
  */
76830
- async getEvents(pools) {
76849
+ async getEvents(pools, maxConcurrency = 5) {
76831
76850
  const events = new Map();
76832
- const poolEventResults = await Promise.allSettled(pools.map(async (pool) => {
76851
+ // Create tasks for batched execution
76852
+ const tasks = pools.map((pool) => async () => {
76833
76853
  this.logger.info(`Fetching events for pool`, {
76834
76854
  poolAddress: pool.address,
76835
76855
  poolChainId: pool.chainId,
@@ -76846,7 +76866,9 @@ class AccountService {
76846
76866
  withdrawalEvents,
76847
76867
  ragequitEvents,
76848
76868
  };
76849
- }));
76869
+ });
76870
+ // Execute with concurrency control
76871
+ const poolEventResults = await batchWithConcurrency(tasks, maxConcurrency);
76850
76872
  for (const result of poolEventResults) {
76851
76873
  if (result.status === "fulfilled") {
76852
76874
  const { scope, depositEvents, withdrawalEvents, ragequitEvents } = result.value;
@@ -76985,10 +77007,11 @@ class AccountService {
76985
77007
  * @param dataService - The data service to use for fetching events
76986
77008
  * @param source - The source to use for initializing the account. Either a mnemonic or an existing account service instance
76987
77009
  * @param pools - The pools to fetch events for
77010
+ * @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
76988
77011
  *
76989
77012
  * @remarks
76990
77013
  * This method performs the following steps for each pool:
76991
- * 1. Fetches deposit, withdrawal, and ragequit events for each pool
77014
+ * 1. Fetches deposit, withdrawal, and ragequit events for each pool (with concurrency control)
76992
77015
  * 2. Processes deposit events and creates pool accounts
76993
77016
  * 3. Processes withdrawal events and adds commitments to pool accounts
76994
77017
  * 4. Processes ragequit events and adds ragequit to pool accounts
@@ -77000,7 +77023,7 @@ class AccountService {
77000
77023
  *
77001
77024
  * @throws {AccountError} If account state reconstruction fails or if duplicate pools are found
77002
77025
  */
77003
- static async initializeWithEvents(dataService, source, pools) {
77026
+ static async initializeWithEvents(dataService, source, pools, maxConcurrency = 5) {
77004
77027
  // Log the start of the history retrieval process
77005
77028
  const logger = new Logger({ prefix: "Account" });
77006
77029
  logger.info(`Fetching events for pools`, { poolLength: pools.length });
@@ -77016,7 +77039,7 @@ class AccountService {
77016
77039
  const account = new AccountService(dataService, "mnemonic" in source
77017
77040
  ? { mnemonic: source.mnemonic }
77018
77041
  : { account: source.service.account });
77019
- const events = await account.getEvents(pools);
77042
+ const events = await account.getEvents(pools, maxConcurrency);
77020
77043
  for (const [scope, result] of events.entries()) {
77021
77044
  if ("reason" in result) {
77022
77045
  errors.push(result);
@@ -77227,7 +77250,9 @@ class DataService {
77227
77250
  throw new Error(`Missing RPC URL for chain ${config.chainId}`);
77228
77251
  }
77229
77252
  const client = createPublicClient({
77230
- transport: http(config.rpcUrl),
77253
+ transport: http(config.rpcUrl, {
77254
+ timeout: 20_000,
77255
+ }),
77231
77256
  });
77232
77257
  this.clients.set(config.chainId, client);
77233
77258
  }
@@ -77403,4 +77428,4 @@ class DataService {
77403
77428
  }
77404
77429
 
77405
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 };
77406
- //# sourceMappingURL=index-DB1uYJPF.js.map
77431
+ //# sourceMappingURL=index-DGsIfUGw.js.map