@defillama/sdk 5.0.204 → 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/abi/multicall3.js +2 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +2 -1
- package/build/providers.json +1 -1
- 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/updateProviderList.js +28 -0
- 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
|
+
}
|
|
@@ -8,6 +8,7 @@ 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);
|
|
13
14
|
const droppedTestnetChainsSet = new Set([]);
|
|
@@ -28,6 +29,21 @@ async function getChainData() {
|
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
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');
|
|
31
47
|
const oldProviders = await (0, generalUtil_1.fetchJson)(`https://unpkg.com/@defillama/sdk@latest/build/providers.json`);
|
|
32
48
|
const currentChains = await (0, generalUtil_1.fetchJson)(`https://raw.githubusercontent.com/DefiLlama/DefiLlama-Adapters/refs/heads/main/projects/helper/chains.json`);
|
|
33
49
|
const currentChainsSet = new Set(currentChains);
|
|
@@ -121,6 +137,15 @@ async function main() {
|
|
|
121
137
|
continue;
|
|
122
138
|
providerList[key] = providerList[shorName];
|
|
123
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
|
+
});
|
|
124
149
|
const droppedChains = Object.keys(oldProviders).filter(oldChain => providerList[oldChain] === undefined);
|
|
125
150
|
const filteredDroppedChains = droppedChains.filter(i => !droppedTestnetChainsSet.has(i) && !i.includes('test'));
|
|
126
151
|
console.log('Dropped chains before testnet filtering:', droppedChains.length);
|
|
@@ -131,12 +156,15 @@ async function main() {
|
|
|
131
156
|
delete providerList.bitcoin; // what were they smoking?
|
|
132
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);
|
|
133
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);
|
|
134
160
|
console.log('Final provider list:');
|
|
135
161
|
console.log('Chain count:', Object.keys(providerList).length);
|
|
162
|
+
console.log('Newly added chains count:', newlyAddedChains.length);
|
|
136
163
|
console.log('Dropped chain count:', filteredDroppedChains.length);
|
|
137
164
|
console.log('RPC count:', rpcCount);
|
|
138
165
|
console.log('RPC count current:', rpcCountOld);
|
|
139
166
|
console.log('Dropped chains:', filteredDroppedChains.join(', '));
|
|
167
|
+
console.log('Newly added chains:', newlyAddedChains.join(', '));
|
|
140
168
|
fs_1.default.writeFileSync(__dirname + '/../providers.json', JSON.stringify(providerList));
|
|
141
169
|
}
|
|
142
170
|
const blacklist = [
|