@defillama/sdk 5.0.218 → 5.0.220

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/README.md CHANGED
@@ -20,6 +20,20 @@ ETHEREUM_RPC="https://..."
20
20
  BSC_RPC="https://..."
21
21
  ```
22
22
 
23
+ ### Environment variables
24
+
25
+ Most settings can be overridden per chain via environment variables. The chain
26
+ name is uppercased and used as a prefix, e.g. `ETHEREUM_RPC`, `BSC_RPC_MULTICALL_V3`.
27
+ Every key is also resolved with an `SDK_` or `LLAMA_SDK_` prefix (checked in the
28
+ order `LLAMA_SDK_<KEY>` → `SDK_<KEY>` → `<KEY>`), so `SDK_ETHEREUM_RPC` works too.
29
+
30
+ | Variable | Description |
31
+ | --- | --- |
32
+ | `<CHAIN>_RPC` | RPC URL(s) for the chain (comma-separated for multiple). |
33
+ | `<CHAIN>_RPC_MULTICALL_V3` | Address of a Multicall3 contract for the chain. Setting it enables the Multicall3 code path for that chain (even if the chain is not in the built-in registry) and uses this address. Takes precedence over the built-in registry and the deployment-block gating. |
34
+ | `<CHAIN>_RPC_MULTICALL` | Address of a legacy (v2) multicall contract, used only when Multicall3 is not available for the chain. |
35
+ | `<CHAIN>_MULTICALL_CHUNK_SIZE` | Max number of calls per multicall batch for the chain. |
36
+
23
37
  ## Chain RPC PR
24
38
 
25
39
  Before putting up a PR for new chain, check if we already support it here: https://unpkg.com/@defillama/sdk@latest/build/providers.json
package/build/Balances.js CHANGED
@@ -195,7 +195,7 @@ class Balances {
195
195
  }
196
196
  async getUSDValue() {
197
197
  let { usdTvl } = await (0, computeTVL_1.default)(this.getBalances(), this.timestamp);
198
- usdTvl = Object.values(this._usdBalances).reduce((a, b) => a + b, usdTvl);
198
+ usdTvl = Object.values(this._usdBalances).reduce((a, b) => a + Number(b), usdTvl);
199
199
  return usdTvl;
200
200
  }
201
201
  async getUSDString() {
package/build/ChainApi.js CHANGED
@@ -193,8 +193,8 @@ class ChainApi {
193
193
  tokens.forEach((i) => tokensAndOwners.push([i, owner]));
194
194
  if (skipDuplicates)
195
195
  tokensAndOwners = getUniqueTokensAndOwners(tokensAndOwners, this.chain);
196
- blacklistedOwners = (0, common_1.getUniqueAddresses)(blacklistedOwners);
197
- blacklistedTokens = (0, common_1.getUniqueAddresses)(blacklistedTokens);
196
+ blacklistedOwners = (0, common_1.getUniqueAddresses)(blacklistedOwners, this.chain);
197
+ blacklistedTokens = (0, common_1.getUniqueAddresses)(blacklistedTokens, this.chain);
198
198
  tokensAndOwners = tokensAndOwners.filter(i => !blacklistedTokens.includes(i[0]) && !blacklistedOwners.includes(i[1]));
199
199
  const tokenBalances = [];
200
200
  const erc20TokensResponseIndex = [];
package/build/abi/abi2.js CHANGED
@@ -63,7 +63,7 @@ async function call(params) {
63
63
  for (let i = 0; i < abis.length - 1; i++) {
64
64
  const res = await call({ ...restParams, abi: abis[i], permitFailure: true, withMetadata: true });
65
65
  const response = params.withMetadata ? res : res.output;
66
- if (res.success)
66
+ if (res.success !== false)
67
67
  return response;
68
68
  }
69
69
  const lastAbi = abis[abis.length - 1];
@@ -195,13 +195,34 @@ async function multiCall(params) {
195
195
  if (!params.skipCache)
196
196
  return cachedMultiCall(params);
197
197
  const abi = resolveABI(params.abi);
198
+ const chunkedCalls = (0, util_1.sliceIntoChunks)(contractCalls, chunkSize);
198
199
  const results = await (0, util_1.runInPromisePool)({
199
- items: (0, util_1.sliceIntoChunks)(contractCalls, chunkSize),
200
+ items: chunkedCalls,
200
201
  concurrency: 10,
201
202
  processor: (calls) => (0, multicall3_1.default)(abi, calls, chain, params.block),
202
203
  permitFailure: params.permitFailure,
203
204
  });
204
- const flatResults = [].concat.apply([], results);
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);
205
226
  const failedQueries = flatResults.filter(r => !r.success);
206
227
  if (failedQueries.length) {
207
228
  // debugLog(`[chain: ${params.chain ?? "ethereum"}] [abi: ${params.abi}] Failed multicalls:`, failedQueries.map(r => r.input))
@@ -374,6 +374,7 @@ function multicallAddress(chainId) {
374
374
  case 38833: return '0x7B2Fa3e6CE90Ce6037395630a4C6DF45B7ef25Af'; // igra
375
375
  case 8721: return '0x965b692662d431cc4714f4E6d1191b0B18733243'; // ebchain
376
376
  case 7119: return '0xFd4b34b5763f54a580a0d9f7997A2A993ef9ceE9'; // sentrix
377
+ case 36900: return '0x73df6E8F0D112D22bD672952323b43d6893AB6D2'; // adi
377
378
  default:
378
379
  return null;
379
380
  }
@@ -4,4 +4,4 @@ export default function makeMultiCall(functionABI: any, calls: {
4
4
  params: any[];
5
5
  }[], chain: Chain, block?: string | number): Promise<any>;
6
6
  export declare function isMulticallV3Supported(chain: Chain, block?: string | number): boolean;
7
- export declare function getMulticallAddress(chain: Chain, block?: string | number): string | null;
7
+ export declare function getMulticallAddress(chain: Chain, block?: string | number): any;
@@ -10,6 +10,7 @@ const ethers_1 = require("ethers");
10
10
  const convertResults_1 = __importDefault(require("./convertResults"));
11
11
  const multicall_1 = __importDefault(require("./multicall"));
12
12
  const index_1 = require("./index");
13
+ const env_1 = require("../util/env");
13
14
  // https://github.com/mds1/multicall
14
15
  // https://www.multicall3.com/deployments
15
16
  const MULTICALL_V3_ADDRESS = '0xca11bde05977b3631167028862be2a173976ca11';
@@ -221,6 +222,9 @@ const DEPLOYMENT_BLOCK = {
221
222
  robinhood: 1,
222
223
  srx: 1,
223
224
  xo: 1,
225
+ rls: 1,
226
+ quai: 1,
227
+ adi: 1,
224
228
  };
225
229
  async function makeMultiCall(functionABI, calls, chain, block) {
226
230
  if (!functionABI)
@@ -235,16 +239,17 @@ async function makeMultiCall(functionABI, calls, chain, block) {
235
239
  const goodEncodingIndexes = [];
236
240
  const goodCalls = [];
237
241
  const contractCalls = calls.map((call, idx) => {
238
- var _a;
239
242
  try {
240
243
  const data = contractInterface.encodeFunctionData(fd, call.params);
241
- if ((_a = call.contract) === null || _a === void 0 ? void 0 : _a.startsWith('0x')) {
242
- const _isValidAddress = ethers_1.ethers.getAddress(call.contract); // Validates and checksums the address
244
+ let contract = call.contract;
245
+ if (contract === null || contract === void 0 ? void 0 : contract.startsWith('0x')) {
246
+ contract = contract.toLowerCase(); // lowercase so a bad EIP-55 checksum does not reject the call - single `call` passes the target as-is to eth_call, so multiCall should accept the same input
247
+ const _isValidAddress = ethers_1.ethers.getAddress(contract); // Validates the address
243
248
  }
244
249
  goodCalls.push(call);
245
250
  goodEncodingIndexes.push(idx);
246
251
  return {
247
- to: call.contract,
252
+ to: contract,
248
253
  data,
249
254
  };
250
255
  }
@@ -299,7 +304,18 @@ async function makeMultiCall(functionABI, calls, chain, block) {
299
304
  returnValues = returnData;
300
305
  }
301
306
  }
307
+ const envMulticallCache = {};
308
+ function getMulticallV3ContractFromEnv(chain) {
309
+ var _a;
310
+ if (!envMulticallCache.hasOwnProperty(chain)) {
311
+ envMulticallCache[chain] = (_a = (0, env_1.getEnvValue)(`${chain}_RPC_MULTICALL_V3`)) !== null && _a !== void 0 ? _a : null;
312
+ }
313
+ return envMulticallCache[chain];
314
+ }
302
315
  function isMulticallV3Supported(chain, block) {
316
+ const contractFromEnv = getMulticallV3ContractFromEnv(chain);
317
+ if (contractFromEnv)
318
+ return true;
303
319
  const startBlock = DEPLOYMENT_BLOCK[chain];
304
320
  if (!startBlock)
305
321
  return false;
@@ -311,6 +327,9 @@ function isMulticallV3Supported(chain, block) {
311
327
  }
312
328
  function getMulticallAddress(chain, block) {
313
329
  var _a;
330
+ const contractFromEnv = getMulticallV3ContractFromEnv(chain);
331
+ if (contractFromEnv)
332
+ return contractFromEnv;
314
333
  if (!isMulticallV3Supported(chain, block))
315
334
  return null;
316
335
  return (_a = CUSTOM_MULTICALL_ADDRESSES[chain]) !== null && _a !== void 0 ? _a : MULTICALL_V3_ADDRESS;
@@ -353,4 +372,6 @@ const CUSTOM_MULTICALL_ADDRESSES = {
353
372
  'anubi': '0x2BaB36196519Ce9Cc31Bc4899FCBB8124A413b02',
354
373
  'srx': '0xFd4b34b5763f54a580a0d9f7997A2A993ef9ceE9',
355
374
  'xo': '0x7c6d6eAafF566E3B8a6D072ca1825E8F18141fDb',
375
+ 'quai': '0x00567637197E6554e2CF47a3988Cb7B819f4E92C',
376
+ 'adi': '0xcC5fae7aF4A6684d05D92Db59279B70e827F31BE',
356
377
  };
package/build/index.d.ts CHANGED
@@ -21,3 +21,10 @@ export * as chainUtils from "./util/chainUtils";
21
21
  export declare const log: typeof debugLog;
22
22
  export declare const logTable: typeof debugTable;
23
23
  export declare const humanizeNumber: typeof humanN.humanizeNumber;
24
+ export declare const providerListJSON: {
25
+ [chain: string]: {
26
+ rpc: string[];
27
+ chainId: number;
28
+ explorer?: string;
29
+ };
30
+ };
package/build/index.js CHANGED
@@ -32,8 +32,11 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.humanizeNumber = exports.logTable = exports.log = exports.chainUtils = exports.coins = exports.erc20 = exports.tron = exports.types = exports.indexer = exports.graph = exports.blocks = exports.api2 = exports.elastic = exports.api = exports.sdkCache = exports.getEventLogs = exports.cache = exports.util = exports.setProvider = exports.getProvider = exports.Balances = exports.ChainApi = void 0;
39
+ exports.providerListJSON = exports.humanizeNumber = exports.logTable = exports.log = exports.chainUtils = exports.coins = exports.erc20 = exports.tron = exports.types = exports.indexer = exports.graph = exports.blocks = exports.api2 = exports.elastic = exports.api = exports.sdkCache = exports.getEventLogs = exports.cache = exports.util = exports.setProvider = exports.getProvider = exports.Balances = exports.ChainApi = void 0;
37
40
  const debugLog_1 = require("./util/debugLog");
38
41
  var ChainApi_1 = require("./ChainApi");
39
42
  Object.defineProperty(exports, "ChainApi", { enumerable: true, get: function () { return ChainApi_1.ChainApi; } });
@@ -59,6 +62,8 @@ exports.tron = __importStar(require("./abi/tron"));
59
62
  exports.erc20 = __importStar(require("./erc20"));
60
63
  exports.coins = __importStar(require("./util/coins"));
61
64
  exports.chainUtils = __importStar(require("./util/chainUtils"));
65
+ const providers_json_1 = __importDefault(require("./providers.json"));
62
66
  exports.log = debugLog_1.debugLog;
63
67
  exports.logTable = debugLog_1.debugTable;
64
68
  exports.humanizeNumber = humanN.humanizeNumber;
69
+ exports.providerListJSON = providers_json_1.default;