@defillama/sdk 5.0.185 → 5.0.187
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/generalUtil.d.ts +1 -0
- package/build/generalUtil.js +5 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/build/providers.json +1 -1
- package/build/util/LlamaProvider.d.ts +10 -0
- package/build/util/LlamaProvider.js +23 -1
- package/build/util/coins.d.ts +1 -0
- package/build/util/updateProviderList.js +61 -16
- package/package.json +1 -1
|
@@ -4,6 +4,13 @@ type ProviderWithURL = {
|
|
|
4
4
|
url: string;
|
|
5
5
|
provider: AbstractProvider;
|
|
6
6
|
};
|
|
7
|
+
type ProviderConfigMap = {
|
|
8
|
+
[chain: string]: {
|
|
9
|
+
rpc?: string[];
|
|
10
|
+
chainId?: number;
|
|
11
|
+
explorer?: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
7
14
|
export declare class LlamaProvider extends FallbackProvider {
|
|
8
15
|
isCustomLlamaProvider: boolean;
|
|
9
16
|
rpcs: ProviderWithURL[];
|
|
@@ -28,6 +35,9 @@ export declare class LlamaProvider extends FallbackProvider {
|
|
|
28
35
|
getTransactionReceipt(_hash: string): Promise<any>;
|
|
29
36
|
_performAction(method: string, params: any, attempts?: number): Promise<any>;
|
|
30
37
|
}
|
|
38
|
+
export declare function getEVMProvidersConfigMap(): ProviderConfigMap;
|
|
39
|
+
export declare function getEVMChainSet(): Set<string>;
|
|
40
|
+
export declare function isEvmChain(chain: string): boolean;
|
|
31
41
|
export declare const providers: {
|
|
32
42
|
[chain: string]: AbstractProvider;
|
|
33
43
|
};
|
|
@@ -4,6 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.providers = exports.LlamaProvider = void 0;
|
|
7
|
+
exports.getEVMProvidersConfigMap = getEVMProvidersConfigMap;
|
|
8
|
+
exports.getEVMChainSet = getEVMChainSet;
|
|
9
|
+
exports.isEvmChain = isEvmChain;
|
|
7
10
|
exports.setProvider = setProvider;
|
|
8
11
|
exports.getProvider = getProvider;
|
|
9
12
|
const ethers_1 = require("ethers");
|
|
@@ -146,6 +149,25 @@ class LlamaProvider extends ethers_1.FallbackProvider {
|
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
151
|
exports.LlamaProvider = LlamaProvider;
|
|
152
|
+
function getEVMProvidersConfigMap() {
|
|
153
|
+
return buildProviders !== null && buildProviders !== void 0 ? buildProviders : providers_json_1.default;
|
|
154
|
+
}
|
|
155
|
+
let evmChainSet = null;
|
|
156
|
+
function getEVMChainSet() {
|
|
157
|
+
if (!evmChainSet) {
|
|
158
|
+
const pList = getEVMProvidersConfigMap();
|
|
159
|
+
evmChainSet = new Set(Object.keys(pList));
|
|
160
|
+
}
|
|
161
|
+
return evmChainSet;
|
|
162
|
+
}
|
|
163
|
+
function isEvmChain(chain) {
|
|
164
|
+
const pList = getEVMProvidersConfigMap();
|
|
165
|
+
if (pList[chain])
|
|
166
|
+
return true;
|
|
167
|
+
// check if we have RPC config for this chain via env variable
|
|
168
|
+
// let rpcList: (string | undefined) = getChainRPCs(chain, undefined) // skip this check as it can be true for non-evm chains like solana as well
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
149
171
|
function createProvider(name, rpcString, chainId = 400069, archivalRPCList = []) {
|
|
150
172
|
chainId = (0, env_1.getChainId)(name, chainId);
|
|
151
173
|
const networkish = { name, chainId };
|
|
@@ -193,7 +215,7 @@ function getProvider(chain = "ethereum", _getArchivalNode = false) {
|
|
|
193
215
|
chainKey = chain + '_historical';
|
|
194
216
|
if (exports.providers[chainKey])
|
|
195
217
|
return exports.providers[chainKey];
|
|
196
|
-
const pList =
|
|
218
|
+
const pList = getEVMProvidersConfigMap();
|
|
197
219
|
// use RPC from env variable if set else use RPC from providers.json
|
|
198
220
|
let rpcList = (0, env_1.getChainRPCs)(rpcKey, (_a = pList[chain]) === null || _a === void 0 ? void 0 : _a.rpc);
|
|
199
221
|
let archivalRPCList = (0, env_1.getArchivalRPCs)(rpcKey);
|
package/build/util/coins.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ 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 concurrentCheckChains = +(process.env.SDK_BUILD_CONCURRENT_CHAINS || 7);
|
|
12
|
+
const chainRemovalThreshold = +(process.env.SDK_BUILD_CHAIN_REMOVAL_THRESHOLD || 20);
|
|
11
13
|
const providerList = providers_json_1.default;
|
|
12
14
|
async function getChainData() {
|
|
13
15
|
try {
|
|
@@ -26,17 +28,52 @@ async function getChainData() {
|
|
|
26
28
|
}
|
|
27
29
|
async function main() {
|
|
28
30
|
const oldProviders = await (0, generalUtil_1.fetchJson)(`https://unpkg.com/@defillama/sdk@latest/build/providers.json`);
|
|
31
|
+
const currentChains = await (0, generalUtil_1.fetchJson)(`https://raw.githubusercontent.com/DefiLlama/DefiLlama-Adapters/refs/heads/main/projects/helper/chains.json`);
|
|
32
|
+
const currentChainsSet = new Set(currentChains);
|
|
29
33
|
let chainData = await getChainData();
|
|
30
34
|
const providerIDMap = {};
|
|
31
35
|
Object.values(providerList).forEach((i) => providerIDMap[i.chainId] = i.rpc);
|
|
32
36
|
chainData = chainData
|
|
33
37
|
.filter((i) => i.rpc.length)
|
|
34
38
|
// .filter((i: any) => !i.status || (i.status === 'active' || i.status === 'incubating'))
|
|
35
|
-
.filter((i) => i.shortName)
|
|
39
|
+
.filter((i) => i.shortName)
|
|
40
|
+
.filter((i) => {
|
|
41
|
+
if (currentChainsSet.has(i.shortName))
|
|
42
|
+
return true;
|
|
43
|
+
const bannedKeys = ['sepolia', 'test', 'goerli', 'devnet', 'holesky',];
|
|
44
|
+
const bannedRPCKeys = ['sepolia', 'goerli', 'devnet', 'holesky'];
|
|
45
|
+
const isTestnetKey = bannedKeys.some((j) => i.shortName.includes(j));
|
|
46
|
+
const hasTestnetRPC = i.rpc.some((rpc) => bannedRPCKeys.some((k) => rpc === null || rpc === void 0 ? void 0 : rpc.url.includes(k)));
|
|
47
|
+
if (isTestnetKey || hasTestnetRPC)
|
|
48
|
+
console.log(`Excluding testnet chain ${i.name} (${i.shortName})`);
|
|
49
|
+
return !isTestnetKey && !hasTestnetRPC;
|
|
50
|
+
});
|
|
51
|
+
// trim/remove mainnet|-mainnet|_mainnet from short names, preliminary rpc filtering
|
|
52
|
+
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)/;
|
|
53
|
+
chainData.forEach((i) => {
|
|
54
|
+
if (currentChainsSet.has(i.shortName)) {
|
|
55
|
+
// keep the short name as is
|
|
56
|
+
}
|
|
57
|
+
if (i.shortName.endsWith('-mainnet'))
|
|
58
|
+
i.shortName = i.shortName.slice(0, -8);
|
|
59
|
+
else if (i.shortName.endsWith('_mainnet'))
|
|
60
|
+
i.shortName = i.shortName.slice(0, -8);
|
|
61
|
+
else if (i.shortName.endsWith('mainnet'))
|
|
62
|
+
i.shortName = i.shortName.slice(0, -7);
|
|
63
|
+
i.rpc = i.rpc.filter((j) => {
|
|
64
|
+
if (!j.url)
|
|
65
|
+
return false;
|
|
66
|
+
if (rpcFilterRegex.test(j.url)) {
|
|
67
|
+
console.log(`Removing blacklisted rpc ${j.url} from ${i.name}`);
|
|
68
|
+
return false; // remove anything with blacklisted words
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
});
|
|
72
|
+
});
|
|
36
73
|
// shuffle the array
|
|
37
74
|
chainData.sort(() => Math.random() - 0.5);
|
|
38
75
|
await promise_pool_1.default
|
|
39
|
-
.withConcurrency(
|
|
76
|
+
.withConcurrency(concurrentCheckChains)
|
|
40
77
|
.for(chainData)
|
|
41
78
|
.process(async (i) => {
|
|
42
79
|
var _a, _b;
|
|
@@ -63,16 +100,12 @@ async function main() {
|
|
|
63
100
|
}
|
|
64
101
|
});
|
|
65
102
|
Object.entries(providerList).forEach(([key, i]) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
103
|
+
i.rpc.forEach((j) => {
|
|
104
|
+
if (filterRPCs([j]).length === 0) {
|
|
105
|
+
(0, debugLog_1.debugLog)(`Removing rpc ${j} from ${key}`);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
70
108
|
i.rpc = Array.from(new Set(filterRPCs(i.rpc)));
|
|
71
|
-
if (key.endsWith('-mainnet') || key.endsWith('_mainnet')) {
|
|
72
|
-
const shortName = key.slice(0, -8);
|
|
73
|
-
if (!providerList[shortName])
|
|
74
|
-
providerList[shortName] = i;
|
|
75
|
-
}
|
|
76
109
|
});
|
|
77
110
|
Object.keys(providerList).forEach((i) => {
|
|
78
111
|
if (!providerList[i].rpc.length)
|
|
@@ -84,25 +117,34 @@ async function main() {
|
|
|
84
117
|
providerList[key] = providerList[shorName];
|
|
85
118
|
}
|
|
86
119
|
const droppedChains = Object.keys(oldProviders).filter(oldChain => providerList[oldChain] === undefined);
|
|
87
|
-
if (droppedChains.length >
|
|
88
|
-
throw new Error(`Following chains used to be included but is not anymore, can the devs fix please?\n${droppedChains.join('
|
|
120
|
+
if (droppedChains.length > chainRemovalThreshold) {
|
|
121
|
+
throw new Error(`Following chains used to be included but is not anymore, can the devs fix please?\n${droppedChains.join(', ')}`);
|
|
89
122
|
}
|
|
90
123
|
delete providerList.bitcoin; // what were they smoking?
|
|
124
|
+
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);
|
|
125
|
+
console.log('Final provider list:');
|
|
126
|
+
console.log('Chain count:', Object.keys(providerList).length);
|
|
127
|
+
console.log('Dropped chain count:', droppedChains.length);
|
|
128
|
+
console.log('RPC count:', rpcCount);
|
|
129
|
+
console.log('Dropped chains:', droppedChains.join(', '));
|
|
91
130
|
fs_1.default.writeFileSync(__dirname + '/../providers.json', JSON.stringify(providerList));
|
|
92
131
|
}
|
|
93
132
|
const blacklist = [
|
|
94
133
|
'https://eth.api.onfinality.io/public'
|
|
95
134
|
];
|
|
135
|
+
// this is stricter filtering used only when chain has more than 10 rpcs
|
|
96
136
|
function filterRPCs(rpc) {
|
|
97
137
|
return rpc.filter((i) => {
|
|
98
138
|
if (blacklist.includes(i))
|
|
99
139
|
return false; // remove rpcs returning bad block heights etc
|
|
100
140
|
if (i.endsWith('/demo'))
|
|
101
141
|
return false; // remove demo rpc
|
|
142
|
+
if (!i.startsWith('http'))
|
|
143
|
+
return false; // remove demo rpc
|
|
102
144
|
if (i.includes('$'))
|
|
103
145
|
return false; // remove anything where api key is injected
|
|
104
146
|
// reject websocket, http, testnet, devnet, and anything with '='
|
|
105
|
-
if (/(wss\:|ws\:|http\:|test|devnet|terminet\.io|huobichain\.com|getblock\.io|bitstack\.com|nodereal.io\/v1|pokt\.network|ankr\.com|histori\.xyz|chainstacklabs\.com|owlracle\.info
|
|
147
|
+
if (/(wss\:|ws\:|http\:|test|devnet|terminet\.io|huobichain\.com|getblock\.io|bitstack\.com|nodereal.io\/v1|pokt\.network|ankr\.com|histori\.xyz|chainstacklabs\.com|owlracle\.info|blastapi\.io|\=)/.test(i))
|
|
106
148
|
return false; // remove anything with blacklisted words
|
|
107
149
|
return true;
|
|
108
150
|
}).map((i) => {
|
|
@@ -127,6 +169,8 @@ const chainShortNameMapping = {
|
|
|
127
169
|
elsm: 'ely',
|
|
128
170
|
tac: 'tacchain',
|
|
129
171
|
xone: 'xoc',
|
|
172
|
+
hydragon: 'hydra',
|
|
173
|
+
camp: 'campmainnet',
|
|
130
174
|
};
|
|
131
175
|
async function filterForWorkingRPCs(rpc, chain, chainId) {
|
|
132
176
|
if (rpc.length < 10)
|
|
@@ -143,11 +187,12 @@ async function filterForWorkingRPCs(rpc, chain, chainId) {
|
|
|
143
187
|
timeout: 30000
|
|
144
188
|
});
|
|
145
189
|
if (data.result)
|
|
146
|
-
return
|
|
190
|
+
return true;
|
|
147
191
|
}
|
|
148
192
|
catch (e) {
|
|
149
|
-
console.log(chain, e === null || e === void 0 ? void 0 : e.message);
|
|
193
|
+
console.log('ignoring bad rpc', chain, e === null || e === void 0 ? void 0 : e.message);
|
|
150
194
|
}
|
|
195
|
+
return false;
|
|
151
196
|
}));
|
|
152
197
|
return rpc.filter((_i, index) => promises[index]);
|
|
153
198
|
}
|