@defisaver/automation-sdk 3.3.9 → 3.3.10

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.
@@ -19,20 +19,27 @@ const utils_1 = require("./utils");
19
19
  function multicall(web3, chainId, calls, block = 'latest') {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
21
  const multicallContract = (0, contractService_1.makeUniMulticallContract)(web3, chainId).contract;
22
- const formattedCalls = calls.map((call) => ({
23
- callData: web3_eth_abi_1.default.encodeFunctionCall(call.abiItem, call.params),
24
- target: call.target || '0x0',
25
- gasLimit: call.gasLimit || 1e6,
26
- }));
27
- const callResult = yield multicallContract.methods.multicall(formattedCalls.filter(item => item.target !== '0x0')).call({}, block);
28
- let formattedResult = [];
29
- callResult.returnData.forEach(([success, gasUsed, result], i) => {
30
- const formattedRes = (result !== '0x'
31
- ? web3_eth_abi_1.default.decodeParameters(calls[i].abiItem.outputs, result)
32
- : undefined);
33
- formattedResult = [...formattedResult, formattedRes];
34
- });
35
- return formattedResult;
22
+ const MAX_CALLS_PER_BATCH = 1000;
23
+ const allResults = [];
24
+ // Process each chunk
25
+ for (let i = 0; i < calls.length; i += MAX_CALLS_PER_BATCH) {
26
+ const chunk = calls.slice(i, i + MAX_CALLS_PER_BATCH);
27
+ const formattedCalls = chunk.map((call) => ({
28
+ callData: web3_eth_abi_1.default.encodeFunctionCall(call.abiItem, call.params),
29
+ target: call.target || '0x0',
30
+ gasLimit: call.gasLimit || 1e6,
31
+ }));
32
+ const callResult = yield multicallContract.methods.multicall(formattedCalls).call({}, block);
33
+ let formattedResult = [];
34
+ callResult.returnData.forEach(([success, , result], j) => {
35
+ const formattedRes = (success && result !== '0x'
36
+ ? web3_eth_abi_1.default.decodeParameters(chunk[j].abiItem.outputs, result)
37
+ : undefined);
38
+ formattedResult = [...formattedResult, formattedRes];
39
+ });
40
+ allResults.push(...formattedResult);
41
+ }
42
+ return allResults;
36
43
  });
37
44
  }
38
45
  exports.multicall = multicall;
@@ -13,20 +13,27 @@ import { addToObjectIf, isDefined } from './utils';
13
13
  export function multicall(web3, chainId, calls, block = 'latest') {
14
14
  return __awaiter(this, void 0, void 0, function* () {
15
15
  const multicallContract = makeUniMulticallContract(web3, chainId).contract;
16
- const formattedCalls = calls.map((call) => ({
17
- callData: AbiCoder.encodeFunctionCall(call.abiItem, call.params),
18
- target: call.target || '0x0',
19
- gasLimit: call.gasLimit || 1e6,
20
- }));
21
- const callResult = yield multicallContract.methods.multicall(formattedCalls.filter(item => item.target !== '0x0')).call({}, block);
22
- let formattedResult = [];
23
- callResult.returnData.forEach(([success, gasUsed, result], i) => {
24
- const formattedRes = (result !== '0x'
25
- ? AbiCoder.decodeParameters(calls[i].abiItem.outputs, result)
26
- : undefined);
27
- formattedResult = [...formattedResult, formattedRes];
28
- });
29
- return formattedResult;
16
+ const MAX_CALLS_PER_BATCH = 1000;
17
+ const allResults = [];
18
+ // Process each chunk
19
+ for (let i = 0; i < calls.length; i += MAX_CALLS_PER_BATCH) {
20
+ const chunk = calls.slice(i, i + MAX_CALLS_PER_BATCH);
21
+ const formattedCalls = chunk.map((call) => ({
22
+ callData: AbiCoder.encodeFunctionCall(call.abiItem, call.params),
23
+ target: call.target || '0x0',
24
+ gasLimit: call.gasLimit || 1e6,
25
+ }));
26
+ const callResult = yield multicallContract.methods.multicall(formattedCalls).call({}, block);
27
+ let formattedResult = [];
28
+ callResult.returnData.forEach(([success, , result], j) => {
29
+ const formattedRes = (success && result !== '0x'
30
+ ? AbiCoder.decodeParameters(chunk[j].abiItem.outputs, result)
31
+ : undefined);
32
+ formattedResult = [...formattedResult, formattedRes];
33
+ });
34
+ allResults.push(...formattedResult);
35
+ }
36
+ return allResults;
30
37
  });
31
38
  }
32
39
  export function getEventsFromContract(contractWithMeta, contractWithMetaFork, event, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.3.9",
3
+ "version": "3.3.10",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -18,27 +18,34 @@ export async function multicall(
18
18
  block: BlockNumber = 'latest',
19
19
  ): Promise<Multicall.Payload> {
20
20
  const multicallContract = makeUniMulticallContract(web3, chainId).contract;
21
+ const MAX_CALLS_PER_BATCH = 1000;
21
22
 
22
- const formattedCalls: Multicall.FormattedCalls[] = calls.map((call) => ({
23
- callData: AbiCoder.encodeFunctionCall(call.abiItem, call.params),
24
- target: call.target || '0x0',
25
- gasLimit: call.gasLimit || 1e6,
26
- }));
23
+ const allResults: Multicall.Payload = [];
27
24
 
28
- const callResult = await multicallContract.methods.multicall(
29
- formattedCalls.filter(item => item.target !== '0x0'),
30
- ).call({}, block);
25
+ // Process each chunk
26
+ for (let i = 0; i < calls.length; i += MAX_CALLS_PER_BATCH) {
27
+ const chunk = calls.slice(i, i + MAX_CALLS_PER_BATCH);
28
+ const formattedCalls: Multicall.FormattedCalls[] = chunk.map((call) => ({
29
+ callData: AbiCoder.encodeFunctionCall(call.abiItem, call.params),
30
+ target: call.target || '0x0',
31
+ gasLimit: call.gasLimit || 1e6,
32
+ }));
31
33
 
32
- let formattedResult: Multicall.Payload = [];
34
+ const callResult = await multicallContract.methods.multicall(
35
+ formattedCalls,
36
+ ).call({}, block);
33
37
 
34
- callResult.returnData.forEach(([success, gasUsed, result], i) => {
35
- const formattedRes = (result !== '0x'
36
- ? AbiCoder.decodeParameters(calls[i].abiItem.outputs!, result)
37
- : undefined);
38
- formattedResult = [...formattedResult, formattedRes];
39
- });
38
+ let formattedResult: Multicall.Payload = [];
39
+ callResult.returnData.forEach(([success,, result], j) => {
40
+ const formattedRes = (success && result !== '0x'
41
+ ? AbiCoder.decodeParameters(chunk[j].abiItem.outputs!, result)
42
+ : undefined);
43
+ formattedResult = [...formattedResult, formattedRes];
44
+ });
45
+ allResults.push(...formattedResult);
46
+ }
40
47
 
41
- return formattedResult as Multicall.Payload;
48
+ return allResults;
42
49
  }
43
50
 
44
51
  export async function getEventsFromContract<T extends BaseContract>(