@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,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getClient = getClient;
4
- exports.writeLog = writeLog;
5
- exports.addDebugLog = addDebugLog;
6
- exports.addRuntimeLog = addRuntimeLog;
7
- exports.addErrorLog = addErrorLog;
8
- exports.search = search;
9
- exports.getAllLogs = getAllLogs;
10
- const elasticsearch_1 = require("@elastic/elasticsearch");
11
- const env_1 = require("./env");
12
- const debugLog_1 = require("./debugLog");
13
- let _client;
14
- function getClient() {
15
- if (_client)
16
- return _client;
17
- let config;
18
- try {
19
- const envString = (0, env_1.getEnvValue)('ELASTICSEARCH_CONFIG');
20
- if (!envString)
21
- return;
22
- config = JSON.parse(envString.replace(/\\"/g, '"')); // replace escaped quotes
23
- }
24
- catch (error) {
25
- return;
26
- }
27
- if (!_client)
28
- _client = new elasticsearch_1.Client({
29
- maxRetries: 3,
30
- requestTimeout: 5000,
31
- compression: true,
32
- node: config.host,
33
- auth: {
34
- username: config.username,
35
- password: config.password,
36
- },
37
- });
38
- return _client;
39
- }
40
- async function writeLog(index, log) {
41
- const client = getClient();
42
- if (!client)
43
- return;
44
- index = addYearAndMonth(index);
45
- if (!log.hasOwnProperty('timestamp'))
46
- log.timestamp = +Date.now();
47
- try {
48
- await client.index({ index, body: log });
49
- }
50
- catch (error) {
51
- (0, debugLog_1.debugLog)((error === null || error === void 0 ? void 0 : error.message) || 'Error writing log to Elasticsearch');
52
- }
53
- }
54
- function addYearAndMonth(index) {
55
- const date = new Date();
56
- return `${index}-${date.getUTCFullYear()}-${date.getUTCMonth()}`;
57
- }
58
- async function addDebugLog(body) {
59
- await writeLog('debug-logs', body);
60
- }
61
- async function addRuntimeLog(body) {
62
- await writeLog('debug-runtime-logs', body);
63
- }
64
- async function addErrorLog(body) {
65
- await writeLog('error-logs', body);
66
- }
67
- /**
68
- * Performs a search operation using the Elasticsearch client
69
- *
70
- * This is a wrapper around the Elasticsearch client's search method.
71
- * See the Elasticsearch documentation for details:
72
- * https://www.elastic.co/guide/en/elasticsearch/reference/8.13/search-search.html
73
- *
74
- * @returns The search results as returned by Elasticsearch
75
- * @throws Error if Elasticsearch client is not configured
76
- *
77
- * @see {@link https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#_search | Elasticsearch Node.js client search API}
78
- */
79
- async function search(...options) {
80
- const client = getClient();
81
- if (!client)
82
- throw new Error('Elasticsearch client not configured');
83
- return client.search(...options);
84
- }
85
- async function getAllLogs({ index, scrollTime = '1m', size = 100000, query = {
86
- match_all: {},
87
- } }) {
88
- const client = getClient();
89
- if (!client)
90
- throw new Error('Elasticsearch client not configured');
91
- const allLogs = [];
92
- let response = await client.search({
93
- index: index,
94
- scroll: scrollTime,
95
- body: { query, size, },
96
- });
97
- while (response.hits.hits.length) {
98
- allLogs.push(...response.hits.hits.map((i) => {
99
- const source = i._source;
100
- // reduce final file size by removing fields we don't need
101
- // delete source.chain
102
- // delete source.address
103
- // delete source.adapter
104
- return source;
105
- }));
106
- (0, debugLog_1.debugLog)(`Fetched ${allLogs.length} records, ${response.hits.hits.length} in batch`);
107
- response = await client.scroll({
108
- scroll_id: response._scroll_id,
109
- scroll: scrollTime,
110
- });
111
- }
112
- return allLogs;
113
- }
@@ -1,19 +0,0 @@
1
- export declare const whitelistedEnvConstants: string[];
2
- export declare const ENV_CONSTANTS: {
3
- [key: string]: string | boolean | undefined;
4
- };
5
- export declare function getChainId(chain: string, chainId: number): number;
6
- export declare function getMaxParallelRequests(chain: string): number;
7
- export declare function getParallelGetLogsLimit(chain: string, providerUrl?: string): number;
8
- export declare function getParallelGetBlocksLimit(chain: string): number;
9
- export declare function getEnvRPC(chain: string): string | undefined;
10
- export declare function getEnvValue(key: string, defaultValue?: string): string;
11
- export declare function getEnvCacheFolder(defaultCacheFolder: string): string;
12
- export declare function getEnvMulticallAddress(chain: string): string | undefined;
13
- export declare function getDefaultChunkSize(chain: string): number;
14
- export declare function getBatchMaxCount(chain: string): number;
15
- export declare function getArchivalRPCs(chain: string): string[];
16
- export declare function getChainRPCs(chain: string, defaultList?: string[]): string | undefined;
17
- export declare function getWhitelistedRPCs(chain: string): string[];
18
- export declare function shouldSkipBlockValidation(chain: string): boolean;
19
- export declare function getBoolEnvValue(key: string, defaultValue?: boolean): boolean;
package/build/util/env.js DELETED
@@ -1,158 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ENV_CONSTANTS = exports.whitelistedEnvConstants = void 0;
5
- exports.getChainId = getChainId;
6
- exports.getMaxParallelRequests = getMaxParallelRequests;
7
- exports.getParallelGetLogsLimit = getParallelGetLogsLimit;
8
- exports.getParallelGetBlocksLimit = getParallelGetBlocksLimit;
9
- exports.getEnvRPC = getEnvRPC;
10
- exports.getEnvValue = getEnvValue;
11
- exports.getEnvCacheFolder = getEnvCacheFolder;
12
- exports.getEnvMulticallAddress = getEnvMulticallAddress;
13
- exports.getDefaultChunkSize = getDefaultChunkSize;
14
- exports.getBatchMaxCount = getBatchMaxCount;
15
- exports.getArchivalRPCs = getArchivalRPCs;
16
- exports.getChainRPCs = getChainRPCs;
17
- exports.getWhitelistedRPCs = getWhitelistedRPCs;
18
- exports.shouldSkipBlockValidation = shouldSkipBlockValidation;
19
- exports.getBoolEnvValue = getBoolEnvValue;
20
- exports.whitelistedEnvConstants = [
21
- 'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY', 'COINS_API_KEY', 'INTERNAL_API_KEY',
22
- 'ELASTICSEARCH_CONFIG', 'GRAPH_API_KEY', 'LLAMA_INDEXER_V2_ENDPOINT', 'LLAMA_INDEXER_V2_API_KEY', 'LLAMA_INDEXER_TIMEOUT_MS',
23
- 'LLAMA_INDEXER_V4_ENDPOINT', 'LLAMA_INDEXER_V4_API_KEY', 'LLAMA_INDEXER_PREFER_V4', 'LLAMA_INDEXER_V4_ONLY_CHAINS',
24
- 'LLAMA_INDEXER_SQL_ENDPOINT', 'LLAMA_INDEXER_SQL_USER', 'LLAMA_INDEXER_SQL_PASSWORD',
25
- ];
26
- const isDebugLevel3 = process.env.LLAMA_SDK_DEBUG_LEVEL_3 === 'true';
27
- const defaultEnvValues = {
28
- EVMOS_MULTICALL_CHUNK_SIZE: "3", // evmos reduced gas limit, this is a workaround to make multicall work
29
- CRONOS_MULTICALL_CHUNK_SIZE: "10", // cronos reduced gas limit, this is a workaround to make multicall work
30
- HEDERA_MULTICALL_CHUNK_SIZE: "50", // cronos reduced gas limit, this is a workaround to make multicall work
31
- KATANA_MULTICALL_CHUNK_SIZE: "50",
32
- INTERNAL_SDK_CACHE_FILE: './cache.json',
33
- TRON_RPC_CONCURRENCY_LIMIT: '5',
34
- LLAMA_INDEXER_ADDRESS_CHUNK_SIZE: '20',
35
- LLAMA_INDEXER_TIMEOUT_MS: '300000',
36
- TRON_WALLET_RPC: 'https://api.trongrid.io',
37
- // TRON_EVM_RPC: 'https://rpc.ankr.com/tron_jsonrpc', // no longer used
38
- NAKA_RPC: 'https://node.nakachain.xyz',
39
- ETHF_RPC: 'https://rpc.dischain.xyz/',
40
- CORE_RPC: "https://rpc.coredao.org,https://rpc.ankr.com/core,https://1rpc.io/core,https://rpc-core.icecreamswap.com",
41
- BITGERT_RPC: "https://flux-rpc2.brisescan.com,https://mainnet-rpc.brisescan.com,https://chainrpc.com,https://serverrpc.com,https://flux-rpc.brisescan.com",
42
- BITCHAIN_RPC: "https://rpc.bitchain.biz/",
43
- OZONE_RPC: "https://node1.ozonechain.io",
44
- ZETA_RPC: "https://zetachain-evm.blockpi.network/v1/rpc/public,https://zetachain-mainnet-archive.allthatnode.com:8545",
45
- DEFIVERSE_RPC: "https://rpc.defi-verse.org/",
46
- };
47
- const _ENV_CONSTANTS = {
48
- DEBUG_ENABLED: getEnvValue('DEBUG') === "true" || process.env.LLAMA_DEBUG_MODE ? 'true' : 'false',
49
- DEBUG_ERROR_STACK: getEnvValue('DEBUG_ERROR_STACK') === "true",
50
- DEBUG_LEVEL2: process.env.LLAMA_DEBUG_LEVEL2 || process.env.LLAMA_SDK_DEBUG_LEVEL_3 ? 'true' : 'false',
51
- DEBUG_LEBEL_3: isDebugLevel3,
52
- LOG_LLAMA_PROVIDER_CALLS: isDebugLevel3 || process.env.LLAMA_SDK_LOG_LLAMA_PROVIDER_CALLS === 'true',
53
- GET_BLOCK_STATS: isDebugLevel3 || process.env.LLAMA_SDK_GET_BLOCK_STATS === 'true',
54
- // GET_LOGS_ERRORS: isDebugLevel3 || process.env.LLAMA_SDK_GET_LOGS_ERRORS === 'true',
55
- GET_LOGS_DEBUG: isDebugLevel3 || process.env.LLAMA_SDK_GET_LOGS_DEBUG === 'true',
56
- GET_LOGS_INDEXER: isDebugLevel3 || process.env.LLAMA_SDK_GET_LOGS_INDEXER === 'true',
57
- DEFAULT_SHORTEN_STRING_LENGTH: (_a = process.env.LLAMA_SDK_DEFAULT_SHORTEN_STRING_LENGTH) !== null && _a !== void 0 ? _a : '120',
58
- };
59
- exports.whitelistedEnvConstants.forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key));
60
- Object.keys(defaultEnvValues).forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key, defaultEnvValues[key]));
61
- // doing this as I am paranoid that that empty object when first declared might be exported before values are set
62
- exports.ENV_CONSTANTS = { ..._ENV_CONSTANTS };
63
- function getChainId(chain, chainId) {
64
- var _a;
65
- const value = (_a = getEnvValue(`${chain}_RPC_CHAIN_ID`)) !== null && _a !== void 0 ? _a : chainId;
66
- return +value;
67
- }
68
- function getMaxParallelRequests(chain) {
69
- const chainKey = `${chain}_RPC_MAX_PARALLEL`;
70
- if (getEnvValue(chainKey))
71
- return +getEnvValue(chainKey);
72
- if (['harmony', 'avax'].includes(chain))
73
- return 20;
74
- return +getEnvValue('MAX_PARALLEL', '100');
75
- }
76
- function getParallelGetLogsLimit(chain, providerUrl) {
77
- let defaultLimit = getEnvValue('GET_LOGS_CONCURRENCY_LIMIT', '25');
78
- if (chain === 'fantom')
79
- defaultLimit = '10';
80
- const defaultAlchemyLimit = getEnvValue('ALCHEMY_GET_LOGS_CONCURRENCY_LIMIT', '25');
81
- if (providerUrl && providerUrl.includes('alchemy.com'))
82
- return +(defaultAlchemyLimit);
83
- return +(getEnvValue(`${chain}_RPC_GET_LOGS_CONCURRENCY_LIMIT`, defaultLimit));
84
- }
85
- function getParallelGetBlocksLimit(chain) {
86
- const defaultLimit = getEnvValue('GET_BLOCKS_CONCURRENCY_LIMIT', '5');
87
- return +(getEnvValue(`${chain}_RPC_GET_BLOCKS_CONCURRENCY_LIMIT`, defaultLimit));
88
- }
89
- function getEnvRPC(chain) {
90
- const key = `${chain}_RPC`.toUpperCase();
91
- return getEnvValue(key, defaultEnvValues[key]);
92
- }
93
- function getEnvValue(key, defaultValue) {
94
- var _a, _b, _c;
95
- key = key.toUpperCase();
96
- defaultValue = defaultValue !== null && defaultValue !== void 0 ? defaultValue : defaultEnvValues[key];
97
- return (_c = (_b = (_a = process.env['LLAMA_SDK_' + key]) !== null && _a !== void 0 ? _a : process.env['SDK_' + key]) !== null && _b !== void 0 ? _b : process.env[key]) !== null && _c !== void 0 ? _c : defaultValue;
98
- }
99
- function getEnvCacheFolder(defaultCacheFolder) {
100
- return getEnvValue('TVL_LOCAL_CACHE_ROOT_FOLDER', defaultCacheFolder);
101
- }
102
- function getEnvMulticallAddress(chain) {
103
- return getEnvValue(`${chain}_RPC_MULTICALL`);
104
- }
105
- function getDefaultChunkSize(chain) {
106
- const key = chain + '_MULTICALL_CHUNK_SIZE';
107
- if (getEnvValue(key))
108
- return +getEnvValue(key);
109
- if (chain === 'cronos')
110
- return 50;
111
- return +(getEnvValue('MULTICALL_CHUNK_SIZE', '300'));
112
- }
113
- function getBatchMaxCount(chain) {
114
- const key = chain + '_BATCH_MAX_COUNT';
115
- if (getEnvValue(key))
116
- return +getEnvValue(key);
117
- switch (chain) {
118
- case 'zkfair': return 1;
119
- default: return +getEnvValue('BATCH_MAX_COUNT', '5');
120
- }
121
- }
122
- function getArchivalRPCs(chain) {
123
- const key = chain + '_ARCHIVAL_RPC';
124
- if (getEnvValue(key))
125
- return getEnvValue(key).split(',');
126
- return [];
127
- }
128
- function getChainRPCs(chain, defaultList = []) {
129
- const envValue = getEnvRPC(chain);
130
- if (defaultList.length) {
131
- const listString = defaultList.join(',');
132
- if (envValue)
133
- return envValue + ',' + listString;
134
- return listString;
135
- }
136
- return envValue || undefined;
137
- }
138
- function getWhitelistedRPCs(chain) {
139
- const key = chain + '_WHITELISTED_RPC';
140
- if (getEnvValue(key))
141
- return getEnvValue(key).split(',');
142
- return [];
143
- }
144
- let skipBlockValidationChainSet = null;
145
- function shouldSkipBlockValidation(chain) {
146
- if (!skipBlockValidationChainSet) {
147
- const envValue = getEnvValue('SKIP_BLOCK_VALIDATION_CHAINS', '');
148
- const chainList = envValue ? envValue.split(',').map(c => c.trim()) : [];
149
- skipBlockValidationChainSet = new Set(chainList);
150
- }
151
- return skipBlockValidationChainSet.has(chain);
152
- }
153
- function getBoolEnvValue(key, defaultValue = false) {
154
- const envValue = getEnvValue(key);
155
- if (envValue === undefined)
156
- return defaultValue;
157
- return envValue === 'true';
158
- }
@@ -1,8 +0,0 @@
1
- export declare function request(endpoint: string, query: string, { cache, cacheKey, variables, withMetadata, network, }?: {
2
- cache?: boolean;
3
- cacheKey?: string;
4
- withMetadata?: boolean;
5
- variables?: any;
6
- network?: string;
7
- }): Promise<any>;
8
- export declare function modifyEndpoint(endpoint: string, network?: string): string;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.request = request;
4
- exports.modifyEndpoint = modifyEndpoint;
5
- const common_1 = require("./common");
6
- const cache_1 = require("./cache");
7
- const debugLog_1 = require("./debugLog");
8
- const env_1 = require("./env");
9
- async function request(endpoint, query, { cache = false, cacheKey, variables, withMetadata = false, network, } = {}) {
10
- try {
11
- const data = await _request();
12
- if (cache) {
13
- if (!cacheKey)
14
- throw new Error('cacheKey is required');
15
- await (0, cache_1.writeCache)('graph-data/' + cacheKey, data);
16
- }
17
- return data;
18
- }
19
- catch (error) {
20
- if (!cache)
21
- throw error;
22
- (0, debugLog_1.debugLog)('Error fetching data, reading from cache:', error);
23
- const cacheData = await (0, cache_1.readCache)('graph-data/' + cacheKey);
24
- return cacheData;
25
- }
26
- async function _request() {
27
- endpoint = modifyEndpoint(endpoint, network);
28
- const result = await (0, common_1.postJson)(endpoint, { query, variables });
29
- if (result.errors)
30
- throw new Error(result.errors[0].message);
31
- return withMetadata ? result : result.data;
32
- }
33
- }
34
- let graphKeyWarned = false;
35
- function modifyEndpoint(endpoint, network = 'arbitrum') {
36
- // example: https://api.thegraph.com/subgraphs/name/yieldyak/reinvest-tracker
37
- let graphKey = (0, env_1.getEnvValue)('GRAPH_API_KEY');
38
- if (!endpoint.includes('http')) // we assume it is subgraph id
39
- endpoint = `https://gateway-${network}.network.thegraph.com/api/[api-key]/subgraphs/id/${endpoint}`;
40
- if (!endpoint.includes('thegraph.com'))
41
- return endpoint;
42
- else if (!graphKey) {
43
- graphKey = "5a1340b49fa9efe00" + "21452daa260564e";
44
- // if (!graphKeyWarned)
45
- // console.log("GRAPH_API_KEY env variable is not set, using the default api key")
46
- graphKeyWarned = true;
47
- }
48
- endpoint = endpoint.replace('[api-key]', graphKey);
49
- return endpoint;
50
- }
@@ -1,32 +0,0 @@
1
- import { Chain } from "../general";
2
- import type { Address } from "../types";
3
- import { ethers, EventLog } from "ethers";
4
- import runInPromisePoolOrig from "./promisePool";
5
- export { getLatestBlock, getTimestamp, lookupBlock, } from "./blocks";
6
- export { convertToBigInt } from "./common";
7
- export declare const runInPromisePool: typeof runInPromisePoolOrig;
8
- export declare function sliceIntoChunks(arr: any[], chunkSize?: number): any[][];
9
- type GetLogsOptions = {
10
- target?: Address;
11
- topic: string;
12
- keys: string[];
13
- fromBlock: number;
14
- toBlock: number;
15
- topics?: (string | null)[];
16
- chain?: Chain;
17
- provider?: ethers.Provider;
18
- };
19
- export declare function getLogs(options: GetLogsOptions): Promise<{
20
- output: EventLog[];
21
- }>;
22
- export declare function normalizeAddress(address: string): string;
23
- export declare function normalizePrefixes(address: string): string;
24
- export declare function normalizeBalances(balances: {
25
- [address: string]: string;
26
- }): {
27
- [address: string]: string;
28
- };
29
- export declare function tableToString(data: any, columns?: any, { title, columns: _columns }?: {
30
- title?: string;
31
- columns?: string[];
32
- }): string;
@@ -1,227 +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.runInPromisePool = exports.convertToBigInt = exports.lookupBlock = exports.getTimestamp = exports.getLatestBlock = void 0;
7
- exports.sliceIntoChunks = sliceIntoChunks;
8
- exports.getLogs = getLogs;
9
- exports.normalizeAddress = normalizeAddress;
10
- exports.normalizePrefixes = normalizePrefixes;
11
- exports.normalizeBalances = normalizeBalances;
12
- exports.tableToString = tableToString;
13
- const general_1 = require("../general");
14
- const ethers_1 = require("ethers");
15
- const common_1 = require("./common");
16
- const debugLog_1 = require("./debugLog");
17
- const promisePool_1 = __importDefault(require("./promisePool"));
18
- var blocks_1 = require("./blocks");
19
- Object.defineProperty(exports, "getLatestBlock", { enumerable: true, get: function () { return blocks_1.getLatestBlock; } });
20
- Object.defineProperty(exports, "getTimestamp", { enumerable: true, get: function () { return blocks_1.getTimestamp; } });
21
- Object.defineProperty(exports, "lookupBlock", { enumerable: true, get: function () { return blocks_1.lookupBlock; } });
22
- var common_2 = require("./common");
23
- Object.defineProperty(exports, "convertToBigInt", { enumerable: true, get: function () { return common_2.convertToBigInt; } });
24
- const p_limit_1 = __importDefault(require("p-limit"));
25
- const env_1 = require("./env");
26
- exports.runInPromisePool = promisePool_1.default;
27
- function sliceIntoChunks(arr, chunkSize = 100) {
28
- const res = [];
29
- for (let i = 0; i < arr.length; i += chunkSize) {
30
- const chunk = arr.slice(i, i + chunkSize);
31
- res.push(chunk);
32
- }
33
- return res;
34
- }
35
- const chainLogLimiters = {};
36
- function getChainLimiter(chain, providerUrl) {
37
- if (!chainLogLimiters[chain])
38
- chainLogLimiters[chain] = createLimiter(chain);
39
- return chainLogLimiters[chain];
40
- function createLimiter(chain) {
41
- return (0, p_limit_1.default)((0, env_1.getParallelGetLogsLimit)(chain, providerUrl));
42
- }
43
- }
44
- async function getLogs(options) {
45
- const getLimiter = () => getChainLimiter(options.chain, (0, common_1.getProviderUrl)(options.provider));
46
- // if provider is not passed, we try with archival node first (if set) and then with non-archival node
47
- let provider;
48
- if (!options.provider) {
49
- options.provider = (0, general_1.getProvider)(options.chain, true);
50
- provider = options.provider;
51
- try {
52
- const res = await getLimiter()(() => _getLogs(options));
53
- return res;
54
- }
55
- catch (e) {
56
- options.provider = (0, general_1.getProvider)(options.chain, false);
57
- // if (provider === options.provider) throw e // the provider for archival and non-archival request is the same
58
- if (env_1.ENV_CONSTANTS.GET_LOGS_DEBUG)
59
- (0, debugLog_1.debugLog)(`Error fetching logs for chain ${options.chain} ${(0, common_1.formError)(e, { chain: options.chain, target: options.target, })}, retrying...`);
60
- return getLimiter()(() => _getLogs(options));
61
- }
62
- }
63
- return getLimiter()(() => _getLogs(options));
64
- }
65
- // SMALL INCOMPATIBILITY: On the old API we don't return ids but we should
66
- async function _getLogs(params) {
67
- var _a, _b;
68
- if (params.toBlock === undefined || params.fromBlock === undefined) {
69
- throw new Error("toBlock and fromBlock need to be defined in all calls to getLogs");
70
- }
71
- const filter = {
72
- address: params.target,
73
- topics: (_a = params.topics) !== null && _a !== void 0 ? _a : [ethers_1.ethers.id(params.topic)],
74
- fromBlock: params.fromBlock,
75
- toBlock: params.toBlock // We don't replicate Defipulse's bug because the results end up being the same anyway and hopefully they'll eventually fix it
76
- };
77
- let logs = [];
78
- let blockSpread = params.toBlock - params.fromBlock;
79
- let currentBlock = params.fromBlock;
80
- const provider = (_b = params.provider) !== null && _b !== void 0 ? _b : (0, general_1.getProvider)(params.chain, true);
81
- while (currentBlock < params.toBlock) {
82
- const nextBlock = Math.min(params.toBlock, currentBlock + blockSpread);
83
- let logParams = {
84
- ...filter,
85
- fromBlock: currentBlock,
86
- toBlock: nextBlock
87
- };
88
- try {
89
- const partLogs = await provider.getLogs(logParams);
90
- logs = logs.concat(partLogs);
91
- currentBlock = nextBlock;
92
- }
93
- catch (e) {
94
- if (env_1.ENV_CONSTANTS.GET_LOGS_DEBUG)
95
- (0, debugLog_1.debugLog)(`Error fetching logs for chain ${params.chain} blockSpread: ${blockSpread}. ${(0, common_1.formError)(e, { chain: params.chain, target: params.target, provider })}`);
96
- if (blockSpread >= 1001) {
97
- // We got too many results
98
- // We could chop it up into 1001 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
99
- blockSpread = Math.floor(blockSpread / 2);
100
- if (blockSpread > 510 && blockSpread < 2000)
101
- blockSpread = 999;
102
- if (blockSpread > 5100 && blockSpread < 10000)
103
- blockSpread = 9999;
104
- }
105
- else {
106
- const error = (0, common_1.formError)(e, { chain: params.chain, target: params.target, provider });
107
- error.message = `[chain: ${params.chain}] ${error === null || error === void 0 ? void 0 : error.message} params: ${JSON.stringify(logParams)}`;
108
- throw e;
109
- }
110
- }
111
- }
112
- if (params.keys.length > 0) {
113
- if (params.keys[0] !== "topics") {
114
- throw new Error("Unsupported");
115
- }
116
- return {
117
- output: logs.map((log) => log.topics)
118
- };
119
- }
120
- // ethers v5 logs had 'logIndex' but not ethers v6, so adding field to keep it compatible
121
- logs.forEach((log) => {
122
- log.logIndex = log.index;
123
- delete log.provider;
124
- });
125
- return {
126
- output: logs
127
- };
128
- }
129
- function normalizeAddress(address) {
130
- // sol amd tezos case sensitive so no normalising
131
- const prefix = address.substring(0, address.indexOf(":"));
132
- if (["solana", "tezos"].includes(prefix))
133
- return address;
134
- return address.toLowerCase();
135
- }
136
- function normalizePrefixes(address) {
137
- const prefix = address.substring(0, address.indexOf(":"));
138
- if (["solana", "tezos"].includes(prefix))
139
- return address;
140
- return address.startsWith("0x")
141
- ? `ethereum:${address.toLowerCase()}`
142
- : !address.includes(":")
143
- ? `coingecko:${address.toLowerCase()}`
144
- : address.toLowerCase();
145
- }
146
- const ethereumAddress = "ethereum:0x0000000000000000000000000000000000000000";
147
- const weth = "ethereum:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
148
- function normalizeBalances(balances) {
149
- var _a;
150
- Object.keys(balances).map((key) => {
151
- if (+balances[key] === 0) {
152
- delete balances[key];
153
- return;
154
- }
155
- const normalisedKey = normalizePrefixes(key);
156
- if (normalisedKey == key)
157
- return;
158
- (0, common_1.sumSingleBalance)(balances, normalisedKey, balances[key]);
159
- delete balances[key];
160
- });
161
- const eth = balances[ethereumAddress];
162
- if (eth !== undefined) {
163
- balances[weth] = (BigInt((_a = balances[weth]) !== null && _a !== void 0 ? _a : 0) + BigInt(eth)).toString();
164
- delete balances[ethereumAddress];
165
- }
166
- return balances;
167
- }
168
- function tableToString(data, columns, { title, columns: _columns } = {}) {
169
- // If only two arguments are passed and the second is not an array, treat it as options
170
- if (arguments.length === 2 && !Array.isArray(columns) && typeof columns === 'object') {
171
- ({ title, columns: _columns } = columns !== null && columns !== void 0 ? columns : {});
172
- columns = undefined;
173
- }
174
- if (_columns && Array.isArray(_columns))
175
- columns = _columns;
176
- let tableString = '';
177
- if (!Array.isArray(data) && typeof data === 'object') {
178
- data = Object.entries(data).map(([key, value]) => {
179
- const row = { key };
180
- if (typeof value === 'object' && !Array.isArray(value)) {
181
- Object.entries(value).forEach(([subKey, subValue]) => {
182
- row[subKey] = subValue;
183
- });
184
- }
185
- else {
186
- row.value = value;
187
- }
188
- return row;
189
- });
190
- }
191
- if (!data || !Array.isArray(data) || data.length === 0) {
192
- return '';
193
- }
194
- data = [...data]; // Ensure we don't modify the original data
195
- if (!columns || !Array.isArray(columns) || columns.length === 0) {
196
- const columnsSet = new Set();
197
- data.forEach((row) => {
198
- Object.keys(row).forEach((col) => {
199
- columnsSet.add(col);
200
- });
201
- });
202
- columns = Array.from(columnsSet);
203
- }
204
- if (title)
205
- tableString += `# ${title}\n\n`;
206
- // Add the header row
207
- const headerObject = {};
208
- const headerObject1 = {};
209
- columns.forEach((col) => {
210
- headerObject[col] = col;
211
- headerObject1[col] = '---';
212
- });
213
- data.unshift(headerObject1);
214
- data.unshift(headerObject);
215
- // Calculate the maximum width for each column
216
- const columnWidths = columns.map((col) => Math.max(col.length, ...data.map((row) => (row[col] !== undefined ? String(row[col]).length : 0))));
217
- // Add the data rows
218
- data.forEach((row) => {
219
- // Format the row with padded values
220
- const tableRow = columns.map((col, index) => {
221
- const cell = row[col] !== undefined ? String(row[col]) : '';
222
- return cell.padEnd(columnWidths[index], ' ');
223
- }).join(' | ');
224
- tableString += tableRow + '\n';
225
- });
226
- return tableString;
227
- }
@@ -1,6 +0,0 @@
1
- type RowKind = "logs" | "transfers" | "transactions";
2
- /** Preserve v2 REST field types and padding; never applied to SQL results. */
3
- export declare function normalizeV4Row(row: any, kind: RowKind): any;
4
- /** Capture an unquoted UInt256 id before JSON.parse can round it. */
5
- export declare function parseTransferResponse(text: string): Promise<any>;
6
- export {};