@defillama/sdk 5.0.240 → 5.0.244

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 (133) hide show
  1. package/build/Balances.d.ts +139 -0
  2. package/build/Balances.js +363 -0
  3. package/build/ChainApi.d.ts +142 -0
  4. package/build/ChainApi.js +310 -0
  5. package/build/abi/abi2.d.ts +5 -0
  6. package/build/abi/abi2.js +215 -0
  7. package/build/abi/cachedABIs.d.ts +4 -0
  8. package/build/abi/cachedABIs.js +8 -0
  9. package/build/abi/convertResults.d.ts +5 -0
  10. package/build/abi/convertResults.js +60 -0
  11. package/build/abi/index.d.ts +31 -0
  12. package/build/abi/index.js +327 -0
  13. package/build/abi/multicall.d.ts +23 -0
  14. package/build/abi/multicall.js +383 -0
  15. package/build/abi/multicall3.d.ts +7 -0
  16. package/build/abi/multicall3.js +405 -0
  17. package/build/abi/rpcCall.d.ts +4 -0
  18. package/build/abi/rpcCall.js +62 -0
  19. package/build/abi/tron.d.ts +33 -0
  20. package/build/abi/tron.js +118 -0
  21. package/build/api.d.ts +10 -0
  22. package/build/api.js +45 -0
  23. package/build/api2.d.ts +5 -0
  24. package/build/api2.js +41 -0
  25. package/build/chains/algorand.d.ts +277 -0
  26. package/build/chains/algorand.js +618 -0
  27. package/build/chains/aptos.d.ts +269 -0
  28. package/build/chains/aptos.js +700 -0
  29. package/build/chains/cardano.d.ts +242 -0
  30. package/build/chains/cardano.js +407 -0
  31. package/build/chains/cosmos.d.ts +252 -0
  32. package/build/chains/cosmos.js +623 -0
  33. package/build/chains/icp.d.ts +235 -0
  34. package/build/chains/icp.js +1040 -0
  35. package/build/chains/index.d.ts +23 -0
  36. package/build/chains/index.js +59 -0
  37. package/build/chains/near.d.ts +192 -0
  38. package/build/chains/near.js +446 -0
  39. package/build/chains/rpc.d.ts +125 -0
  40. package/build/chains/rpc.js +332 -0
  41. package/build/chains/starknet.d.ts +205 -0
  42. package/build/chains/starknet.js +886 -0
  43. package/build/chains/stellar.d.ts +410 -0
  44. package/build/chains/stellar.js +1082 -0
  45. package/build/chains/substrate.d.ts +333 -0
  46. package/build/chains/substrate.js +1042 -0
  47. package/build/chains/sui.d.ts +392 -0
  48. package/build/chains/sui.js +1213 -0
  49. package/build/chains/svm.d.ts +340 -0
  50. package/build/chains/svm.js +764 -0
  51. package/build/chains/tezos.d.ts +225 -0
  52. package/build/chains/tezos.js +412 -0
  53. package/build/chains/ton.d.ts +353 -0
  54. package/build/chains/ton.js +788 -0
  55. package/build/chains/tron.d.ts +45 -0
  56. package/build/chains/tron.js +110 -0
  57. package/build/chains/utxo.d.ts +210 -0
  58. package/build/chains/utxo.js +678 -0
  59. package/build/chains/xrpl.d.ts +179 -0
  60. package/build/chains/xrpl.js +467 -0
  61. package/build/computeTVL/blocks.d.ts +1 -0
  62. package/build/computeTVL/blocks.js +12 -0
  63. package/build/computeTVL/humanizeNumber.d.ts +1 -0
  64. package/build/computeTVL/humanizeNumber.js +19 -0
  65. package/build/erc20/index.d.ts +31 -0
  66. package/build/erc20/index.js +56 -0
  67. package/build/eth/index.d.ts +22 -0
  68. package/build/eth/index.js +118 -0
  69. package/build/general.d.ts +5 -0
  70. package/build/general.js +20 -0
  71. package/build/generalUtil.d.ts +8 -0
  72. package/build/generalUtil.js +73 -0
  73. package/build/index.d.ts +33 -0
  74. package/build/index.js +75 -0
  75. package/build/providers.json +1 -0
  76. package/build/types.d.ts +76 -0
  77. package/build/types.js +2 -0
  78. package/build/util/LlamaProvider.d.ts +46 -0
  79. package/build/util/LlamaProvider.js +343 -0
  80. package/build/util/blocks.d.ts +36 -0
  81. package/build/util/blocks.js +500 -0
  82. package/build/util/cache.d.ts +45 -0
  83. package/build/util/cache.js +309 -0
  84. package/build/util/callStats.d.ts +74 -0
  85. package/build/util/callStats.js +385 -0
  86. package/build/util/chainUtils/data.json +1459 -0
  87. package/build/util/chainUtils/index.d.ts +11 -0
  88. package/build/util/chainUtils/index.js +136 -0
  89. package/build/util/coins.d.ts +19 -0
  90. package/build/util/coins.js +124 -0
  91. package/build/util/common.d.ts +34 -0
  92. package/build/util/common.js +376 -0
  93. package/build/util/computeTVL.d.ts +19 -0
  94. package/build/util/computeTVL.js +102 -0
  95. package/build/util/cosmos.d.ts +1 -0
  96. package/build/util/cosmos.js +8 -0
  97. package/build/util/debugLog.d.ts +4 -0
  98. package/build/util/debugLog.js +18 -0
  99. package/build/util/discord.d.ts +1 -0
  100. package/build/util/discord.js +33 -0
  101. package/build/util/elastic.d.ts +43 -0
  102. package/build/util/elastic.js +113 -0
  103. package/build/util/env.d.ts +20 -0
  104. package/build/util/env.js +176 -0
  105. package/build/util/graph.d.ts +8 -0
  106. package/build/util/graph.js +50 -0
  107. package/build/util/index.d.ts +32 -0
  108. package/build/util/index.js +227 -0
  109. package/build/util/indexer.compatibility.d.ts +6 -0
  110. package/build/util/indexer.compatibility.js +64 -0
  111. package/build/util/indexer.d.ts +92 -0
  112. package/build/util/indexer.js +854 -0
  113. package/build/util/indexerSql.d.ts +9 -0
  114. package/build/util/indexerSql.js +102 -0
  115. package/build/util/internal-cache.d.ts +11 -0
  116. package/build/util/internal-cache.js +77 -0
  117. package/build/util/logs.d.ts +58 -0
  118. package/build/util/logs.decode.shared.d.ts +8 -0
  119. package/build/util/logs.decode.shared.js +289 -0
  120. package/build/util/logs.js +432 -0
  121. package/build/util/promisePool.d.ts +8 -0
  122. package/build/util/promisePool.js +31 -0
  123. package/build/util/r2.d.ts +4 -0
  124. package/build/util/r2.js +52 -0
  125. package/build/util/removeRedundantRPCs.d.ts +1 -0
  126. package/build/util/removeRedundantRPCs.js +49 -0
  127. package/build/util/transactions.d.ts +35 -0
  128. package/build/util/transactions.js +22 -0
  129. package/build/util/updateChainLabels.d.ts +1 -0
  130. package/build/util/updateChainLabels.js +5 -0
  131. package/build/util/updateProviderList.d.ts +1 -0
  132. package/build/util/updateProviderList.js +275 -0
  133. package/package.json +3 -2
