@defillama/sdk 5.0.180 → 5.0.184

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.shouldSkipBlockValidation)(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);
@@ -229,8 +232,9 @@ async function _lookupBlock(timestamp, extraParams) {
229
232
  }
230
233
  if (i > 2 && env_1.ENV_CONSTANTS.GET_BLOCK_STATS)
231
234
  (0, debugLog_1.debugLog)(`chain: ${chain} block: ${block.number} #calls: ${i} imprecision: ${Number((imprecision) / 60).toFixed(2)} (min) Time Taken: ${Number((Date.now() - time) / 1000).toFixed(2)} (in sec)`);
232
- if (chain !== "bsc" && // this check is there because bsc halted the chain for few days
233
- Math.abs(block.timestamp - timestamp) > 3600) {
235
+ if (Math.abs(block.timestamp - timestamp) > 3600
236
+ && chain !== "bsc" // this check is there because bsc halted the chain for few days
237
+ && !(0, env_1.shouldSkipBlockValidation)(chain)) {
234
238
  throw new Error("Block selected is more than 1 hour away from the requested timestamp");
235
239
  }
236
240
  return {
@@ -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 shouldSkipBlockValidation(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.shouldSkipBlockValidation = shouldSkipBlockValidation;
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 skipBlockValidationChainSet = null;
138
+ function shouldSkipBlockValidation(chain) {
139
+ if (!skipBlockValidationChainSet) {
140
+ const envValue = getEnvValue('SKIP_BLOCK_VALIDATION_CHAINS', '');
141
+ const chainList = envValue ? envValue.split(',').map(c => c.trim()) : [];
142
+ skipBlockValidationChainSet = new Set(chainList);
143
+ }
144
+ return skipBlockValidationChainSet.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,15 +1,16 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "5.0.180",
3
+ "version": "5.0.184",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
7
7
  "start": "npm run build && node build/index.js",
8
+ "pack-and-publish": "bash ./scripts/skipTestPatchAndPublish.sh",
8
9
  "build": "tsc",
9
10
  "watch": "tsc --watch",
10
- "load-providers": "wget https://unpkg.com/@defillama/sdk@latest/build/providers.json -O build/providers.json",
11
- "test": "npm run load-providers && TEST_MODE=true LLAMA_DEBUG_MODE='' SDK_DEBUG='' LLAMA_DEBUG_LEVEL2='' jest",
12
- "test-only": "echo 'skipped building providers.json' && TEST_MODE=true LLAMA_DEBUG_MODE='' SDK_DEBUG='' LLAMA_DEBUG_LEVEL2='' jest",
11
+ "load-providers": "mkdir -p build && wget https://unpkg.com/@defillama/sdk@latest/build/providers.json -O build/providers.json",
12
+ "test": "npm run load-providers && TEST_MODE=true LLAMA_DEBUG_MODE='' SDK_DEBUG='' LLAMA_DEBUG_LEVEL2='' LLAMA_DEBUG_LEVEL3='' jest",
13
+ "test-only": "echo 'skipped building providers.json' && TEST_MODE=true LLAMA_DEBUG_MODE='' SDK_DEBUG='' LLAMA_DEBUG_LEVEL2='' LLAMA_DEBUG_LEVEL3='' jest",
13
14
  "test-debug": "TEST_MODE=true jest",
14
15
  "update-providers": "ts-node src/util/updateProviderList.ts",
15
16
  "remove-rpcs": "ts-node src/util/removeRedundantRPCs.ts",