@defillama/sdk 5.0.10 → 5.0.12

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 (40) hide show
  1. package/build/Balances.d.ts +10 -0
  2. package/build/Balances.js +51 -107
  3. package/build/ChainApi.d.ts +1 -0
  4. package/build/ChainApi.js +152 -253
  5. package/build/abi/abi2.js +47 -144
  6. package/build/abi/convertResults.js +9 -29
  7. package/build/abi/index.js +220 -326
  8. package/build/abi/multicall.js +115 -217
  9. package/build/abi/multicall3.js +59 -123
  10. package/build/abi/rpcCall.js +43 -106
  11. package/build/abi/tron.js +153 -283
  12. package/build/api.js +3 -4
  13. package/build/computeTVL/blocks.d.ts +1 -1
  14. package/build/computeTVL/blocks.js +2 -1
  15. package/build/computeTVL/humanizeNumber.js +6 -7
  16. package/build/computeTVL/prices.js +55 -145
  17. package/build/erc20/index.js +34 -122
  18. package/build/eth/index.js +37 -107
  19. package/build/general.js +22 -23
  20. package/build/generalUtil.js +68 -127
  21. package/build/index.js +2 -2
  22. package/build/providers.json +1 -1
  23. package/build/util/blocks.d.ts +5 -2
  24. package/build/util/blocks.js +234 -373
  25. package/build/util/blockscout.js +13 -58
  26. package/build/util/cache.js +112 -274
  27. package/build/util/computeTVL.js +72 -150
  28. package/build/util/cosmos.js +21 -75
  29. package/build/util/debugLog.js +5 -13
  30. package/build/util/env.d.ts +3 -2
  31. package/build/util/env.js +30 -35
  32. package/build/util/index.d.ts +5 -3
  33. package/build/util/index.js +105 -134
  34. package/build/util/internal-cache.js +7 -8
  35. package/build/util/logs.d.ts +1 -2
  36. package/build/util/logs.js +148 -236
  37. package/build/util/promisePool.js +11 -62
  38. package/build/util/r2.js +36 -95
  39. package/build/util/updateProviderList.js +23 -83
  40. package/package.json +2 -3
@@ -1,166 +1,88 @@
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 env_1 = require("./env");
11
+ const currentPriceCache = {};
12
+ const priceCaches = {};
13
+ let lastPriceUpdate = 0;
14
+ const confidenceThreshold = 0.5;
15
+ const priceUpdateTime = 1000 * 60 * 30; // 30 minutes
16
+ async function computeTVL(balances, timestamp) {
17
+ const usdTokenBalances = {};
18
+ let usdTvl = 0;
19
+ const keys = Object.keys(balances).filter(i => +balances[i] > 0).map(tokenToKey);
20
+ await updatePriceCache(keys, timestamp);
21
+ const priceCache = getPriceCache(timestamp);
22
+ Object.entries(balances).forEach(([token, balance]) => {
23
+ var _a;
24
+ if (+balance <= 0)
25
+ return;
26
+ const key = tokenToKey(token).toLowerCase();
27
+ let { price, confidence, decimals = 0, symbol = token } = (_a = priceCache[key]) !== null && _a !== void 0 ? _a : {};
28
+ if (!price || confidence < confidenceThreshold)
29
+ return;
30
+ const value = +balance * price / (10 ** decimals);
31
+ usdTvl += value;
32
+ if (symbol === 'ETH')
33
+ symbol = 'WETH';
34
+ (0, generalUtil_1.sumSingleBalance)(usdTokenBalances, symbol, value);
82
35
  });
36
+ return { usdTvl, usdTokenBalances };
83
37
  }
84
38
  exports.default = computeTVL;
