@defillama/sdk 5.0.236 → 5.0.240

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 (131) hide show
  1. package/package.json +3 -3
  2. package/build/Balances.d.ts +0 -139
  3. package/build/Balances.js +0 -363
  4. package/build/ChainApi.d.ts +0 -142
  5. package/build/ChainApi.js +0 -297
  6. package/build/abi/abi2.d.ts +0 -5
  7. package/build/abi/abi2.js +0 -215
  8. package/build/abi/cachedABIs.d.ts +0 -4
  9. package/build/abi/cachedABIs.js +0 -8
  10. package/build/abi/convertResults.d.ts +0 -5
  11. package/build/abi/convertResults.js +0 -60
  12. package/build/abi/index.d.ts +0 -31
  13. package/build/abi/index.js +0 -327
  14. package/build/abi/multicall.d.ts +0 -23
  15. package/build/abi/multicall.js +0 -382
  16. package/build/abi/multicall3.d.ts +0 -7
  17. package/build/abi/multicall3.js +0 -397
  18. package/build/abi/rpcCall.d.ts +0 -4
  19. package/build/abi/rpcCall.js +0 -62
  20. package/build/abi/tron.d.ts +0 -33
  21. package/build/abi/tron.js +0 -110
  22. package/build/api.d.ts +0 -10
  23. package/build/api.js +0 -45
  24. package/build/api2.d.ts +0 -5
  25. package/build/api2.js +0 -41
  26. package/build/chains/algorand.d.ts +0 -277
  27. package/build/chains/algorand.js +0 -618
  28. package/build/chains/aptos.d.ts +0 -230
  29. package/build/chains/aptos.js +0 -612
  30. package/build/chains/cardano.d.ts +0 -242
  31. package/build/chains/cardano.js +0 -407
  32. package/build/chains/cosmos.d.ts +0 -252
  33. package/build/chains/cosmos.js +0 -618
  34. package/build/chains/icp.d.ts +0 -235
  35. package/build/chains/icp.js +0 -1040
  36. package/build/chains/index.d.ts +0 -23
  37. package/build/chains/index.js +0 -59
  38. package/build/chains/near.d.ts +0 -192
  39. package/build/chains/near.js +0 -446
  40. package/build/chains/rpc.d.ts +0 -125
  41. package/build/chains/rpc.js +0 -326
  42. package/build/chains/starknet.d.ts +0 -205
  43. package/build/chains/starknet.js +0 -884
  44. package/build/chains/stellar.d.ts +0 -410
  45. package/build/chains/stellar.js +0 -1082
  46. package/build/chains/substrate.d.ts +0 -333
  47. package/build/chains/substrate.js +0 -1042
  48. package/build/chains/sui.d.ts +0 -365
  49. package/build/chains/sui.js +0 -1135
  50. package/build/chains/svm.d.ts +0 -340
  51. package/build/chains/svm.js +0 -760
  52. package/build/chains/tezos.d.ts +0 -225
  53. package/build/chains/tezos.js +0 -412
  54. package/build/chains/ton.d.ts +0 -353
  55. package/build/chains/ton.js +0 -788
  56. package/build/chains/tron.d.ts +0 -45
  57. package/build/chains/tron.js +0 -110
  58. package/build/chains/utxo.d.ts +0 -202
  59. package/build/chains/utxo.js +0 -592
  60. package/build/chains/xrpl.d.ts +0 -179
  61. package/build/chains/xrpl.js +0 -467
  62. package/build/computeTVL/blocks.d.ts +0 -1
  63. package/build/computeTVL/blocks.js +0 -12
  64. package/build/computeTVL/humanizeNumber.d.ts +0 -1
  65. package/build/computeTVL/humanizeNumber.js +0 -19
  66. package/build/erc20/index.d.ts +0 -31
  67. package/build/erc20/index.js +0 -56
  68. package/build/eth/index.d.ts +0 -22
  69. package/build/eth/index.js +0 -118
  70. package/build/general.d.ts +0 -5
  71. package/build/general.js +0 -20
  72. package/build/generalUtil.d.ts +0 -8
  73. package/build/generalUtil.js +0 -73
  74. package/build/index.d.ts +0 -32
  75. package/build/index.js +0 -74
  76. package/build/providers.json +0 -1
  77. package/build/types.d.ts +0 -76
  78. package/build/types.js +0 -2
  79. package/build/util/LlamaProvider.d.ts +0 -46
  80. package/build/util/LlamaProvider.js +0 -365
  81. package/build/util/blocks.d.ts +0 -36
  82. package/build/util/blocks.js +0 -292
  83. package/build/util/cache.d.ts +0 -45
  84. package/build/util/cache.js +0 -309
  85. package/build/util/chainUtils/data.json +0 -1356
  86. package/build/util/chainUtils/index.d.ts +0 -11
  87. package/build/util/chainUtils/index.js +0 -136
  88. package/build/util/coins.d.ts +0 -19
  89. package/build/util/coins.js +0 -113
  90. package/build/util/common.d.ts +0 -34
  91. package/build/util/common.js +0 -373
  92. package/build/util/computeTVL.d.ts +0 -19
  93. package/build/util/computeTVL.js +0 -102
  94. package/build/util/cosmos.d.ts +0 -1
  95. package/build/util/cosmos.js +0 -8
  96. package/build/util/debugLog.d.ts +0 -4
  97. package/build/util/debugLog.js +0 -18
  98. package/build/util/discord.d.ts +0 -1
  99. package/build/util/discord.js +0 -33
  100. package/build/util/elastic.d.ts +0 -43
  101. package/build/util/elastic.js +0 -113
  102. package/build/util/env.d.ts +0 -19
  103. package/build/util/env.js +0 -158
  104. package/build/util/graph.d.ts +0 -8
  105. package/build/util/graph.js +0 -50
  106. package/build/util/index.d.ts +0 -32
  107. package/build/util/index.js +0 -227
  108. package/build/util/indexer.compatibility.d.ts +0 -6
  109. package/build/util/indexer.compatibility.js +0 -64
  110. package/build/util/indexer.d.ts +0 -92
  111. package/build/util/indexer.js +0 -744
  112. package/build/util/indexerSql.d.ts +0 -9
  113. package/build/util/indexerSql.js +0 -102
  114. package/build/util/internal-cache.d.ts +0 -11
  115. package/build/util/internal-cache.js +0 -77
  116. package/build/util/logs.d.ts +0 -55
  117. package/build/util/logs.decode.shared.d.ts +0 -8
  118. package/build/util/logs.decode.shared.js +0 -289
  119. package/build/util/logs.js +0 -401
  120. package/build/util/promisePool.d.ts +0 -8
  121. package/build/util/promisePool.js +0 -31
  122. package/build/util/r2.d.ts +0 -4
  123. package/build/util/r2.js +0 -52
  124. package/build/util/removeRedundantRPCs.d.ts +0 -1
  125. package/build/util/removeRedundantRPCs.js +0 -49
  126. package/build/util/transactions.d.ts +0 -35
  127. package/build/util/transactions.js +0 -22
  128. package/build/util/updateChainLabels.d.ts +0 -1
  129. package/build/util/updateChainLabels.js +0 -5
  130. package/build/util/updateProviderList.d.ts +0 -1
  131. package/build/util/updateProviderList.js +0 -274
