@defillama/sdk 5.0.180 → 5.0.182

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.
@@ -134,6 +134,9 @@ let lastBlockCacheSave = Date.now();
134
134
  const blockCacheSaveInterval = 1000 * 60 * 5; // 5 minutes
135
135
  const { data: blockTimeCache, saveCacheFile: saveBlockCacheFile } = (0, cache_1.getTempLocalCache)({ file: 'BlockCache.json', defaultData: {}, clearAfter: cache_1.ONE_WEEK, returnWithSaveFunction: true });
136
136
  function validateCurrentBlock(block, chain = 'ethereum') {
137
+ // sometimes the chain is halted or facing issues, so we skip the validation for those chains
138
+ if ((0, env_1.shouldSkipCurrentBlockValidation)(chain))
139
+ return;
137
140
  const provider = getExtraProvider(chain);
138
141
  const now = Math.floor(Date.now() / 1000);
139
142
  const minutesDiff = Math.floor((now - block.timestamp) / 60);
@@ -234,7 +234,7 @@ function formErrorString(e, errorParams = {}) {
234
234
  }
235
235
  if (e.llamaRPCError) {
236
236
  const errorString = `Llama RPC error! method: ${e.method} `;
237
- const errors = e.errors.map((i) => { var _a; return `- host: ${i === null || i === void 0 ? void 0 : i.host} error: ${(_a = i === null || i === void 0 ? void 0 : i.error) === null || _a === void 0 ? void 0 : _a.message}`; });
237
+ const errors = e.errors.map((i) => { var _a; return `- host: ${i === null || i === void 0 ? void 0 : i.host} error: ${typeof (i === null || i === void 0 ? void 0 : i.error) === 'string' ? i === null || i === void 0 ? void 0 : i.error : (_a = i === null || i === void 0 ? void 0 : i.error) === null || _a === void 0 ? void 0 : _a.message}`; });
238
238
  return errorString + '\n' + errors.join('\n');
239
239
  }
240
240
  let errorString = e.toString();
@@ -302,6 +302,9 @@ function shortenString(str, length) {
302
302
  }
303
303
  function formError(e, errorParams = {}) {
304
304
  var _a;
305
+ if (e instanceof Error && (0, env_1.getBoolEnvValue)('DEBUG_ERROR_STACK')) {
306
+ console.error(e);
307
+ }
305
308
  const errorParamsSet = Object.keys(errorParams).length;
306
309
  if ((e === null || e === void 0 ? void 0 : e._isCustomError) || (!errorParamsSet && typeof e === 'object' && !Object.keys(e).length))
307
310
  return e; // already formatted or vannila error
@@ -14,3 +14,5 @@ export declare function getBatchMaxCount(chain: string): number;
14
14
  export declare function getArchivalRPCs(chain: string): string[];
15
15
  export declare function getChainRPCs(chain: string, defaultList?: string[]): string | undefined;
16
16
  export declare function getWhitelistedRPCs(chain: string): string[];
17
+ export declare function shouldSkipCurrentBlockValidation(chain: string): boolean;
18
+ export declare function getBoolEnvValue(key: string, defaultValue?: boolean): boolean;
package/build/util/env.js CHANGED
@@ -15,6 +15,8 @@ exports.getBatchMaxCount = getBatchMaxCount;
15
15
  exports.getArchivalRPCs = getArchivalRPCs;
16
16
  exports.getChainRPCs = getChainRPCs;
17
17
  exports.getWhitelistedRPCs = getWhitelistedRPCs;
18
+ exports.shouldSkipCurrentBlockValidation = shouldSkipCurrentBlockValidation;
19
+ exports.getBoolEnvValue = getBoolEnvValue;
18
20
  const whitelistedEnvConstants = [
19
21
  'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY', 'COINS_API_KEY',
20
22
  'ELASTICSEARCH_CONFIG', 'GRAPH_API_KEY', 'LLAMA_INDEXER_ENDPOINT', 'LLAMA_INDEXER_API_KEY', 'LLAMA_INDEXER_V2_ENDPOINT', 'LLAMA_INDEXER_V2_API_KEY',
@@ -37,6 +39,7 @@ const defaultEnvValues = {
37
39
  };
38
40
  const _ENV_CONSTANTS = {
39
41
  DEBUG_ENABLED: getEnvValue('DEBUG') === "true" || process.env.LLAMA_DEBUG_MODE ? 'true' : 'false',
42
+ DEBUG_ERROR_STACK: getEnvValue('DEBUG_ERROR_STACK') === "true",
40
43
  DEBUG_LEVEL2: process.env.LLAMA_DEBUG_LEVEL2 || process.env.LLAMA_SDK_DEBUG_LEVEL_3 ? 'true' : 'false',
41
44
  DEBUG_LEBEL_3: isDebugLevel3,
42
45
  LOG_LLAMA_PROVIDER_CALLS: isDebugLevel3 || process.env.LLAMA_SDK_LOG_LLAMA_PROVIDER_CALLS === 'true',
@@ -131,3 +134,18 @@ function getWhitelistedRPCs(chain) {
131
134
  return getEnvValue(key).split(',');
132
135
  return [];
133
136
  }
137
+ let skipCurrentBlockValidationChainSet = null;
138
+ function shouldSkipCurrentBlockValidation(chain) {
139
+ if (!skipCurrentBlockValidationChainSet) {
140
+ const envValue = getEnvValue('SKIP_CURRENT_BLOCK_VALIDATION_CHAINS', '');
141
+ const chainList = envValue ? envValue.split(',').map(c => c.trim()) : [];
142
+ skipCurrentBlockValidationChainSet = new Set(chainList);
143
+ }
144
+ return skipCurrentBlockValidationChainSet.has(chain);
145
+ }
146
+ function getBoolEnvValue(key, defaultValue = false) {
147
+ const envValue = getEnvValue(key);
148
+ if (envValue === undefined)
149
+ return defaultValue;
150
+ return envValue === 'true';
151
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "5.0.180",
3
+ "version": "5.0.182",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {