@woof-software/contracts-tools-sdk-ethers 0.0.18 → 0.0.20

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/lib/config.d.ts CHANGED
@@ -18,6 +18,7 @@ export declare const config: {
18
18
  multiplier: number;
19
19
  };
20
20
  batchDelayMs: number;
21
+ maxAsyncReadBatches: number;
21
22
  };
22
23
  contract: {
23
24
  staticCalls: {
package/lib/config.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DEFAULT_LOGS_BLOCKS_STEP, DEFAULT_LOGS_DELAY_MS, DEFAULT_MULTICALL_ALLOW_FAILURE, DEFAULT_MULTICALL_BATCH_DELAY_MS, DEFAULT_MULTICALL_MUTABLE_CALLS_BATCH_LIMIT, DEFAULT_MULTICALL_STATIC_CALLS_BATCH_LIMIT, DEFAULT_MULTICALL_WAIT_FOR_TXS, DEFAULT_MUTABLE_CALLS_TIMEOUT_MS, DEFAULT_PRIORITY_CALL_MULTIPLIER, DEFAULT_STATIC_CALLS_TIMEOUT_MS, DEFAULT_WAIT_CALLS_TIMEOUT_MS, MULTICALL_ADDRESS, } from "./constant.js";
1
+ import { DEFAULT_LOGS_BLOCKS_STEP, DEFAULT_LOGS_DELAY_MS, DEFAULT_MULTICALL_ALLOW_FAILURE, DEFAULT_MULTICALL_ASYNC_READ_BATCHES, DEFAULT_MULTICALL_BATCH_DELAY_MS, DEFAULT_MULTICALL_MUTABLE_CALLS_BATCH_LIMIT, DEFAULT_MULTICALL_STATIC_CALLS_BATCH_LIMIT, DEFAULT_MULTICALL_WAIT_FOR_TXS, DEFAULT_MUTABLE_CALLS_TIMEOUT_MS, DEFAULT_PRIORITY_CALL_MULTIPLIER, DEFAULT_STATIC_CALLS_TIMEOUT_MS, DEFAULT_WAIT_CALLS_TIMEOUT_MS, MULTICALL_ADDRESS, } from "./constant.js";
2
2
  export const config = {
3
3
  multicallUnit: {
4
4
  address: MULTICALL_ADDRESS,
@@ -19,6 +19,7 @@ export const config = {
19
19
  multiplier: DEFAULT_PRIORITY_CALL_MULTIPLIER,
20
20
  },
21
21
  batchDelayMs: DEFAULT_MULTICALL_BATCH_DELAY_MS,
22
+ maxAsyncReadBatches: DEFAULT_MULTICALL_ASYNC_READ_BATCHES,
22
23
  },
23
24
  contract: {
24
25
  staticCalls: {
package/lib/constant.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const DEFAULT_MULTICALL_ALLOW_FAILURE = false;
4
4
  export declare const DEFAULT_MULTICALL_STATIC_CALLS_BATCH_LIMIT = 50;
5
5
  export declare const DEFAULT_MULTICALL_MUTABLE_CALLS_BATCH_LIMIT = 10;
6
6
  export declare const DEFAULT_MULTICALL_BATCH_DELAY_MS = 0;
7
+ export declare const DEFAULT_MULTICALL_ASYNC_READ_BATCHES = 1;
7
8
  export declare const DEFAULT_PRIORITY_CALL_MULTIPLIER = 1.3;
8
9
  export declare const DEFAULT_LOGS_BLOCKS_STEP = 5000;
9
10
  export declare const DEFAULT_LOGS_DELAY_MS = 1000;
package/lib/constant.js CHANGED
@@ -4,6 +4,7 @@ export const DEFAULT_MULTICALL_ALLOW_FAILURE = false;
4
4
  export const DEFAULT_MULTICALL_STATIC_CALLS_BATCH_LIMIT = 50;
5
5
  export const DEFAULT_MULTICALL_MUTABLE_CALLS_BATCH_LIMIT = 10;
6
6
  export const DEFAULT_MULTICALL_BATCH_DELAY_MS = 0;
7
+ export const DEFAULT_MULTICALL_ASYNC_READ_BATCHES = 1;
7
8
  export const DEFAULT_PRIORITY_CALL_MULTIPLIER = 1.3;
8
9
  export const DEFAULT_LOGS_BLOCKS_STEP = 5000;
9
10
  export const DEFAULT_LOGS_DELAY_MS = 1000;
@@ -39,6 +39,7 @@ export class MulticallUnit extends BaseContract {
39
39
  waitForTxs: config.multicallUnit.waitForTxs,
40
40
  waitCallsTimeoutMs: config.multicallUnit.waitCalls.timeoutMs,
41
41
  batchDelayMs: config.multicallUnit.batchDelayMs,
42
+ maxAsyncReadBatches: config.multicallUnit.maxAsyncReadBatches,
42
43
  ...options,
43
44
  };
44
45
  }
@@ -133,13 +134,22 @@ export class MulticallUnit extends BaseContract {
133
134
  await waitWithSignals(runOptions.batchDelayMs, runOptions.signals);
134
135
  }
135
136
  // Process static
136
- for (let i = 0; i < staticCalls.length; i += runOptions.maxStaticCallsStack) {
137
+ const staticBatchSize = runOptions.maxStaticCallsStack;
138
+ const maxAsync = runOptions.maxAsyncReadBatches;
139
+ const staticBatches = [];
140
+ const staticIndexesBatches = [];
141
+ for (let i = 0; i < staticCalls.length; i += staticBatchSize) {
142
+ staticBatches.push(staticCalls.slice(i, i + staticBatchSize));
143
+ staticIndexesBatches.push(staticIndexes.slice(i, i + staticBatchSize));
144
+ }
145
+ for (let i = 0; i < staticBatches.length; i += maxAsync) {
137
146
  checkSignals(runOptions.signals);
138
- const border = Math.min(i + runOptions.maxStaticCallsStack, staticCalls.length);
139
- const iterationCalls = staticCalls.slice(i, border); // half-opened interval
140
- const iterationIndexes = staticIndexes.slice(i, border); // half-opened interval
141
- const iterationResponse = await this.processStaticCalls(iterationCalls, runOptions);
142
- this.saveResponse(iterationResponse, iterationIndexes, tags);
147
+ const batchGroup = staticBatches.slice(i, i + maxAsync);
148
+ const indexGroup = staticIndexesBatches.slice(i, i + maxAsync);
149
+ const results = await Promise.all(batchGroup.map((batch) => this.processStaticCalls(batch, runOptions)));
150
+ for (let j = 0; j < results.length; j++) {
151
+ this.saveResponse(results[j], indexGroup[j], tags);
152
+ }
143
153
  await waitWithSignals(runOptions.batchDelayMs, runOptions.signals);
144
154
  }
145
155
  }
@@ -161,15 +171,14 @@ export class MulticallUnit extends BaseContract {
161
171
  const tags = this.tags;
162
172
  const calls = this.calls;
163
173
  checkSignals(runOptions.signals);
164
- const { mutableCalls, mutableTags } = this.splitCalls(calls, tags, options.forceMutability);
174
+ const { mutableCalls } = this.splitCalls(calls, tags, options.forceMutability);
165
175
  const estimates = [];
166
176
  // Process mutable
167
177
  for (let i = 0; i < mutableCalls.length; i += runOptions.maxMutableCallsStack) {
168
178
  checkSignals(runOptions.signals);
169
179
  const border = Math.min(i + runOptions.maxMutableCallsStack, mutableCalls.length);
170
180
  const iterationCalls = mutableCalls.slice(i, border); // half-opened interval
171
- const iterationTags = mutableTags.slice(i, border);
172
- const estimation = await this.estimateMutableCallsBatch(iterationCalls, iterationTags, runOptions);
181
+ const estimation = await this.estimateMutableCallsBatch(iterationCalls, runOptions);
173
182
  estimates.push(estimation);
174
183
  }
175
184
  return estimates;
@@ -249,7 +258,7 @@ export class MulticallUnit extends BaseContract {
249
258
  }
250
259
  return result;
251
260
  }
252
- async estimateMutableCallsBatch(iterationCalls, iterationTags, runOptions) {
261
+ async estimateMutableCallsBatch(iterationCalls, runOptions) {
253
262
  return this.estimate(aggregate3, [iterationCalls], {
254
263
  forceMutability: CallMutability.Mutable,
255
264
  highPriorityTx: runOptions.highPriorityTxs,
@@ -12,4 +12,5 @@ export interface MulticallOptions {
12
12
  mutableCallsTimeoutMs?: number;
13
13
  waitCallsTimeoutMs?: number;
14
14
  batchDelayMs?: number;
15
+ maxAsyncReadBatches?: number;
15
16
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@woof-software/contracts-tools-sdk-ethers",
3
3
  "description": "Module simplify smart contract interactions and multicall3 aggregation on the Ethereum blockchain and other EVM-compatible networks.",
4
- "version": "0.0.18",
4
+ "version": "0.0.20",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/woof-compound/sandbox-sdks.git"