@defillama/sdk 5.0.10 → 5.0.11

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,166 +1,86 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
5
  Object.defineProperty(exports, "__esModule", { value: true });
42
6
  exports.getUnique = void 0;
43
- var _1 = require(".");
44
- var generalUtil_1 = require("../generalUtil");
45
- var node_fetch_1 = __importDefault(require("node-fetch"));
46
- var currentPriceCache = {};
47
- var priceCaches = {};
48
- var lastPriceUpdate = 0;
49
- var confidenceThreshold = 0.5;
50
- var priceUpdateTime = 1000 * 60 * 30; // 30 minutes
51
- function computeTVL(balances, timestamp) {
52
- return __awaiter(this, void 0, void 0, function () {
53
- var usdTokenBalances, usdTvl, keys, priceCache;
54
- return __generator(this, function (_a) {
55
- switch (_a.label) {
56
- case 0:
57
- usdTokenBalances = {};
58
- usdTvl = 0;
59
- keys = Object.keys(balances).filter(function (i) { return +balances[i] > 0; }).map(tokenToKey);
60
- return [4 /*yield*/, updatePriceCache(keys, timestamp)];
61
- case 1:
62
- _a.sent();
63
- priceCache = getPriceCache(timestamp);
64
- Object.entries(balances).forEach(function (_a) {
65
- var _b;
66
- var token = _a[0], balance = _a[1];
67
- if (+balance <= 0)
68
- return;
69
- var key = tokenToKey(token).toLowerCase();
70
- var _c = (_b = priceCache[key]) !== null && _b !== void 0 ? _b : {}, price = _c.price, confidence = _c.confidence, _d = _c.decimals, decimals = _d === void 0 ? 0 : _d, _e = _c.symbol, symbol = _e === void 0 ? token : _e;
71
- if (!price || confidence < confidenceThreshold)
72
- return;
73
- var value = +balance * price / (Math.pow(10, decimals));
74
- usdTvl += value;
75
- if (symbol === 'ETH')
76
- symbol = 'WETH';
77
- (0, generalUtil_1.sumSingleBalance)(usdTokenBalances, symbol, value);
78
- });
79
- return [2 /*return*/, { usdTvl: usdTvl, usdTokenBalances: usdTokenBalances }];
80
- }
81
- });
7
+ const _1 = require(".");
8
+ const generalUtil_1 = require("../generalUtil");
9
+ const axios_1 = __importDefault(require("axios"));
10
+ const currentPriceCache = {};
11
+ const priceCaches = {};
12
+ let lastPriceUpdate = 0;
13
+ const confidenceThreshold = 0.5;
14
+ const priceUpdateTime = 1000 * 60 * 30; // 30 minutes
15
+ async function computeTVL(balances, timestamp) {
16
+ const usdTokenBalances = {};
17
+ let usdTvl = 0;
18
+ const keys = Object.keys(balances).filter(i => +balances[i] > 0).map(tokenToKey);
19
+ await updatePriceCache(keys, timestamp);
20
+ const priceCache = getPriceCache(timestamp);
21
+ Object.entries(balances).forEach(([token, balance]) => {
22
+ var _a;
23
+ if (+balance <= 0)
24
+ return;
25
+ const key = tokenToKey(token).toLowerCase();
26
+ let { price, confidence, decimals = 0, symbol = token } = (_a = priceCache[key]) !== null && _a !== void 0 ? _a : {};
27
+ if (!price || confidence < confidenceThreshold)
28
+ return;
29
+ const value = +balance * price / (10 ** decimals);
30
+ usdTvl += value;
31
+ if (symbol === 'ETH')
32
+ symbol = 'WETH';
33
+ (0, generalUtil_1.sumSingleBalance)(usdTokenBalances, symbol, value);
82
34
  });
35
+ return { usdTvl, usdTokenBalances };
83
36
  }
84
37
  exports.default = computeTVL;
85
38
  function tokenToKey(token) {
86
39
  if (token.startsWith("0x"))
87
- token = "ethereum:".concat(token);
40
+ token = `ethereum:${token}`;
88
41
  else if (!token.includes(':'))
89
- token = "coingecko:".concat(token);
42
+ token = `coingecko:${token}`;
90
43
  return token;
91
44
  }
92
- function updatePriceCache(keys, timestamp) {
93
- return __awaiter(this, void 0, void 0, function () {
94
- function getPrices(keys) {
95
- return __awaiter(this, void 0, void 0, function () {
96
- var coins_1, coins;
97
- return __generator(this, function (_a) {
98
- switch (_a.label) {
99
- case 0:
100
- if (!!timestamp) return [3 /*break*/, 2];
101
- return [4 /*yield*/, (0, node_fetch_1.default)("https://coins.llama.fi/prices/current/".concat(keys.join(','))).then(function (res) { return res.json(); })];
102
- case 1:
103
- coins_1 = (_a.sent()).coins;
104
- return [2 /*return*/, coins_1];
105
- case 2: return [4 /*yield*/, (0, node_fetch_1.default)("https://coins.llama.fi/prices?source=internal", {
106
- method: 'POST',
107
- body: JSON.stringify({ coins: keys, timestamp: timestamp }),
108
- headers: { "Content-Type": "application/json" },
109
- }).then(function (res) { return res.json(); })];
110
- case 3:
111
- coins = (_a.sent()).coins;
112
- return [2 /*return*/, coins];
113
- }
114
- });
115
- });
45
+ async function updatePriceCache(keys, timestamp) {
46
+ if (isNearlyNow(timestamp))
47
+ timestamp = undefined;
48
+ keys = getUnique(keys);
49
+ const pricesCache = getPriceCache(timestamp);
50
+ if (!timestamp && lastPriceUpdate && +Date.now() > lastPriceUpdate + priceUpdateTime) {
51
+ lastPriceUpdate = +Date.now();
52
+ Object.keys(pricesCache).forEach(key => delete pricesCache[key]); // clear cache
53
+ }
54
+ // hardcode cache for USDT
55
+ pricesCache['coingecko:tether'] = {
56
+ "price": 1,
57
+ "symbol": "USDT",
58
+ "confidence": 1
59
+ };
60
+ pricesCache['ethereum:0xdac17f958d2ee523a2206206994597c13d831ec7'] = {
61
+ "price": 1,
62
+ "symbol": "USDT",
63
+ "decimals": 6,
64
+ "confidence": 1
65
+ };
66
+ const missingKeys = keys.filter(key => !pricesCache[key.toLowerCase()]);
67
+ const chunks = (0, _1.sliceIntoChunks)(missingKeys, 100);
68
+ for (const chunk of chunks) {
69
+ const coins = await getPrices(chunk);
70
+ for (const [token, data] of Object.entries(coins)) {
71
+ pricesCache[token.toLowerCase()] = data;
116
72
  }
117
- var pricesCache, missingKeys, chunks, _i, chunks_1, chunk, coins, _a, _b, _c, token, data;
118
- return __generator(this, function (_d) {
119
- switch (_d.label) {
120
- case 0:
121
- if (isNearlyNow(timestamp))
122
- timestamp = undefined;
123
- keys = getUnique(keys);
124
- pricesCache = getPriceCache(timestamp);
125
- if (!timestamp && lastPriceUpdate && +Date.now() > lastPriceUpdate + priceUpdateTime) {
126
- lastPriceUpdate = +Date.now();
127
- Object.keys(pricesCache).forEach(function (key) { return delete pricesCache[key]; }); // clear cache
128
- }
129
- // hardcode cache for USDT
130
- pricesCache['coingecko:tether'] = {
131
- "price": 1,
132
- "symbol": "USDT",
133
- "confidence": 1
134
- };
135
- pricesCache['ethereum:0xdac17f958d2ee523a2206206994597c13d831ec7'] = {
136
- "price": 1,
137
- "symbol": "USDT",
138
- "decimals": 6,
139
- "confidence": 1
140
- };
141
- missingKeys = keys.filter(function (key) { return !pricesCache[key.toLowerCase()]; });
142
- chunks = (0, _1.sliceIntoChunks)(missingKeys, 100);
143
- _i = 0, chunks_1 = chunks;
144
- _d.label = 1;
145
- case 1:
146
- if (!(_i < chunks_1.length)) return [3 /*break*/, 4];
147
- chunk = chunks_1[_i];
148
- return [4 /*yield*/, getPrices(chunk)];
149
- case 2:
150
- coins = _d.sent();
151
- for (_a = 0, _b = Object.entries(coins); _a < _b.length; _a++) {
152
- _c = _b[_a], token = _c[0], data = _c[1];
153
- pricesCache[token.toLowerCase()] = data;
154
- }
155
- chunk.map(function (i) { return i.toLowerCase(); }).filter(function (i) { return !pricesCache[i]; }).forEach(function (i) { return pricesCache[i] = {}; });
156
- _d.label = 3;
157
- case 3:
158
- _i++;
159
- return [3 /*break*/, 1];
160
- case 4: return [2 /*return*/];
161
- }
162
- });
163
- });
73
+ chunk.map(i => i.toLowerCase()).filter(i => !pricesCache[i]).forEach(i => pricesCache[i] = {});
74
+ }
75
+ async function getPrices(keys) {
76
+ if (!timestamp) {
77
+ const { coins } = await (0, axios_1.default)(`https://coins.llama.fi/prices/current/${keys.join(',')}`).then((res) => res.data);
78
+ return coins;
79
+ }
80
+ // fetch post with timestamp in body
81
+ const { coins } = await axios_1.default.post("https://coins.llama.fi/prices?source=internal", { coins: keys, timestamp }).then((res) => res.data);
82
+ return coins;
83
+ }
164
84
  }
165
85
  function getPriceCache(timestamp) {
166
86
  if (timestamp)
@@ -170,8 +90,8 @@ function getPriceCache(timestamp) {
170
90
  return timestamp ? priceCaches[timestamp] : currentPriceCache;
171
91
  }
172
92
  function getUnique(addresses) {
173
- var set = {};
174
- addresses.forEach(function (i) { return set[i] = true; });
93
+ const set = {};
94
+ addresses.forEach(i => set[i] = true);
175
95
  return Object.keys(set);
176
96
  }
177
97
  exports.getUnique = getUnique;
@@ -1,52 +1,16 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
5
  Object.defineProperty(exports, "__esModule", { value: true });
42
6
  exports.getCosmosProvider = exports.getCosmosBlock = exports.isCosmosChain = void 0;
43
- var node_fetch_1 = __importDefault(require("node-fetch"));
44
- var env_1 = require("./env");
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const env_1 = require("./env");
45
9
  // where to find chain info
46
10
  // https://proxy.atomscan.com/chains.json
47
11
  // https://cosmos-chain.directory/chains/cosmoshub
48
12
  // https://cosmos-chain.directory/chains
49
- var endPoints = {
13
+ const endPoints = {
50
14
  crescent: "https://mainnet.crescent.network:1317",
51
15
  osmosis: "https://osmosis-api.polkachu.com",
52
16
  cosmos: "https://cosmoshub-lcd.stakely.io",
@@ -78,48 +42,30 @@ var endPoints = {
78
42
  nolus: "https://pirin-cl.nolus.network:1317",
79
43
  bostrom: "https://lcd.bostrom.cybernode.ai"
80
44
  };
81
- var ibcChains = ['terra', 'terra2', 'crescent', 'osmosis', 'kujira', 'stargaze', 'juno', 'injective', 'cosmos', 'comdex', 'umee', 'orai', 'persistence', 'fxcore', 'neutron', 'quasar', 'chihuahua', 'sei', 'archway', 'migaloo', 'secret', 'aura', 'xpla', 'bostrom'];
82
- var isCosmosChain = function (chain) { return ibcChains.includes(chain) || !!endPoints[chain]; };
45
+ const ibcChains = ['terra', 'terra2', 'crescent', 'osmosis', 'kujira', 'stargaze', 'juno', 'injective', 'cosmos', 'comdex', 'umee', 'orai', 'persistence', 'fxcore', 'neutron', 'quasar', 'chihuahua', 'sei', 'archway', 'migaloo', 'secret', 'aura', 'xpla', 'bostrom'];
46
+ const isCosmosChain = (chain) => ibcChains.includes(chain) || !!endPoints[chain];
83
47
  exports.isCosmosChain = isCosmosChain;
84
- function getCosmosBlock(block, chain) {
48
+ async function getCosmosBlock(block = 'latest', chain = 'cosmos') {
85
49
  var _a;
86
- if (block === void 0) { block = 'latest'; }
87
- if (chain === void 0) { chain = 'cosmos'; }
88
- return __awaiter(this, void 0, void 0, function () {
89
- var endPoint, data, _b, height, time, e_1, message;
90
- return __generator(this, function (_c) {
91
- switch (_c.label) {
92
- case 0:
93
- endPoint = (0, env_1.getEnvRPC)(chain) || endPoints[chain] || 'https://rest.cosmos.directory/' + chain;
94
- _c.label = 1;
95
- case 1:
96
- _c.trys.push([1, 4, , 5]);
97
- return [4 /*yield*/, (0, node_fetch_1.default)("".concat(endPoint, "/blocks/").concat(block))];
98
- case 2:
99
- data = _c.sent();
100
- return [4 /*yield*/, data.json()];
101
- case 3:
102
- _b = (_c.sent()).block.header, height = _b.height, time = _b.time;
103
- return [2 /*return*/, {
104
- number: Number(height),
105
- timestamp: Math.floor(Date.parse(time) / 1000),
106
- }];
107
- case 4:
108
- e_1 = _c.sent();
109
- message = "Error fetchin cosmos block -\n chain: ".concat(chain, ", block: ").concat(block, ", endPoint: ").concat(endPoint, ", error: ").concat((_a = e_1 === null || e_1 === void 0 ? void 0 : e_1.message) !== null && _a !== void 0 ? _a : JSON.stringify(e_1));
110
- throw new Error(message);
111
- case 5: return [2 /*return*/];
112
- }
113
- });
114
- });
50
+ const endPoint = (0, env_1.getEnvRPC)(chain) || endPoints[chain] || 'https://rest.cosmos.directory/' + chain;
51
+ try {
52
+ const { data } = await (0, axios_1.default)(`${endPoint}/blocks/${block}`);
53
+ const { block: { header: { height, time } } } = await data;
54
+ return {
55
+ number: Number(height),
56
+ timestamp: Math.floor(Date.parse(time) / 1000),
57
+ };
58
+ }
59
+ catch (e) {
60
+ const message = `Error fetchin cosmos block -
61
+ chain: ${chain}, block: ${block}, endPoint: ${endPoint}, error: ${(_a = e === null || e === void 0 ? void 0 : e.message) !== null && _a !== void 0 ? _a : JSON.stringify(e)}`;
62
+ throw new Error(message);
63
+ }
115
64
  }
116
65
  exports.getCosmosBlock = getCosmosBlock;
117
66
  function getCosmosProvider(chain) {
118
67
  return {
119
- getBlock: function (block) {
120
- if (block === void 0) { block = 'latest'; }
121
- return getCosmosBlock(block, chain);
122
- }
68
+ getBlock: (block = 'latest') => getCosmosBlock(block, chain)
123
69
  };
124
70
  }
125
71
  exports.getCosmosProvider = getCosmosProvider;
@@ -1,25 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.debugTable = exports.debugLog = exports.DEBUG_ENABLED = void 0;
4
- var env_1 = require("./env");
4
+ const env_1 = require("./env");
5
5
  exports.DEBUG_ENABLED = env_1.ENV_CONSTANTS.DEBUG_ENABLED === "true";
6
- function debugLog() {
7
- var args = [];
8
- for (var _i = 0; _i < arguments.length; _i++) {
9
- args[_i] = arguments[_i];
10
- }
6
+ function debugLog(...args) {
11
7
  if (!exports.DEBUG_ENABLED)
12
8
  return;
13
- console.log.apply(console, args);
9
+ console.log(...args);
14
10
  }
15
11
  exports.debugLog = debugLog;
16
- function debugTable() {
17
- var args = [];
18
- for (var _i = 0; _i < arguments.length; _i++) {
19
- args[_i] = arguments[_i];
20
- }
12
+ function debugTable(...args) {
21
13
  if (!exports.DEBUG_ENABLED)
22
14
  return;
23
- console.table.apply(console, args);
15
+ console.table(...args);
24
16
  }
25
17
  exports.debugTable = debugTable;
@@ -1,7 +1,7 @@
1
1
  export declare const ENV_CONSTANTS: {
2
2
  [x: string]: string | undefined;
3
3
  };
4
- export declare function getChainId(chain: string, chainId: number | undefined): number | undefined;
4
+ export declare function getChainId(chain: string, chainId: number): number;
5
5
  export declare function getMaxParallelRequests(chain: string): number;
6
6
  export declare function getParallelGetLogsLimit(chain: string): number;
7
7
  export declare function getEnvRPC(chain: string): string | undefined;
package/build/util/env.js CHANGED
@@ -1,41 +1,29 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.getChainRPCs = exports.getArchivalRPCs = exports.getBatchMaxCount = exports.getDefaultChunkSize = exports.getEnvMulticallAddress = exports.getEnvCacheFolder = exports.getEnvValue = exports.getEnvRPC = exports.getParallelGetLogsLimit = exports.getMaxParallelRequests = exports.getChainId = exports.ENV_CONSTANTS = void 0;
15
- var _ENV_CONSTANTS = {
4
+ const _ENV_CONSTANTS = {
16
5
  DEBUG_ENABLED: getEnvValue('DEBUG') === "true" || process.env.LLAMA_DEBUG_MODE ? 'true' : 'false',
17
6
  };
18
- var whitelistedEnvConstants = [
7
+ const whitelistedEnvConstants = [
19
8
  'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY',
20
9
  ];
21
- var defaultEnvValues = {
10
+ const defaultEnvValues = {
22
11
  INTERNAL_SDK_CACHE_FILE: './cache.json',
23
12
  TRON_RPC_CONCURRENCY_LIMIT: '5',
24
13
  TRON_RPC: 'https://api.trongrid.io',
25
14
  };
26
- whitelistedEnvConstants.forEach(function (key) { return _ENV_CONSTANTS[key] = getEnvValue(key); });
27
- Object.keys(defaultEnvValues).forEach(function (key) { return _ENV_CONSTANTS[key] = getEnvValue(key, defaultEnvValues[key]); });
15
+ whitelistedEnvConstants.forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key));
16
+ Object.keys(defaultEnvValues).forEach(key => _ENV_CONSTANTS[key] = getEnvValue(key, defaultEnvValues[key]));
28
17
  // doing this as I am paranoid that that empty object when first declared might be exported before values are set
29
- exports.ENV_CONSTANTS = __assign({}, _ENV_CONSTANTS);
18
+ exports.ENV_CONSTANTS = { ..._ENV_CONSTANTS };
30
19
  function getChainId(chain, chainId) {
31
20
  var _a;
32
- var value = (_a = getEnvValue("".concat(chain, "_RPC_CHAIN_ID"))) !== null && _a !== void 0 ? _a : chainId;
33
- if (value)
34
- return +value;
21
+ const value = (_a = getEnvValue(`${chain}_RPC_CHAIN_ID`)) !== null && _a !== void 0 ? _a : chainId;
22
+ return +value;
35
23
  }
36
24
  exports.getChainId = getChainId;
37
25
  function getMaxParallelRequests(chain) {
38
- var chainKey = "".concat(chain, "_RPC_MAX_PARALLEL");
26
+ const chainKey = `${chain}_RPC_MAX_PARALLEL`;
39
27
  if (getEnvValue(chainKey))
40
28
  return +getEnvValue(chainKey);
41
29
  if (['harmony', 'avax'].includes(chain))
@@ -44,18 +32,18 @@ function getMaxParallelRequests(chain) {
44
32
  }
45
33
  exports.getMaxParallelRequests = getMaxParallelRequests;
46
34
  function getParallelGetLogsLimit(chain) {
47
- var defaultLimit = chain === 'fantom' ? '10' : '42';
48
- return +(getEnvValue("".concat(chain, "_RPC_GET_LOGS_CONCURRENCY_LIMIT"), defaultLimit));
35
+ let defaultLimit = chain === 'fantom' ? '10' : '42';
36
+ return +(getEnvValue(`${chain}_RPC_GET_LOGS_CONCURRENCY_LIMIT`, defaultLimit));
49
37
  }
50
38
  exports.getParallelGetLogsLimit = getParallelGetLogsLimit;
51
39
  function getEnvRPC(chain) {
52
- return getEnvValue("".concat(chain, "_RPC"));
40
+ return getEnvValue(`${chain}_RPC`);
53
41
  }
54
42
  exports.getEnvRPC = getEnvRPC;
55
43
  function getEnvValue(key, defaultValue) {
56
44
  var _a, _b, _c;
57
45
  key = key.toUpperCase();
58
- return (_c = (_b = (_a = process.env[key]) !== null && _a !== void 0 ? _a : process.env['SDK_' + key]) !== null && _b !== void 0 ? _b : process.env['LLAMA_SDK_' + key]) !== null && _c !== void 0 ? _c : defaultValue;
46
+ 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;
59
47
  }
60
48
  exports.getEnvValue = getEnvValue;
61
49
  function getEnvCacheFolder(defaultCacheFolder) {
@@ -63,11 +51,11 @@ function getEnvCacheFolder(defaultCacheFolder) {
63
51
  }
64
52
  exports.getEnvCacheFolder = getEnvCacheFolder;
65
53
  function getEnvMulticallAddress(chain) {
66
- return getEnvValue("".concat(chain, "_RPC_MULTICALL"));
54
+ return getEnvValue(`${chain}_RPC_MULTICALL`);
67
55
  }
68
56
  exports.getEnvMulticallAddress = getEnvMulticallAddress;
69
57
  function getDefaultChunkSize(chain) {
70
- var key = chain + '_MULTICALL_CHUNK_SIZE';
58
+ const key = chain + '_MULTICALL_CHUNK_SIZE';
71
59
  if (getEnvValue(key))
72
60
  return +getEnvValue(key);
73
61
  if (chain === 'cronos')
@@ -76,7 +64,7 @@ function getDefaultChunkSize(chain) {
76
64
  }
77
65
  exports.getDefaultChunkSize = getDefaultChunkSize;
78
66
  function getBatchMaxCount(chain) {
79
- var key = chain + '_BATCH_MAX_COUNT';
67
+ const key = chain + '_BATCH_MAX_COUNT';
80
68
  if (getEnvValue(key))
81
69
  return +getEnvValue(key);
82
70
  switch (chain) {
@@ -87,15 +75,14 @@ function getBatchMaxCount(chain) {
87
75
  }
88
76
  exports.getBatchMaxCount = getBatchMaxCount;
89
77
  function getArchivalRPCs(chain) {
90
- var key = chain + '_ARCHIVAL_RPC';
78
+ const key = chain + '_ARCHIVAL_RPC';
91
79
  if (getEnvValue(key))
92
80
  return getEnvValue(key).split(',');
93
81
  return [];
94
82
  }
95
83
  exports.getArchivalRPCs = getArchivalRPCs;
96
- function getChainRPCs(chain, defaultList) {
97
- if (defaultList === void 0) { defaultList = []; }
98
- var key = chain + '_RPC';
84
+ function getChainRPCs(chain, defaultList = []) {
85
+ const key = chain + '_RPC';
99
86
  if (getEnvValue(key))
100
87
  return getEnvValue(key).split(',').concat(defaultList).join(',');
101
88
  if (defaultList.length === 0)