@defillama/sdk 5.0.175 → 5.0.177
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.d.ts +2 -2
- package/build/ChainApi.d.ts +26 -14
- package/build/ChainApi.js +58 -28
- package/build/abi/abi2.js +23 -15
- package/build/abi/cachedABIs.d.ts +1 -1
- package/build/abi/convertResults.d.ts +4 -1
- package/build/abi/convertResults.js +20 -15
- package/build/abi/index.js +16 -39
- package/build/abi/multicall.js +6 -31
- package/build/abi/multicall3.js +36 -37
- package/build/abi/rpcCall.js +1 -2
- package/build/abi/tron.d.ts +5 -6
- package/build/abi/tron.js +79 -198
- package/build/api.js +17 -7
- package/build/api2.js +17 -7
- package/build/computeTVL/humanizeNumber.js +1 -2
- package/build/erc20/index.js +5 -6
- package/build/eth/index.d.ts +1 -0
- package/build/eth/index.js +39 -16
- package/build/general.js +2 -2
- package/build/generalUtil.d.ts +2 -24
- package/build/generalUtil.js +39 -246
- package/build/index.js +17 -7
- package/build/providers.json +1 -1
- package/build/util/LlamaProvider.js +8 -3
- package/build/util/blocks.js +17 -20
- package/build/util/cache.d.ts +11 -2
- package/build/util/cache.js +53 -9
- package/build/util/common.d.ts +33 -0
- package/build/util/common.js +352 -0
- package/build/util/computeTVL.js +6 -11
- package/build/util/cosmos.js +6 -9
- package/build/util/debugLog.js +3 -3
- package/build/util/elastic.d.ts +19 -0
- package/build/util/elastic.js +54 -6
- package/build/util/env.d.ts +7 -1
- package/build/util/env.js +28 -15
- package/build/util/graph.js +4 -8
- package/build/util/index.d.ts +1 -1
- package/build/util/index.js +17 -15
- package/build/util/indexer.js +21 -19
- package/build/util/internal-cache.js +22 -13
- package/build/util/logs.js +7 -7
- package/build/util/promisePool.d.ts +4 -1
- package/build/util/promisePool.js +22 -7
- package/build/util/r2.d.ts +0 -1
- package/build/util/r2.js +4 -9
- package/build/util/removeRedundantRPCs.js +2 -2
- package/build/util/transactions.js +1 -2
- package/build/util/updateProviderList.js +6 -6
- package/package.json +2 -2
- package/build/computeTVL/prices.d.ts +0 -9
- package/build/computeTVL/prices.js +0 -73
package/build/util/env.js
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
+
exports.ENV_CONSTANTS = exports.defaultShortenStringLength = exports.logGetLogsIndexer = exports.logGetLogsDebug = exports.logGetLogsErrors = exports.logGetBlockStats = void 0;
|
|
5
|
+
exports.getChainId = getChainId;
|
|
6
|
+
exports.getMaxParallelRequests = getMaxParallelRequests;
|
|
7
|
+
exports.getParallelGetLogsLimit = getParallelGetLogsLimit;
|
|
8
|
+
exports.getParallelGetBlocksLimit = getParallelGetBlocksLimit;
|
|
9
|
+
exports.getEnvRPC = getEnvRPC;
|
|
10
|
+
exports.getEnvValue = getEnvValue;
|
|
11
|
+
exports.getEnvCacheFolder = getEnvCacheFolder;
|
|
12
|
+
exports.getEnvMulticallAddress = getEnvMulticallAddress;
|
|
13
|
+
exports.getDefaultChunkSize = getDefaultChunkSize;
|
|
14
|
+
exports.getBatchMaxCount = getBatchMaxCount;
|
|
15
|
+
exports.getArchivalRPCs = getArchivalRPCs;
|
|
16
|
+
exports.getChainRPCs = getChainRPCs;
|
|
17
|
+
exports.getWhitelistedRPCs = getWhitelistedRPCs;
|
|
4
18
|
const whitelistedEnvConstants = [
|
|
5
19
|
'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY', 'COINS_API_KEY',
|
|
6
20
|
'ELASTICSEARCH_CONFIG', 'GRAPH_API_KEY', 'LLAMA_INDEXER_ENDPOINT', 'LLAMA_INDEXER_API_KEY', 'LLAMA_INDEXER_V2_ENDPOINT', 'LLAMA_INDEXER_V2_API_KEY',
|
|
7
21
|
];
|
|
22
|
+
exports.logGetBlockStats = process.env.LLAMA_SDK_LOG_GET_BLOCK_STATS === 'true' || false;
|
|
23
|
+
exports.logGetLogsErrors = process.env.LLAMA_SDK_LOG_GET_LOGS_ERRORS === 'true' || false;
|
|
24
|
+
exports.logGetLogsDebug = process.env.LLAMA_SDK_LOG_GET_LOGS_DEBUG === 'true' || false;
|
|
25
|
+
exports.logGetLogsIndexer = process.env.LLAMA_SDK_LOG_GET_LOGS_INDEXER === 'true' || false;
|
|
26
|
+
exports.defaultShortenStringLength = +((_a = process.env.LLAMA_SDK_DEFAULT_SHORTEN_STRING_LENGTH) !== null && _a !== void 0 ? _a : '120');
|
|
8
27
|
const defaultEnvValues = {
|
|
9
28
|
INTERNAL_SDK_CACHE_FILE: './cache.json',
|
|
10
29
|
TRON_RPC_CONCURRENCY_LIMIT: '5',
|
|
11
30
|
LLAMA_INDEXER_ADDRESS_CHUNK_SIZE: '20',
|
|
12
|
-
|
|
13
|
-
TRON_EVM_RPC: 'https://rpc.ankr.com/tron_jsonrpc',
|
|
31
|
+
TRON_WALLET_RPC: 'https://api.trongrid.io',
|
|
32
|
+
// TRON_EVM_RPC: 'https://rpc.ankr.com/tron_jsonrpc', // no longer used
|
|
14
33
|
NAKA_RPC: 'https://node.nakachain.xyz',
|
|
15
34
|
ETHF_RPC: 'https://rpc.dischain.xyz/',
|
|
16
35
|
CORE_RPC: "https://rpc.coredao.org,https://rpc.ankr.com/core,https://1rpc.io/core,https://rpc-core.icecreamswap.com",
|
|
@@ -33,7 +52,6 @@ function getChainId(chain, chainId) {
|
|
|
33
52
|
const value = (_a = getEnvValue(`${chain}_RPC_CHAIN_ID`)) !== null && _a !== void 0 ? _a : chainId;
|
|
34
53
|
return +value;
|
|
35
54
|
}
|
|
36
|
-
exports.getChainId = getChainId;
|
|
37
55
|
function getMaxParallelRequests(chain) {
|
|
38
56
|
const chainKey = `${chain}_RPC_MAX_PARALLEL`;
|
|
39
57
|
if (getEnvValue(chainKey))
|
|
@@ -42,7 +60,6 @@ function getMaxParallelRequests(chain) {
|
|
|
42
60
|
return 20;
|
|
43
61
|
return +getEnvValue('MAX_PARALLEL', '100');
|
|
44
62
|
}
|
|
45
|
-
exports.getMaxParallelRequests = getMaxParallelRequests;
|
|
46
63
|
function getParallelGetLogsLimit(chain, providerUrl) {
|
|
47
64
|
let defaultLimit = getEnvValue('GET_LOGS_CONCURRENCY_LIMIT', '25');
|
|
48
65
|
if (chain === 'fantom')
|
|
@@ -52,32 +69,26 @@ function getParallelGetLogsLimit(chain, providerUrl) {
|
|
|
52
69
|
return +(defaultAlchemyLimit);
|
|
53
70
|
return +(getEnvValue(`${chain}_RPC_GET_LOGS_CONCURRENCY_LIMIT`, defaultLimit));
|
|
54
71
|
}
|
|
55
|
-
exports.getParallelGetLogsLimit = getParallelGetLogsLimit;
|
|
56
72
|
function getParallelGetBlocksLimit(chain) {
|
|
57
73
|
const defaultLimit = getEnvValue('GET_BLOCKS_CONCURRENCY_LIMIT', '5');
|
|
58
74
|
return +(getEnvValue(`${chain}_RPC_GET_BLOCKS_CONCURRENCY_LIMIT`, defaultLimit));
|
|
59
75
|
}
|
|
60
|
-
exports.getParallelGetBlocksLimit = getParallelGetBlocksLimit;
|
|
61
76
|
function getEnvRPC(chain) {
|
|
62
77
|
const key = `${chain}_RPC`.toUpperCase();
|
|
63
78
|
return getEnvValue(key, defaultEnvValues[key]);
|
|
64
79
|
}
|
|
65
|
-
exports.getEnvRPC = getEnvRPC;
|
|
66
80
|
function getEnvValue(key, defaultValue) {
|
|
67
81
|
var _a, _b, _c;
|
|
68
82
|
key = key.toUpperCase();
|
|
69
83
|
defaultValue = defaultValue !== null && defaultValue !== void 0 ? defaultValue : defaultEnvValues[key];
|
|
70
84
|
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;
|
|
71
85
|
}
|
|
72
|
-
exports.getEnvValue = getEnvValue;
|
|
73
86
|
function getEnvCacheFolder(defaultCacheFolder) {
|
|
74
87
|
return getEnvValue('TVL_LOCAL_CACHE_ROOT_FOLDER', defaultCacheFolder);
|
|
75
88
|
}
|
|
76
|
-
exports.getEnvCacheFolder = getEnvCacheFolder;
|
|
77
89
|
function getEnvMulticallAddress(chain) {
|
|
78
90
|
return getEnvValue(`${chain}_RPC_MULTICALL`);
|
|
79
91
|
}
|
|
80
|
-
exports.getEnvMulticallAddress = getEnvMulticallAddress;
|
|
81
92
|
function getDefaultChunkSize(chain) {
|
|
82
93
|
const key = chain + '_MULTICALL_CHUNK_SIZE';
|
|
83
94
|
if (getEnvValue(key))
|
|
@@ -86,7 +97,6 @@ function getDefaultChunkSize(chain) {
|
|
|
86
97
|
return 50;
|
|
87
98
|
return +(getEnvValue('MULTICALL_CHUNK_SIZE', '300'));
|
|
88
99
|
}
|
|
89
|
-
exports.getDefaultChunkSize = getDefaultChunkSize;
|
|
90
100
|
function getBatchMaxCount(chain) {
|
|
91
101
|
const key = chain + '_BATCH_MAX_COUNT';
|
|
92
102
|
if (getEnvValue(key))
|
|
@@ -96,14 +106,12 @@ function getBatchMaxCount(chain) {
|
|
|
96
106
|
default: return +getEnvValue('BATCH_MAX_COUNT', '5');
|
|
97
107
|
}
|
|
98
108
|
}
|
|
99
|
-
exports.getBatchMaxCount = getBatchMaxCount;
|
|
100
109
|
function getArchivalRPCs(chain) {
|
|
101
110
|
const key = chain + '_ARCHIVAL_RPC';
|
|
102
111
|
if (getEnvValue(key))
|
|
103
112
|
return getEnvValue(key).split(',');
|
|
104
113
|
return [];
|
|
105
114
|
}
|
|
106
|
-
exports.getArchivalRPCs = getArchivalRPCs;
|
|
107
115
|
function getChainRPCs(chain, defaultList = []) {
|
|
108
116
|
const envValue = getEnvRPC(chain);
|
|
109
117
|
if (defaultList.length) {
|
|
@@ -114,4 +122,9 @@ function getChainRPCs(chain, defaultList = []) {
|
|
|
114
122
|
}
|
|
115
123
|
return envValue || undefined;
|
|
116
124
|
}
|
|
117
|
-
|
|
125
|
+
function getWhitelistedRPCs(chain) {
|
|
126
|
+
const key = chain + '_WHITELISTED_RPC';
|
|
127
|
+
if (getEnvValue(key))
|
|
128
|
+
return getEnvValue(key).split(',');
|
|
129
|
+
return [];
|
|
130
|
+
}
|
package/build/util/graph.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
|
|
3
|
+
exports.request = request;
|
|
4
|
+
exports.modifyEndpoint = modifyEndpoint;
|
|
5
|
+
const common_1 = require("./common");
|
|
8
6
|
const cache_1 = require("./cache");
|
|
9
7
|
const debugLog_1 = require("./debugLog");
|
|
10
8
|
const env_1 = require("./env");
|
|
@@ -27,13 +25,12 @@ async function request(endpoint, query, { cache = false, cacheKey, variables, wi
|
|
|
27
25
|
}
|
|
28
26
|
async function _request() {
|
|
29
27
|
endpoint = modifyEndpoint(endpoint, network);
|
|
30
|
-
const
|
|
28
|
+
const result = await (0, common_1.postJson)(endpoint, { query, variables });
|
|
31
29
|
if (result.errors)
|
|
32
30
|
throw new Error(result.errors[0].message);
|
|
33
31
|
return withMetadata ? result : result.data;
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
|
-
exports.request = request;
|
|
37
34
|
let graphKeyWarned = false;
|
|
38
35
|
function modifyEndpoint(endpoint, network = 'arbitrum') {
|
|
39
36
|
// example: https://api.thegraph.com/subgraphs/name/yieldyak/reinvest-tracker
|
|
@@ -51,4 +48,3 @@ function modifyEndpoint(endpoint, network = 'arbitrum') {
|
|
|
51
48
|
endpoint = endpoint.replace('[api-key]', graphKey);
|
|
52
49
|
return endpoint;
|
|
53
50
|
}
|
|
54
|
-
exports.modifyEndpoint = modifyEndpoint;
|
package/build/util/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Address } from "../types";
|
|
|
3
3
|
import { ethers, EventLog } from "ethers";
|
|
4
4
|
import runInPromisePoolOrig from "./promisePool";
|
|
5
5
|
export { getLatestBlock, getTimestamp, lookupBlock, } from "./blocks";
|
|
6
|
-
export { convertToBigInt } from "
|
|
6
|
+
export { convertToBigInt } from "./common";
|
|
7
7
|
export declare const runInPromisePool: typeof runInPromisePoolOrig;
|
|
8
8
|
export declare function sliceIntoChunks(arr: any[], chunkSize?: number): any[][];
|
|
9
9
|
type GetLogsOptions = {
|
package/build/util/index.js
CHANGED
|
@@ -3,18 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.runInPromisePool = exports.convertToBigInt = exports.lookupBlock = exports.getTimestamp = exports.getLatestBlock = void 0;
|
|
7
|
+
exports.sliceIntoChunks = sliceIntoChunks;
|
|
8
|
+
exports.getLogs = getLogs;
|
|
9
|
+
exports.normalizeAddress = normalizeAddress;
|
|
10
|
+
exports.normalizePrefixes = normalizePrefixes;
|
|
11
|
+
exports.normalizeBalances = normalizeBalances;
|
|
12
|
+
exports.tableToString = tableToString;
|
|
7
13
|
const general_1 = require("../general");
|
|
8
14
|
const ethers_1 = require("ethers");
|
|
9
|
-
const
|
|
15
|
+
const common_1 = require("./common");
|
|
10
16
|
const debugLog_1 = require("./debugLog");
|
|
11
17
|
const promisePool_1 = __importDefault(require("./promisePool"));
|
|
12
18
|
var blocks_1 = require("./blocks");
|
|
13
19
|
Object.defineProperty(exports, "getLatestBlock", { enumerable: true, get: function () { return blocks_1.getLatestBlock; } });
|
|
14
20
|
Object.defineProperty(exports, "getTimestamp", { enumerable: true, get: function () { return blocks_1.getTimestamp; } });
|
|
15
21
|
Object.defineProperty(exports, "lookupBlock", { enumerable: true, get: function () { return blocks_1.lookupBlock; } });
|
|
16
|
-
var
|
|
17
|
-
Object.defineProperty(exports, "convertToBigInt", { enumerable: true, get: function () { return
|
|
22
|
+
var common_2 = require("./common");
|
|
23
|
+
Object.defineProperty(exports, "convertToBigInt", { enumerable: true, get: function () { return common_2.convertToBigInt; } });
|
|
18
24
|
const p_limit_1 = __importDefault(require("p-limit"));
|
|
19
25
|
const env_1 = require("./env");
|
|
20
26
|
exports.runInPromisePool = promisePool_1.default;
|
|
@@ -26,7 +32,6 @@ function sliceIntoChunks(arr, chunkSize = 100) {
|
|
|
26
32
|
}
|
|
27
33
|
return res;
|
|
28
34
|
}
|
|
29
|
-
exports.sliceIntoChunks = sliceIntoChunks;
|
|
30
35
|
const chainLogLimiters = {};
|
|
31
36
|
function getChainLimiter(chain, providerUrl) {
|
|
32
37
|
if (!chainLogLimiters[chain])
|
|
@@ -37,7 +42,7 @@ function getChainLimiter(chain, providerUrl) {
|
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
44
|
async function getLogs(options) {
|
|
40
|
-
const getLimiter = () => getChainLimiter(options.chain, (0,
|
|
45
|
+
const getLimiter = () => getChainLimiter(options.chain, (0, common_1.getProviderUrl)(options.provider));
|
|
41
46
|
// if provider is not passed, we try with archival node first (if set) and then with non-archival node
|
|
42
47
|
let provider;
|
|
43
48
|
if (!options.provider) {
|
|
@@ -50,13 +55,13 @@ async function getLogs(options) {
|
|
|
50
55
|
catch (e) {
|
|
51
56
|
options.provider = (0, general_1.getProvider)(options.chain, false);
|
|
52
57
|
// if (provider === options.provider) throw e // the provider for archival and non-archival request is the same
|
|
53
|
-
|
|
58
|
+
if (env_1.logGetLogsDebug)
|
|
59
|
+
(0, debugLog_1.debugLog)(`Error fetching logs for chain ${options.chain} ${(0, common_1.formError)(e, { chain: options.chain, target: options.target, })}, retrying...`);
|
|
54
60
|
return getLimiter()(() => _getLogs(options));
|
|
55
61
|
}
|
|
56
62
|
}
|
|
57
63
|
return getLimiter()(() => _getLogs(options));
|
|
58
64
|
}
|
|
59
|
-
exports.getLogs = getLogs;
|
|
60
65
|
// SMALL INCOMPATIBILITY: On the old API we don't return ids but we should
|
|
61
66
|
async function _getLogs(params) {
|
|
62
67
|
var _a, _b;
|
|
@@ -86,7 +91,8 @@ async function _getLogs(params) {
|
|
|
86
91
|
currentBlock = nextBlock;
|
|
87
92
|
}
|
|
88
93
|
catch (e) {
|
|
89
|
-
|
|
94
|
+
if (env_1.logGetLogsDebug)
|
|
95
|
+
(0, debugLog_1.debugLog)(`Error fetching logs for chain ${params.chain} blockSpread: ${blockSpread}. ${(0, common_1.formError)(e, { chain: params.chain, target: params.target, provider })}`);
|
|
90
96
|
if (blockSpread >= 1001) {
|
|
91
97
|
// We got too many results
|
|
92
98
|
// 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
|
|
@@ -97,7 +103,7 @@ async function _getLogs(params) {
|
|
|
97
103
|
blockSpread = 9999;
|
|
98
104
|
}
|
|
99
105
|
else {
|
|
100
|
-
const error = (0,
|
|
106
|
+
const error = (0, common_1.formError)(e, { chain: params.chain, target: params.target, provider });
|
|
101
107
|
error.message = `[chain: ${params.chain}] ${error === null || error === void 0 ? void 0 : error.message} params: ${JSON.stringify(logParams)}`;
|
|
102
108
|
throw e;
|
|
103
109
|
}
|
|
@@ -127,7 +133,6 @@ function normalizeAddress(address) {
|
|
|
127
133
|
return address;
|
|
128
134
|
return address.toLowerCase();
|
|
129
135
|
}
|
|
130
|
-
exports.normalizeAddress = normalizeAddress;
|
|
131
136
|
function normalizePrefixes(address) {
|
|
132
137
|
const prefix = address.substring(0, address.indexOf(":"));
|
|
133
138
|
if (["solana", "tezos"].includes(prefix))
|
|
@@ -138,7 +143,6 @@ function normalizePrefixes(address) {
|
|
|
138
143
|
? `coingecko:${address.toLowerCase()}`
|
|
139
144
|
: address.toLowerCase();
|
|
140
145
|
}
|
|
141
|
-
exports.normalizePrefixes = normalizePrefixes;
|
|
142
146
|
const ethereumAddress = "ethereum:0x0000000000000000000000000000000000000000";
|
|
143
147
|
const weth = "ethereum:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
|
|
144
148
|
function normalizeBalances(balances) {
|
|
@@ -151,7 +155,7 @@ function normalizeBalances(balances) {
|
|
|
151
155
|
const normalisedKey = normalizePrefixes(key);
|
|
152
156
|
if (normalisedKey == key)
|
|
153
157
|
return;
|
|
154
|
-
(0,
|
|
158
|
+
(0, common_1.sumSingleBalance)(balances, normalisedKey, balances[key]);
|
|
155
159
|
delete balances[key];
|
|
156
160
|
});
|
|
157
161
|
const eth = balances[ethereumAddress];
|
|
@@ -161,7 +165,6 @@ function normalizeBalances(balances) {
|
|
|
161
165
|
}
|
|
162
166
|
return balances;
|
|
163
167
|
}
|
|
164
|
-
exports.normalizeBalances = normalizeBalances;
|
|
165
168
|
function tableToString(data, columns, { title, columns: _columns } = {}) {
|
|
166
169
|
// If only two arguments are passed and the second is not an array, treat it as options
|
|
167
170
|
if (arguments.length === 2 && !Array.isArray(columns) && typeof columns === 'object') {
|
|
@@ -222,4 +225,3 @@ function tableToString(data, columns, { title, columns: _columns } = {}) {
|
|
|
222
225
|
});
|
|
223
226
|
return tableString;
|
|
224
227
|
}
|
|
225
|
-
exports.tableToString = tableToString;
|
package/build/util/indexer.js
CHANGED
|
@@ -3,11 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.supportedChainSet2 = exports.supportedChainSet = void 0;
|
|
7
|
+
exports.getTokens = getTokens;
|
|
8
|
+
exports.getLogs = getLogs;
|
|
9
|
+
exports.getTokenTransfers = getTokenTransfers;
|
|
10
|
+
exports.getTransactions = getTransactions;
|
|
11
|
+
exports.isIndexerEnabled = isIndexerEnabled;
|
|
12
|
+
exports.isIndexer2Enabled = isIndexer2Enabled;
|
|
7
13
|
const axios_1 = __importDefault(require("axios"));
|
|
8
14
|
const _1 = require(".");
|
|
9
15
|
const general_1 = require("../general");
|
|
10
|
-
const
|
|
16
|
+
const common_1 = require("./common");
|
|
11
17
|
const blocks_1 = require("./blocks");
|
|
12
18
|
const cache_1 = require("./cache");
|
|
13
19
|
const debugLog_1 = require("./debugLog");
|
|
@@ -104,7 +110,7 @@ async function getChainIndexStatus(version = "v2") {
|
|
|
104
110
|
return state.chainIndexStatus;
|
|
105
111
|
state.timestamp = Date.now();
|
|
106
112
|
state.chainIndexStatus = (async () => {
|
|
107
|
-
const { data: { syncStatus }, } = await axiosInstances[version].get(`/sync`);
|
|
113
|
+
const { data: { syncStatus }, } = await axiosInstances[version].get(`/sync`).catch(e => { throw (0, common_1.formError)(e); });
|
|
108
114
|
const info = {};
|
|
109
115
|
syncStatus.forEach((d) => {
|
|
110
116
|
const chain = indexerConfigs[version].chainMapping[d.chain];
|
|
@@ -154,7 +160,8 @@ async function getTokens(address, { onlyWhitelisted = true, skipCacheRead = fals
|
|
|
154
160
|
if (cache.timestamp && timeNow - cache.timestamp < THREE_DAYS)
|
|
155
161
|
return cache.tokens;
|
|
156
162
|
}
|
|
157
|
-
(
|
|
163
|
+
if (env_1.logGetLogsIndexer)
|
|
164
|
+
(0, debugLog_1.debugLog)("[Indexer] Pulling tokens for " + address);
|
|
158
165
|
const tokens = (_b = cache.tokens) !== null && _b !== void 0 ? _b : {};
|
|
159
166
|
const { data: { balances }, } = await axiosInstances.v1(`/balances`, {
|
|
160
167
|
params: {
|
|
@@ -162,7 +169,7 @@ async function getTokens(address, { onlyWhitelisted = true, skipCacheRead = fals
|
|
|
162
169
|
chainId,
|
|
163
170
|
type: tokenType,
|
|
164
171
|
},
|
|
165
|
-
});
|
|
172
|
+
}).catch(e => { throw (0, common_1.formError)(e); });
|
|
166
173
|
balances
|
|
167
174
|
.filter((b) => +b.total_amount > 0)
|
|
168
175
|
.forEach((b) => {
|
|
@@ -176,13 +183,12 @@ async function getTokens(address, { onlyWhitelisted = true, skipCacheRead = fals
|
|
|
176
183
|
const tokenCache = { timestamp: timeNow, tokens };
|
|
177
184
|
Object.entries(tokens).forEach(([chain, values]) => {
|
|
178
185
|
values.push(general_1.ETHER_ADDRESS);
|
|
179
|
-
tokens[chain] = (0,
|
|
186
|
+
tokens[chain] = (0, common_1.getUniqueAddresses)(values);
|
|
180
187
|
});
|
|
181
188
|
if (!skipCache)
|
|
182
189
|
await (0, cache_1.writeCache)(file, tokenCache);
|
|
183
190
|
return tokens;
|
|
184
191
|
}
|
|
185
|
-
exports.getTokens = getTokens;
|
|
186
192
|
// ---------------------------------------------------------------------------
|
|
187
193
|
// LOGS (v2 only)
|
|
188
194
|
// ---------------------------------------------------------------------------
|
|
@@ -191,7 +197,7 @@ async function getLogs(options) {
|
|
|
191
197
|
let { all = true, limit = 1000, offset: initialOffset = 0, target, targets = [], flatten = true, debugMode = false, noTarget = false, maxBlockRange, processor, } = options;
|
|
192
198
|
const { chain, fromBlock, toBlock, topic, topic1, topic2, topic3, transformLog, } = await (0, logs_1.getLogParams)(options, true);
|
|
193
199
|
if (!debugMode)
|
|
194
|
-
debugMode = debugLog_1.DEBUG_LEVEL2;
|
|
200
|
+
debugMode = debugLog_1.DEBUG_LEVEL2 && env_1.logGetLogsIndexer;
|
|
195
201
|
const blockRange = toBlock - fromBlock;
|
|
196
202
|
const effectiveMaxBlockRange = maxBlockRange !== null && maxBlockRange !== void 0 ? maxBlockRange : (noTarget ? 10000 : Infinity);
|
|
197
203
|
if (noTarget && blockRange > 500000) {
|
|
@@ -207,7 +213,8 @@ async function getLogs(options) {
|
|
|
207
213
|
const percentageMissing = ((toBlock - lastIndexedBlock) / (toBlock - fromBlock)) * 100;
|
|
208
214
|
if (percentageMissing > 50) // more than 50% of the requested range is missing, throw an error and so we pull the logs through rpc calls
|
|
209
215
|
throw new Error(`Indexer not up to date for ${chain}. Last indexed block: ${lastIndexedBlock}, requested block: ${toBlock}`);
|
|
210
|
-
|
|
216
|
+
if (env_1.logGetLogsIndexer)
|
|
217
|
+
(0, debugLog_1.debugLog)(`Indexer only partially up to date for ${chain}. Last indexed block: ${lastIndexedBlock}, requested block: ${toBlock}, missing ${Number(percentageMissing).toFixed(2)}%. Pulling part of the logs through RPC calls.`);
|
|
211
218
|
// now we split the request into two parts, one that goes to the indexer and one that goes through rpc calls
|
|
212
219
|
const breakBlock = lastIndexedBlock - 50; // we add a small buffer to avoid missing logs due to reorgs
|
|
213
220
|
const indexerLogs = await getLogs({ ...options, fromBlock, toBlock: breakBlock });
|
|
@@ -273,7 +280,7 @@ async function getLogs(options) {
|
|
|
273
280
|
parseLog: options.parseLog,
|
|
274
281
|
onlyArgs: options.onlyArgs,
|
|
275
282
|
};
|
|
276
|
-
const { data: { logs: _logs, totalCount }, } = await axiosInstances.v2(`/logs`, { params });
|
|
283
|
+
const { data: { logs: _logs, totalCount }, } = await axiosInstances.v2(`/logs`, { params }).catch(e => { throw (0, common_1.formError)(e); });
|
|
277
284
|
const filtered = _logs.filter((l) => {
|
|
278
285
|
const isWhitelisted = !addressSet.size || addressSet.has(l.source.toLowerCase());
|
|
279
286
|
if (!isWhitelisted)
|
|
@@ -316,14 +323,13 @@ async function getLogs(options) {
|
|
|
316
323
|
}
|
|
317
324
|
return allLogs.map(i => i.transformed);
|
|
318
325
|
}
|
|
319
|
-
exports.getLogs = getLogs;
|
|
320
326
|
// ---------------------------------------------------------------------------
|
|
321
327
|
// TOKEN TRANSFERS (v2 only)
|
|
322
328
|
// ---------------------------------------------------------------------------
|
|
323
329
|
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, }) {
|
|
324
330
|
var _a, _b;
|
|
325
331
|
if (!debugMode)
|
|
326
|
-
debugMode = debugLog_1.DEBUG_LEVEL2;
|
|
332
|
+
debugMode = debugLog_1.DEBUG_LEVEL2 && env_1.logGetLogsIndexer;
|
|
327
333
|
checkIndexerConfig("v2");
|
|
328
334
|
const chainId = getChainId(chain, "v2");
|
|
329
335
|
// -----------------------------------------------------------------------
|
|
@@ -401,7 +407,7 @@ async function getTokenTransfers({ chain = "ethereum", fromAddressFilter, fromBl
|
|
|
401
407
|
default:
|
|
402
408
|
throw new Error("Invalid transferType");
|
|
403
409
|
}
|
|
404
|
-
const { data: { transfers: _logs, totalCount }, } = await axiosInstances.v2(`/token-transfers`, { params });
|
|
410
|
+
const { data: { transfers: _logs, totalCount }, } = await axiosInstances.v2(`/token-transfers`, { params }).catch(e => { throw (0, common_1.formError)(e); });
|
|
405
411
|
rawTransfers.push(..._logs);
|
|
406
412
|
currentOffset += limit;
|
|
407
413
|
if (_logs.length < limit || totalCount <= rawTransfers.length || _logs.length === 0)
|
|
@@ -434,14 +440,13 @@ async function getTokenTransfers({ chain = "ethereum", fromAddressFilter, fromBl
|
|
|
434
440
|
}
|
|
435
441
|
return filteredTransfers;
|
|
436
442
|
}
|
|
437
|
-
exports.getTokenTransfers = getTokenTransfers;
|
|
438
443
|
// ---------------------------------------------------------------------------
|
|
439
444
|
// TRANSACTIONS (v2 only)
|
|
440
445
|
// ---------------------------------------------------------------------------
|
|
441
446
|
async function getTransactions({ chain = "ethereum", addresses, transaction_hashes, from_block, to_block, all = true, limit = 1000, offset = 0, debugMode = false, transactionType = "from", }) {
|
|
442
447
|
var _a, _b;
|
|
443
448
|
if (!debugMode)
|
|
444
|
-
debugMode = debugLog_1.DEBUG_LEVEL2;
|
|
449
|
+
debugMode = debugLog_1.DEBUG_LEVEL2 && env_1.logGetLogsIndexer;
|
|
445
450
|
checkIndexerConfig("v2");
|
|
446
451
|
const chainId = getChainId(chain, "v2");
|
|
447
452
|
if ((!addresses || addresses.length === 0) && (!transaction_hashes || transaction_hashes.length === 0))
|
|
@@ -479,7 +484,7 @@ async function getTransactions({ chain = "ethereum", addresses, transaction_hash
|
|
|
479
484
|
(0, debugLog_1.debugLog)("[Indexer] Pulling transactions " + debugTimeKey);
|
|
480
485
|
console.time(debugTimeKey);
|
|
481
486
|
}
|
|
482
|
-
const { data: { transactions } } = await axiosInstances.v2(`/transactions`, { params });
|
|
487
|
+
const { data: { transactions } } = await axiosInstances.v2(`/transactions`, { params }).catch(e => { throw (0, common_1.formError)(e); });
|
|
483
488
|
if (debugMode) {
|
|
484
489
|
console.timeEnd(debugTimeKey);
|
|
485
490
|
(0, debugLog_1.debugLog)("Transactions pulled " + chain, addresses || transaction_hashes, (transactions === null || transactions === void 0 ? void 0 : transactions.length) || 0);
|
|
@@ -510,7 +515,6 @@ async function getTransactions({ chain = "ethereum", addresses, transaction_hash
|
|
|
510
515
|
timestamp: t.timestamp,
|
|
511
516
|
}));
|
|
512
517
|
}
|
|
513
|
-
exports.getTransactions = getTransactions;
|
|
514
518
|
// ---------------------------------------------------------------------------
|
|
515
519
|
// Public helpers
|
|
516
520
|
// ---------------------------------------------------------------------------
|
|
@@ -522,9 +526,7 @@ function isIndexerEnabled(chain) {
|
|
|
522
526
|
return false;
|
|
523
527
|
return true;
|
|
524
528
|
}
|
|
525
|
-
exports.isIndexerEnabled = isIndexerEnabled;
|
|
526
529
|
function isIndexer2Enabled(chain) {
|
|
527
530
|
// Alias – retained so external calls do not break
|
|
528
531
|
return isIndexerEnabled(chain);
|
|
529
532
|
}
|
|
530
|
-
exports.isIndexer2Enabled = isIndexer2Enabled;
|
|
@@ -15,15 +15,29 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
36
|
+
exports.getCache = getCache;
|
|
37
|
+
exports.setCache = setCache;
|
|
38
|
+
exports.saveCache = saveCache;
|
|
39
|
+
exports.startCache = startCache;
|
|
40
|
+
exports.retriveCache = retriveCache;
|
|
27
41
|
const fs = __importStar(require("fs"));
|
|
28
42
|
const env_1 = require("./env");
|
|
29
43
|
// const cacheFile = __dirname + '/../../../sc-cache1.json'
|
|
@@ -41,7 +55,6 @@ function getCache(options) {
|
|
|
41
55
|
cache[chain][abi] = {};
|
|
42
56
|
return cache[chain][abi][address];
|
|
43
57
|
}
|
|
44
|
-
exports.getCache = getCache;
|
|
45
58
|
function setCache(options) {
|
|
46
59
|
let { address, abi, chain = "ethereum", value } = options;
|
|
47
60
|
if (!address)
|
|
@@ -53,16 +66,12 @@ function setCache(options) {
|
|
|
53
66
|
cache[chain][abi] = {};
|
|
54
67
|
cache[chain][abi][address] = value;
|
|
55
68
|
}
|
|
56
|
-
exports.setCache = setCache;
|
|
57
69
|
function saveCache() {
|
|
58
70
|
fs.writeFileSync(cacheFile || './cache.json', JSON.stringify(cache));
|
|
59
71
|
}
|
|
60
|
-
exports.saveCache = saveCache;
|
|
61
72
|
function startCache(_cache = {}) {
|
|
62
73
|
cache = _cache;
|
|
63
74
|
}
|
|
64
|
-
exports.startCache = startCache;
|
|
65
75
|
function retriveCache() {
|
|
66
76
|
return cache;
|
|
67
77
|
}
|
|
68
|
-
exports.retriveCache = retriveCache;
|
package/build/util/logs.js
CHANGED
|
@@ -3,15 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getLogs = getLogs;
|
|
7
|
+
exports.toFilterTopic = toFilterTopic;
|
|
8
|
+
exports.getLogParams = getLogParams;
|
|
7
9
|
const ethers_1 = require("ethers");
|
|
8
10
|
const _1 = require(".");
|
|
9
|
-
const tron_1 = require("../abi/tron");
|
|
10
11
|
const blocks_1 = require("./blocks");
|
|
11
12
|
const cache_1 = require("./cache");
|
|
12
13
|
const debugLog_1 = require("./debugLog");
|
|
13
14
|
const indexer_1 = require("./indexer");
|
|
14
15
|
const promisePool_1 = __importDefault(require("./promisePool"));
|
|
16
|
+
const env_1 = require("./env");
|
|
17
|
+
const common_1 = require("./common");
|
|
15
18
|
const currentVersion = "v3";
|
|
16
19
|
/* -------------------------------------------------------------------------- */
|
|
17
20
|
/* getLogs */
|
|
@@ -43,7 +46,7 @@ async function getLogs(options) {
|
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
if (!debugMode)
|
|
46
|
-
debugMode = debugLog_1.DEBUG_LEVEL2;
|
|
49
|
+
debugMode = debugLog_1.DEBUG_LEVEL2 && env_1.logGetLogsDebug;
|
|
47
50
|
/* ----------------------- Split by maxBlockRange ------------------------- */
|
|
48
51
|
const blockRange = toBlock - fromBlock;
|
|
49
52
|
if (maxBlockRange && blockRange > maxBlockRange) {
|
|
@@ -76,7 +79,7 @@ async function getLogs(options) {
|
|
|
76
79
|
}
|
|
77
80
|
/* ----------------------------- RPC fallback ----------------------------- */
|
|
78
81
|
if (chain === "tron")
|
|
79
|
-
target = (0,
|
|
82
|
+
target = (0, common_1.tronToEvmAddress)(target);
|
|
80
83
|
let caches = (await _getCache());
|
|
81
84
|
const firstRun = !caches.length;
|
|
82
85
|
if (firstRun || skipCacheRead) {
|
|
@@ -203,7 +206,6 @@ async function getLogs(options) {
|
|
|
203
206
|
return `event-logs/${chain}/${(_a = target === null || target === void 0 ? void 0 : target.toLowerCase()) !== null && _a !== void 0 ? _a : null}-${extraKey}`;
|
|
204
207
|
}
|
|
205
208
|
}
|
|
206
|
-
exports.getLogs = getLogs;
|
|
207
209
|
/* -------------------------------------------------------------------------- */
|
|
208
210
|
/* Utility helpers exported */
|
|
209
211
|
/* -------------------------------------------------------------------------- */
|
|
@@ -213,7 +215,6 @@ function toFilterTopic(topic) {
|
|
|
213
215
|
const fragment = ethers_1.EventFragment.from(topic);
|
|
214
216
|
return (0, ethers_1.id)(fragment.format());
|
|
215
217
|
}
|
|
216
|
-
exports.toFilterTopic = toFilterTopic;
|
|
217
218
|
exports.default = getLogs;
|
|
218
219
|
async function getLogParams(options, isIndexerCall = false) {
|
|
219
220
|
let { target, chain = "ethereum", fromBlock, toBlock, fromTimestamp, toTimestamp, eventAbi, topic, topics, extraTopics, entireLog = false, onlyArgs = false, targets = [], noTarget = false, parseLog = false, allowParseFailure = false, processor, flatten = false, } = options;
|
|
@@ -331,4 +332,3 @@ async function getLogParams(options, isIndexerCall = false) {
|
|
|
331
332
|
topics,
|
|
332
333
|
};
|
|
333
334
|
}
|
|
334
|
-
exports.getLogParams = getLogParams;
|
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = runInPromisePool;
|
|
4
|
+
exports.runInPromisePool = runInPromisePool;
|
|
3
5
|
const promise_pool_1 = require("@supercharge/promise-pool");
|
|
4
|
-
const
|
|
5
|
-
generalUtil_1.formError;
|
|
6
|
+
const common_1 = require("./common");
|
|
6
7
|
async function runInPromisePool(params) {
|
|
7
|
-
const
|
|
8
|
+
const errors = [];
|
|
9
|
+
const { results, } = await promise_pool_1.PromisePool
|
|
8
10
|
.withConcurrency(params.concurrency)
|
|
9
11
|
.for(params.items)
|
|
10
|
-
.process(async (item, i) =>
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
.process(async (item, i) => {
|
|
13
|
+
try {
|
|
14
|
+
if (errors.length && !params.permitFailure)
|
|
15
|
+
throw new Error('Aborting, previous errors in promise pool');
|
|
16
|
+
const res = await params.processor(item, i);
|
|
17
|
+
return [res, i];
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
errors.push(e);
|
|
21
|
+
return [undefined, i];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
if (errors.length && !params.permitFailure)
|
|
25
|
+
throw (0, common_1.formError)(null, { promisePoolErrors: errors });
|
|
26
|
+
// Preserve order of results
|
|
13
27
|
const flatResults = results.sort((a, b) => a[1] - b[1]).map((i => i[0]));
|
|
28
|
+
if (params.withMetadata)
|
|
29
|
+
return { results: flatResults, errors };
|
|
14
30
|
return flatResults;
|
|
15
31
|
}
|
|
16
|
-
exports.default = runInPromisePool;
|
package/build/util/r2.d.ts
CHANGED
package/build/util/r2.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
|
|
3
|
+
exports.storeR2JSONString = storeR2JSONString;
|
|
4
|
+
exports.getR2JSONString = getR2JSONString;
|
|
8
5
|
const env_1 = require("./env");
|
|
6
|
+
const common_1 = require("./common");
|
|
9
7
|
const { S3Client, PutObjectCommand, GetObjectCommand, } = require("@aws-sdk/client-s3");
|
|
10
8
|
const { R2_ENDPOINT, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY } = env_1.ENV_CONSTANTS;
|
|
11
9
|
const datasetBucket = "defillama-datasets";
|
|
@@ -35,7 +33,6 @@ async function storeR2JSONString(filename, body) {
|
|
|
35
33
|
});
|
|
36
34
|
return R2.send(command);
|
|
37
35
|
}
|
|
38
|
-
exports.storeR2JSONString = storeR2JSONString;
|
|
39
36
|
async function getR2JSONString(filename) {
|
|
40
37
|
try {
|
|
41
38
|
if (!R2)
|
|
@@ -48,8 +45,6 @@ async function getR2JSONString(filename) {
|
|
|
48
45
|
return {};
|
|
49
46
|
}
|
|
50
47
|
async function _fetchData() {
|
|
51
|
-
|
|
52
|
-
return response.data;
|
|
48
|
+
return (0, common_1.fetchJson)(`${publicBucketUrl}/${filename}`);
|
|
53
49
|
}
|
|
54
50
|
}
|
|
55
|
-
exports.getR2JSONString = getR2JSONString;
|