@defillama/sdk 5.0.198 → 5.0.206
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 +1 -0
- package/build/ChainApi.js +6 -2
- package/build/abi/abi2.js +52 -1
- package/build/abi/index.js +4 -0
- package/build/abi/multicall3.js +3 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +2 -1
- package/build/providers.json +1 -1
- package/build/types.d.ts +4 -2
- package/build/util/chainUtils/data.json +1064 -0
- package/build/util/chainUtils/index.d.ts +6 -0
- package/build/util/chainUtils/index.js +74 -0
- package/build/util/common.js +3 -0
- package/build/util/computeTVL.js +5 -0
- package/build/util/indexer.js +1 -0
- package/build/util/updateProviderList.js +76 -27
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { chainKeyToChainLabelMap, chainLabelsToKeyMap } from './data.json';
|
|
2
|
+
export { chainKeyToChainLabelMap, chainLabelsToKeyMap, };
|
|
3
|
+
export declare function updateData(): Promise<void>;
|
|
4
|
+
export declare const sluggifyString: (name: string) => string;
|
|
5
|
+
export declare function getChainKeyFromLabel(label: string): string;
|
|
6
|
+
export declare function getChainLabelFromKey(id: string): string;
|
|
@@ -0,0 +1,74 @@
|
|
|
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.sluggifyString = exports.chainLabelsToKeyMap = exports.chainKeyToChainLabelMap = void 0;
|
|
7
|
+
exports.updateData = updateData;
|
|
8
|
+
exports.getChainKeyFromLabel = getChainKeyFromLabel;
|
|
9
|
+
exports.getChainLabelFromKey = getChainLabelFromKey;
|
|
10
|
+
const data_json_1 = require("./data.json");
|
|
11
|
+
Object.defineProperty(exports, "chainKeyToChainLabelMap", { enumerable: true, get: function () { return data_json_1.chainKeyToChainLabelMap; } });
|
|
12
|
+
Object.defineProperty(exports, "chainLabelsToKeyMap", { enumerable: true, get: function () { return data_json_1.chainLabelsToKeyMap; } });
|
|
13
|
+
const fs_1 = __importDefault(require("fs"));
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
15
|
+
async function updateData() {
|
|
16
|
+
try {
|
|
17
|
+
// mapping pulled from https://github.com/DefiLlama/defillama-server/blob/master/defi/src/utils/normalizeChain.ts
|
|
18
|
+
const response = await fetch('https://api.llama.fi/overview/_internal/chain-name-id-map-v2');
|
|
19
|
+
const remoteData = await response.json();
|
|
20
|
+
for (const [key, value] of Object.entries(remoteData.chainKeyToChainLabelMap)) {
|
|
21
|
+
data_json_1.chainKeyToChainLabelMap[key] = value;
|
|
22
|
+
}
|
|
23
|
+
for (const [key, value] of Object.entries(remoteData.chainLabelsToKeyMap)) {
|
|
24
|
+
data_json_1.chainLabelsToKeyMap[key] = value;
|
|
25
|
+
}
|
|
26
|
+
// Save to data.json file
|
|
27
|
+
const dataFilePath = path_1.default.join(__dirname, 'data.json');
|
|
28
|
+
fs_1.default.writeFileSync(dataFilePath, JSON.stringify({
|
|
29
|
+
chainKeyToChainLabelMap: sortJSONData(data_json_1.chainKeyToChainLabelMap),
|
|
30
|
+
chainLabelsToKeyMap: sortJSONData(data_json_1.chainLabelsToKeyMap),
|
|
31
|
+
}, null, 2));
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error('Error updating chain data:', error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const sluggifyString = (name) => name.toLowerCase().split(" ").join("-").split("'").join("");
|
|
38
|
+
exports.sluggifyString = sluggifyString;
|
|
39
|
+
function sortJSONData(jsonData) {
|
|
40
|
+
const sortedKeys = Object.keys(jsonData).sort();
|
|
41
|
+
const sortedData = {};
|
|
42
|
+
for (const key of sortedKeys) {
|
|
43
|
+
sortedData[key] = jsonData[key];
|
|
44
|
+
}
|
|
45
|
+
return sortedData;
|
|
46
|
+
}
|
|
47
|
+
const _chainLabelToChainIdCache = {};
|
|
48
|
+
Object.entries(data_json_1.chainLabelsToKeyMap).forEach(([label, id]) => {
|
|
49
|
+
_chainLabelToChainIdCache[label] = id;
|
|
50
|
+
_chainLabelToChainIdCache[(0, exports.sluggifyString)(label)] = id;
|
|
51
|
+
});
|
|
52
|
+
// to be used if we are unsure if a label exists in our system, if it is known, use chainLabelsToKeyMap instead
|
|
53
|
+
function getChainKeyFromLabel(label) {
|
|
54
|
+
let value = _chainLabelToChainIdCache[label];
|
|
55
|
+
if (!value) {
|
|
56
|
+
let sluggifiedLabel = (0, exports.sluggifyString)(label);
|
|
57
|
+
value = _chainLabelToChainIdCache[sluggifiedLabel];
|
|
58
|
+
if (!value) {
|
|
59
|
+
value = sluggifiedLabel.replace(/\-/g, '_'); // try replacing - with _
|
|
60
|
+
_chainLabelToChainIdCache[sluggifiedLabel] = value;
|
|
61
|
+
}
|
|
62
|
+
_chainLabelToChainIdCache[label] = value;
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
// to be used if we are unsure if a label exists in our system, if it is known, use chainKeyToChainLabelMap instead
|
|
67
|
+
function getChainLabelFromKey(id) {
|
|
68
|
+
let value = data_json_1.chainKeyToChainLabelMap[id];
|
|
69
|
+
if (value)
|
|
70
|
+
return value;
|
|
71
|
+
value = id.slice(0, 1).toUpperCase() + id.slice(1); // Capitalize first letter
|
|
72
|
+
data_json_1.chainKeyToChainLabelMap[id] = value;
|
|
73
|
+
return value;
|
|
74
|
+
}
|
package/build/util/common.js
CHANGED
|
@@ -122,6 +122,9 @@ function sumSingleBalance(balances, token, balance, chain) {
|
|
|
122
122
|
else
|
|
123
123
|
throw new Error('Invalid balance value:' + balance + ' ' + token);
|
|
124
124
|
}
|
|
125
|
+
if (!token || token.trim() === '') {
|
|
126
|
+
throw new Error('Missing token address/symbol');
|
|
127
|
+
}
|
|
125
128
|
if (typeof balance === 'number' || (balances[token] && typeof balances[token] === 'number')) {
|
|
126
129
|
const prevBalance = +(balances.hasOwnProperty(token) ? balances[token] : 0);
|
|
127
130
|
if (typeof prevBalance !== 'number' || isNaN(prevBalance))
|
package/build/util/computeTVL.js
CHANGED
|
@@ -26,6 +26,9 @@ async function computeTVL(balances, timestamp, { debug = false } = {}) {
|
|
|
26
26
|
// if (+balance <= 0) return;
|
|
27
27
|
if (+balance === 0)
|
|
28
28
|
return;
|
|
29
|
+
if (!token || token.trim() === '') {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
29
32
|
const key = tokenToKey(token).toLowerCase();
|
|
30
33
|
let { price, confidence, decimals = 0, symbol = token } = (_a = priceCache[key]) !== null && _a !== void 0 ? _a : {};
|
|
31
34
|
if (!price || confidence < confidenceThreshold)
|
|
@@ -34,6 +37,8 @@ async function computeTVL(balances, timestamp, { debug = false } = {}) {
|
|
|
34
37
|
usdTvl += value;
|
|
35
38
|
if (symbol === 'ETH')
|
|
36
39
|
symbol = 'WETH';
|
|
40
|
+
if (!symbol || symbol.trim() === '')
|
|
41
|
+
symbol = '-';
|
|
37
42
|
(0, generalUtil_1.sumSingleBalance)(usdTokenBalances, symbol, value);
|
|
38
43
|
if (debug && !isNaN(+value))
|
|
39
44
|
debugData.tokenData.push({ symbol, value, token, price, confidence, balance, decimals, });
|
package/build/util/indexer.js
CHANGED
|
@@ -8,8 +8,10 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const debugLog_1 = require("./debugLog");
|
|
9
9
|
const promise_pool_1 = __importDefault(require("@supercharge/promise-pool"));
|
|
10
10
|
const generalUtil_1 = require("../generalUtil");
|
|
11
|
+
const chainUtils_1 = require("../util/chainUtils");
|
|
11
12
|
const concurrentCheckChains = +(process.env.SDK_BUILD_CONCURRENT_CHAINS || 7);
|
|
12
13
|
const chainRemovalThreshold = +(process.env.SDK_BUILD_CHAIN_REMOVAL_THRESHOLD || 20);
|
|
14
|
+
const droppedTestnetChainsSet = new Set([]);
|
|
13
15
|
const providerList = providers_json_1.default;
|
|
14
16
|
async function getChainData() {
|
|
15
17
|
try {
|
|
@@ -27,6 +29,21 @@ async function getChainData() {
|
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
async function main() {
|
|
32
|
+
const chainKeyLabelMapCountBefore = Object.keys(chainUtils_1.chainKeyToChainLabelMap).length;
|
|
33
|
+
const chainLabelsKeyMapCountBefore = Object.keys(chainUtils_1.chainLabelsToKeyMap).length;
|
|
34
|
+
await (0, chainUtils_1.updateData)();
|
|
35
|
+
const chainKeyLabelMapCountAfter = Object.keys(chainUtils_1.chainKeyToChainLabelMap).length;
|
|
36
|
+
const chainLabelsKeyMapCountAfter = Object.keys(chainUtils_1.chainLabelsToKeyMap).length;
|
|
37
|
+
if (chainKeyLabelMapCountAfter > chainKeyLabelMapCountBefore) {
|
|
38
|
+
console.log(`Updated chainKeyToChainLabelMap: ${chainKeyLabelMapCountBefore} -> ${chainKeyLabelMapCountAfter}`);
|
|
39
|
+
}
|
|
40
|
+
if (chainLabelsKeyMapCountAfter > chainLabelsKeyMapCountBefore) {
|
|
41
|
+
console.log(`Updated chainLabelsToKeyMap: ${chainLabelsKeyMapCountBefore} -> ${chainLabelsKeyMapCountAfter}`);
|
|
42
|
+
}
|
|
43
|
+
if (chainKeyLabelMapCountAfter < chainKeyLabelMapCountBefore)
|
|
44
|
+
throw new Error('chainKeyToChainLabelMap count decreased, please investigate');
|
|
45
|
+
if (chainLabelsKeyMapCountAfter < chainLabelsKeyMapCountBefore)
|
|
46
|
+
throw new Error('chainLabelsToKeyMap count decreased, please investigate');
|
|
30
47
|
const oldProviders = await (0, generalUtil_1.fetchJson)(`https://unpkg.com/@defillama/sdk@latest/build/providers.json`);
|
|
31
48
|
const currentChains = await (0, generalUtil_1.fetchJson)(`https://raw.githubusercontent.com/DefiLlama/DefiLlama-Adapters/refs/heads/main/projects/helper/chains.json`);
|
|
32
49
|
const currentChainsSet = new Set(currentChains);
|
|
@@ -38,15 +55,19 @@ async function main() {
|
|
|
38
55
|
// .filter((i: any) => !i.status || (i.status === 'active' || i.status === 'incubating'))
|
|
39
56
|
.filter((i) => i.shortName)
|
|
40
57
|
.filter((i) => {
|
|
58
|
+
var _a, _b;
|
|
41
59
|
if (currentChainsSet.has(i.shortName))
|
|
42
60
|
return true;
|
|
43
61
|
const bannedKeys = ['sepolia', 'test', 'goerli', 'devnet', 'holesky',];
|
|
44
62
|
const bannedRPCKeys = ['sepolia', 'goerli', 'devnet', 'holesky'];
|
|
45
63
|
const isTestnetKey = bannedKeys.some((j) => i.shortName.includes(j));
|
|
46
64
|
const hasTestnetRPC = i.rpc.some((rpc) => bannedRPCKeys.some((k) => rpc === null || rpc === void 0 ? void 0 : rpc.url.includes(k)));
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
65
|
+
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'));
|
|
66
|
+
if (isTestnetKey || hasTestnetRPC || hasTestnetName) {
|
|
67
|
+
droppedTestnetChainsSet.add(i.shortName);
|
|
68
|
+
// console.log(`Excluding testnet chain ${i.name} (${i.shortName})`)
|
|
69
|
+
}
|
|
70
|
+
return !isTestnetKey && !hasTestnetRPC && !hasTestnetName;
|
|
50
71
|
});
|
|
51
72
|
// trim/remove mainnet|-mainnet|_mainnet from short names, preliminary rpc filtering
|
|
52
73
|
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)/;
|
|
@@ -64,7 +85,7 @@ async function main() {
|
|
|
64
85
|
if (!j.url)
|
|
65
86
|
return false;
|
|
66
87
|
if (rpcFilterRegex.test(j.url)) {
|
|
67
|
-
console.log(`Removing blacklisted rpc ${j.url} from ${i.name}`)
|
|
88
|
+
// console.log(`Removing blacklisted rpc ${j.url} from ${i.name}`)
|
|
68
89
|
return false; // remove anything with blacklisted words
|
|
69
90
|
}
|
|
70
91
|
return true;
|
|
@@ -116,17 +137,34 @@ async function main() {
|
|
|
116
137
|
continue;
|
|
117
138
|
providerList[key] = providerList[shorName];
|
|
118
139
|
}
|
|
140
|
+
// add from the old providers any missing rpcs that is in the tvl chain list
|
|
141
|
+
Object.entries(oldProviders).forEach(([key, i]) => {
|
|
142
|
+
if (!currentChainsSet.has(key))
|
|
143
|
+
return;
|
|
144
|
+
if (providerList[key])
|
|
145
|
+
return;
|
|
146
|
+
console.log(`Adding missing chain ${key} from old providers`);
|
|
147
|
+
providerList[key] = i;
|
|
148
|
+
});
|
|
119
149
|
const droppedChains = Object.keys(oldProviders).filter(oldChain => providerList[oldChain] === undefined);
|
|
120
|
-
|
|
121
|
-
|
|
150
|
+
const filteredDroppedChains = droppedChains.filter(i => !droppedTestnetChainsSet.has(i) && !i.includes('test'));
|
|
151
|
+
console.log('Dropped chains before testnet filtering:', droppedChains.length);
|
|
152
|
+
console.log('Dropped chains after testnet filtering:', filteredDroppedChains.length);
|
|
153
|
+
if (filteredDroppedChains.length > chainRemovalThreshold) {
|
|
154
|
+
throw new Error(`Following chains used to be included but is not anymore, can the devs fix please?\n${filteredDroppedChains.join(', ')}`);
|
|
122
155
|
}
|
|
123
156
|
delete providerList.bitcoin; // what were they smoking?
|
|
124
157
|
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);
|
|
158
|
+
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);
|
|
159
|
+
const newlyAddedChains = Object.keys(providerList).filter(chain => oldProviders[chain] === undefined);
|
|
125
160
|
console.log('Final provider list:');
|
|
126
161
|
console.log('Chain count:', Object.keys(providerList).length);
|
|
127
|
-
console.log('
|
|
162
|
+
console.log('Newly added chains count:', newlyAddedChains.length);
|
|
163
|
+
console.log('Dropped chain count:', filteredDroppedChains.length);
|
|
128
164
|
console.log('RPC count:', rpcCount);
|
|
129
|
-
console.log('
|
|
165
|
+
console.log('RPC count current:', rpcCountOld);
|
|
166
|
+
console.log('Dropped chains:', filteredDroppedChains.join(', '));
|
|
167
|
+
console.log('Newly added chains:', newlyAddedChains.join(', '));
|
|
130
168
|
fs_1.default.writeFileSync(__dirname + '/../providers.json', JSON.stringify(providerList));
|
|
131
169
|
}
|
|
132
170
|
const blacklist = [
|
|
@@ -172,29 +210,40 @@ const chainShortNameMapping = {
|
|
|
172
210
|
hydragon: 'hydra',
|
|
173
211
|
camp: 'campmainnet',
|
|
174
212
|
mantra: 'mantrachain',
|
|
213
|
+
saga: 'sagaevm',
|
|
175
214
|
};
|
|
176
215
|
async function filterForWorkingRPCs(rpc, chain, chainId) {
|
|
177
|
-
if (rpc.length <
|
|
216
|
+
if (rpc.length < 4)
|
|
178
217
|
return rpc;
|
|
179
218
|
rpc = filterRPCs(rpc);
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
219
|
+
const filteredRPCs = [];
|
|
220
|
+
await (0, generalUtil_1.runInPromisePool)({
|
|
221
|
+
items: rpc,
|
|
222
|
+
concurrency: concurrentCheckChains,
|
|
223
|
+
permitFailure: true,
|
|
224
|
+
processor: async (i) => {
|
|
225
|
+
try {
|
|
226
|
+
const data = await (0, generalUtil_1.postJson)(i, {
|
|
227
|
+
jsonrpc: '2.0',
|
|
228
|
+
method: 'eth_chainId',
|
|
229
|
+
params: [],
|
|
230
|
+
id: 1
|
|
231
|
+
}, {
|
|
232
|
+
timeout: 60000
|
|
233
|
+
});
|
|
234
|
+
if (data.result) {
|
|
235
|
+
const returnedChainId = parseInt(data.result, 16);
|
|
236
|
+
if (returnedChainId !== chainId) {
|
|
237
|
+
console.log(`RPC ${i} for ${chain} returned invalid chainId ${returnedChainId}, expected ${chainId}`);
|
|
238
|
+
}
|
|
239
|
+
filteredRPCs.push(i);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
catch (e) {
|
|
243
|
+
console.log('ignoring bad rpc', chain, e === null || e === void 0 ? void 0 : e.message);
|
|
244
|
+
}
|
|
195
245
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return rpc.filter((_i, index) => promises[index]);
|
|
246
|
+
});
|
|
247
|
+
return filteredRPCs;
|
|
199
248
|
}
|
|
200
249
|
main();
|