@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.
- package/dist/esm/{fetchArtifacts.esm-D0mKkSYH.js → fetchArtifacts.esm-C_DNv-_D.js} +2 -2
- package/dist/esm/{fetchArtifacts.esm-D0mKkSYH.js.map → fetchArtifacts.esm-C_DNv-_D.js.map} +1 -1
- package/dist/esm/{fetchArtifacts.node-D2RwI1ei.js → fetchArtifacts.node-BBPNjgiT.js} +2 -2
- package/dist/esm/{fetchArtifacts.node-D2RwI1ei.js.map → fetchArtifacts.node-BBPNjgiT.js.map} +1 -1
- package/dist/esm/{index-CysEkDfm.js → index-BxzIe_IR.js} +43 -11
- package/dist/esm/index-BxzIe_IR.js.map +1 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/index.d.mts +6 -4
- package/dist/node/{fetchArtifacts.esm-GuREmUVE.js → fetchArtifacts.esm-l-EDo53-.js} +2 -2
- package/dist/node/{fetchArtifacts.esm-GuREmUVE.js.map → fetchArtifacts.esm-l-EDo53-.js.map} +1 -1
- package/dist/node/{fetchArtifacts.node-80qrImLq.js → fetchArtifacts.node-DYwQHSF4.js} +2 -2
- package/dist/node/{fetchArtifacts.node-80qrImLq.js.map → fetchArtifacts.node-DYwQHSF4.js.map} +1 -1
- package/dist/node/{index-bIu80opN.js → index-DGsIfUGw.js} +43 -11
- package/dist/node/index-DGsIfUGw.js.map +1 -0
- package/dist/node/index.mjs +1 -1
- package/dist/types/core/account.service.d.ts +6 -4
- package/dist/types/{fetchArtifacts.esm-Ok2Ropox.js → fetchArtifacts.esm-IMTIZwq7.js} +1 -1
- package/dist/types/{fetchArtifacts.node-DpNFJc75.js → fetchArtifacts.node-BcXsBNCT.js} +1 -1
- package/dist/types/{index-xpjDqElC.js → index-DbuAhDci.js} +42 -10
- package/dist/types/index.js +1 -1
- package/dist/types/utils/concurrency.d.ts +15 -0
- package/package.json +2 -1
- package/src/core/account.service.ts +35 -26
- package/src/core/data.service.ts +8 -6
- package/src/utils/concurrency.ts +32 -0
- package/dist/esm/index-CysEkDfm.js.map +0 -1
- package/dist/node/artifacts/commitment.vkey +0 -109
- package/dist/node/artifacts/commitment.wasm +0 -0
- package/dist/node/artifacts/commitment.zkey +0 -0
- package/dist/node/artifacts/withdraw.vkey +0 -129
- package/dist/node/artifacts/withdraw.wasm +0 -0
- package/dist/node/artifacts/withdraw.zkey +0 -0
- package/dist/node/index-bIu80opN.js.map +0 -1
package/dist/node/index.mjs
CHANGED
|
@@ -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-
|
|
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-DGsIfUGw.js';
|
|
2
2
|
import 'viem/accounts';
|
|
3
3
|
import 'buffer';
|
|
4
4
|
import 'http';
|
|
@@ -223,13 +223,14 @@ export declare class AccountService {
|
|
|
223
223
|
*/
|
|
224
224
|
getRagequitEvents(pool: PoolInfo): Promise<Map<Hash, RagequitEvent>>;
|
|
225
225
|
/**
|
|
226
|
-
* Fetches events for a given set of pools
|
|
226
|
+
* Fetches events for a given set of pools with concurrency control
|
|
227
227
|
*
|
|
228
228
|
* @param pools - The pools to fetch events for
|
|
229
|
+
* @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
|
|
229
230
|
*
|
|
230
231
|
* @returns A map of pool scopes to their events
|
|
231
232
|
*/
|
|
232
|
-
getEvents(pools: PoolInfo[]): Promise<PoolEventsResult>;
|
|
233
|
+
getEvents(pools: PoolInfo[], maxConcurrency?: number): Promise<PoolEventsResult>;
|
|
233
234
|
/**
|
|
234
235
|
* Processes deposit events for a given scope and adds them to the account
|
|
235
236
|
* Deterministically generate deposit secrets and check if they match on-chain deposits
|
|
@@ -279,10 +280,11 @@ export declare class AccountService {
|
|
|
279
280
|
* @param dataService - The data service to use for fetching events
|
|
280
281
|
* @param source - The source to use for initializing the account. Either a mnemonic or an existing account service instance
|
|
281
282
|
* @param pools - The pools to fetch events for
|
|
283
|
+
* @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
|
|
282
284
|
*
|
|
283
285
|
* @remarks
|
|
284
286
|
* This method performs the following steps for each pool:
|
|
285
|
-
* 1. Fetches deposit, withdrawal, and ragequit events for each pool
|
|
287
|
+
* 1. Fetches deposit, withdrawal, and ragequit events for each pool (with concurrency control)
|
|
286
288
|
* 2. Processes deposit events and creates pool accounts
|
|
287
289
|
* 3. Processes withdrawal events and adds commitments to pool accounts
|
|
288
290
|
* 4. Processes ragequit events and adds ragequit to pool accounts
|
|
@@ -298,7 +300,7 @@ export declare class AccountService {
|
|
|
298
300
|
mnemonic: string;
|
|
299
301
|
} | {
|
|
300
302
|
service: AccountService;
|
|
301
|
-
}, pools: PoolInfo[]): Promise<{
|
|
303
|
+
}, pools: PoolInfo[], maxConcurrency?: number): Promise<{
|
|
302
304
|
account: AccountService;
|
|
303
305
|
errors: PoolEventsError[];
|
|
304
306
|
}>;
|
|
@@ -51070,10 +51070,10 @@ const circuitToAsset = {
|
|
|
51070
51070
|
|
|
51071
51071
|
async function importFetchVersionedArtifact(isBrowser) {
|
|
51072
51072
|
if (isBrowser) {
|
|
51073
|
-
return import('./fetchArtifacts.esm-
|
|
51073
|
+
return import('./fetchArtifacts.esm-IMTIZwq7.js');
|
|
51074
51074
|
}
|
|
51075
51075
|
else {
|
|
51076
|
-
return import('./fetchArtifacts.node-
|
|
51076
|
+
return import('./fetchArtifacts.node-BcXsBNCT.js');
|
|
51077
51077
|
}
|
|
51078
51078
|
}
|
|
51079
51079
|
|
|
@@ -76385,6 +76385,31 @@ class Logger {
|
|
|
76385
76385
|
}
|
|
76386
76386
|
}
|
|
76387
76387
|
|
|
76388
|
+
/**
|
|
76389
|
+
* Executes an array of promise-returning functions with a maximum concurrency limit.
|
|
76390
|
+
* This prevents overwhelming RPC endpoints with too many concurrent requests.
|
|
76391
|
+
*
|
|
76392
|
+
* @param tasks - Array of functions that return promises
|
|
76393
|
+
* @param maxConcurrency - Maximum number of concurrent executions (default: 5)
|
|
76394
|
+
* @returns Promise that resolves to an array of settled results
|
|
76395
|
+
*
|
|
76396
|
+
* @example
|
|
76397
|
+
* ```typescript
|
|
76398
|
+
* const tasks = pools.map(pool => () => fetchPoolData(pool));
|
|
76399
|
+
* const results = await batchWithConcurrency(tasks, 5);
|
|
76400
|
+
* ```
|
|
76401
|
+
*/
|
|
76402
|
+
async function batchWithConcurrency(tasks, maxConcurrency = 5) {
|
|
76403
|
+
const results = [];
|
|
76404
|
+
// Process tasks in batches
|
|
76405
|
+
for (let i = 0; i < tasks.length; i += maxConcurrency) {
|
|
76406
|
+
const batch = tasks.slice(i, i + maxConcurrency);
|
|
76407
|
+
const batchResults = await Promise.allSettled(batch.map(task => task()));
|
|
76408
|
+
results.push(...batchResults);
|
|
76409
|
+
}
|
|
76410
|
+
return results;
|
|
76411
|
+
}
|
|
76412
|
+
|
|
76388
76413
|
class DataError extends SDKError {
|
|
76389
76414
|
constructor(message, code = ErrorCode.NETWORK_ERROR, details) {
|
|
76390
76415
|
super(message, code, details);
|
|
@@ -76828,15 +76853,17 @@ class AccountService {
|
|
|
76828
76853
|
}
|
|
76829
76854
|
}
|
|
76830
76855
|
/**
|
|
76831
|
-
* Fetches events for a given set of pools
|
|
76856
|
+
* Fetches events for a given set of pools with concurrency control
|
|
76832
76857
|
*
|
|
76833
76858
|
* @param pools - The pools to fetch events for
|
|
76859
|
+
* @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
|
|
76834
76860
|
*
|
|
76835
76861
|
* @returns A map of pool scopes to their events
|
|
76836
76862
|
*/
|
|
76837
|
-
async getEvents(pools) {
|
|
76863
|
+
async getEvents(pools, maxConcurrency = 5) {
|
|
76838
76864
|
const events = new Map();
|
|
76839
|
-
|
|
76865
|
+
// Create tasks for batched execution
|
|
76866
|
+
const tasks = pools.map((pool) => async () => {
|
|
76840
76867
|
this.logger.info(`Fetching events for pool`, {
|
|
76841
76868
|
poolAddress: pool.address,
|
|
76842
76869
|
poolChainId: pool.chainId,
|
|
@@ -76853,7 +76880,9 @@ class AccountService {
|
|
|
76853
76880
|
withdrawalEvents,
|
|
76854
76881
|
ragequitEvents,
|
|
76855
76882
|
};
|
|
76856
|
-
})
|
|
76883
|
+
});
|
|
76884
|
+
// Execute with concurrency control
|
|
76885
|
+
const poolEventResults = await batchWithConcurrency(tasks, maxConcurrency);
|
|
76857
76886
|
for (const result of poolEventResults) {
|
|
76858
76887
|
if (result.status === "fulfilled") {
|
|
76859
76888
|
const { scope, depositEvents, withdrawalEvents, ragequitEvents } = result.value;
|
|
@@ -76992,10 +77021,11 @@ class AccountService {
|
|
|
76992
77021
|
* @param dataService - The data service to use for fetching events
|
|
76993
77022
|
* @param source - The source to use for initializing the account. Either a mnemonic or an existing account service instance
|
|
76994
77023
|
* @param pools - The pools to fetch events for
|
|
77024
|
+
* @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
|
|
76995
77025
|
*
|
|
76996
77026
|
* @remarks
|
|
76997
77027
|
* This method performs the following steps for each pool:
|
|
76998
|
-
* 1. Fetches deposit, withdrawal, and ragequit events for each pool
|
|
77028
|
+
* 1. Fetches deposit, withdrawal, and ragequit events for each pool (with concurrency control)
|
|
76999
77029
|
* 2. Processes deposit events and creates pool accounts
|
|
77000
77030
|
* 3. Processes withdrawal events and adds commitments to pool accounts
|
|
77001
77031
|
* 4. Processes ragequit events and adds ragequit to pool accounts
|
|
@@ -77007,7 +77037,7 @@ class AccountService {
|
|
|
77007
77037
|
*
|
|
77008
77038
|
* @throws {AccountError} If account state reconstruction fails or if duplicate pools are found
|
|
77009
77039
|
*/
|
|
77010
|
-
static async initializeWithEvents(dataService, source, pools) {
|
|
77040
|
+
static async initializeWithEvents(dataService, source, pools, maxConcurrency = 5) {
|
|
77011
77041
|
// Log the start of the history retrieval process
|
|
77012
77042
|
const logger = new Logger({ prefix: "Account" });
|
|
77013
77043
|
logger.info(`Fetching events for pools`, { poolLength: pools.length });
|
|
@@ -77023,7 +77053,7 @@ class AccountService {
|
|
|
77023
77053
|
const account = new AccountService(dataService, "mnemonic" in source
|
|
77024
77054
|
? { mnemonic: source.mnemonic }
|
|
77025
77055
|
: { account: source.service.account });
|
|
77026
|
-
const events = await account.getEvents(pools);
|
|
77056
|
+
const events = await account.getEvents(pools, maxConcurrency);
|
|
77027
77057
|
for (const [scope, result] of events.entries()) {
|
|
77028
77058
|
if ("reason" in result) {
|
|
77029
77059
|
errors.push(result);
|
|
@@ -77234,7 +77264,9 @@ class DataService {
|
|
|
77234
77264
|
throw new Error(`Missing RPC URL for chain ${config.chainId}`);
|
|
77235
77265
|
}
|
|
77236
77266
|
const client = createPublicClient({
|
|
77237
|
-
transport: http(config.rpcUrl
|
|
77267
|
+
transport: http(config.rpcUrl, {
|
|
77268
|
+
timeout: 20_000,
|
|
77269
|
+
}),
|
|
77238
77270
|
});
|
|
77239
77271
|
this.clients.set(config.chainId, client);
|
|
77240
77272
|
}
|
package/dist/types/index.js
CHANGED
|
@@ -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-
|
|
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-DbuAhDci.js';
|
|
2
2
|
import 'viem/accounts';
|
|
3
3
|
import 'buffer';
|
|
4
4
|
import 'http';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes an array of promise-returning functions with a maximum concurrency limit.
|
|
3
|
+
* This prevents overwhelming RPC endpoints with too many concurrent requests.
|
|
4
|
+
*
|
|
5
|
+
* @param tasks - Array of functions that return promises
|
|
6
|
+
* @param maxConcurrency - Maximum number of concurrent executions (default: 5)
|
|
7
|
+
* @returns Promise that resolves to an array of settled results
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const tasks = pools.map(pool => () => fetchPoolData(pool));
|
|
12
|
+
* const results = await batchWithConcurrency(tasks, 5);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function batchWithConcurrency<T>(tasks: (() => Promise<T>)[], maxConcurrency?: number): Promise<PromiseSettledResult<T>[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xbow/privacy-pools-core-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"@types/node": "20.3.1",
|
|
70
70
|
"@types/snarkjs": "0.7.9",
|
|
71
71
|
"commitlint": "19.4.1",
|
|
72
|
+
"dotenv": "^17.3.1",
|
|
72
73
|
"globals": "15.14.0",
|
|
73
74
|
"husky": "9.1.5",
|
|
74
75
|
"lint-staged": "15.2.10",
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from "../types/events.js";
|
|
19
19
|
|
|
20
20
|
import { Logger } from "../utils/logger.js";
|
|
21
|
+
import { batchWithConcurrency } from "../utils/concurrency.js";
|
|
21
22
|
import { AccountError } from "../errors/account.error.js";
|
|
22
23
|
import { ErrorCode } from "../errors/base.error.js";
|
|
23
24
|
import { EventError } from "../errors/events.error.js";
|
|
@@ -561,38 +562,44 @@ export class AccountService {
|
|
|
561
562
|
}
|
|
562
563
|
|
|
563
564
|
/**
|
|
564
|
-
* Fetches events for a given set of pools
|
|
565
|
+
* Fetches events for a given set of pools with concurrency control
|
|
565
566
|
*
|
|
566
567
|
* @param pools - The pools to fetch events for
|
|
568
|
+
* @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
|
|
567
569
|
*
|
|
568
570
|
* @returns A map of pool scopes to their events
|
|
569
571
|
*/
|
|
570
|
-
public async getEvents(
|
|
572
|
+
public async getEvents(
|
|
573
|
+
pools: PoolInfo[],
|
|
574
|
+
maxConcurrency: number = 5
|
|
575
|
+
): Promise<PoolEventsResult> {
|
|
571
576
|
const events: PoolEventsResult = new Map();
|
|
572
577
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
578
|
+
// Create tasks for batched execution
|
|
579
|
+
const tasks = pools.map((pool) => async () => {
|
|
580
|
+
this.logger.info(`Fetching events for pool`, {
|
|
581
|
+
poolAddress: pool.address,
|
|
582
|
+
poolChainId: pool.chainId,
|
|
583
|
+
poolDeploymentBlock: pool.deploymentBlock,
|
|
584
|
+
});
|
|
580
585
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
586
|
+
const [depositEvents, withdrawalEvents, ragequitEvents] =
|
|
587
|
+
await Promise.all([
|
|
588
|
+
this.getDepositEvents(pool),
|
|
589
|
+
this.getWithdrawalEvents(pool),
|
|
590
|
+
this.getRagequitEvents(pool),
|
|
591
|
+
]);
|
|
587
592
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
593
|
+
return {
|
|
594
|
+
scope: pool.scope,
|
|
595
|
+
depositEvents,
|
|
596
|
+
withdrawalEvents,
|
|
597
|
+
ragequitEvents,
|
|
598
|
+
};
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
// Execute with concurrency control
|
|
602
|
+
const poolEventResults = await batchWithConcurrency(tasks, maxConcurrency);
|
|
596
603
|
|
|
597
604
|
for (const result of poolEventResults) {
|
|
598
605
|
if (result.status === "fulfilled") {
|
|
@@ -783,10 +790,11 @@ export class AccountService {
|
|
|
783
790
|
* @param dataService - The data service to use for fetching events
|
|
784
791
|
* @param source - The source to use for initializing the account. Either a mnemonic or an existing account service instance
|
|
785
792
|
* @param pools - The pools to fetch events for
|
|
793
|
+
* @param maxConcurrency - Maximum number of concurrent pool fetches (default: 5)
|
|
786
794
|
*
|
|
787
795
|
* @remarks
|
|
788
796
|
* This method performs the following steps for each pool:
|
|
789
|
-
* 1. Fetches deposit, withdrawal, and ragequit events for each pool
|
|
797
|
+
* 1. Fetches deposit, withdrawal, and ragequit events for each pool (with concurrency control)
|
|
790
798
|
* 2. Processes deposit events and creates pool accounts
|
|
791
799
|
* 3. Processes withdrawal events and adds commitments to pool accounts
|
|
792
800
|
* 4. Processes ragequit events and adds ragequit to pool accounts
|
|
@@ -807,7 +815,8 @@ export class AccountService {
|
|
|
807
815
|
| {
|
|
808
816
|
service: AccountService;
|
|
809
817
|
},
|
|
810
|
-
pools: PoolInfo[]
|
|
818
|
+
pools: PoolInfo[],
|
|
819
|
+
maxConcurrency: number = 5
|
|
811
820
|
): Promise<{ account: AccountService; errors: PoolEventsError[] }> {
|
|
812
821
|
// Log the start of the history retrieval process
|
|
813
822
|
const logger = new Logger({ prefix: "Account" });
|
|
@@ -830,7 +839,7 @@ export class AccountService {
|
|
|
830
839
|
: { account: source.service.account }
|
|
831
840
|
);
|
|
832
841
|
|
|
833
|
-
const events = await account.getEvents(pools);
|
|
842
|
+
const events = await account.getEvents(pools, maxConcurrency);
|
|
834
843
|
|
|
835
844
|
for (const [scope, result] of events.entries()) {
|
|
836
845
|
if ("reason" in result) {
|
package/src/core/data.service.ts
CHANGED
|
@@ -24,7 +24,7 @@ const RAGEQUIT_EVENT = parseAbiItem('event Ragequit(address indexed _ragequitter
|
|
|
24
24
|
/**
|
|
25
25
|
* Service responsible for fetching and managing privacy pool events across multiple chains.
|
|
26
26
|
* Handles event retrieval, parsing, and validation for deposits, withdrawals, and ragequits.
|
|
27
|
-
*
|
|
27
|
+
*
|
|
28
28
|
* @remarks
|
|
29
29
|
* This service uses viem's PublicClient to efficiently fetch and process blockchain events.
|
|
30
30
|
* It supports multiple chains and provides robust error handling and validation.
|
|
@@ -36,7 +36,7 @@ export class DataService {
|
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Initialize the data service with chain configurations
|
|
39
|
-
*
|
|
39
|
+
*
|
|
40
40
|
* @param chainConfigs - Array of chain configurations containing chainId, RPC URL, and API key
|
|
41
41
|
* @throws {DataError} If client initialization fails for any chain
|
|
42
42
|
*/
|
|
@@ -50,7 +50,9 @@ export class DataService {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
const client = createPublicClient({
|
|
53
|
-
transport: http(config.rpcUrl
|
|
53
|
+
transport: http(config.rpcUrl, {
|
|
54
|
+
timeout: 20_000,
|
|
55
|
+
}),
|
|
54
56
|
});
|
|
55
57
|
this.clients.set(config.chainId, client);
|
|
56
58
|
}
|
|
@@ -65,7 +67,7 @@ export class DataService {
|
|
|
65
67
|
|
|
66
68
|
/**
|
|
67
69
|
* Get deposit events for a specific chain
|
|
68
|
-
*
|
|
70
|
+
*
|
|
69
71
|
* @param chainId - Chain ID to fetch events from
|
|
70
72
|
* @param options - Event filter options including fromBlock, toBlock, and other filters
|
|
71
73
|
* @returns Array of deposit events with properly typed fields (bigint for numbers, Hash for commitments)
|
|
@@ -130,7 +132,7 @@ export class DataService {
|
|
|
130
132
|
|
|
131
133
|
/**
|
|
132
134
|
* Get withdrawal events for a specific chain
|
|
133
|
-
*
|
|
135
|
+
*
|
|
134
136
|
* @param chainId - Chain ID to fetch events from
|
|
135
137
|
* @param options - Event filter options including fromBlock, toBlock, and other filters
|
|
136
138
|
* @returns Array of withdrawal events with properly typed fields (bigint for numbers, Hash for commitments)
|
|
@@ -192,7 +194,7 @@ export class DataService {
|
|
|
192
194
|
|
|
193
195
|
/**
|
|
194
196
|
* Get ragequit events for a specific chain
|
|
195
|
-
*
|
|
197
|
+
*
|
|
196
198
|
* @param chainId - Chain ID to fetch events from
|
|
197
199
|
* @param options - Event filter options including fromBlock, toBlock, and other filters
|
|
198
200
|
* @returns Array of ragequit events with properly typed fields (bigint for numbers, Hash for commitments)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes an array of promise-returning functions with a maximum concurrency limit.
|
|
3
|
+
* This prevents overwhelming RPC endpoints with too many concurrent requests.
|
|
4
|
+
*
|
|
5
|
+
* @param tasks - Array of functions that return promises
|
|
6
|
+
* @param maxConcurrency - Maximum number of concurrent executions (default: 5)
|
|
7
|
+
* @returns Promise that resolves to an array of settled results
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const tasks = pools.map(pool => () => fetchPoolData(pool));
|
|
12
|
+
* const results = await batchWithConcurrency(tasks, 5);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export async function batchWithConcurrency<T>(
|
|
16
|
+
tasks: (() => Promise<T>)[],
|
|
17
|
+
maxConcurrency: number = 5
|
|
18
|
+
): Promise<PromiseSettledResult<T>[]> {
|
|
19
|
+
const results: PromiseSettledResult<T>[] = [];
|
|
20
|
+
|
|
21
|
+
// Process tasks in batches
|
|
22
|
+
for (let i = 0; i < tasks.length; i += maxConcurrency) {
|
|
23
|
+
const batch = tasks.slice(i, i + maxConcurrency);
|
|
24
|
+
const batchResults = await Promise.allSettled(
|
|
25
|
+
batch.map(task => task())
|
|
26
|
+
);
|
|
27
|
+
results.push(...batchResults);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return results;
|
|
31
|
+
}
|
|
32
|
+
|