@defillama/sdk 5.0.238 → 5.0.240

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.
Files changed (131) hide show
  1. package/package.json +1 -1
  2. package/build/Balances.d.ts +0 -139
  3. package/build/Balances.js +0 -363
  4. package/build/ChainApi.d.ts +0 -142
  5. package/build/ChainApi.js +0 -310
  6. package/build/abi/abi2.d.ts +0 -5
  7. package/build/abi/abi2.js +0 -215
  8. package/build/abi/cachedABIs.d.ts +0 -4
  9. package/build/abi/cachedABIs.js +0 -8
  10. package/build/abi/convertResults.d.ts +0 -5
  11. package/build/abi/convertResults.js +0 -60
  12. package/build/abi/index.d.ts +0 -31
  13. package/build/abi/index.js +0 -327
  14. package/build/abi/multicall.d.ts +0 -23
  15. package/build/abi/multicall.js +0 -382
  16. package/build/abi/multicall3.d.ts +0 -7
  17. package/build/abi/multicall3.js +0 -397
  18. package/build/abi/rpcCall.d.ts +0 -4
  19. package/build/abi/rpcCall.js +0 -62
  20. package/build/abi/tron.d.ts +0 -33
  21. package/build/abi/tron.js +0 -116
  22. package/build/api.d.ts +0 -10
  23. package/build/api.js +0 -45
  24. package/build/api2.d.ts +0 -5
  25. package/build/api2.js +0 -41
  26. package/build/chains/algorand.d.ts +0 -277
  27. package/build/chains/algorand.js +0 -618
  28. package/build/chains/aptos.d.ts +0 -230
  29. package/build/chains/aptos.js +0 -612
  30. package/build/chains/cardano.d.ts +0 -242
  31. package/build/chains/cardano.js +0 -407
  32. package/build/chains/cosmos.d.ts +0 -252
  33. package/build/chains/cosmos.js +0 -618
  34. package/build/chains/icp.d.ts +0 -235
  35. package/build/chains/icp.js +0 -1040
  36. package/build/chains/index.d.ts +0 -23
  37. package/build/chains/index.js +0 -59
  38. package/build/chains/near.d.ts +0 -192
  39. package/build/chains/near.js +0 -446
  40. package/build/chains/rpc.d.ts +0 -125
  41. package/build/chains/rpc.js +0 -326
  42. package/build/chains/starknet.d.ts +0 -205
  43. package/build/chains/starknet.js +0 -884
  44. package/build/chains/stellar.d.ts +0 -410
  45. package/build/chains/stellar.js +0 -1082
  46. package/build/chains/substrate.d.ts +0 -333
  47. package/build/chains/substrate.js +0 -1042
  48. package/build/chains/sui.d.ts +0 -365
  49. package/build/chains/sui.js +0 -1135
  50. package/build/chains/svm.d.ts +0 -340
  51. package/build/chains/svm.js +0 -760
  52. package/build/chains/tezos.d.ts +0 -225
  53. package/build/chains/tezos.js +0 -412
  54. package/build/chains/ton.d.ts +0 -353
  55. package/build/chains/ton.js +0 -788
  56. package/build/chains/tron.d.ts +0 -45
  57. package/build/chains/tron.js +0 -110
  58. package/build/chains/utxo.d.ts +0 -202
  59. package/build/chains/utxo.js +0 -592
  60. package/build/chains/xrpl.d.ts +0 -179
  61. package/build/chains/xrpl.js +0 -467
  62. package/build/computeTVL/blocks.d.ts +0 -1
  63. package/build/computeTVL/blocks.js +0 -12
  64. package/build/computeTVL/humanizeNumber.d.ts +0 -1
  65. package/build/computeTVL/humanizeNumber.js +0 -19
  66. package/build/erc20/index.d.ts +0 -31
  67. package/build/erc20/index.js +0 -56
  68. package/build/eth/index.d.ts +0 -22
  69. package/build/eth/index.js +0 -118
  70. package/build/general.d.ts +0 -5
  71. package/build/general.js +0 -20
  72. package/build/generalUtil.d.ts +0 -8
  73. package/build/generalUtil.js +0 -73
  74. package/build/index.d.ts +0 -32
  75. package/build/index.js +0 -74
  76. package/build/providers.json +0 -1
  77. package/build/types.d.ts +0 -76
  78. package/build/types.js +0 -2
  79. package/build/util/LlamaProvider.d.ts +0 -46
  80. package/build/util/LlamaProvider.js +0 -367
  81. package/build/util/blocks.d.ts +0 -36
  82. package/build/util/blocks.js +0 -500
  83. package/build/util/cache.d.ts +0 -45
  84. package/build/util/cache.js +0 -309
  85. package/build/util/chainUtils/data.json +0 -1425
  86. package/build/util/chainUtils/index.d.ts +0 -11
  87. package/build/util/chainUtils/index.js +0 -136
  88. package/build/util/coins.d.ts +0 -19
  89. package/build/util/coins.js +0 -124
  90. package/build/util/common.d.ts +0 -34
  91. package/build/util/common.js +0 -376
  92. package/build/util/computeTVL.d.ts +0 -19
  93. package/build/util/computeTVL.js +0 -102
  94. package/build/util/cosmos.d.ts +0 -1
  95. package/build/util/cosmos.js +0 -8
  96. package/build/util/debugLog.d.ts +0 -4
  97. package/build/util/debugLog.js +0 -18
  98. package/build/util/discord.d.ts +0 -1
  99. package/build/util/discord.js +0 -33
  100. package/build/util/elastic.d.ts +0 -43
  101. package/build/util/elastic.js +0 -113
  102. package/build/util/env.d.ts +0 -20
  103. package/build/util/env.js +0 -175
  104. package/build/util/graph.d.ts +0 -8
  105. package/build/util/graph.js +0 -50
  106. package/build/util/index.d.ts +0 -32
  107. package/build/util/index.js +0 -227
  108. package/build/util/indexer.compatibility.d.ts +0 -6
  109. package/build/util/indexer.compatibility.js +0 -64
  110. package/build/util/indexer.d.ts +0 -92
  111. package/build/util/indexer.js +0 -850
  112. package/build/util/indexerSql.d.ts +0 -9
  113. package/build/util/indexerSql.js +0 -102
  114. package/build/util/internal-cache.d.ts +0 -11
  115. package/build/util/internal-cache.js +0 -77
  116. package/build/util/logs.d.ts +0 -58
  117. package/build/util/logs.decode.shared.d.ts +0 -8
  118. package/build/util/logs.decode.shared.js +0 -289
  119. package/build/util/logs.js +0 -432
  120. package/build/util/promisePool.d.ts +0 -8
  121. package/build/util/promisePool.js +0 -31
  122. package/build/util/r2.d.ts +0 -4
  123. package/build/util/r2.js +0 -52
  124. package/build/util/removeRedundantRPCs.d.ts +0 -1
  125. package/build/util/removeRedundantRPCs.js +0 -49
  126. package/build/util/transactions.d.ts +0 -35
  127. package/build/util/transactions.js +0 -22
  128. package/build/util/updateChainLabels.d.ts +0 -1
  129. package/build/util/updateChainLabels.js +0 -5
  130. package/build/util/updateProviderList.d.ts +0 -1
  131. package/build/util/updateProviderList.js +0 -275
