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

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-aHubC6Nb.js → fetchArtifacts.esm-B6qveiM8.js} +2 -2
  2. package/dist/esm/{fetchArtifacts.esm-aHubC6Nb.js.map → fetchArtifacts.esm-B6qveiM8.js.map} +1 -1
  3. package/dist/esm/{fetchArtifacts.node-DUdhNM9Z.js → fetchArtifacts.node-BPQQPsnb.js} +2 -2
  4. package/dist/esm/{fetchArtifacts.node-DUdhNM9Z.js.map → fetchArtifacts.node-BPQQPsnb.js.map} +1 -1
  5. package/dist/esm/{index-BQLhaPQL.js → index-CRtEyHEf.js} +2880 -78
  6. package/dist/esm/index-CRtEyHEf.js.map +1 -0
  7. package/dist/esm/index.mjs +1 -1
  8. package/dist/index.d.mts +83 -8
  9. package/dist/node/{fetchArtifacts.esm-CRX34p8g.js → fetchArtifacts.esm-z-KXbilc.js} +2 -2
  10. package/dist/node/{fetchArtifacts.esm-CRX34p8g.js.map → fetchArtifacts.esm-z-KXbilc.js.map} +1 -1
  11. package/dist/node/{fetchArtifacts.node-CuPs4jZ1.js → fetchArtifacts.node-DvqhqpW9.js} +2 -2
  12. package/dist/node/{fetchArtifacts.node-CuPs4jZ1.js.map → fetchArtifacts.node-DvqhqpW9.js.map} +1 -1
  13. package/dist/node/{index-DB1uYJPF.js → index-BsmEKESv.js} +2880 -78
  14. package/dist/node/index-BsmEKESv.js.map +1 -0
  15. package/dist/node/index.mjs +1 -1
  16. package/dist/types/core/account.service.d.ts +4 -0
  17. package/dist/types/core/data.service.d.ts +28 -8
  18. package/dist/types/{fetchArtifacts.esm-CzBDJOwj.js → fetchArtifacts.esm-DF01Zpo3.js} +1 -1
  19. package/dist/types/{fetchArtifacts.node-CtMsXhR9.js → fetchArtifacts.node-BO6FBCAw.js} +1 -1
  20. package/dist/types/{index-BL6xN-P5.js → index-CH7gk4sK.js} +2879 -77
  21. package/dist/types/index.js +1 -1
  22. package/dist/types/types/index.d.ts +1 -0
  23. package/dist/types/types/rateLimit.d.ts +51 -0
  24. package/package.json +4 -1
  25. package/src/core/account.service.ts +46 -24
  26. package/src/core/contracts.service.ts +2 -6
  27. package/src/core/data.service.ts +324 -95
  28. package/src/providers/blockchainProvider.ts +1 -3
  29. package/src/types/index.ts +1 -0
  30. package/src/types/rateLimit.ts +66 -0
  31. package/dist/esm/index-BQLhaPQL.js.map +0 -1
  32. package/dist/node/index-DB1uYJPF.js.map +0 -1
  33. 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-BL6xN-P5.js';
1
+ export { o as AccountError, A as AccountService, B as BlockchainProvider, p as CircuitName, k as Circuits, C as CommitmentService, n as ContractError, l as ContractInteractionsService, a as DEFAULT_LOG_FETCH_CONFIG, D as DataService, E as ErrorCode, I as InvalidRpcUrl, P as PrivacyPoolSDK, m as ProofError, S as SDKError, W as WithdrawalService, f as bigintToHash, i as bigintToHex, j as calculateContext, b as generateDepositSecrets, g as generateMasterKeys, e as generateMerkleProof, c as generateWithdrawalSecrets, d as getCommitment, h as hashPrecommitment } from './index-CH7gk4sK.js';
2
2
  import 'viem/accounts';
3
3
  import 'buffer';
4
4
  import 'http';
@@ -1,3 +1,4 @@
1
1
  export * from "./commitment.js";
2
2
  export * from "./withdrawal.js";
3
3
  export * from "./keys.js";