85
39
  function tokenToKey(token) {
86
40
  if (token.startsWith("0x"))
87
- token = "ethereum:".concat(token);
41
+ token = `ethereum:${token}`;
88
42
  else if (!token.includes(':'))
89
- token = "coingecko:".concat(token);
43
+ token = `coingecko:${token}`;
90
44
  return token;
91
45
  }
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
- });
46
+ async function updatePriceCache(keys, timestamp) {
47
+ if (isNearlyNow(timestamp))
48
+ timestamp = undefined;
49
+ keys = getUnique(keys);
50
+ const pricesCache = getPriceCache(timestamp);
51
+ if (!timestamp && lastPriceUpdate && +Date.now() > lastPriceUpdate + priceUpdateTime) {
52
+ lastPriceUpdate = +Date.now();
53
+ Object.keys(pricesCache).forEach(key => delete pricesCache[key]); // clear cache
54
+ }
55
+ // hardcode cache for USDT
56
+ pricesCache['coingecko:tether'] = {
57
+ "price": 1,
58
+ "symbol": "USDT",
59
+ "confidence": 1
60
+ };
61
+ pricesCache['ethereum:0xdac17f958d2ee523a2206206994597c13d831ec7'] = {
62
+ "price": 1,
63
+ "symbol": "USDT",
64
+ "decimals": 6,
65
+ "confidence": 1
66
+ };
67
+ const missingKeys = keys.filter(key => !pricesCache[key.toLowerCase()]);
68
+ const chunks = (0, _1.sliceIntoChunks)(missingKeys, 100);
69
+ for (const chunk of chunks) {
70
+ const coins = await getPrices(chunk);
71
+ for (const [token, data] of Object.entries(coins)) {
72
+ pricesCache[token.toLowerCase()] = data;
116
73
  }
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
- });
74
+ chunk.map(i => i.toLowerCase()).filter(i => !pricesCache[i]).forEach(i => pricesCache[i] = {});
75
+ }
76
+ async function getPrices(keys) {
77
+ if (!timestamp) {
78
+ const { coins } = await axios_1.default.get(`https://coins.llama.fi/prices/current/${keys.join(',')}`).then((res) => res.data);
79
+ return coins;
80
+ }
81
+ // fetch post with timestamp in body
82
+ const coinsApiKey = env_1.ENV_CONSTANTS['COINS_API_KEY'];
83
+ const { coins } = await axios_1.default.post("https://coins.llama.fi/prices?source=internal&apikey=" + coinsApiKey, { coins: keys, timestamp }).then((res) => res.data);
84
+ return coins;
85
+ }
164
86
  }