package/build/types.d.ts DELETED
@@ -1,76 +0,0 @@
1
- export type Address = string;
2
- export type StringNumber = string;
3
- export type Block = number | string;
4
- export type Balances = {
5
- [address: string]: StringNumber | number;
6
- };
7
- type CallParams = string | number | (string | number)[] | undefined;
8
- export type CallsParams = {
9
- target?: Address;
10
- params?: CallParams;
11
- };
12
- export type CallOptions = {
13
- target: Address;
14
- abi?: string | any;
15
- abis?: string[];
16
- block?: Block;
17
- params?: CallParams;
18
- chain?: Chain | string;
19
- withMetadata?: boolean;
20
- skipCache?: boolean;
21
- logArray?: LogArray;
22
- permitFailure?: boolean;
23
- field?: string;
24
- };
25
- export type Chain = string;
26
- export type MulticallOptions = {
27
- abi?: string | any;
28
- abis?: string[];
29
- calls: CallsParams[] | (string | number)[];
30
- block?: Block;
31
- target?: Address;
32
- chain?: Chain | string;
33
- requery?: boolean;
34
- withMetadata?: boolean;
35
- skipCache?: boolean;
36
- permitFailure?: boolean;
37
- excludeFailed?: boolean;
38
- logArray?: LogArray;
39
- field?: string;
40
- };
41
- export type FetchListOptions = {
42
- lengthAbi?: string | any;
43
- itemAbi: string | any;
44
- itemAbi2?: string | any;
45
- block?: Block;
46
- startFrom?: number;
47
- target?: Address;
48
- calls?: Address[];
49
- targets?: Address[];
50
- chain?: Chain | string;
51
- withMetadata?: boolean;
52
- startFromOne?: boolean;
53
- itemCount?: number;
54
- permitFailure?: boolean;
55
- logArray?: LogArray;
56
- groupedByInput?: boolean;
57
- excludeFailed?: boolean;
58
- field?: string;
59
- field2?: string;
60
- };
61
- export type ByteCodeCallOptions = {
62
- bytecode: string;
63
- inputTypes: string[];
64
- inputs: any[];
65
- block?: number | string;
66
- chain?: Chain | string;
67
- outputTypes: string[];
68
- withMetadata?: boolean;
69
- };
70
- export type LogArray = {
71
- token: Address;
72
- holder: Address;
73
- chain: Chain;
74
- amount: any;
75
- }[];
76
- export {};
package/build/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,46 +0,0 @@
1
- import { AbstractProvider, AddressLike, Block, BlockTag, FallbackProvider, Filter, FilterByBlockHash, Log, TransactionRequest } from "ethers";
2
- import { Chain } from "../types";
3
- type ProviderWithURL = {
4
- url: string;
5
- provider: AbstractProvider;
6
- };
7
- type ProviderConfigMap = {
8
- [chain: string]: {
9
- rpc?: string[];
10
- chainId?: number;
11
- explorer?: string;
12
- };
13
- };
14
- export declare class LlamaProvider extends FallbackProvider {
15
- isCustomLlamaProvider: boolean;
16
- rpcs: ProviderWithURL[];
17
- archivalRPCs: ProviderWithURL[];
18
- _isReady: Promise<void>;
19
- chainName: string;
20
- chainId: number;
21
- constructor({ providers, chainId, chainName, archivalRPCs, }: {
22
- providers: ProviderWithURL[];
23
- archivalRPCs: ProviderWithURL[];
24
- chainId: number;
25
- chainName: string;
26
- }, fallbackConfig?: any);
27
- getNetwork(): any;
28
- _removeProvider(rpc: string): void;
29
- _ready(): Promise<void>;
30
- call(_tx: TransactionRequest): Promise<string>;
31
- getBalance(address: AddressLike, blockTag?: BlockTag): Promise<bigint>;
32
- getBlock(block: BlockTag, prefetchTxs?: boolean | undefined): Promise<Block | null>;
33
- getLogs(_filter: Filter | FilterByBlockHash): Promise<Log[]>;
34
- getTransaction(_hash: string): Promise<any>;
35
- getTransactionReceipt(_hash: string): Promise<any>;
36
- _performAction(method: string, params: any, attempts?: number): Promise<any>;
37
- }
38
- export declare function getEVMProvidersConfigMap(): ProviderConfigMap;
39
- export declare function getEVMChainSet(): Set<string>;
40
- export declare function isEvmChain(chain: string): boolean;
41
- export declare const providers: {
42
- [chain: string]: AbstractProvider;
43
- };
44
- export declare function setProvider(chain: Chain, provider: AbstractProvider): void;
45
- export declare function getProvider(chain?: Chain, _getArchivalNode?: boolean): AbstractProvider;
46
- export {};
@@ -1,367 +0,0 @@
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.providers = exports.LlamaProvider = void 0;
7
- exports.getEVMProvidersConfigMap = getEVMProvidersConfigMap;
8
- exports.getEVMChainSet = getEVMChainSet;
9
- exports.isEvmChain = isEvmChain;
10
- exports.setProvider = setProvider;
11
- exports.getProvider = getProvider;
12
- const ethers_1 = require("ethers");
13
- const providers_json_1 = __importDefault(require("../providers.json"));
14
- const env_1 = require("./env");
15
- const debugLog_1 = require("./debugLog");
16
- const axios_1 = __importDefault(require("axios"));
17
- let buildProviders = undefined;
18
- if (process.env['TEST_MODE']) {
19
- buildProviders = require('../../build/providers.json');
20
- }
21
- const rpcRequestCounter = {};
22
- class LlamaProvider extends ethers_1.FallbackProvider {
23
- constructor({ providers, chainId, chainName, archivalRPCs, }, fallbackConfig) {
24
- const networkish = { name: chainName, chainId };
25
- super(providers.map(i => i.provider), networkish, fallbackConfig);
26
- this.isCustomLlamaProvider = true;
27
- this.rpcs = providers;
28
- this.archivalRPCs = archivalRPCs;
29
- this.chainName = chainName;
30
- this.chainId = chainId;
31
- this._isReady = this._ready();
32
- }
33
- getNetwork() {
34
- return { chainId: this.chainId, name: this.chainName };
35
- }
36
- _removeProvider(rpc) {
37
- this.rpcs = this.rpcs.filter(i => i.url !== rpc);
38
- this.archivalRPCs = this.archivalRPCs.filter(i => i.url !== rpc);
39
- }
40
- async _ready() {
41
- if (process.env["SKIP_RPC_CHECK"] === "true") {
42
- return;
43
- }
44
- const outOfSyncLimit = 1000;
45
- const _this = this;
46
- const currentBlocks = {};
47
- await Promise.all(this.rpcs.map(checkRPCWorks));
48
- if (this.archivalRPCs.length) {
49
- await Promise.all(this.archivalRPCs.map(checkRPCWorks));
50
- }
51
- // we are doing this because I noticed that one of the rpcs can go rouge and return very high block number
52
- const medianBlockValue = getMedianBlockValue(Object.values(currentBlocks));
53
- Object.entries(currentBlocks).forEach(([url, block]) => {
54
- if (medianBlockValue - block > outOfSyncLimit) {
55
- (0, debugLog_1.debugLog)(`RPC ${url} is out of sync by ${medianBlockValue - block} blocks`);
56
- _this.rpcs = _this.rpcs.filter(i => i.url !== url);
57
- _this.archivalRPCs = _this.archivalRPCs.filter(i => i.url !== url);
58
- }
59
- });
60
- async function checkRPCWorks({ url, provider }) {
61
- try {
62
- const block = await httpRPC.getBlockNumber(url);
63
- currentBlocks[url] = block;
64
- }
65
- catch (e) {
66
- if (env_1.ENV_CONSTANTS.LOG_LLAMA_PROVIDER_CALLS)
67
- (0, debugLog_1.debugLog)(`${_this.chainName} skipping RPC ${url} is not working, error: ${e.message}`);
68
- _this._removeProvider(url);
69
- }
70
- }
71
- }
72
- async call(_tx) {
73
- var _a;
74
- return this._performAction('call', [{ to: _tx.to, data: _tx.data }, (_a = _tx.blockTag) !== null && _a !== void 0 ? _a : 'latest']);
75
- }
76
- async getBalance(address, blockTag = 'latest') {
77
- return this._performAction('getBalance', [address, blockTag]);
78
- }
79
- async getBlock(block, prefetchTxs) {
80
- return this._performAction('getBlock', [block, false]);
81
- }
82
- async getLogs(_filter) {
83
- return this._performAction('getLogs', [_filter], 7);
84
- }
85
- async getTransaction(_hash) {
86
- return this._performAction('getTransaction', [_hash]);
87
- }
88
- async getTransactionReceipt(_hash) {
89
- return this._performAction('getTransactionReceipt', [_hash]);
90
- }
91
- async _performAction(method, params, attempts = 7) {
92
- var _a;
93
- if (!rpcRequestCounter[this.chainName])
94
- rpcRequestCounter[this.chainName] = 0;
95
- rpcRequestCounter[this.chainName]++;
96
- await this._isReady;
97
- let runners = [...this.rpcs];
98
- if (method === 'getLogs') {
99
- runners = [...this.archivalRPCs];
100
- this.rpcs.filter(i => !runners.map(i => i.url).includes(i.url)).forEach(i => runners.push(i)); // ensure that there are no duplicates
101
- runners = runners.filter(i => !i.url.includes('llamarpc.com'));
102
- }
103
- if (!runners.length)
104
- throw new Error('No RPCs available for ' + this.chainName);
105
- let primaryRunner = runners[0];
106
- let errors = [];
107
- if (method === 'getLogs') {
108
- runners = runners.slice(1).concat(this.rpcs);
109
- runners = runners.sort(() => Math.random() - 0.5); // randomize order of runners
110
- }
111
- else
112
- runners = runners.slice(1).sort(() => Math.random() - 0.5); // randomize order of runners
113
- const isArchivalRequest = ['call', 'getBalance'].includes(method) && params[1] !== 'latest';
114
- // check if domain name of primaryRunner.url is llama
115
- const isLlamaRPC = primaryRunner.url.includes('llama');
116
- let noPlayingAround = (0, env_1.getEnvValue)('RPC_NO_PLAYING_AROUND') === 'true' || isLlamaRPC || method === 'getLogs' || isArchivalRequest;
117
- if (noPlayingAround) {
118
- // if primary runner is llama.fi or alchemy, then try it first
119
- runners.unshift(primaryRunner);
120
- }
121
- else {
122
- // add it as second runner
123
- runners.splice(1, 0, primaryRunner);
124
- }
125
- runners = runners.slice(0, attempts);
126
- // print stats every 5 minutes
127
- let currentTimeMS = Date.now();
128
- if (currentTimeMS - lastPrintTimeMS > 1000 * 60 * 5) {
129
- lastPrintTimeMS = currentTimeMS;
130
- printRPCCallStats();
131
- }
132
- // if (this.chainName === 'rsk' && method === 'getLogs') {
133
- // const hostString = getEnvValue('RSK_ARCHIVAL_RPC')
134
- // if (!hostString)
135
- // throw new Error('RSK public nodes dont support getLogs. need to set RSK_ARCHIVAL_RPC');
136
- // (runners as any) = hostString.split(',').map(host => ({ url: host }))
137
- // }
138
- for (const runner of runners) {
139
- try {
140
- const result = await httpRPC[method](runner.url, params);
141
- return result;
142
- }
143
- catch (e) {
144
- // console.log('failed', runner.url, (e as any).message)
145
- errors.push({ host: runner.url, error: ((_a = e === null || e === void 0 ? void 0 : e.message) !== null && _a !== void 0 ? _a : e) });
146
- }
147
- }
148
- throw { llamaRPCError: true, errors, method, };
149
- }
150
- }
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
- }
171
- function createProvider(name, rpcString, chainId = 400069, archivalRPCList = []) {
172
- chainId = (0, env_1.getChainId)(name, chainId);
173
- const networkish = { name, chainId };
174
- let rpcList = rpcString.split(',');
175
- if ((0, env_1.getEnvValue)('HISTORICAL')) {
176
- if (chainId === 1) {
177
- (0, debugLog_1.debugLog)("RPC providers set to historical, only the first RPC provider will be used");
178
- }
179
- // return getProviderObject(rpcList[0], name)
180
- rpcList = [rpcList[0]];
181
- }
182
- try {
183
- const fallbackConfig = { cacheTimeout: 5 * 1000, quorum: 1, eventQuorum: 1, };
184
- const getProviderWithURL = (url) => ({ url, provider: getProviderObject(url, name) });
185
- const providers = rpcList.map(getProviderWithURL);
186
- const archivalRPCs = archivalRPCList.map(getProviderWithURL);
187
- return new LlamaProvider({ providers, archivalRPCs, chainId, chainName: name, }, fallbackConfig);
188
- // return new FallbackProvider(providers, networkish, fallbackConfig)
189
- }
190
- catch (e) {
191
- // debugLog(`Error creating provider for ${name} with RPCs: ${rpcList.join(', ')}`)
192
- // we dont throw errors for chains not present in providers.json, these can be non-evm chains like solana
193
- if (providers_json_1.default[name])
194
- throw e;
195
- return null;
196
- }
197
- function getProviderObject(url, chain) {
198
- const jsonRpcApiProviderOptions = { staticNetwork: true, batchMaxCount: 1, };
199
- if (url.startsWith('wss://')) {
200
- return null; // websocket provider is not supported
201
- // return new WebSocketProvider(url, networkish, jsonRpcApiProviderOptions)
202
- }
203
- return new ethers_1.JsonRpcProvider(url, networkish, jsonRpcApiProviderOptions);
204
- }
205
- }
206
- exports.providers = {};
207
- function setProvider(chain, provider) {
208
- exports.providers[chain] = provider;
209
- }
210
- function getProvider(chain = "ethereum", _getArchivalNode = false) {
211
- var _a, _b;
212
- const rpcKey = chain === 'tron' ? 'tron_evm' : chain;
213
- let chainKey = chain;
214
- if ((0, env_1.getEnvValue)('HISTORICAL'))
215
- chainKey = chain + '_historical';
216
- if (exports.providers[chainKey])
217
- return exports.providers[chainKey];
218
- const pList = getEVMProvidersConfigMap();
219
- // use RPC from env variable if set else use RPC from providers.json
220
- let rpcList = (0, env_1.getChainRPCs)(rpcKey, (_a = pList[chain]) === null || _a === void 0 ? void 0 : _a.rpc);
221
- let archivalRPCList = (0, env_1.getArchivalRPCs)(rpcKey);
222
- let whitelistedRPCList = (0, env_1.getWhitelistedRPCs)(rpcKey);
223
- if (whitelistedRPCList === null || whitelistedRPCList === void 0 ? void 0 : whitelistedRPCList.length) {
224
- rpcList = [...whitelistedRPCList].join(',');
225
- archivalRPCList = whitelistedRPCList;
226
- }
227
- if (!rpcList) {
228
- // @ts-ignore (throwing error here would alter function behavior and have side effects)
229
- return null;
230
- }
231
- if (!exports.providers[chainKey])
232
- exports.providers[chainKey] = createProvider(chain, rpcList, (_b = providers_json_1.default[chain]) === null || _b === void 0 ? void 0 : _b.chainId, archivalRPCList);
233
- return exports.providers[chainKey];
234
- }
235
- function toHex(n) {
236
- if (typeof n === 'string')
237
- return n;
238
- return '0x' + n.toString(16);
239
- }
240
- const httpRPC = {
241
- getBlockNumber: async (rpc) => {
242
- const getData = async () => {
243
- const data = (await axios_1.default.post(rpc, {
244
- jsonrpc: '2.0', id: 1, params: [],
245
- method: 'eth_blockNumber',
246
- }, {
247
- timeout: +(0, env_1.getEnvValue)('LLAMA_PROVIDER_RPC_GET_BLOCKNUMBER_TIMEOUT', '30000')
248
- })).data;
249
- if (data.error)
250
- throw data.error;
251
- return data.result;
252
- };
253
- let data;
254
- try {
255
- data = await getData();
256
- }
257
- catch (e) {
258
- // try again
259
- data = await getData();
260
- }
261
- return parseInt(data);
262
- },
263
- getBlock: async (rpc, params) => {
264
- params[0] = toHex(params[0]);
265
- const { data: { result, error } } = await axios_1.default.post(rpc, {
266
- jsonrpc: '2.0', id: 1, params,
267
- method: 'eth_getBlockByNumber',
268
- }, {
269
- timeout: +(0, env_1.getEnvValue)('LLAMA_PROVIDER_RPC_GET_BLOCK_TIMEOUT', '60000')
270
- });
271
- if (error)
272
- throw error;
273
- if (!result)
274
- throw new Error(`block ${params[0]} not found`); // pruned or not yet synced, let callers recognise it
275
- result.number = parseInt(result.number);
276
- result.timestamp = parseInt(result.timestamp);
277
- return result;
278
- },
279
- getBalance: async (rpc, params) => {
280
- params[1] = toHex(params[1]);
281
- const { data: { result, error } } = await axios_1.default.post(rpc, {
282
- jsonrpc: '2.0', id: 1, params,
283
- method: 'eth_getBalance',
284
- }, {
285
- timeout: +(0, env_1.getEnvValue)('LLAMA_PROVIDER_RPC_GET_BALANCE_TIMEOUT', '30000')
286
- });
287
- if (error)
288
- throw error;
289
- return BigInt(result).toString();
290
- },
291
- call: async (rpc, params) => {
292
- params[1] = toHex(params[1]);
293
- const { data } = await axios_1.default.post(rpc, {
294
- jsonrpc: '2.0', id: 1, params,
295
- method: 'eth_call',
296
- }, {
297
- timeout: +(0, env_1.getEnvValue)('LLAMA_PROVIDER_RPC_CALL_TIMEOUT', '30000')
298
- });
299
- if (data.error)
300
- throw data.error;
301
- return data.result;
302
- },
303
- getLogs: async (rpc, params) => {
304
- params[0].fromBlock = toHex(params[0].fromBlock);
305
- params[0].toBlock = toHex(params[0].toBlock);
306
- const { data: { result, error } } = await axios_1.default.post(rpc, {
307
- jsonrpc: '2.0', id: 1, params,
308
- method: 'eth_getLogs',
309
- }, {
310
- timeout: +(0, env_1.getEnvValue)('LLAMA_PROVIDER_RPC_GET_LOGS_TIMEOUT', '30000')
311
- });
312
- if (error)
313
- throw error;
314
- result.forEach((i) => {
315
- i.blockNumber = parseInt(i.blockNumber);
316
- i.transactionIndex = parseInt(i.transactionIndex);
317
- i.logIndex = parseInt(i.logIndex);
318
- i.index = i.logIndex;
319
- });
320
- return result;
321
- },
322
- getTransaction: async (rpc, params) => {
323
- const { data: { result, error } } = await axios_1.default.post(rpc, {
324
- jsonrpc: '2.0', id: 1, params,
325
- method: 'eth_getTransactionByHash',
326
- }, {
327
- timeout: +(0, env_1.getEnvValue)('LLAMA_PROVIDER_RPC_GET_TRANSACTION_TIMEOUT', '180000')
328
- });
329
- if (error)
330
- throw error;
331
- if (!result)
332
- return null;
333
- result.blockNumber = parseInt(result.blockNumber);
334
- result.transactionIndex = parseInt(result.transactionIndex);
335
- result.data = result.input;
336
- return result;
337
- },
338
- getTransactionReceipt: async (rpc, params) => {
339
- const { data: { result, error } } = await axios_1.default.post(rpc, {
340
- jsonrpc: '2.0', id: 1, params,
341
- method: 'eth_getTransactionReceipt',
342
- }, {
343
- timeout: +(0, env_1.getEnvValue)('LLAMA_PROVIDER_RPC_GET_TXN_RECEIPT_TIMEOUT', '180000')
344
- });
345
- if (error)
346
- throw error;
347
- if (!result)
348
- return null;
349
- result.blockNumber = parseInt(result.blockNumber);
350
- result.transactionIndex = parseInt(result.transactionIndex);
351
- return result;
352
- }
353
- };
354
- function getMedianBlockValue(blocks) {
355
- blocks.sort((a, b) => a - b);
356
- const mid = Math.floor(blocks.length / 3);
357
- return blocks.length % 2 !== 0 ? blocks[mid] : (blocks[mid - 1] + blocks[mid]) / 2;
358
- }
359
- let lastPrintTimeMS = Date.now();
360
- function printRPCCallStats() {
361
- const entries = Object.entries(rpcRequestCounter).map(([chain, count]) => ({ chain, count })).filter(i => i.count > 50);
362
- if (entries.length > 7) {
363
- (0, debugLog_1.debugLog)('RPC request count per chain (only over 100)');
364
- (0, debugLog_1.debugTable)(entries);
365
- }
366
- }
367
- process.on('exit', printRPCCallStats);
@@ -1,36 +0,0 @@
1
- import { Chain } from "../general";
2
- export declare const chainsForBlocks: string[];
3
- export declare function getChainBlocks(timestamp: number | undefined, chains?: Chain[]): Promise<{
4
- [chain: string]: number;
5
- }>;
6
- export declare function getBlocks(timestamp: number, chains?: Chain[] | undefined): Promise<{
7
- ethereumBlock: number;
8
- chainBlocks: {
9
- [chain: string]: number;
10
- };
11
- }>;
12
- export declare function getCurrentBlocks(chains?: Chain[] | undefined): Promise<{
13
- timestamp: number;
14
- ethereumBlock: number;
15
- chainBlocks: {
16
- [chain: string]: number;
17
- };
18
- }>;
19
- export declare function getBlock(chain: Chain, timestamp?: number, options?: LookupBlockOptionalParams): Promise<Block>;
20
- export declare function getBlockNumber(chain: Chain, timestamp?: number): Promise<number>;
21
- export declare function getCurrentChainBlock(chain?: Chain): Promise<Block>;
22
- export declare const getLatestBlock: typeof getCurrentChainBlock;
23
- type LookupBlockOptionalParams = {
24
- chain?: Chain | "kava" | "algorand";
25
- allowedTimeRange?: number;
26
- acceptableBlockImprecision?: number;
27
- };
28
- export declare function lookupBlock(timestamp: number, extraParams?: LookupBlockOptionalParams): Promise<Block>;
29
- export declare function getTimestamp(height: number, chain: Chain): Promise<number>;
30
- export type Block = {
31
- timestamp: number;
32
- block: number;
33
- hash?: string;
34
- number: number;
35
- };
36
- export {};