@defillama/sdk 5.0.5 → 5.0.8
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/ChainApi.d.ts +8 -1
- package/build/ChainApi.js +10 -6
- package/build/abi/index.js +2 -2
- package/build/abi/multicall.js +3 -2
- package/build/abi/rpcCall.js +2 -4
- package/build/abi/tron.js +7 -7
- package/build/general.js +26 -20
- package/build/generalUtil.d.ts +1 -0
- package/build/generalUtil.js +37 -36
- package/build/providers.json +1 -1
- package/build/util/cache.js +7 -2
- package/build/util/cosmos.js +2 -1
- package/build/util/debugLog.d.ts +1 -1
- package/build/util/debugLog.js +2 -1
- package/build/util/env.d.ts +14 -0
- package/build/util/env.js +103 -0
- package/build/util/index.d.ts +1 -0
- package/build/util/index.js +5 -3
- package/build/util/internal-cache.js +2 -1
- package/build/util/logs.js +2 -4
- package/build/util/r2.js +2 -1
- package/package.json +1 -1
package/build/util/cache.js
CHANGED
|
@@ -42,6 +42,7 @@ var debugLog_1 = require("./debugLog");
|
|
|
42
42
|
var r2_1 = require("./r2");
|
|
43
43
|
var zlib_1 = require("zlib");
|
|
44
44
|
var util_1 = require("util");
|
|
45
|
+
var env_1 = require("./env");
|
|
45
46
|
var brotliOptions = (_a = {},
|
|
46
47
|
_a[zlib_1.constants.BROTLI_PARAM_MODE] = zlib_1.constants.BROTLI_MODE_TEXT,
|
|
47
48
|
_a[zlib_1.constants.BROTLI_PARAM_QUALITY] = zlib_1.constants.BROTLI_MAX_QUALITY,
|
|
@@ -58,7 +59,8 @@ var path = require('path');
|
|
|
58
59
|
var foldersCreated = {};
|
|
59
60
|
exports.currentVersion = 'zlib-1.0';
|
|
60
61
|
function getCacheRootFolder() {
|
|
61
|
-
|
|
62
|
+
var defaultCacheRootFolder = path.join(__dirname, 'local_cache');
|
|
63
|
+
return path.join((0, env_1.getEnvCacheFolder)(defaultCacheRootFolder), exports.currentVersion);
|
|
62
64
|
}
|
|
63
65
|
function getFilePath(file) {
|
|
64
66
|
return path.join(getCacheRootFolder(), file);
|
|
@@ -257,7 +259,10 @@ function getTempLocalCache(_a) {
|
|
|
257
259
|
removePromisesAndFunctions(fileData);
|
|
258
260
|
_fs.writeFileSync(filePath, JSON.stringify(fileData));
|
|
259
261
|
}
|
|
260
|
-
catch (error) {
|
|
262
|
+
catch (error) {
|
|
263
|
+
(0, debugLog_1.debugLog)('Error saving cache:', error);
|
|
264
|
+
}
|
|
265
|
+
process.exit(0);
|
|
261
266
|
}
|
|
262
267
|
function removePromisesAndFunctions(data) {
|
|
263
268
|
if (typeof data === 'object') {
|
package/build/util/cosmos.js
CHANGED
|
@@ -41,6 +41,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.getCosmosProvider = exports.getCosmosBlock = exports.isCosmosChain = void 0;
|
|
43
43
|
var node_fetch_1 = __importDefault(require("node-fetch"));
|
|
44
|
+
var env_1 = require("./env");
|
|
44
45
|
// where to find chain info
|
|
45
46
|
// https://proxy.atomscan.com/chains.json
|
|
46
47
|
// https://cosmos-chain.directory/chains/cosmoshub
|
|
@@ -89,7 +90,7 @@ function getCosmosBlock(block, chain) {
|
|
|
89
90
|
return __generator(this, function (_c) {
|
|
90
91
|
switch (_c.label) {
|
|
91
92
|
case 0:
|
|
92
|
-
endPoint =
|
|
93
|
+
endPoint = (0, env_1.getEnvRPC)(chain) || endPoints[chain] || 'https://rest.cosmos.directory/' + chain;
|
|
93
94
|
_c.label = 1;
|
|
94
95
|
case 1:
|
|
95
96
|
_c.trys.push([1, 4, , 5]);
|
package/build/util/debugLog.d.ts
CHANGED
package/build/util/debugLog.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.debugTable = exports.debugLog = exports.DEBUG_ENABLED = void 0;
|
|
4
|
-
|
|
4
|
+
var env_1 = require("./env");
|
|
5
|
+
exports.DEBUG_ENABLED = env_1.ENV_CONSTANTS.SDK_DEBUG === "true";
|
|
5
6
|
function debugLog() {
|
|
6
7
|
var args = [];
|
|
7
8
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const ENV_CONSTANTS: {
|
|
2
|
+
[x: string]: string | undefined;
|
|
3
|
+
};
|
|
4
|
+
export declare function getChainId(chain: string, chainId: number | undefined): number | undefined;
|
|
5
|
+
export declare function getMaxParallelRequests(chain: string): number;
|
|
6
|
+
export declare function getParallelGetLogsLimit(chain: string): number;
|
|
7
|
+
export declare function getEnvRPC(chain: string): string | undefined;
|
|
8
|
+
export declare function getEnvValue(key: string, defaultValue?: string): string | undefined;
|
|
9
|
+
export declare function getEnvCacheFolder(defaultCacheFolder: string): string;
|
|
10
|
+
export declare function getEnvMulticallAddress(chain: string): string | undefined;
|
|
11
|
+
export declare function getDefaultChunkSize(chain: string): number;
|
|
12
|
+
export declare function getBatchMaxCount(chain: string): number;
|
|
13
|
+
export declare function getArchivalRPCs(chain: string): string[];
|
|
14
|
+
export declare function getChainRPCs(chain: string, defaultList?: string[]): string | undefined;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.getChainRPCs = exports.getArchivalRPCs = exports.getBatchMaxCount = exports.getDefaultChunkSize = exports.getEnvMulticallAddress = exports.getEnvCacheFolder = exports.getEnvValue = exports.getEnvRPC = exports.getParallelGetLogsLimit = exports.getMaxParallelRequests = exports.getChainId = exports.ENV_CONSTANTS = void 0;
|
|
15
|
+
var _ENV_CONSTANTS = {
|
|
16
|
+
DEBUG_ENABLED: getEnvValue('DEBUG') === "true" || process.env.LLAMA_DEBUG_MODE ? 'true' : 'false',
|
|
17
|
+
};
|
|
18
|
+
var whitelistedEnvConstants = [
|
|
19
|
+
'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY',
|
|
20
|
+
];
|
|
21
|
+
var defaultEnvValues = {
|
|
22
|
+
INTERNAL_SDK_CACHE_FILE: './cache.json',
|
|
23
|
+
TRON_RPC_CONCURRENCY_LIMIT: '5',
|
|
24
|
+
TRON_RPC: 'https://api.trongrid.io',
|
|
25
|
+
};
|
|
26
|
+
whitelistedEnvConstants.forEach(function (key) { return _ENV_CONSTANTS[key] = getEnvValue(key); });
|
|
27
|
+
Object.keys(defaultEnvValues).forEach(function (key) { return _ENV_CONSTANTS[key] = getEnvValue(key, defaultEnvValues[key]); });
|
|
28
|
+
// doing this as I am paranoid that that empty object when first declared might be exported before values are set
|
|
29
|
+
exports.ENV_CONSTANTS = __assign({}, _ENV_CONSTANTS);
|
|
30
|
+
function getChainId(chain, chainId) {
|
|
31
|
+
var _a;
|
|
32
|
+
var value = (_a = getEnvValue("".concat(chain, "_RPC_CHAIN_ID"))) !== null && _a !== void 0 ? _a : chainId;
|
|
33
|
+
if (value)
|
|
34
|
+
return +value;
|
|
35
|
+
}
|
|
36
|
+
exports.getChainId = getChainId;
|
|
37
|
+
function getMaxParallelRequests(chain) {
|
|
38
|
+
var chainKey = "".concat(chain, "_RPC_MAX_PARALLEL");
|
|
39
|
+
if (getEnvValue(chainKey))
|
|
40
|
+
return +getEnvValue(chainKey);
|
|
41
|
+
if (['harmony', 'avax'].includes(chain))
|
|
42
|
+
return 20;
|
|
43
|
+
return +getEnvValue('MAX_PARALLEL', '100');
|
|
44
|
+
}
|
|
45
|
+
exports.getMaxParallelRequests = getMaxParallelRequests;
|
|
46
|
+
function getParallelGetLogsLimit(chain) {
|
|
47
|
+
var defaultLimit = chain === 'fantom' ? '10' : '42';
|
|
48
|
+
return +(getEnvValue("".concat(chain, "_RPC_GET_LOGS_CONCURRENCY_LIMIT"), defaultLimit));
|
|
49
|
+
}
|
|
50
|
+
exports.getParallelGetLogsLimit = getParallelGetLogsLimit;
|
|
51
|
+
function getEnvRPC(chain) {
|
|
52
|
+
return getEnvValue("".concat(chain, "_RPC"));
|
|
53
|
+
}
|
|
54
|
+
exports.getEnvRPC = getEnvRPC;
|
|
55
|
+
function getEnvValue(key, defaultValue) {
|
|
56
|
+
var _a, _b, _c;
|
|
57
|
+
key = key.toUpperCase();
|
|
58
|
+
return (_c = (_b = (_a = process.env[key]) !== null && _a !== void 0 ? _a : process.env['SDK_' + key]) !== null && _b !== void 0 ? _b : process.env['LLAMA_SDK_' + key]) !== null && _c !== void 0 ? _c : defaultValue;
|
|
59
|
+
}
|
|
60
|
+
exports.getEnvValue = getEnvValue;
|
|
61
|
+
function getEnvCacheFolder(defaultCacheFolder) {
|
|
62
|
+
return getEnvValue('TVL_LOCAL_CACHE_ROOT_FOLDER', defaultCacheFolder);
|
|
63
|
+
}
|
|
64
|
+
exports.getEnvCacheFolder = getEnvCacheFolder;
|
|
65
|
+
function getEnvMulticallAddress(chain) {
|
|
66
|
+
return getEnvValue("".concat(chain, "_RPC_MULTICALL"));
|
|
67
|
+
}
|
|
68
|
+
exports.getEnvMulticallAddress = getEnvMulticallAddress;
|
|
69
|
+
function getDefaultChunkSize(chain) {
|
|
70
|
+
var key = chain + '_MULTICALL_CHUNK_SIZE';
|
|
71
|
+
if (getEnvValue(key))
|
|
72
|
+
return +getEnvValue(key);
|
|
73
|
+
if (chain === 'cronos')
|
|
74
|
+
return 50;
|
|
75
|
+
return +(getEnvValue('MULTICALL_CHUNK_SIZE', '300'));
|
|
76
|
+
}
|
|
77
|
+
exports.getDefaultChunkSize = getDefaultChunkSize;
|
|
78
|
+
function getBatchMaxCount(chain) {
|
|
79
|
+
var key = chain + 'BATCH_MAX_COUNT';
|
|
80
|
+
if (getEnvValue(key))
|
|
81
|
+
return +getEnvValue(key);
|
|
82
|
+
if (chain === 'cronos')
|
|
83
|
+
return 10;
|
|
84
|
+
return +(getEnvValue('BATCH_MAX_COUNT', '99'));
|
|
85
|
+
}
|
|
86
|
+
exports.getBatchMaxCount = getBatchMaxCount;
|
|
87
|
+
function getArchivalRPCs(chain) {
|
|
88
|
+
var key = chain + '_ARCHIVAL_RPC';
|
|
89
|
+
if (getEnvValue(key))
|
|
90
|
+
return getEnvValue(key).split(',');
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
exports.getArchivalRPCs = getArchivalRPCs;
|
|
94
|
+
function getChainRPCs(chain, defaultList) {
|
|
95
|
+
if (defaultList === void 0) { defaultList = []; }
|
|
96
|
+
var key = chain + '_RPC';
|
|
97
|
+
if (getEnvValue(key))
|
|
98
|
+
return getEnvValue(key).split(',').concat(defaultList).join(',');
|
|
99
|
+
if (defaultList.length === 0)
|
|
100
|
+
return undefined;
|
|
101
|
+
return defaultList.join(',');
|
|
102
|
+
}
|
|
103
|
+
exports.getChainRPCs = getChainRPCs;
|
package/build/util/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Address } from "../types";
|
|
|
3
3
|
import { EventLog } from "ethers";
|
|
4
4
|
import runInPromisePoolOrig from "./promisePool";
|
|
5
5
|
export { getLatestBlock, getTimestamp, lookupBlock, } from "./blocks";
|
|
6
|
+
export { convertToBigInt } from "../generalUtil";
|
|
6
7
|
export declare const runInPromisePool: typeof runInPromisePoolOrig;
|
|
7
8
|
export declare function sliceIntoChunks(arr: any[], chunkSize?: number): any[][];
|
|
8
9
|
export declare function getLogs(params: {
|
package/build/util/index.js
CHANGED
|
@@ -50,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.normalizeBalances = exports.normalizePrefixes = exports.normalizeAddress = exports.getLogs = exports.sliceIntoChunks = exports.runInPromisePool = exports.lookupBlock = exports.getTimestamp = exports.getLatestBlock = void 0;
|
|
53
|
+
exports.normalizeBalances = exports.normalizePrefixes = exports.normalizeAddress = exports.getLogs = exports.sliceIntoChunks = exports.runInPromisePool = exports.convertToBigInt = exports.lookupBlock = exports.getTimestamp = exports.getLatestBlock = void 0;
|
|
54
54
|
var general_1 = require("../general");
|
|
55
55
|
var ethers_1 = require("ethers");
|
|
56
56
|
var generalUtil_1 = require("../generalUtil");
|
|
@@ -60,6 +60,8 @@ var blocks_1 = require("./blocks");
|
|
|
60
60
|
Object.defineProperty(exports, "getLatestBlock", { enumerable: true, get: function () { return blocks_1.getLatestBlock; } });
|
|
61
61
|
Object.defineProperty(exports, "getTimestamp", { enumerable: true, get: function () { return blocks_1.getTimestamp; } });
|
|
62
62
|
Object.defineProperty(exports, "lookupBlock", { enumerable: true, get: function () { return blocks_1.lookupBlock; } });
|
|
63
|
+
var generalUtil_2 = require("../generalUtil");
|
|
64
|
+
Object.defineProperty(exports, "convertToBigInt", { enumerable: true, get: function () { return generalUtil_2.convertToBigInt; } });
|
|
63
65
|
exports.runInPromisePool = promisePool_1.default;
|
|
64
66
|
function sliceIntoChunks(arr, chunkSize) {
|
|
65
67
|
if (chunkSize === void 0) { chunkSize = 100; }
|
|
@@ -109,9 +111,9 @@ function getLogs(params) {
|
|
|
109
111
|
case 4:
|
|
110
112
|
e_1 = _b.sent();
|
|
111
113
|
(0, debugLog_1.debugLog)("Error fetching logs for chain ".concat(params.chain, " blockSpread: ").concat(blockSpread, ". ").concat((0, generalUtil_1.formError)(e_1, { chain: params.chain, target: params.target, provider: provider })));
|
|
112
|
-
if (blockSpread >=
|
|
114
|
+
if (blockSpread >= 1500) {
|
|
113
115
|
// We got too many results
|
|
114
|
-
// We could chop it up into
|
|
116
|
+
// We could chop it up into 1500 block spreads as that is guaranteed to always return but then we'll have to make a lot of queries (easily >1000), so instead we'll keep dividing the block spread by two until we make it
|
|
115
117
|
blockSpread = Math.floor(blockSpread / 2);
|
|
116
118
|
}
|
|
117
119
|
else {
|
|
@@ -25,8 +25,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.retriveCache = exports.startCache = exports.saveCache = exports.setCache = exports.getCache = void 0;
|
|
27
27
|
var fs = __importStar(require("fs"));
|
|
28
|
+
var env_1 = require("./env");
|
|
28
29
|
// const cacheFile = __dirname + '/../../../sc-cache1.json'
|
|
29
|
-
var cacheFile =
|
|
30
|
+
var cacheFile = env_1.ENV_CONSTANTS.INTERNAL_SDK_CACHE_FILE;
|
|
30
31
|
var cache = {};
|
|
31
32
|
// if (cacheFile) cache = require(cacheFile) // disabled for now
|
|
32
33
|
function getCache(options) {
|
package/build/util/logs.js
CHANGED
|
@@ -57,6 +57,7 @@ var blocks_1 = require("./blocks");
|
|
|
57
57
|
var cache_1 = require("./cache");
|
|
58
58
|
var debugLog_1 = require("./debugLog");
|
|
59
59
|
var p_limit_1 = __importDefault(require("p-limit"));
|
|
60
|
+
var env_1 = require("./env");
|
|
60
61
|
var currentVersion = 'v2';
|
|
61
62
|
function getLogs(options) {
|
|
62
63
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -240,10 +241,7 @@ function getChainLimiter(chain) {
|
|
|
240
241
|
chainLimiters[chain] = createLimiter(chain);
|
|
241
242
|
return chainLimiters[chain];
|
|
242
243
|
function createLimiter(chain) {
|
|
243
|
-
|
|
244
|
-
var defaultLimit = chain === 'fantom' ? 10 : 20;
|
|
245
|
-
var limit = +((_a = process.env["".concat(chain.toUpperCase(), "_RPC_GET_LOGS_CONCURRENCY_LIMIT")]) !== null && _a !== void 0 ? _a : defaultLimit);
|
|
246
|
-
return (0, p_limit_1.default)(limit);
|
|
244
|
+
return (0, p_limit_1.default)((0, env_1.getParallelGetLogsLimit)(chain));
|
|
247
245
|
}
|
|
248
246
|
}
|
|
249
247
|
exports.default = getLogs;
|
package/build/util/r2.js
CHANGED
|
@@ -37,8 +37,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.getR2JSONString = exports.storeR2JSONString = void 0;
|
|
40
|
+
var env_1 = require("./env");
|
|
40
41
|
var _a = require("@aws-sdk/client-s3"), S3Client = _a.S3Client, PutObjectCommand = _a.PutObjectCommand, GetObjectCommand = _a.GetObjectCommand;
|
|
41
|
-
var
|
|
42
|
+
var R2_ENDPOINT = env_1.ENV_CONSTANTS.R2_ENDPOINT, R2_ACCESS_KEY_ID = env_1.ENV_CONSTANTS.R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY = env_1.ENV_CONSTANTS.R2_SECRET_ACCESS_KEY;
|
|
42
43
|
var datasetBucket = "defillama-datasets";
|
|
43
44
|
var publicBucketUrl = "https://defillama-datasets.llama.fi";
|
|
44
45
|
var R2;
|