165
87
  function getPriceCache(timestamp) {
166
88
  if (timestamp)
@@ -170,8 +92,8 @@ function getPriceCache(timestamp) {
170
92
  return timestamp ? priceCaches[timestamp] : currentPriceCache;
171
93
  }
172
94
  function getUnique(addresses) {
173
- var set = {};
174
- addresses.forEach(function (i) { return set[i] = true; });
95
+ const set = {};
96
+ addresses.forEach(i => set[i] = true);
175
97
  return Object.keys(set);
176
98
  }
177
99
  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,9 +1,10 @@
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
- export declare function getParallelGetLogsLimit(chain: string): number;
6
+ export declare function getParallelGetLogsLimit(chain: string, providerUrl?: string): number;
7
+ export declare function getParallelGetBlocksLimit(chain: string): number;
7
8
  export declare function getEnvRPC(chain: string): string | undefined;
8
9
  export declare function getEnvValue(key: string, defaultValue?: string): string | undefined;
9
10
  export declare function getEnvCacheFolder(defaultCacheFolder: string): string;
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
- 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 = {
3
+ exports.getChainRPCs = exports.getArchivalRPCs = exports.getBatchMaxCount = exports.getDefaultChunkSize = exports.getEnvMulticallAddress = exports.getEnvCacheFolder = exports.getEnvValue = exports.getEnvRPC = exports.getParallelGetBlocksLimit = exports.getParallelGetLogsLimit = exports.getMaxParallelRequests = exports.getChainId = exports.ENV_CONSTANTS = void 0;
4
+ const _ENV_CONSTANTS = {
16
5
  DEBUG_ENABLED: getEnvValue('DEBUG') === "true" || process.env.LLAMA_DEBUG_MODE ? 'true' : 'false',
17
6
  };
18
- var whitelistedEnvConstants = [
19
- 'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY',
7
+ const whitelistedEnvConstants = [
8
+ 'R2_ENDPOINT', 'R2_ACCESS_KEY_ID', 'R2_SECRET_ACCESS_KEY', 'TRON_PRO_API_KEY', 'COINS_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))
@@ -43,19 +31,27 @@ function getMaxParallelRequests(chain) {
43
31
  return +getEnvValue('MAX_PARALLEL', '100');
44
32
  }
45
33
  exports.getMaxParallelRequests = getMaxParallelRequests;
46
- function getParallelGetLogsLimit(chain) {
47
- var defaultLimit = chain === 'fantom' ? '10' : '42';
48
- return +(getEnvValue("".concat(chain, "_RPC_GET_LOGS_CONCURRENCY_LIMIT"), defaultLimit));
34
+ function getParallelGetLogsLimit(chain, providerUrl) {
35
+ const defaultLimit = getEnvValue('GET_LOGS_CONCURRENCY_LIMIT', '5');
36
+ const defaultAlchemyLimit = getEnvValue('ALCHEMY_GET_LOGS_CONCURRENCY_LIMIT', '4');
37
+ if (providerUrl && providerUrl.includes('alchemy.com'))
38
+ return +(defaultAlchemyLimit);
39
+ return +(getEnvValue(`${chain}_RPC_GET_LOGS_CONCURRENCY_LIMIT`, defaultLimit));
49
40
  }
50
41
  exports.getParallelGetLogsLimit = getParallelGetLogsLimit;
42
+ function getParallelGetBlocksLimit(chain) {
43
+ const defaultLimit = getEnvValue('GET_BLOCKS_CONCURRENCY_LIMIT', '5');
44
+ return +(getEnvValue(`${chain}_RPC_GET_BLOCKS_CONCURRENCY_LIMIT`, defaultLimit));
45
+ }
46
+ exports.getParallelGetBlocksLimit = getParallelGetBlocksLimit;
51
47
  function getEnvRPC(chain) {
52
- return getEnvValue("".concat(chain, "_RPC"));
48
+ return getEnvValue(`${chain}_RPC`);
53
49
  }
54
50
  exports.getEnvRPC = getEnvRPC;
55
51
  function getEnvValue(key, defaultValue) {
56
52
  var _a, _b, _c;
57
53
  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;
54
+ 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
55
  }
60
56
  exports.getEnvValue = getEnvValue;
61
57
  function getEnvCacheFolder(defaultCacheFolder) {
@@ -63,11 +59,11 @@ function getEnvCacheFolder(defaultCacheFolder) {
63
59
  }
64
60
  exports.getEnvCacheFolder = getEnvCacheFolder;
65
61
  function getEnvMulticallAddress(chain) {
66
- return getEnvValue("".concat(chain, "_RPC_MULTICALL"));
62
+ return getEnvValue(`${chain}_RPC_MULTICALL`);
67
63
  }
68
64
  exports.getEnvMulticallAddress = getEnvMulticallAddress;
69
65
  function getDefaultChunkSize(chain) {
70
- var key = chain + '_MULTICALL_CHUNK_SIZE';
66
+ const key = chain + '_MULTICALL_CHUNK_SIZE';
71
67
  if (getEnvValue(key))
72
68
  return +getEnvValue(key);
73
69
  if (chain === 'cronos')
@@ -76,7 +72,7 @@ function getDefaultChunkSize(chain) {
76
72
  }
77
73
  exports.getDefaultChunkSize = getDefaultChunkSize;
78
74
  function getBatchMaxCount(chain) {
79
- var key = chain + '_BATCH_MAX_COUNT';
75
+ const key = chain + '_BATCH_MAX_COUNT';
80
76
  if (getEnvValue(key))
81
77
  return +getEnvValue(key);
82
78
  switch (chain) {
@@ -87,15 +83,14 @@ function getBatchMaxCount(chain) {
87
83
  }
88
84
  exports.getBatchMaxCount = getBatchMaxCount;
89
85
  function getArchivalRPCs(chain) {
90
- var key = chain + '_ARCHIVAL_RPC';
86
+ const key = chain + '_ARCHIVAL_RPC';
91
87
  if (getEnvValue(key))
92
88
  return getEnvValue(key).split(',');
93
89
  return [];
94
90
  }
95
91
  exports.getArchivalRPCs = getArchivalRPCs;
96
- function getChainRPCs(chain, defaultList) {
97
- if (defaultList === void 0) { defaultList = []; }
98
- var key = chain + '_RPC';
92
+ function getChainRPCs(chain, defaultList = []) {
93
+ const key = chain + '_RPC';
99
94
  if (getEnvValue(key))
100
95
  return getEnvValue(key).split(',').concat(defaultList).join(',');
101
96
  if (defaultList.length === 0)
@@ -1,12 +1,12 @@
1
1
  import { Chain } from "../general";
2
2
  import type { Address } from "../types";
3
- import { EventLog } from "ethers";
3
+ import { ethers, EventLog } from "ethers";
4
4
  import runInPromisePoolOrig from "./promisePool";
5
5
  export { getLatestBlock, getTimestamp, lookupBlock, } from "./blocks";
6
6
  export { convertToBigInt } from "../generalUtil";
7
7
  export declare const runInPromisePool: typeof runInPromisePoolOrig;
8
8
  export declare function sliceIntoChunks(arr: any[], chunkSize?: number): any[][];
9
- export declare function getLogs(params: {
9
+ type GetLogsOptions = {
10
10
  target: Address;
11
11
  topic: string;
12
12
  keys: string[];
@@ -14,7 +14,9 @@ export declare function getLogs(params: {
14
14
  toBlock: number;
15
15
  topics?: (string | null)[];
16
16
  chain?: Chain;
17
- }): Promise<{
17
+ provider?: ethers.Provider;
18
+ };
19
+ export declare function getLogs(options: GetLogsOptions): Promise<{
18
20
  output: EventLog[];
19
21
  }>;
20
22
  export declare function normalizeAddress(address: string): string;