@@ -1,327 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.call = call;
7
- exports.bytecodeCall = bytecodeCall;
8
- exports.multiCall = multiCall;
9
- const cachedABIs_1 = __importDefault(require("./cachedABIs"));
10
- const ethers_1 = require("ethers");
11
- const general_1 = require("../general");
12
- const multicall3_1 = __importDefault(require("./multicall3"));
13
- const convertResults_1 = __importDefault(require("./convertResults"));
14
- const debugLog_1 = require("../util/debugLog");
15
- const internal_cache_1 = require("../util/internal-cache");
16
- const util_1 = require("../util");
17
- const common_1 = require("../util/common");
18
- const env_1 = require("../util/env");
19
- const nullAddress = '0x0000000000000000000000000000000000000000';
20
- // https://docs.soliditylang.org/en/latest/abi-spec.html
21
- const knownTypes = [
22
- 'string', 'address', 'bool', 'bytes32',
23
- 'int', 'int8', 'int16', 'int24', 'int32', 'int64', 'int96', 'int128', 'int256',
24
- 'uint', 'uint8', 'uint16', 'uint24', 'uint32', 'uint64', 'uint96', 'uint128', 'uint256',
25
- ];
26
- ([...knownTypes]).forEach(i => knownTypes.push(i + '[]')); // support array type for all known types
27
- function resolveABI(providedAbi) {
28
- if (!providedAbi)
29
- throw new Error('Missing ABI parameter!');
30
- let abi = providedAbi;
31
- if (typeof abi === "string") {
32
- const [outputType, name] = providedAbi.split(':');
33
- if (!knownTypes.includes(outputType) || !name) {
34
- const contractInterface = new ethers_1.ethers.Interface([providedAbi]);
35
- const jsonAbi = contractInterface.formatJson();
36
- return JSON.parse(jsonAbi)[0];
37
- }
38
- abi = {
39
- constant: true,
40
- inputs: [],
41
- name,
42
- outputs: [
43
- {
44
- internalType: outputType,
45
- name: "",
46
- type: outputType,
47
- },
48
- ],
49
- payable: false,
50
- stateMutability: "view",
51
- type: "function",
52
- };
53
- }
54
- // If type is omitted DP's sdk processes it fine but we don't, so we need to add it
55
- return {
56
- type: "function",
57
- ...abi,
58
- };
59
- }
60
- function normalizeParams(params) {
61
- if (params === undefined) {
62
- return [];
63
- }
64
- else if (typeof params === "object") {
65
- return params;
66
- }
67
- else {
68
- return [params];
69
- }
70
- }
71
- function fixBlockTag(params) {
72
- let { block } = params;
73
- if (typeof block !== 'string' || block === 'latest')
74
- return;
75
- block = +block;
76
- if (isNaN(block))
77
- throw new Error('Invalid block: ' + params.block);
78
- params.block = block;
79
- }
80
- function isValidTarget(target, chain) {
81
- if (typeof target !== 'string')
82
- return false;
83
- return target.startsWith('0x') && target !== nullAddress;
84
- }
85
- async function call(params) {
86
- var _a;
87
- if (!params.abi)
88
- throw new Error('Missing ABI parameter ("abis" is supported only in abi2/ChainApi)!');
89
- if (params.chain === 'tron')
90
- (0, common_1.fixTronCallParams)(params);
91
- if (!isValidTarget(params.target, params.chain))
92
- throw new Error('Invalid target: ' + params.target);
93
- fixBlockTag(params);
94
- const chain = (_a = params.chain) !== null && _a !== void 0 ? _a : "ethereum";
95
- if (cachedABIs_1.default[params.abi])
96
- params.abi = cachedABIs_1.default[params.abi];
97
- let errorParams = { ...params };
98
- try {
99
- if (!params.skipCache)
100
- return cachedCall(params);
101
- const abi = resolveABI(params.abi);
102
- const callParams = normalizeParams(params.params);
103
- // if (chain === 'tron') return Tron.call({ ...params, abi, params: callParams })
104
- const contractInterface = new ethers_1.ethers.Interface([abi]);
105
- const functionABI = ethers_1.ethers.FunctionFragment.from(abi);
106
- const callData = contractInterface.encodeFunctionData(functionABI, callParams);
107
- const provider = (0, general_1.getProvider)(chain);
108
- errorParams.provider = provider;
109
- const result = await provider.call({
110
- to: params.target,
111
- data: callData,
112
- blockTag: params.block,
113
- });
114
- errorParams.result = result;
115
- const decodedResult = contractInterface.decodeFunctionResult(abi, result);
116
- const output = (0, convertResults_1.default)(decodedResult, { functionABI, chain });
117
- if (params.logArray && abi.name == 'balanceOf' && abi.outputs[0].type == 'uint256')
118
- params.logArray.push({
119
- chain,
120
- token: params.target,
121
- holder: Array.isArray(params.params) ? params.params[0] : params.params,
122
- amount: output
123
- });
124
- return {
125
- output,
126
- };
127
- }
128
- catch (e) {
129
- errorParams.isCallError = true;
130
- throw (0, common_1.formError)(e, errorParams);
131
- }
132
- }
133
- async function bytecodeCall(params) {
134
- fixBlockTag(params);
135
- const { block, bytecode, inputTypes, inputs, outputTypes, chain } = params;
136
- if (!bytecode)
137
- throw new Error('Missing bytecode parameter!');
138
- if (chain === 'tron')
139
- throw new Error('Bytecode call is not supported on Tron');
140
- const inputData = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(inputTypes, inputs);
141
- const callData = '0x' + bytecode.concat(inputData.slice(2));
142
- const result = await (0, general_1.getProvider)(chain).call({ data: callData, blockTag: block });
143
- const decodedResult = ethers_1.ethers.AbiCoder.defaultAbiCoder().decode(outputTypes, result);
144
- return {
145
- output: (0, convertResults_1.default)(decodedResult, { chain }),
146
- };
147
- }
148
- async function multiCall(params) {
149
- var _a;
150
- if (!params.abi)
151
- throw new Error('Missing ABI parameter ("abis" is supported only in abi2/ChainApi)!');
152
- fixBlockTag(params);
153
- if (params.chain === 'tron')
154
- (0, common_1.fixTronCallParams)(params);
155
- if (cachedABIs_1.default[params.abi])
156
- params.abi = cachedABIs_1.default[params.abi];
157
- const chain = (_a = params.chain) !== null && _a !== void 0 ? _a : 'ethereum';
158
- if (!params.calls)
159
- throw new Error('Missing calls parameter');
160
- if (params.target && !isValidTarget(params.target, chain))
161
- throw new Error('Invalid target: ' + params.target);
162
- if (!params.calls.length) {
163
- return { output: [] };
164
- }
165
- let chunkSize = params.chunkSize;
166
- if (!params.chunkSize) {
167
- // Only a max of around 500 calls are supported by multicall, we have to split bigger batches
168
- chunkSize = (0, env_1.getDefaultChunkSize)(chain);
169
- }
170
- if (!params.target && !params.permitFailure) {
171
- // check if target adddress is missing for one of the calls
172
- if (params.calls.some((i) => {
173
- if (typeof i === 'string' && i.startsWith('0x'))
174
- return !isValidTarget(i, params.chain);
175
- if (typeof i === 'object')
176
- return !isValidTarget(i.target, params.chain);
177
- return true;
178
- })) {
179
- // debugLog('Multicall is missing target', JSON.stringify(params, null, 2))
180
- throw new Error('Multicall is missing a target');
181
- }
182
- }
183
- let contractCalls = params.contractCalls;
184
- if (!contractCalls) {
185
- contractCalls = (params.calls).map((call) => {
186
- var _a;
187
- const callParams = normalizeParams(call.params);
188
- return {
189
- params: callParams,
190
- contract: (_a = call.target) !== null && _a !== void 0 ? _a : params.target,
191
- };
192
- });
193
- params.contractCalls = contractCalls;
194
- }
195
- if (!params.skipCache)
196
- return cachedMultiCall(params);
197
- const abi = resolveABI(params.abi);
198
- const chunkedCalls = (0, util_1.sliceIntoChunks)(contractCalls, chunkSize);
199
- const results = await (0, util_1.runInPromisePool)({
200
- items: chunkedCalls,
201
- concurrency: 10,
202
- processor: (calls) => (0, multicall3_1.default)(abi, calls, chain, params.block),
203
- permitFailure: params.permitFailure,
204
- });
205
- // When an entire chunk's processor call throws (e.g. a chunk-level RPC
206
- // failure, as opposed to an individual call within it), runInPromisePool
207
- // returns `undefined` for that chunk's slot instead of the expected array
208
- // of one result per call. If permitFailure is set, that undefined flows
209
- // straight through here uncaught, and both the .filter(r => !r.success)
210
- // below and the flatResults[i].output access further down crash on it -
211
- // and even without the crash, replacing a whole chunk's many calls with a
212
- // single slot silently shortens and misaligns the array against
213
- // contractCalls. Reconstruct a properly-shaped failure entry per call in
214
- // any failed chunk instead, matching what makeMultiCall itself returns on
215
- // an individual call failure, so length/order stay correct either way.
216
- const resultsWithFailedChunksExpanded = results.map((chunkResult, i) => {
217
- if (chunkResult !== undefined)
218
- return chunkResult;
219
- return chunkedCalls[i].map((call) => ({
220
- input: { params: call.params, target: call.contract },
221
- success: false,
222
- output: null,
223
- }));
224
- });
225
- const flatResults = [].concat.apply([], resultsWithFailedChunksExpanded);
226
- const failedQueries = flatResults.filter(r => !r.success);
227
- if (failedQueries.length) {
228
- // debugLog(`[chain: ${params.chain ?? "ethereum"}] [abi: ${params.abi}] Failed multicalls:`, failedQueries.map(r => r.input))
229
- if (!params.permitFailure) {
230
- params.failedQueries = failedQueries;
231
- params.isMultiCallError = true;
232
- throw (0, common_1.formError)(null, params);
233
- }
234
- }
235
- if (params.logArray && abi.name == 'balanceOf' && abi.outputs[0].type == 'uint256')
236
- params.logArray.push(...contractCalls.map((c, i) => ({
237
- chain,
238
- holder: c.params.length ? c.params[0] : c.params,
239
- token: c.contract,
240
- amount: flatResults[i].output
241
- })));
242
- return {
243
- output: flatResults, // flatten array
244
- };
245
- }
246
- async function cachedCall(params) {
247
- params.skipCache = true;
248
- if (!isCachableAbi(params.abi))
249
- return call(params);
250
- const cacheObject = {
251
- abi: params.abi,
252
- chain: params.chain,
253
- address: params.target,
254
- };
255
- const cachedValue = (0, internal_cache_1.getCache)(cacheObject);
256
- if (cachedValue)
257
- return {
258
- output: cachedValue
259
- };
260
- const value = await call(params);
261
- if (value) {
262
- cacheObject.value = value.output;
263
- (0, internal_cache_1.setCache)(cacheObject);
264
- }
265
- return value;
266
- }
267
- async function cachedMultiCall(params) {
268
- params.skipCache = true;
269
- const isCacheable = isCachableAbi(params.abi);
270
- const response = [];
271
- const missing = [];
272
- const missingIndices = [];
273
- params.contractCalls.forEach((value, i) => {
274
- if (!isValidTarget(value.contract, params.chain)) {
275
- response[i] = {
276
- input: { target: value.contract, params: value.params, },
277
- output: null,
278
- success: false,
279
- };
280
- (0, debugLog_1.debugLog)(params.abi, 'Bad target passed:', value.contract, 'skipping call and returning null output for this');
281
- return;
282
- }
283
- if (isCacheable) {
284
- const cacheObject = {
285
- abi: params.abi,
286
- chain: params.chain,
287
- address: value.contract,
288
- };
289
- const cachedValue = (0, internal_cache_1.getCache)(cacheObject);
290
- if (cachedValue) {
291
- response[i] = {
292
- input: { target: value.contract, params: value.params, },
293
- output: cachedValue,
294
- success: true,
295
- };
296
- return;
297
- }
298
- }
299
- missing.push(value);
300
- missingIndices.push(i);
301
- });
302
- if (!missing.length)
303
- return { output: response };
304
- params.contractCalls = missing;
305
- const response_ = await multiCall(params);
306
- response_.output.forEach((value, i) => {
307
- if (isCacheable) {
308
- const cacheObject = {
309
- abi: params.abi,
310
- chain: params.chain,
311
- address: value.input.target,
312
- value: value.output
313
- };
314
- (0, internal_cache_1.setCache)(cacheObject);
315
- }
316
- response[missingIndices[i]] = value;
317
- });
318
- return { output: response };
319
- }
320
- const cachableAbiSet = new Set([
321
- 'uint8:decimals',
322
- ]);
323
- function isCachableAbi(abi) {
324
- if (typeof abi !== 'string')
325
- return false;
326
- return abi.startsWith('address:') || abi.startsWith('string:') || cachableAbiSet.has(abi);
327
- }
@@ -1,23 +0,0 @@
1
- import { Chain } from "../general";
2
- export declare const MULTICALL_ADDRESS_MAINNET = "0xeefba1e63905ef1d7acba5a8513c70307c1ce441";
3
- export declare const MULTICALL_ADDRESS_KOVAN = "0x2cc8688c5f75e365aaeeb4ea8d6a480405a48d2a";
4
- export declare const MULTICALL_ADDRESS_RINKEBY = "0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821";
5
- export declare const MULTICALL_ADDRESS_GOERLI = "0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e";
6
- export declare const MULTICALL_ADDRESS_POLYGON = "0x95028E5B8a734bb7E2071F96De89BABe75be9C8E";
7
- export declare const MULTICALL_ADDRESS_BSC = "0x1Ee38d535d541c55C9dae27B12edf090C608E6Fb";
8
- export declare const MULTICALL_ADDRESS_FANTOM = "0xb828C456600857abd4ed6C32FAcc607bD0464F4F";
9
- export declare const MULTICALL_ADDRESS_XDAI = "0xb5b692a88BDFc81ca69dcB1d924f59f0413A602a";
10
- export declare const MULTICALL_ADDRESS_HECO = "0xc9a9F768ebD123A00B52e7A0E590df2e9E998707";
11
- export declare const MULTICALL_ADDRESS_HARMONY = "0xFE4980f62D708c2A84D3929859Ea226340759320";
12
- export declare const MULTICALL_ADDRESS_ARBITRUM = "0x842eC2c7D803033Edf55E478F461FC547Bc54EB2";
13
- export declare const MULTICALL_ADDRESS_AVAX = "0xdf2122931FEb939FB8Cf4e67Ea752D1125e18858";
14
- export declare const MULTICALL_ADDRESS_MOONRIVER = "0xe05349d6fE12602F6084550995B247a5C80C0E2C";
15
- export declare const MULTICALL_ADDRESS_AURORA = "0xe0e3887b158F7F9c80c835a61ED809389BC08d1b";
16
- export declare const MULTICALL_ADDRESS_OPTIMISM = "0xD0E99f15B24F265074747B2A1444eB02b9E30422";
17
- export declare const AGGREGATE_SELECTOR = "0x252dba42";
18
- export default function makeMultiCall(functionABI: any, calls: {
19
- contract: string;
20
- params: any[];
21
- }[], chain: Chain, block?: string | number): Promise<any>;
22
- export declare function multicallAddressOrThrow(chain: Chain): Promise<string>;
23
- export declare function networkSupportsMulticall(chain: Chain): Promise<boolean>;