@defillama/sdk 5.0.74 → 5.0.77

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/build/abi/abi2.js CHANGED
@@ -29,6 +29,8 @@ const debugLog_1 = require("../util/debugLog");
29
29
  async function call(params) {
30
30
  try {
31
31
  const response = await abi1.call(params);
32
+ if (params.field)
33
+ response.output = response.output[params.field];
32
34
  if (params.withMetadata)
33
35
  return response;
34
36
  return response.output;
@@ -58,15 +60,21 @@ async function multiCall(params) {
58
60
  let { output } = await abi1.multiCall(params);
59
61
  if (params.excludeFailed)
60
62
  output = output.filter((i) => i.success);
63
+ if (params.field)
64
+ output = output.forEach((i) => i.output = i.output[params.field]);
61
65
  if (params.withMetadata)
62
66
  return output;
63
67
  return output.map((i) => i.output);
64
68
  }
65
69
  exports.multiCall = multiCall;
66
70
  async function fetchList(params) {
67
- let { startFrom = 0, lengthAbi, itemAbi, withMetadata, startFromOne = false, itemCount, target, targets, calls: _targets, chain, block, permitFailure, groupedByInput, excludeFailed, } = params;
71
+ // itemAbi2 is used when we need to make a second call to get the final result
72
+ let { startFrom = 0, lengthAbi, itemAbi, withMetadata, startFromOne = false, itemCount, target, targets, calls: _targets, chain, block, permitFailure, groupedByInput, excludeFailed, itemAbi2, field, field2, } = params;
68
73
  if (!targets)
69
74
  targets = _targets;
75
+ const _groupedByInputOrignal = groupedByInput;
76
+ if (targets && itemAbi2)
77
+ groupedByInput = true;
70
78
  permitFailure = permitFailure || excludeFailed;
71
79
  if (excludeFailed && groupedByInput)
72
80
  throw new Error('excludeFailed and groupedByInput cannot be used together!');
@@ -93,14 +101,17 @@ async function fetchList(params) {
93
101
  }
94
102
  for (let i = startFrom; i < itemLength; i++)
95
103
  calls.push({ target, params: [i] });
96
- return multiCall({ chain, block, permitFailure, abi: itemAbi, calls, withMetadata, excludeFailed, });
104
+ const response = await multiCall({ chain, block, permitFailure, abi: itemAbi, calls, withMetadata, excludeFailed, field, });
105
+ if (!itemAbi2)
106
+ return response;
107
+ return multiCall({ chain, block, target, permitFailure, abi: itemAbi2, calls: response, withMetadata, excludeFailed, field: field2, });
97
108
  }
98
109
  if (itemCount)
99
110
  itemLengths = targets.map(() => itemCount);
100
111
  else
101
112
  itemLengths = await multiCall({ chain, block, calls: targets, abi: lengthAbi, });
102
113
  (0, debugLog_1.debugLog)('itemLengths: ', itemLengths);
103
- const groupedByRes = itemLengths.map(() => []);
114
+ let groupedByRes = itemLengths.map(() => []);
104
115
  const indexToTargetMapping = {};
105
116
  let k = 0;
106
117
  for (let i = 0; i < itemLengths.length; i++) {
@@ -116,10 +127,23 @@ async function fetchList(params) {
116
127
  k++;
117
128
  }
118
129
  }
119
- const res = await multiCall({ chain, block, permitFailure, abi: itemAbi, calls, withMetadata, excludeFailed, });
130
+ const res = await multiCall({ chain, block, permitFailure, abi: itemAbi, calls, withMetadata, excludeFailed, field, });
120
131
  if (!groupedByInput)
121
132
  return res;
122
133
  res.forEach((i, idx) => groupedByRes[indexToTargetMapping[idx]].push(i));
134
+ if (!itemAbi2)
135
+ return groupedByRes;
136
+ const calls2 = [];
137
+ for (let i = 0; i < targets.length; i++) {
138
+ for (let j = 0; j < groupedByRes[i].length; j++) {
139
+ calls2.push({ target: targets[i], params: groupedByRes[i][j] });
140
+ }
141
+ }
142
+ const res2 = await multiCall({ chain, block, permitFailure, abi: itemAbi2, calls: calls2, withMetadata, excludeFailed, field: field2, });
143
+ if (!_groupedByInputOrignal)
144
+ return res2;
145
+ groupedByRes = itemLengths.map(() => []);
146
+ res2.forEach((i, idx) => groupedByRes[indexToTargetMapping[idx]].push(i));
123
147
  return groupedByRes;
124
148
  }
125
149
  exports.fetchList = fetchList;