@defillama/sdk 5.0.112 → 5.0.117
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/Balances.js +4 -0
- package/build/abi/multicall.js +2 -0
- package/build/abi/multicall3.js +3 -0
- package/build/providers.json +1 -1
- package/build/util/env.js +1 -1
- package/build/util/indexer.js +20 -13
- package/build/util/updateProviderList.js +2 -1
- package/package.json +1 -1
package/build/util/env.js
CHANGED
|
@@ -7,7 +7,7 @@ const _ENV_CONSTANTS = {
|
|
|
7
7
|
};
|
|
8
8
|
const whitelistedEnvConstants = [
|
|
9
9
|
'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY', 'COINS_API_KEY',
|
|
10
|
-
'ELASTICSEARCH_CONFIG', 'GRAPH_API_KEY', 'LLAMA_INDEXER_ENDPOINT',
|
|
10
|
+
'ELASTICSEARCH_CONFIG', 'GRAPH_API_KEY', 'LLAMA_INDEXER_ENDPOINT', 'LLAMA_INDEXER_API_KEY',
|
|
11
11
|
];
|
|
12
12
|
const defaultEnvValues = {
|
|
13
13
|
INTERNAL_SDK_CACHE_FILE: './cache.json',
|
package/build/util/indexer.js
CHANGED
|
@@ -14,18 +14,28 @@ const debugLog_1 = require("./debugLog");
|
|
|
14
14
|
const env_1 = require("./env");
|
|
15
15
|
const logs_1 = require("./logs");
|
|
16
16
|
const indexerURL = (0, env_1.getEnvValue)('LLAMA_INDEXER_ENDPOINT');
|
|
17
|
+
const LLAMA_INDEXER_API_KEY = (0, env_1.getEnvValue)('LLAMA_INDEXER_API_KEY');
|
|
18
|
+
const axiosIndexer = axios_1.default.create({
|
|
19
|
+
headers: {
|
|
20
|
+
"x-api-key": LLAMA_INDEXER_API_KEY,
|
|
21
|
+
},
|
|
22
|
+
baseURL: indexerURL,
|
|
23
|
+
});
|
|
24
|
+
function checkIndexerConfig() {
|
|
25
|
+
if (!indexerURL || !LLAMA_INDEXER_API_KEY)
|
|
26
|
+
throw new Error('Llama Indexer URL/api key is not set');
|
|
27
|
+
}
|
|
17
28
|
const state = { chainIndexStatus: {} };
|
|
18
29
|
const cacheTime = 1 * 60 * 1000; // 1 minutes - we cache sync status for 1 minute
|
|
19
30
|
async function getChainIndexStatus() {
|
|
20
|
-
|
|
21
|
-
throw new Error('Llama Indexer URL not set');
|
|
31
|
+
checkIndexerConfig();
|
|
22
32
|
if (state.timestamp && (Date.now() - state.timestamp) < cacheTime)
|
|
23
33
|
return state.chainIndexStatus;
|
|
24
34
|
state.timestamp = Date.now();
|
|
25
35
|
state.chainIndexStatus = _getState();
|
|
26
36
|
return state.chainIndexStatus;
|
|
27
37
|
async function _getState() {
|
|
28
|
-
const { data: { syncStatus } } = await
|
|
38
|
+
const { data: { syncStatus } } = await axiosIndexer.get(`/sync`);
|
|
29
39
|
const syncInfo = {};
|
|
30
40
|
syncStatus.forEach((d) => {
|
|
31
41
|
const chain = indexerChainIdChainMapping[d.chain];
|
|
@@ -70,8 +80,7 @@ var TokenTypes;
|
|
|
70
80
|
})(TokenTypes || (TokenTypes = {}));
|
|
71
81
|
async function getTokens(address, { onlyWhitelisted = true, skipCacheRead = false, skipCache = false, chain, tokenType, } = {}) {
|
|
72
82
|
var _a, _b;
|
|
73
|
-
|
|
74
|
-
throw new Error('Llama Indexer URL not set');
|
|
83
|
+
checkIndexerConfig();
|
|
75
84
|
if (!address)
|
|
76
85
|
throw new Error('Address is required either as a string or an array of strings');
|
|
77
86
|
if (Array.isArray(address) && !address.length)
|
|
@@ -95,12 +104,12 @@ async function getTokens(address, { onlyWhitelisted = true, skipCacheRead = fals
|
|
|
95
104
|
}
|
|
96
105
|
(0, debugLog_1.debugLog)('[Indexer] Pulling tokens for ' + address);
|
|
97
106
|
const tokens = (_b = cache.tokens) !== null && _b !== void 0 ? _b : {};
|
|
98
|
-
const { data: { balances } } = await
|
|
107
|
+
const { data: { balances } } = await axiosIndexer(`/balances`, {
|
|
99
108
|
params: {
|
|
100
109
|
addresses: address,
|
|
101
110
|
chainId,
|
|
102
111
|
type: tokenType,
|
|
103
|
-
}
|
|
112
|
+
},
|
|
104
113
|
});
|
|
105
114
|
balances.filter((b) => +b.total_amount > 0).forEach((b) => {
|
|
106
115
|
const chain = indexerChainIdChainMapping[b.chain];
|
|
@@ -123,8 +132,7 @@ async function getTokens(address, { onlyWhitelisted = true, skipCacheRead = fals
|
|
|
123
132
|
exports.getTokens = getTokens;
|
|
124
133
|
async function getLogs({ chain = 'ethereum', topic, topics, fromBlock, toBlock, all = true, limit = 1000, offset = 0, target, targets, eventAbi, entireLog = false, flatten = true, extraTopics, fromTimestamp, toTimestamp, debugMode = false }) {
|
|
125
134
|
var _a, _b;
|
|
126
|
-
|
|
127
|
-
throw new Error('Llama Indexer URL not set');
|
|
135
|
+
checkIndexerConfig();
|
|
128
136
|
const chainId = chainToIDMapping[chain];
|
|
129
137
|
if (!chainId)
|
|
130
138
|
throw new Error('Chain not supported');
|
|
@@ -184,7 +192,7 @@ async function getLogs({ chain = 'ethereum', topic, topics, fromBlock, toBlock,
|
|
|
184
192
|
limit,
|
|
185
193
|
offset,
|
|
186
194
|
};
|
|
187
|
-
const { data: { logs: _logs, totalCount } } = await
|
|
195
|
+
const { data: { logs: _logs, totalCount } } = await axiosIndexer(`/logs`, { params, });
|
|
188
196
|
logs.push(..._logs.filter((l) => {
|
|
189
197
|
if (!addressSet.size)
|
|
190
198
|
return true;
|
|
@@ -244,8 +252,7 @@ function isIndexerEnabled(chain) {
|
|
|
244
252
|
exports.isIndexerEnabled = isIndexerEnabled;
|
|
245
253
|
async function getTokenTransfers({ chain = 'ethereum', fromAddressFilter, fromBlock, toBlock, all = true, limit = 1000, offset = 0, target, targets = [], flatten = true, fromTimestamp, toTimestamp, debugMode = false, transferType = 'in', token, tokens, }) {
|
|
246
254
|
var _a, _b;
|
|
247
|
-
|
|
248
|
-
throw new Error('Llama Indexer URL not set');
|
|
255
|
+
checkIndexerConfig();
|
|
249
256
|
const chainId = chainToIDMapping[chain];
|
|
250
257
|
if (!chainId)
|
|
251
258
|
throw new Error('Chain not supported');
|
|
@@ -304,7 +311,7 @@ async function getTokenTransfers({ chain = 'ethereum', fromAddressFilter, fromBl
|
|
|
304
311
|
params.to_address = true;
|
|
305
312
|
else
|
|
306
313
|
params.from_address = true;
|
|
307
|
-
const { data: { transfers: _logs, totalCount } } = await
|
|
314
|
+
const { data: { transfers: _logs, totalCount } } = await axiosIndexer(`/token-transfers`, { params, });
|
|
308
315
|
logs.push(..._logs);
|
|
309
316
|
offset += limit;
|
|
310
317
|
// If we have all the logs, or we have reached the limit, or there are no logs, we stop
|
|
@@ -78,7 +78,7 @@ async function main() {
|
|
|
78
78
|
providerList[key] = providerList[shorName];
|
|
79
79
|
}
|
|
80
80
|
const droppedChains = Object.keys(oldProviders).filter(oldChain => providerList[oldChain] === undefined);
|
|
81
|
-
if (droppedChains.length >
|
|
81
|
+
if (droppedChains.length > 20) {
|
|
82
82
|
throw new Error(`Following chains used to be included but is not anymore, can the devs fix please?\n${droppedChains.join('\n')}`);
|
|
83
83
|
}
|
|
84
84
|
fs_1.default.writeFileSync(__dirname + '/../providers.json', JSON.stringify(providerList));
|
|
@@ -112,6 +112,7 @@ const chainShortNameMapping = {
|
|
|
112
112
|
ailayer: 'ailayer-mainnet',
|
|
113
113
|
ontology: 'OntologyMainnet',
|
|
114
114
|
occ: 'edu_chain',
|
|
115
|
+
ely: 'ely',
|
|
115
116
|
};
|
|
116
117
|
async function filterForWorkingRPCs(rpc, chain, chainId) {
|
|
117
118
|
if (rpc.length < 10)
|