@defillama/sdk 5.0.137 → 5.0.141
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/multicall.js +2 -0
- package/build/abi/multicall3.js +11 -0
- package/build/providers.json +1 -1
- package/build/util/LlamaProvider.js +6 -1
- package/build/util/blocks.js +3 -1
- package/build/util/env.d.ts +1 -1
- package/build/util/env.js +5 -4
- package/build/util/index.js +6 -2
- package/build/util/indexer.js +21 -4
- package/build/util/updateProviderList.js +1 -1
- package/package.json +3 -2
|
@@ -9,6 +9,10 @@ const providers_json_1 = __importDefault(require("../providers.json"));
|
|
|
9
9
|
const env_1 = require("./env");
|
|
10
10
|
const debugLog_1 = require("./debugLog");
|
|
11
11
|
const axios_1 = __importDefault(require("axios"));
|
|
12
|
+
let buildProviders = undefined;
|
|
13
|
+
if (process.env['TEST_MODE']) {
|
|
14
|
+
buildProviders = require('../../build/providers.json');
|
|
15
|
+
}
|
|
12
16
|
const rpcRequestCounter = {};
|
|
13
17
|
class LlamaProvider extends ethers_1.FallbackProvider {
|
|
14
18
|
constructor({ providers, chainId, chainName, archivalRPCs, }, fallbackConfig) {
|
|
@@ -181,8 +185,9 @@ function getProvider(chain = "ethereum", _getArchivalNode = false) {
|
|
|
181
185
|
const rpcKey = chain === 'tron' ? 'tron_evm' : chain;
|
|
182
186
|
if (exports.providers[chain])
|
|
183
187
|
return exports.providers[chain];
|
|
188
|
+
const pList = buildProviders !== null && buildProviders !== void 0 ? buildProviders : providers_json_1.default;
|
|
184
189
|
// use RPC from env variable if set else use RPC from providers.json
|
|
185
|
-
let rpcList = (0, env_1.getChainRPCs)(rpcKey, (_a =
|
|
190
|
+
let rpcList = (0, env_1.getChainRPCs)(rpcKey, (_a = pList[chain]) === null || _a === void 0 ? void 0 : _a.rpc);
|
|
186
191
|
let archivalRPCList = (0, env_1.getArchivalRPCs)(rpcKey);
|
|
187
192
|
if (!rpcList) {
|
|
188
193
|
// @ts-ignore (throwing error here would alter function behavior and have side effects)
|
package/build/util/blocks.js
CHANGED
|
@@ -126,7 +126,7 @@ function getExtraProvider(chain = "ethereum") {
|
|
|
126
126
|
}
|
|
127
127
|
exports.getLatestBlock = getCurrentChainBlock;
|
|
128
128
|
const intialBlocks = {
|
|
129
|
-
planq:
|
|
129
|
+
planq: 14000000,
|
|
130
130
|
sei: 78353999,
|
|
131
131
|
terra: 4724001,
|
|
132
132
|
crab: 4969901
|
|
@@ -173,6 +173,8 @@ async function _lookupBlock(timestamp, extraParams) {
|
|
|
173
173
|
low = parseInt(envLowValue);
|
|
174
174
|
let lowBlock = getLowBlock();
|
|
175
175
|
let highBlock = getHighBlock();
|
|
176
|
+
if ((lowBlock === null || lowBlock === void 0 ? void 0 : lowBlock.number) < low)
|
|
177
|
+
lowBlock = undefined;
|
|
176
178
|
let block;
|
|
177
179
|
let i = 0;
|
|
178
180
|
let time = Date.now();
|
package/build/util/env.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare function getMaxParallelRequests(chain: string): number;
|
|
|
6
6
|
export declare function getParallelGetLogsLimit(chain: string, providerUrl?: string): number;
|
|
7
7
|
export declare function getParallelGetBlocksLimit(chain: string): number;
|
|
8
8
|
export declare function getEnvRPC(chain: string): string | undefined;
|
|
9
|
-
export declare function getEnvValue(key: string, defaultValue?: string): string
|
|
9
|
+
export declare function getEnvValue(key: string, defaultValue?: string): string;
|
|
10
10
|
export declare function getEnvCacheFolder(defaultCacheFolder: string): string;
|
|
11
11
|
export declare function getEnvMulticallAddress(chain: string): string | undefined;
|
|
12
12
|
export declare function getDefaultChunkSize(chain: string): number;
|
package/build/util/env.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getChainRPCs = exports.getArchivalRPCs = exports.getBatchMaxCount = exports.getDefaultChunkSize = exports.getEnvMulticallAddress = exports.getEnvCacheFolder = exports.getEnvValue = exports.getEnvRPC = exports.getParallelGetBlocksLimit = exports.getParallelGetLogsLimit = exports.getMaxParallelRequests = exports.getChainId = exports.ENV_CONSTANTS = void 0;
|
|
4
|
-
const _ENV_CONSTANTS = {
|
|
5
|
-
DEBUG_ENABLED: getEnvValue('DEBUG') === "true" || process.env.LLAMA_DEBUG_MODE ? 'true' : 'false',
|
|
6
|
-
DEBUG_LEVEL2: process.env.LLAMA_DEBUG_LEVEL2 ? 'true' : 'false',
|
|
7
|
-
};
|
|
8
4
|
const whitelistedEnvConstants = [
|
|
9
5
|
'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY', 'COINS_API_KEY',
|
|
10
6
|
'ELASTICSEARCH_CONFIG', 'GRAPH_API_KEY', 'LLAMA_INDEXER_ENDPOINT', 'LLAMA_INDEXER_API_KEY',
|
|
@@ -24,6 +20,10 @@ const defaultEnvValues = {
|
|
|
24
20
|
ZETA_RPC: "https://zetachain-evm.blockpi.network/v1/rpc/public,https://zetachain-mainnet-archive.allthatnode.com:8545",
|
|
25
21
|
DEFIVERSE_RPC: "https://rpc.defi-verse.org/",
|
|
26
22
|
};
|
|
23
|
+
const _ENV_CONSTANTS = {
|
|
24
|
+
DEBUG_ENABLED: getEnvValue('DEBUG') === "true" || process.env.LLAMA_DEBUG_MODE ? 'true' : 'false',
|
|
25
|
+
DEBUG_LEVEL2: process.env.LLAMA_DEBUG_LEVEL2 ? 'true' : 'false',
|
|
26
|
+
};
|
|
27
27
|
whitelistedEnvConstants.forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key));
|
|
28
28
|
Object.keys(defaultEnvValues).forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key, defaultEnvValues[key]));
|
|
29
29
|
// doing this as I am paranoid that that empty object when first declared might be exported before values are set
|
|
@@ -66,6 +66,7 @@ exports.getEnvRPC = getEnvRPC;
|
|
|
66
66
|
function getEnvValue(key, defaultValue) {
|
|
67
67
|
var _a, _b, _c;
|
|
68
68
|
key = key.toUpperCase();
|
|
69
|
+
defaultValue = defaultValue !== null && defaultValue !== void 0 ? defaultValue : defaultEnvValues[key];
|
|
69
70
|
return (_c = (_b = (_a = process.env['LLAMA_SDK_' + key]) !== null && _a !== void 0 ? _a : process.env['SDK_' + key]) !== null && _b !== void 0 ? _b : process.env[key]) !== null && _c !== void 0 ? _c : defaultValue;
|
|
70
71
|
}
|
|
71
72
|
exports.getEnvValue = getEnvValue;
|
package/build/util/index.js
CHANGED
|
@@ -87,10 +87,14 @@ async function _getLogs(params) {
|
|
|
87
87
|
}
|
|
88
88
|
catch (e) {
|
|
89
89
|
(0, debugLog_1.debugLog)(`Error fetching logs for chain ${params.chain} blockSpread: ${blockSpread}. ${(0, generalUtil_1.formError)(e, { chain: params.chain, target: params.target, provider })}`);
|
|
90
|
-
if (blockSpread >=
|
|
90
|
+
if (blockSpread >= 1001) {
|
|
91
91
|
// We got too many results
|
|
92
|
-
// We could chop it up into
|
|
92
|
+
// We could chop it up into 1001 block spreads as that is guaranteed to always return but then we'll have to make a lot of queries (easily >1000), so instead we'll keep dividing the block spread by two until we make it
|
|
93
93
|
blockSpread = Math.floor(blockSpread / 2);
|
|
94
|
+
if (blockSpread > 510 && blockSpread < 2000)
|
|
95
|
+
blockSpread = 999;
|
|
96
|
+
if (blockSpread > 5100 && blockSpread < 10000)
|
|
97
|
+
blockSpread = 9999;
|
|
94
98
|
}
|
|
95
99
|
else {
|
|
96
100
|
const error = (0, generalUtil_1.formError)(e, { chain: params.chain, target: params.target, provider });
|
package/build/util/indexer.js
CHANGED
|
@@ -140,8 +140,21 @@ async function getLogs({ chain = 'ethereum', topic, topics, fromBlock, toBlock,
|
|
|
140
140
|
throw new Error('Chain not supported');
|
|
141
141
|
if (!debugMode)
|
|
142
142
|
debugMode = debugLog_1.DEBUG_LEVEL2;
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
let topic1;
|
|
144
|
+
let topic2;
|
|
145
|
+
let topic3;
|
|
146
|
+
if (((topics === null || topics === void 0 ? void 0 : topics.length) && topics.length > 1)) {
|
|
147
|
+
if (topics === null || topics === void 0 ? void 0 : topics.length) {
|
|
148
|
+
topic1 = topics[1];
|
|
149
|
+
topic2 = topics[2];
|
|
150
|
+
topic3 = topics[3];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else if (extraTopics === null || extraTopics === void 0 ? void 0 : extraTopics.length) {
|
|
154
|
+
topic1 = extraTopics[0];
|
|
155
|
+
topic2 = extraTopics[1];
|
|
156
|
+
topic3 = extraTopics[2];
|
|
157
|
+
}
|
|
145
158
|
if (topics === null || topics === void 0 ? void 0 : topics.length)
|
|
146
159
|
topic = topics[0];
|
|
147
160
|
if (!eventAbi)
|
|
@@ -192,6 +205,9 @@ async function getLogs({ chain = 'ethereum', topic, topics, fromBlock, toBlock,
|
|
|
192
205
|
if (noTarget && addressChunks.length === 0)
|
|
193
206
|
addressChunks.push(undefined);
|
|
194
207
|
for (const chunk of addressChunks) {
|
|
208
|
+
if (Array.isArray(chunk) && chunk.length === 0) {
|
|
209
|
+
throw new Error('Address chunk cannot be empty');
|
|
210
|
+
}
|
|
195
211
|
let logCount = 0;
|
|
196
212
|
do {
|
|
197
213
|
const params = {
|
|
@@ -200,8 +216,9 @@ async function getLogs({ chain = 'ethereum', topic, topics, fromBlock, toBlock,
|
|
|
200
216
|
topic0: topic,
|
|
201
217
|
from_block: fromBlock,
|
|
202
218
|
to_block: toBlock,
|
|
203
|
-
|
|
204
|
-
offset,
|
|
219
|
+
topic1, topic2, topic3,
|
|
220
|
+
limit, offset,
|
|
221
|
+
noTarget,
|
|
205
222
|
};
|
|
206
223
|
const { data: { logs: _logs, totalCount } } = await axiosIndexer(`/logs`, { params, });
|
|
207
224
|
// getLogs uses 'address' field to return log source, so we add the field here to make it compatible
|
|
@@ -97,7 +97,7 @@ function filterRPCs(rpc) {
|
|
|
97
97
|
if (i.includes('$'))
|
|
98
98
|
return false; // remove anything where api key is injected
|
|
99
99
|
// reject websocket, http, testnet, devnet, and anything with '='
|
|
100
|
-
if (/(wss\:|ws\:|http\:|test|devnet|terminet\.io|huobichain\.com|getblock\.io|bitstack\.com|nodereal.io\/v1|pokt\.network|ankr\.com
|
|
100
|
+
if (/(wss\:|ws\:|http\:|test|devnet|terminet\.io|huobichain\.com|getblock\.io|bitstack\.com|nodereal.io\/v1|pokt\.network|ankr\.com|histori\.xyz|owlracle\.info\=)/.test(i))
|
|
101
101
|
return false; // remove anything with blacklisted words
|
|
102
102
|
return true;
|
|
103
103
|
}).map((i) => {
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defillama/sdk",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.141",
|
|
4
4
|
"description": "SDK for calculating TVL",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "npm run build && node build/index.js",
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"watch": "tsc --watch",
|
|
10
|
-
"
|
|
10
|
+
"load-providers": "wget https://unpkg.com/@defillama/sdk@latest/build/providers.json -O build/providers.json",
|
|
11
|
+
"test": "npm run load-providers && TEST_MODE=true LLAMA_DEBUG_MODE='' SDK_DEBUG='' LLAMA_DEBUG_LEVEL2='' jest",
|
|
11
12
|
"update-providers": "ts-node src/util/updateProviderList.ts",
|
|
12
13
|
"remove-rpcs": "ts-node src/util/removeRedundantRPCs.ts",
|
|
13
14
|
"format": "prettier --write \"src/**/*.ts\"",
|