4
+ export * from "./rateLimit.js";
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Configuration options for rate-limited log fetching
3
+ */
4
+ export interface LogFetchConfig {
5
+ /**
6
+ * Maximum number of blocks to fetch in a single RPC call.
7
+ * Default: 10000 (typical limit for most RPC providers)
8
+ */
9
+ blockChunkSize: number;
10
+ /**
11
+ * Maximum number of concurrent log fetch operations.
12
+ * Default: 3
13
+ */
14
+ concurrency: number;
15
+ /**
16
+ * Delay in milliseconds between chunk requests (for additional throttling).
17
+ * Default: 0 (no delay)
18
+ */
19
+ chunkDelayMs: number;
20
+ /**
21
+ * Whether to retry failed chunk fetches.
22
+ * Default: true
23
+ */
24
+ retryOnFailure: boolean;
25
+ /**
26
+ * Maximum number of retries for a failed chunk.
27
+ * Default: 3
28
+ */
29
+ maxRetries: number;
30
+ /**
31
+ * Base delay for exponential backoff on retries (ms).
32
+ * Default: 1000
33
+ */
34
+ retryBaseDelayMs: number;
35
+ }
36
+ /**
37
+ * Default log fetch configuration
38
+ */
39
+ export declare const DEFAULT_LOG_FETCH_CONFIG: LogFetchConfig;
40
+ /**
41
+ * Per-chain log fetch configuration map
42
+ * Maps chainId to its specific LogFetchConfig
43
+ */
44
+ export type ChainLogFetchConfig = Map<number, Partial<LogFetchConfig>>;
45
+ /**
46
+ * Block range for chunked fetching
47
+ */
48
+ export interface BlockRange {
49
+ fromBlock: bigint;
50
+ toBlock: bigint;
51
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xbow/privacy-pools-core-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "Typescript SDK for the Privacy Pool protocol",
5
5
  "repository": "https://github.com/0xbow-io/privacy-pools-core",
6
6
  "license": "Apache-2.0",
@@ -50,6 +50,8 @@
50
50
  "dependencies": {
51
51
  "@types/snarkjs": "0.7.9",
52
52
  "@zk-kit/lean-imt": "2.2.4",
53
+ "async": "3.2.6",
54
+ "dotenv": "17.3.1",
53
55
  "maci-crypto": "2.5.0",
54
56
  "snarkjs": "0.7.5",
55
57
  "typescript": "^5.7.3",
@@ -66,6 +68,7 @@
66
68
  "@rollup/plugin-node-resolve": "16.0.0",
67
69
  "@rollup/plugin-typescript": "12.1.2",
68
70
  "@rollup/plugin-wasm": "6.2.2",
71
+ "@types/async": "3.2.24",
69
72
  "@types/node": "20.3.1",
70
73
  "@types/snarkjs": "0.7.9",
71
74
  "commitlint": "19.4.1",
@@ -2,6 +2,7 @@ import { poseidon } from "maci-crypto/build/ts/hashing.js";
2
2
  import { Hash, Secret } from "../types/commitment.js";
3
3
  import { Hex, bytesToNumber } from "viem";
4
4
  import { mnemonicToAccount } from "viem/accounts";
5
+ import { mapLimit } from "async";
5
6
  import { DataService } from "./data.service.js";
6
7
  import {
7
8
  AccountCommitment,
@@ -25,9 +26,11 @@ import { EventError } from "../errors/events.error.js";
25
26
  type AccountServiceConfig =
26
27
  | {
27
28
  mnemonic: string;
29
+ poolConcurrency?: number;
28
30
  }
29
31
  | {
30
32
  account: PrivacyPoolAccount;
33
+ poolConcurrency?: number;
31
34
  };
32
35
 
33
36
  /**
@@ -41,6 +44,7 @@ type AccountServiceConfig =
41
44
  export class AccountService {
42
45
  account: PrivacyPoolAccount;
43
46
  private readonly logger: Logger;
47
+ private readonly poolConcurrency: number;
44
48
 
45
49
  /**
46
50
  * Creates a new AccountService instance.
@@ -49,6 +53,7 @@ export class AccountService {
49
53
  * @param config - Configuration for the account service (either mnemonic or existing account)
50
54
  * @param config.mnemonic - Optional mnemonic for deterministic key generation
51
55
  * @param config.account - Optional existing account to initialize with
56
+ * @param config.poolConcurrency - Optional maximum number of pools to fetch events for concurrently (default: 2)
52
57
  *
53
58
  * @throws {AccountError} If account initialization fails
54
59
  */
@@ -57,6 +62,7 @@ export class AccountService {
57
62
  config: AccountServiceConfig
58
63
  ) {
59
64
  this.logger = new Logger({ prefix: "Account" });
65
+ this.poolConcurrency = config.poolConcurrency ?? 2;
60
66
  if ("mnemonic" in config) {
61
67
  this.account = this._initializeAccount(config.mnemonic);
62
68
  } else {
@@ -570,28 +576,41 @@ export class AccountService {
570
576
  public async getEvents(pools: PoolInfo[]): Promise<PoolEventsResult> {
571
577
  const events: PoolEventsResult = new Map();
572
578
 
573
- const poolEventResults = await Promise.allSettled(
574
- pools.map(async (pool) => {
575
- this.logger.info(`Fetching events for pool`, {
576
- poolAddress: pool.address,
577
- poolChainId: pool.chainId,
578
- poolDeploymentBlock: pool.deploymentBlock,
579
- });
580
-
581
- const [depositEvents, withdrawalEvents, ragequitEvents] =
582
- await Promise.all([
583
- this.getDepositEvents(pool),
584
- this.getWithdrawalEvents(pool),
585
- this.getRagequitEvents(pool),
586
- ]);
587
-
588
- return {
589
- scope: pool.scope,
590
- depositEvents,
591
- withdrawalEvents,
592
- ragequitEvents,
593
- };
594
- })
579
+ // Use mapLimit to control concurrency at pool level
580
+ const poolEventResults = await mapLimit(
581
+ pools,
582
+ this.poolConcurrency,
583
+ async (pool: PoolInfo) => {
584
+ try {
585
+ this.logger.info(`Fetching events for pool`, {
586
+ poolAddress: pool.address,
587
+ poolChainId: pool.chainId,
588
+ poolDeploymentBlock: pool.deploymentBlock,
589
+ });
590
+
591
+ const [depositEvents, withdrawalEvents, ragequitEvents] =
592
+ await Promise.all([
593
+ this.getDepositEvents(pool),
594
+ this.getWithdrawalEvents(pool),
595
+ this.getRagequitEvents(pool),
596
+ ]);
597
+
598
+ return {
599
+ status: "fulfilled" as const,
600
+ value: {
601
+ scope: pool.scope,
602
+ depositEvents,
603
+ withdrawalEvents,
604
+ ragequitEvents,
605
+ },
606
+ };
607
+ } catch (error) {
608
+ return {
609
+ status: "rejected" as const,
610
+ reason: error as Error,
611
+ };
612
+ }
613
+ }
595
614
  );
596
615
 
597
616
  for (const result of poolEventResults) {
@@ -604,9 +623,12 @@ export class AccountService {
604
623
  ragequitEvents,
605
624
  });
606
625
  } else {
607
- events.set(result.reason.details?.scope as Hash, {
626
+ const errorWithDetails = result.reason as Error & { details?: { scope?: Hash } };
627
+ const scope = errorWithDetails.details?.scope as Hash;
628
+
629
+ events.set(scope, {
608
630
  reason: result.reason.message,
609
- scope: result.reason.details?.scope as Hash,
631
+ scope: scope,
610
632
  });
611
633
  }
612
634
  }
@@ -55,17 +55,13 @@ export class ContractInteractionsService implements ContractInteractions {
55
55
 
56
56
  this.walletClient = createWalletClient({
57
57
  chain: chain,
58
- transport: http(rpcUrl, {
59
- timeout: 20_000,
60
- }),
58
+ transport: http(rpcUrl),
61
59
  account: this.account,
62
60
  });
63
61
 
64
62
  this.publicClient = createPublicClient({
65
63
  chain: chain,
66
- transport: http(rpcUrl, {
67
- timeout: 20_000,
68
- }),
64
+ transport: http(rpcUrl),
69
65
  });
70
66
 
71
67
  this.entrypointAddress = entrypointAddress;