@defillama/sdk 5.0.236 → 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.
- package/package.json +3 -3
- package/build/Balances.d.ts +0 -139
- package/build/Balances.js +0 -363
- package/build/ChainApi.d.ts +0 -142
- package/build/ChainApi.js +0 -297
- package/build/abi/abi2.d.ts +0 -5
- package/build/abi/abi2.js +0 -215
- package/build/abi/cachedABIs.d.ts +0 -4
- package/build/abi/cachedABIs.js +0 -8
- package/build/abi/convertResults.d.ts +0 -5
- package/build/abi/convertResults.js +0 -60
- package/build/abi/index.d.ts +0 -31
- package/build/abi/index.js +0 -327
- package/build/abi/multicall.d.ts +0 -23
- package/build/abi/multicall.js +0 -382
- package/build/abi/multicall3.d.ts +0 -7
- package/build/abi/multicall3.js +0 -397
- package/build/abi/rpcCall.d.ts +0 -4
- package/build/abi/rpcCall.js +0 -62
- package/build/abi/tron.d.ts +0 -33
- package/build/abi/tron.js +0 -110
- package/build/api.d.ts +0 -10
- package/build/api.js +0 -45
- package/build/api2.d.ts +0 -5
- package/build/api2.js +0 -41
- package/build/chains/algorand.d.ts +0 -277
- package/build/chains/algorand.js +0 -618
- package/build/chains/aptos.d.ts +0 -230
- package/build/chains/aptos.js +0 -612
- package/build/chains/cardano.d.ts +0 -242
- package/build/chains/cardano.js +0 -407
- package/build/chains/cosmos.d.ts +0 -252
- package/build/chains/cosmos.js +0 -618
- package/build/chains/icp.d.ts +0 -235
- package/build/chains/icp.js +0 -1040
- package/build/chains/index.d.ts +0 -23
- package/build/chains/index.js +0 -59
- package/build/chains/near.d.ts +0 -192
- package/build/chains/near.js +0 -446
- package/build/chains/rpc.d.ts +0 -125
- package/build/chains/rpc.js +0 -326
- package/build/chains/starknet.d.ts +0 -205
- package/build/chains/starknet.js +0 -884
- package/build/chains/stellar.d.ts +0 -410
- package/build/chains/stellar.js +0 -1082
- package/build/chains/substrate.d.ts +0 -333
- package/build/chains/substrate.js +0 -1042
- package/build/chains/sui.d.ts +0 -365
- package/build/chains/sui.js +0 -1135
- package/build/chains/svm.d.ts +0 -340
- package/build/chains/svm.js +0 -760
- package/build/chains/tezos.d.ts +0 -225
- package/build/chains/tezos.js +0 -412
- package/build/chains/ton.d.ts +0 -353
- package/build/chains/ton.js +0 -788
- package/build/chains/tron.d.ts +0 -45
- package/build/chains/tron.js +0 -110
- package/build/chains/utxo.d.ts +0 -202
- package/build/chains/utxo.js +0 -592
- package/build/chains/xrpl.d.ts +0 -179
- package/build/chains/xrpl.js +0 -467
- package/build/computeTVL/blocks.d.ts +0 -1
- package/build/computeTVL/blocks.js +0 -12
- package/build/computeTVL/humanizeNumber.d.ts +0 -1
- package/build/computeTVL/humanizeNumber.js +0 -19
- package/build/erc20/index.d.ts +0 -31
- package/build/erc20/index.js +0 -56
- package/build/eth/index.d.ts +0 -22
- package/build/eth/index.js +0 -118
- package/build/general.d.ts +0 -5
- package/build/general.js +0 -20
- package/build/generalUtil.d.ts +0 -8
- package/build/generalUtil.js +0 -73
- package/build/index.d.ts +0 -32
- package/build/index.js +0 -74
- package/build/providers.json +0 -1
- package/build/types.d.ts +0 -76
- package/build/types.js +0 -2
- package/build/util/LlamaProvider.d.ts +0 -46
- package/build/util/LlamaProvider.js +0 -365
- package/build/util/blocks.d.ts +0 -36
- package/build/util/blocks.js +0 -292
- package/build/util/cache.d.ts +0 -45
- package/build/util/cache.js +0 -309
- package/build/util/chainUtils/data.json +0 -1356
- package/build/util/chainUtils/index.d.ts +0 -11
- package/build/util/chainUtils/index.js +0 -136
- package/build/util/coins.d.ts +0 -19
- package/build/util/coins.js +0 -113
- package/build/util/common.d.ts +0 -34
- package/build/util/common.js +0 -373
- package/build/util/computeTVL.d.ts +0 -19
- package/build/util/computeTVL.js +0 -102
- package/build/util/cosmos.d.ts +0 -1
- package/build/util/cosmos.js +0 -8
- package/build/util/debugLog.d.ts +0 -4
- package/build/util/debugLog.js +0 -18
- package/build/util/discord.d.ts +0 -1
- package/build/util/discord.js +0 -33
- package/build/util/elastic.d.ts +0 -43
- package/build/util/elastic.js +0 -113
- package/build/util/env.d.ts +0 -19
- package/build/util/env.js +0 -158
- package/build/util/graph.d.ts +0 -8
- package/build/util/graph.js +0 -50
- package/build/util/index.d.ts +0 -32
- package/build/util/index.js +0 -227
- package/build/util/indexer.compatibility.d.ts +0 -6
- package/build/util/indexer.compatibility.js +0 -64
- package/build/util/indexer.d.ts +0 -92
- package/build/util/indexer.js +0 -744
- package/build/util/indexerSql.d.ts +0 -9
- package/build/util/indexerSql.js +0 -102
- package/build/util/internal-cache.d.ts +0 -11
- package/build/util/internal-cache.js +0 -77
- package/build/util/logs.d.ts +0 -55
- package/build/util/logs.decode.shared.d.ts +0 -8
- package/build/util/logs.decode.shared.js +0 -289
- package/build/util/logs.js +0 -401
- package/build/util/promisePool.d.ts +0 -8
- package/build/util/promisePool.js +0 -31
- package/build/util/r2.d.ts +0 -4
- package/build/util/r2.js +0 -52
- package/build/util/removeRedundantRPCs.d.ts +0 -1
- package/build/util/removeRedundantRPCs.js +0 -49
- package/build/util/transactions.d.ts +0 -35
- package/build/util/transactions.js +0 -22
- package/build/util/updateChainLabels.d.ts +0 -1
- package/build/util/updateChainLabels.js +0 -5
- package/build/util/updateProviderList.d.ts +0 -1
- package/build/util/updateProviderList.js +0 -274
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,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,365 +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
|
-
result.number = parseInt(result.number);
|
|
274
|
-
result.timestamp = parseInt(result.timestamp);
|
|
275
|
-
return result;
|
|
276
|
-
},
|
|
277
|
-
getBalance: async (rpc, params) => {
|
|
278
|
-
params[1] = toHex(params[1]);
|
|
279
|
-
const { data: { result, error } } = await axios_1.default.post(rpc, {
|
|
280
|
-
jsonrpc: '2.0', id: 1, params,
|
|
281
|
-
method: 'eth_getBalance',
|
|
282
|
-
}, {
|
|
283
|
-
timeout: +(0, env_1.getEnvValue)('LLAMA_PROVIDER_RPC_GET_BALANCE_TIMEOUT', '30000')
|
|
284
|
-
});
|
|
285
|
-
if (error)
|
|
286
|
-
throw error;
|
|
287
|
-
return BigInt(result).toString();
|
|
288
|
-
},
|
|
289
|
-
call: async (rpc, params) => {
|
|
290
|
-
params[1] = toHex(params[1]);
|
|
291
|
-
const { data } = await axios_1.default.post(rpc, {
|
|
292
|
-
jsonrpc: '2.0', id: 1, params,
|
|
293
|
-
method: 'eth_call',
|
|
294
|
-
}, {
|
|
295
|
-
timeout: +(0, env_1.getEnvValue)('LLAMA_PROVIDER_RPC_CALL_TIMEOUT', '30000')
|
|
296
|
-
});
|
|
297
|
-
if (data.error)
|
|
298
|
-
throw data.error;
|
|
299
|
-
return data.result;
|
|
300
|
-
},
|
|
301
|
-
getLogs: async (rpc, params) => {
|
|
302
|
-
params[0].fromBlock = toHex(params[0].fromBlock);
|
|
303
|
-
params[0].toBlock = toHex(params[0].toBlock);
|
|
304
|
-
const { data: { result, error } } = await axios_1.default.post(rpc, {
|
|
305
|
-
jsonrpc: '2.0', id: 1, params,
|
|
306
|
-
method: 'eth_getLogs',
|
|
307
|
-
}, {
|
|
308
|
-
timeout: +(0, env_1.getEnvValue)('LLAMA_PROVIDER_RPC_GET_LOGS_TIMEOUT', '30000')
|
|
309
|
-
});
|
|
310
|
-
if (error)
|
|
311
|
-
throw error;
|
|
312
|
-
result.forEach((i) => {
|
|
313
|
-
i.blockNumber = parseInt(i.blockNumber);
|
|
314
|
-
i.transactionIndex = parseInt(i.transactionIndex);
|
|
315
|
-
i.logIndex = parseInt(i.logIndex);
|
|
316
|
-
i.index = i.logIndex;
|
|
317
|
-
});
|
|
318
|
-
return result;
|
|
319
|
-
},
|
|
320
|
-
getTransaction: async (rpc, params) => {
|
|
321
|
-
const { data: { result, error } } = await axios_1.default.post(rpc, {
|
|
322
|
-
jsonrpc: '2.0', id: 1, params,
|
|
323
|
-
method: 'eth_getTransactionByHash',
|
|
324
|
-
}, {
|
|
325
|
-
timeout: +(0, env_1.getEnvValue)('LLAMA_PROVIDER_RPC_GET_TRANSACTION_TIMEOUT', '180000')
|
|
326
|
-
});
|
|
327
|
-
if (error)
|
|
328
|
-
throw error;
|
|
329
|
-
if (!result)
|
|
330
|
-
return null;
|
|
331
|
-
result.blockNumber = parseInt(result.blockNumber);
|
|
332
|
-
result.transactionIndex = parseInt(result.transactionIndex);
|
|
333
|
-
result.data = result.input;
|
|
334
|
-
return result;
|
|
335
|
-
},
|
|
336
|
-
getTransactionReceipt: async (rpc, params) => {
|
|
337
|
-
const { data: { result, error } } = await axios_1.default.post(rpc, {
|
|
338
|
-
jsonrpc: '2.0', id: 1, params,
|
|
339
|
-
method: 'eth_getTransactionReceipt',
|
|
340
|
-
}, {
|
|
341
|
-
timeout: +(0, env_1.getEnvValue)('LLAMA_PROVIDER_RPC_GET_TXN_RECEIPT_TIMEOUT', '180000')
|
|
342
|
-
});
|
|
343
|
-
if (error)
|
|
344
|
-
throw error;
|
|
345
|
-
if (!result)
|
|
346
|
-
return null;
|
|
347
|
-
result.blockNumber = parseInt(result.blockNumber);
|
|
348
|
-
result.transactionIndex = parseInt(result.transactionIndex);
|
|
349
|
-
return result;
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
function getMedianBlockValue(blocks) {
|
|
353
|
-
blocks.sort((a, b) => a - b);
|
|
354
|
-
const mid = Math.floor(blocks.length / 3);
|
|
355
|
-
return blocks.length % 2 !== 0 ? blocks[mid] : (blocks[mid - 1] + blocks[mid]) / 2;
|
|
356
|
-
}
|
|
357
|
-
let lastPrintTimeMS = Date.now();
|
|
358
|
-
function printRPCCallStats() {
|
|
359
|
-
const entries = Object.entries(rpcRequestCounter).map(([chain, count]) => ({ chain, count })).filter(i => i.count > 50);
|
|
360
|
-
if (entries.length > 7) {
|
|
361
|
-
(0, debugLog_1.debugLog)('RPC request count per chain (only over 100)');
|
|
362
|
-
(0, debugLog_1.debugTable)(entries);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
process.on('exit', printRPCCallStats);
|
package/build/util/blocks.d.ts
DELETED
|
@@ -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 {};
|