@@ -0,0 +1,275 @@
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
+ const providers_json_1 = __importDefault(require("../providers.json"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const debugLog_1 = require("./debugLog");
9
+ const promise_pool_1 = __importDefault(require("@supercharge/promise-pool"));
10
+ const generalUtil_1 = require("../generalUtil");
11
+ const chainUtils_1 = require("../util/chainUtils");
12
+ const concurrentCheckChains = +(process.env.SDK_BUILD_CONCURRENT_CHAINS || 7);
13
+ const chainRemovalThreshold = +(process.env.SDK_BUILD_CHAIN_REMOVAL_THRESHOLD || 20);
14
+ const droppedTestnetChainsSet = new Set([]);
15
+ const providerList = providers_json_1.default;
16
+ async function getChainData() {
17
+ try {
18
+ const chainData = await (0, generalUtil_1.fetchJson)('https://chainlist.org/rpcs.json');
19
+ // fix for zksync era name clash
20
+ const eteriaListing = chainData.find((i) => i.chainId === 140);
21
+ if (eteriaListing)
22
+ eteriaListing.shortName = 'eteria';
23
+ return chainData;
24
+ }
25
+ catch (e) {
26
+ console.log('Failed to fetch chainlist.org, falling back to local copy');
27
+ // https://unpkg.com/@defillama/sdk@latest/build/providers.json
28
+ return require(__dirname + '/chainlistOrgCache.json');
29
+ }
30
+ }
31
+ async function main() {
32
+ await (0, chainUtils_1.updateChainLabels)();
33
+ const oldProviders = await (0, generalUtil_1.fetchJson)(`https://unpkg.com/@defillama/sdk@latest/build/providers.json`);
34
+ const currentChains = await (0, generalUtil_1.fetchJson)(`https://raw.githubusercontent.com/DefiLlama/DefiLlama-Adapters/refs/heads/main/projects/helper/chains.json`);
35
+ const currentChainsSet = new Set(currentChains);
36
+ let chainData = await getChainData();
37
+ const providerIDMap = {};
38
+ const chainIdToKeyMap = {};
39
+ Object.entries(providerList).forEach(([key, i]) => {
40
+ providerIDMap[i.chainId] = i.rpc;
41
+ chainIdToKeyMap[i.chainId] = key;
42
+ });
43
+ const shortNameToKeyMap = {};
44
+ Object.entries(chainShortNameMapping).forEach(([key, shortName]) => shortNameToKeyMap[shortName] = key);
45
+ chainData = chainData
46
+ .filter((i) => i.rpc.length)
47
+ // .filter((i: any) => !i.status || (i.status === 'active' || i.status === 'incubating'))
48
+ .filter((i) => i.shortName)
49
+ .filter((i) => {
50
+ var _a, _b;
51
+ if (currentChainsSet.has(i.shortName))
52
+ return true;
53
+ const bannedKeys = ['sepolia', 'test', 'goerli', 'devnet', 'holesky',];
54
+ const bannedRPCKeys = ['sepolia', 'goerli', 'devnet', 'holesky'];
55
+ const isTestnetKey = bannedKeys.some((j) => i.shortName.includes(j));
56
+ const hasTestnetRPC = i.rpc.some((rpc) => bannedRPCKeys.some((k) => rpc === null || rpc === void 0 ? void 0 : rpc.url.includes(k)));
57
+ const hasTestnetName = ((_a = i.name) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('testnet')) || ((_b = i.name) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes('devnet'));
58
+ if (isTestnetKey || hasTestnetRPC || hasTestnetName) {
59
+ droppedTestnetChainsSet.add(i.shortName);
60
+ // console.log(`Excluding testnet chain ${i.name} (${i.shortName})`)
61
+ }
62
+ return !isTestnetKey && !hasTestnetRPC && !hasTestnetName;
63
+ });
64
+ // trim/remove mainnet|-mainnet|_mainnet from short names, preliminary rpc filtering
65
+ const rpcFilterRegex = /(wss\:|ws\:|terminet\.io|huobichain\.com|getblock\.io|bitstack\.com|nodereal.io\/v1|pokt\.network|histori\.xyz|chainstacklabs\.com|owlracle\.info|blastapi\.io)/;
66
+ chainData.forEach((i) => {
67
+ if (currentChainsSet.has(i.shortName)) {
68
+ // keep the short name as is
69
+ }
70
+ if (i.shortName.endsWith('-mainnet'))
71
+ i.shortName = i.shortName.slice(0, -8);
72
+ else if (i.shortName.endsWith('_mainnet'))
73
+ i.shortName = i.shortName.slice(0, -8);
74
+ else if (i.shortName.endsWith('mainnet'))
75
+ i.shortName = i.shortName.slice(0, -7);
76
+ i.rpc = i.rpc.filter((j) => {
77
+ if (!j.url)
78
+ return false;
79
+ if (rpcFilterRegex.test(j.url)) {
80
+ // console.log(`Removing blacklisted rpc ${j.url} from ${i.name}`)
81
+ return false; // remove anything with blacklisted words
82
+ }
83
+ return true;
84
+ });
85
+ });
86
+ // shuffle the array
87
+ chainData.sort(() => Math.random() - 0.5);
88
+ // chain keys this chain could end up under in providers.json
89
+ const getCandidateKeys = (i) => {
90
+ const keys = [i.shortName.toLowerCase().replace(/-/g, '_')];
91
+ if (chainIdToKeyMap[i.chainId])
92
+ keys.push(chainIdToKeyMap[i.chainId]);
93
+ if (shortNameToKeyMap[i.shortName])
94
+ keys.push(shortNameToKeyMap[i.shortName]);
95
+ return keys;
96
+ };
97
+ // only check rpc health for chains we track and that are not dead, the rest are only filtered statically
98
+ const shouldCheckRPCs = (i) => {
99
+ const keys = getCandidateKeys(i);
100
+ const isTracked = keys.some((k) => currentChainsSet.has(k));
101
+ const isDead = keys.some((k) => (0, chainUtils_1.isDeadChain)(k));
102
+ return isTracked && !isDead;
103
+ };
104
+ const skippedRPCChecks = { dead: 0, untracked: 0 };
105
+ await promise_pool_1.default
106
+ .withConcurrency(concurrentCheckChains)
107
+ .for(chainData)
108
+ .process(async (i) => {
109
+ var _a, _b;
110
+ const rpcs = i.rpc.map((j) => j.url);
111
+ if (shouldCheckRPCs(i)) {
112
+ i.rpc = await filterForWorkingRPCs(rpcs, i.name, i.chainId);
113
+ }
114
+ else {
115
+ if (getCandidateKeys(i).some((k) => (0, chainUtils_1.isDeadChain)(k)))
116
+ skippedRPCChecks.dead++;
117
+ else
118
+ skippedRPCChecks.untracked++;
119
+ i.rpc = rpcs.length < 4 ? rpcs : filterRPCs(rpcs);
120
+ }
121
+ if (!i.rpc.length)
122
+ return;
123
+ if (providerIDMap[i.chainId]) {
124
+ const isBEVM = i.chainId + '' === '11501'; // bevm chain id clashes with
125
+ if (!isBEVM)
126
+ providerIDMap[i.chainId].push(...i.rpc);
127
+ }
128
+ else if (providerList[i.shortName.toLowerCase()]) {
129
+ (0, debugLog_1.debugLog)(`Duplicate short name ${i.chainId} for ${i.shortName}, doing nothing`);
130
+ }
131
+ else {
132
+ const label = i.shortName.toLowerCase().replace(/-/g, '_');
133
+ providerList[label] = {
134
+ rpc: i.rpc,
135
+ chainId: i.chainId
136
+ };
137
+ let explorer = (_b = (_a = i.explorers) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.url;
138
+ if (explorer)
139
+ providerList[label].explorer = explorer;
140
+ }
141
+ });
142
+ Object.entries(providerList).forEach(([key, i]) => {
143
+ i.rpc.forEach((j) => {
144
+ if (filterRPCs([j]).length === 0) {
145
+ (0, debugLog_1.debugLog)(`Removing rpc ${j} from ${key}`);
146
+ }
147
+ });
148
+ i.rpc = Array.from(new Set(filterRPCs(i.rpc)));
149
+ });
150
+ Object.keys(providerList).forEach((i) => {
151
+ if (!providerList[i].rpc.length)
152
+ delete providerList[i];
153
+ });
154
+ for (const [key, shorName] of Object.entries(chainShortNameMapping)) {
155
+ if (providerList[key])
156
+ continue;
157
+ providerList[key] = providerList[shorName];
158
+ }
159
+ // add from the old providers any missing rpcs that is in the tvl chain list
160
+ Object.entries(oldProviders).forEach(([key, i]) => {
161
+ if (!currentChainsSet.has(key))
162
+ return;
163
+ if (providerList[key])
164
+ return;
165
+ console.log(`Adding missing chain ${key} from old providers`);
166
+ providerList[key] = i;
167
+ });
168
+ const droppedChains = Object.keys(oldProviders).filter(oldChain => providerList[oldChain] === undefined);
169
+ const filteredDroppedChains = droppedChains.filter(i => !droppedTestnetChainsSet.has(i) && !i.includes('test'));
170
+ console.log('Dropped chains before testnet filtering:', droppedChains.length);
171
+ console.log('Dropped chains after testnet filtering:', filteredDroppedChains.length);
172
+ if (filteredDroppedChains.length > chainRemovalThreshold) {
173
+ throw new Error(`Following chains used to be included but is not anymore, can the devs fix please?\n${filteredDroppedChains.join(', ')}`);
174
+ }
175
+ delete providerList.bitcoin; // what were they smoking?
176
+ const rpcCount = Object.values(providerList).reduce((acc, i) => { var _a; return acc + ((_a = i === null || i === void 0 ? void 0 : i.rpc.length) !== null && _a !== void 0 ? _a : 0); }, 0);
177
+ const rpcCountOld = Object.values(oldProviders).reduce((acc, i) => { var _a; return acc + ((_a = i === null || i === void 0 ? void 0 : i.rpc.length) !== null && _a !== void 0 ? _a : 0); }, 0);
178
+ const newlyAddedChains = Object.keys(providerList).filter(chain => oldProviders[chain] === undefined);
179
+ console.log('Final provider list:');
180
+ console.log('Skipped rpc checks (dead chains):', skippedRPCChecks.dead);
181
+ console.log('Skipped rpc checks (untracked chains):', skippedRPCChecks.untracked);
182
+ console.log('Chain count:', Object.keys(providerList).length);
183
+ console.log('Newly added chains count:', newlyAddedChains.length);
184
+ console.log('Dropped chain count:', filteredDroppedChains.length);
185
+ console.log('RPC count:', rpcCount);
186
+ console.log('RPC count current:', rpcCountOld);
187
+ console.log('Dropped chains:', filteredDroppedChains.join(', '));
188
+ console.log('Newly added chains:', newlyAddedChains.join(', '));
189
+ fs_1.default.writeFileSync(__dirname + '/../providers.json', JSON.stringify(providerList));
190
+ }
191
+ const blacklist = [
192
+ 'https://eth.api.onfinality.io/public'
193
+ ];
194
+ // this is stricter filtering used only when chain has more than 10 rpcs
195
+ function filterRPCs(rpc) {
196
+ return rpc.filter((i) => {
197
+ if (blacklist.includes(i))
198
+ return false; // remove rpcs returning bad block heights etc
199
+ if (i.endsWith('/demo'))
200
+ return false; // remove demo rpc
201
+ if (!i.startsWith('http'))
202
+ return false; // remove demo rpc
203
+ if (i.includes('$'))
204
+ return false; // remove anything where api key is injected
205
+ // reject websocket, http, testnet, devnet, and anything with '='
206
+ if (/(wss\:|ws\:|http\:|test|devnet|terminet|huobichain|getblock|bitstack|nodereal.io\/v1|pokt\.network|ankr\.com|histori\.xyz|chainstacklabs|owlracle|blastapi|routeme|\=)/.test(i))
207
+ return false; // remove anything with blacklisted words
208
+ return true;
209
+ }).map((i) => {
210
+ if (i.endsWith('/'))
211
+ return i.slice(0, -1);
212
+ return i;
213
+ });
214
+ }
215
+ const chainShortNameMapping = {
216
+ real: 're-al',
217
+ karura: 'karura_evm',
218
+ taiko: 'tko-mainnet',
219
+ bsquared: 'b2-mainnet',
220
+ ox_chain: 'ox-chain',
221
+ ailayer: 'ailayer-mainnet',
222
+ ontology: 'OntologyMainnet',
223
+ occ: 'edu_chain',
224
+ hyperliquid: 'hyper_evm',
225
+ hydradx: 'hdx',
226
+ nibiru: 'cataclysm_1',
227
+ fraxtal: 'frax',
228
+ elsm: 'ely',
229
+ tac: 'tacchain',
230
+ xone: 'xoc',
231
+ wchain: 'wcn',
232
+ hydragon: 'hydra',
233
+ camp: 'campmainnet',
234
+ mantra: 'mantrachain',
235
+ saga: 'sagaevm',
236
+ robinhood: 'robinhoodchain',
237
+ bcypher: 'bchyper',
238
+ area: 'areum',
239
+ };
240
+ async function filterForWorkingRPCs(rpc, chain, chainId) {
241
+ if (rpc.length < 4)
242
+ return rpc;
243
+ rpc = filterRPCs(rpc);
244
+ const filteredRPCs = [];
245
+ await (0, generalUtil_1.runInPromisePool)({
246
+ items: rpc,
247
+ concurrency: concurrentCheckChains,
248
+ permitFailure: true,
249
+ processor: async (i) => {
250
+ try {
251
+ const data = await (0, generalUtil_1.postJson)(i, {
252
+ jsonrpc: '2.0',
253
+ method: 'eth_chainId',
254
+ params: [],
255
+ id: 1
256
+ }, {
257
+ timeout: 60000
258
+ });
259
+ if (data.result) {
260
+ const returnedChainId = parseInt(data.result, 16);
261
+ if (returnedChainId !== chainId) {
262
+ console.log(`RPC ${i} for ${chain} returned invalid chainId ${returnedChainId}, expected ${chainId}, skipping`);
263
+ return;
264
+ }
265
+ filteredRPCs.push(i);
266
+ }
267
+ }
268
+ catch (e) {
269
+ console.log('ignoring bad rpc', chain, e === null || e === void 0 ? void 0 : e.message);
270
+ }
271
+ }
272
+ });
273
+ return filteredRPCs;
274
+ }
275
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "5.0.240",
3
+ "version": "5.0.244",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -16,7 +16,8 @@
16
16
  "update-providers": "ts-node src/util/updateProviderList.ts",
17
17
  "update-chain-labels": "ts-node src/util/updateChainLabels.ts",
18
18
  "remove-rpcs": "ts-node src/util/removeRedundantRPCs.ts",
19
- "prepublishOnly": "npm run build"
19
+ "verify-package": "node scripts/verifyPackage.js",
20
+ "prepublishOnly": "npm run build && npm run verify-package"
20
21
  },
21
22
  "repository": {
22
23
  "type": "git",