@defillama/sdk 5.0.14 → 5.0.18

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.
@@ -1,4 +1,4 @@
1
1
  import { ethers } from "ethers";
2
- export declare function call(provider: ethers.Provider, data: ethers.JsonRpcTransactionRequest, block?: string | number, chain?: string, options?: {
2
+ export declare function call(provider: ethers.AbstractProvider, data: ethers.JsonRpcTransactionRequest, block?: string | number, chain?: string, options?: {
3
3
  retry: boolean;
4
4
  }): Promise<any>;
@@ -29,7 +29,7 @@ async function call(provider, data, block, chain, options = { retry: true }) {
29
29
  }
30
30
  let response;
31
31
  try {
32
- response = await provider.call(data, block);
32
+ response = await provider.call(data);
33
33
  onComplete();
34
34
  }
35
35
  catch (e) {
@@ -1,15 +1,5 @@
1
- import { Provider } from "ethers";
2
- type ProviderWrapped = {
3
- rpcList: string;
4
- _provider: Provider;
5
- };
6
- export declare const providers: {
7
- [chain: string]: ProviderWrapped;
8
- };
9
- export type Chain = string;
10
- export declare function getProvider(chain?: Chain, getArchivalNode?: boolean): Provider;
1
+ export { providers, setProvider, getProvider, } from './util/LlamaProvider';
2
+ export { Chain } from './types';
11
3
  export declare const TEN: bigint;
12
4
  export declare function handleDecimals(num: any, decimals?: number): string;
13
5
  export declare const ETHER_ADDRESS = "0x0000000000000000000000000000000000000000";
14
- export declare function setProvider(chain: Chain, provider: Provider): void;
15
- export {};
package/build/general.js CHANGED
@@ -1,122 +1,10 @@
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.setProvider = exports.ETHER_ADDRESS = exports.handleDecimals = exports.TEN = exports.getProvider = exports.providers = void 0;
7
- const debugLog_1 = require("./util/debugLog");
8
- const ethers_1 = require("ethers");
9
- const providers_json_1 = __importDefault(require("./providers.json"));
10
- const env_1 = require("./util/env");
11
- function createProvider(name, rpcString, chainId = 400069) {
12
- chainId = (0, env_1.getChainId)(name, chainId);
13
- const networkish = { name, chainId };
14
- const rpcList = rpcString.split(',');
15
- if ((0, env_1.getEnvValue)('HISTORICAL')) {
16
- if (chainId === 1) {
17
- (0, debugLog_1.debugLog)("RPC providers set to historical, only the first RPC provider will be used");
18
- }
19
- return getProviderObject(rpcList[0], name);
20
- }
21
- else {
22
- try {
23
- const providerList = rpcList.map((url, i) => ({ provider: getProviderObject(url, name), chainId, }));
24
- return new ethers_1.ethers.FallbackProvider(providerList, networkish, { cacheTimeout: 5 * 1000, quorum: 1, eventQuorum: 1, });
25
- }
26
- catch (e) {
27
- // debugLog(`Error creating provider for ${name} with RPCs: ${rpcList.join(', ')}`)
28
- // we dont throw errors for chains not present in providers.json, these can be non-evm chains like solana
29
- if (providers_json_1.default[name])
30
- throw e;
31
- return null;
32
- }
33
- }
34
- function getProviderObject(url, chain) {
35
- /**
36
- * Options for configuring a [[JsonRpcApiProvider]]. Much of this
37
- * is targetted towards sub-classes, which often will not expose
38
- * any of these options to their consumers.
39
- *
40
- * **``polling``** - use the polling strategy is used immediately
41
- * for events; otherwise, attempt to use filters and fall back onto
42
- * polling (default: ``false``)
43
- *
44
- * **``staticNetwork``** - do not request chain ID on requests to
45
- * validate the underlying chain has not changed (default: ``null``)
46
- *
47
- * This should **ONLY** be used if it is **certain** that the network
48
- * cannot change, such as when using INFURA (since the URL dictates the
49
- * network). If the network is assumed static and it does change, this
50
- * can have tragic consequences. For example, this **CANNOT** be used
51
- * with MetaMask, since the used can select a new network from the
52
- * drop-down at any time.
53
- *
54
- * **``batchStallTime``** - how long (ms) to aggregate requests into a
55
- * single batch. ``0`` indicates batching will only encompass the current
56
- * event loop. If ``batchMaxCount = 1``, this is ignored. (default: ``10``)
57
- *
58
- * **``batchMaxSize``** - target maximum size (bytes) to allow per batch
59
- * request (default: 1Mb)
60
- *
61
- * **``batchMaxCount``** - maximum number of requests to allow in a batch.
62
- * If ``batchMaxCount = 1``, then batching is disabled. (default: ``100``)
63
- *
64
- * **``cacheTimeout``** - passed as [[AbstractProviderOptions]].
65
- * **``cacheTimeout``** - how long to cache a low-level ``_perform``
66
- * for, based on input parameters. This reduces the number of calls
67
- * to getChainId and getBlockNumber, but may break test chains which
68
- * can perform operations (internally) synchronously. Use ``-1`` to
69
- * disable, ``0`` will only buffer within the same event loop and
70
- * any other value is in ms. (default: ``250``)
71
- */
72
- // const batchMaxSize = 10 * (1024 * 1024) // 10Mb
73
- // some rpcs throw error if batchMaxCount is set higher than 100
74
- const batchMaxCount = (0, env_1.getBatchMaxCount)(chain);
75
- const jsonRpcApiProviderOptions = { staticNetwork: true, batchStallTime: 42, batchMaxCount, };
76
- if (url.startsWith('wss://')) {
77
- delete jsonRpcApiProviderOptions.batchMaxCount;
78
- return new ethers_1.ethers.WebSocketProvider(url, networkish, jsonRpcApiProviderOptions);
79
- }
80
- return new ethers_1.ethers.JsonRpcProvider(url, networkish, jsonRpcApiProviderOptions);
81
- }
82
- }
83
- exports.providers = {};
84
- const archivalProviders = {};
85
- function getProvider(chain = "ethereum", getArchivalNode = false) {
86
- var _a, _b, _c;
87
- if (getArchivalNode) {
88
- if (archivalProviders[chain])
89
- return archivalProviders[chain]._provider;
90
- let rpcList = (0, env_1.getArchivalRPCs)(chain);
91
- if (rpcList.length) {
92
- // shuffle rpcList
93
- rpcList = rpcList.sort(() => Math.random() - 0.5);
94
- const provider = createProvider(chain, rpcList.join(','), (_a = providers_json_1.default[chain]) === null || _a === void 0 ? void 0 : _a.chainId);
95
- if (rpcList.length === 1)
96
- archivalProviders[chain] = { rpcList: rpcList[0], _provider: provider };
97
- return provider;
98
- }
99
- }
100
- if (exports.providers[chain] && !getArchivalNode)
101
- return exports.providers[chain]._provider;
102
- // use RPC from env variable if set else use RPC from providers.json
103
- let rpcList = (0, env_1.getChainRPCs)(chain, (_b = providers_json_1.default[chain]) === null || _b === void 0 ? void 0 : _b.rpc);
104
- if (!rpcList) {
105
- // in case provider was set using `setProvider` function
106
- if (exports.providers[chain])
107
- return exports.providers[chain]._provider;
108
- // @ts-ignore (throwing error here would alter function behavior and have side effects)
109
- return null;
110
- }
111
- if (!exports.providers[chain] || exports.providers[chain].rpcList !== rpcList) {
112
- exports.providers[chain] = {
113
- rpcList,
114
- _provider: createProvider(chain, rpcList, (_c = providers_json_1.default[chain]) === null || _c === void 0 ? void 0 : _c.chainId)
115
- };
116
- }
117
- return exports.providers[chain]._provider;
118
- }
119
- exports.getProvider = getProvider;
3
+ exports.ETHER_ADDRESS = exports.handleDecimals = exports.TEN = exports.getProvider = exports.setProvider = exports.providers = void 0;
4
+ var LlamaProvider_1 = require("./util/LlamaProvider");
5
+ Object.defineProperty(exports, "providers", { enumerable: true, get: function () { return LlamaProvider_1.providers; } });
6
+ Object.defineProperty(exports, "setProvider", { enumerable: true, get: function () { return LlamaProvider_1.setProvider; } });
7
+ Object.defineProperty(exports, "getProvider", { enumerable: true, get: function () { return LlamaProvider_1.getProvider; } });
120
8
  exports.TEN = BigInt(10);
121
9
  function handleDecimals(num, decimals) {
122
10
  if (typeof num !== 'number')
@@ -130,10 +18,3 @@ function handleDecimals(num, decimals) {
130
18
  }
131
19
  exports.handleDecimals = handleDecimals;
132
20
  exports.ETHER_ADDRESS = "0x0000000000000000000000000000000000000000";
133
- function setProvider(chain, provider) {
134
- exports.providers[chain] = {
135
- rpcList: "",
136
- _provider: provider
137
- };
138
- }
139
- exports.setProvider = setProvider;
@@ -22,6 +22,6 @@ type ChainBlocks = {
22
22
  export declare function sumChainTvls(chainTvls: Array<(timestamp: number, ethBlock: number, chainBlocks: ChainBlocks, params: any) => Promise<Balances>>): (timestamp: number, ethBlock: number, chainBlocks: ChainBlocks, params: any) => Promise<any>;
23
23
  export { blocks, humanizeNumber, };
24
24
  export declare function getUniqueAddresses(addresses: string[], chain?: string): string[];
25
- export declare function getProviderUrl(provider: any): string;
25
+ export declare function getProviderUrl(provider: any): any;
26
26
  export declare function formErrorString(e: any, errorParams?: any): any;
27
27
  export declare function formError(e: any, errorParams?: any): Error;
@@ -154,6 +154,8 @@ function getUniqueAddresses(addresses, chain) {
154
154
  }
155
155
  exports.getUniqueAddresses = getUniqueAddresses;
156
156
  function getProviderUrl(provider) {
157
+ if (provider === null || provider === void 0 ? void 0 : provider.isCustomLlamaProvider)
158
+ return provider.rpcs.map((i) => i.url).join(', ');
157
159
  if (provider instanceof ethers.FallbackProvider)
158
160
  provider = provider.providerConfigs[0].provider;
159
161
  if (provider instanceof ethers.JsonRpcProvider)
@@ -182,6 +184,11 @@ function formErrorString(e, errorParams = {}) {
182
184
  }
183
185
  return '';
184
186
  }
187
+ if (e.llamaRPCError) {
188
+ const errorString = `Llama RPC error! methos: ${e.method} `;
189
+ const errors = e.errors.map((i) => { var _a; return `- host: ${i === null || i === void 0 ? void 0 : i.host} error: ${(_a = i === null || i === void 0 ? void 0 : i.error) === null || _a === void 0 ? void 0 : _a.message}`; });
190
+ return errorString + '\n' + errors.join('\n');
191
+ }
185
192
  let errorString = e.toString();
186
193
  if (typeof e !== 'object')
187
194
  return errorString;
@@ -254,7 +261,7 @@ function formError(e, errorParams = {}) {
254
261
  }
255
262
  catch (e) { }
256
263
  error._isCustomError = true;
257
- error.message = shortenString(error.message, 999);
264
+ error.message = shortenString(error.message, 2999);
258
265
  error.stack = '';
259
266
  return error;
260
267
  }