@defillama/sdk 5.0.173 → 5.0.177

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 (53) hide show
  1. package/build/Balances.d.ts +2 -2
  2. package/build/ChainApi.d.ts +26 -14
  3. package/build/ChainApi.js +58 -28
  4. package/build/abi/abi2.js +23 -15
  5. package/build/abi/cachedABIs.d.ts +1 -1
  6. package/build/abi/convertResults.d.ts +4 -1
  7. package/build/abi/convertResults.js +20 -15
  8. package/build/abi/index.js +16 -39
  9. package/build/abi/multicall.js +6 -31
  10. package/build/abi/multicall3.js +36 -37
  11. package/build/abi/rpcCall.js +1 -2
  12. package/build/abi/tron.d.ts +5 -6
  13. package/build/abi/tron.js +79 -198
  14. package/build/api.js +17 -7
  15. package/build/api2.js +17 -7
  16. package/build/computeTVL/humanizeNumber.js +1 -2
  17. package/build/erc20/index.js +5 -6
  18. package/build/eth/index.d.ts +1 -0
  19. package/build/eth/index.js +39 -16
  20. package/build/general.js +2 -2
  21. package/build/generalUtil.d.ts +2 -24
  22. package/build/generalUtil.js +39 -246
  23. package/build/index.js +17 -7
  24. package/build/providers.json +1 -1
  25. package/build/util/LlamaProvider.js +8 -3
  26. package/build/util/blocks.js +17 -20
  27. package/build/util/cache.d.ts +11 -2
  28. package/build/util/cache.js +53 -9
  29. package/build/util/common.d.ts +33 -0
  30. package/build/util/common.js +352 -0
  31. package/build/util/computeTVL.js +6 -11
  32. package/build/util/cosmos.js +6 -9
  33. package/build/util/debugLog.js +3 -3
  34. package/build/util/elastic.d.ts +19 -0
  35. package/build/util/elastic.js +54 -6
  36. package/build/util/env.d.ts +7 -1
  37. package/build/util/env.js +28 -15
  38. package/build/util/graph.js +4 -8
  39. package/build/util/index.d.ts +1 -1
  40. package/build/util/index.js +17 -15
  41. package/build/util/indexer.js +29 -19
  42. package/build/util/internal-cache.js +22 -13
  43. package/build/util/logs.js +7 -7
  44. package/build/util/promisePool.d.ts +4 -1
  45. package/build/util/promisePool.js +22 -7
  46. package/build/util/r2.d.ts +0 -1
  47. package/build/util/r2.js +4 -9
  48. package/build/util/removeRedundantRPCs.js +2 -2
  49. package/build/util/transactions.js +1 -2
  50. package/build/util/updateProviderList.js +6 -6
  51. package/package.json +3 -1
  52. package/build/computeTVL/prices.d.ts +0 -9
  53. package/build/computeTVL/prices.js +0 -73
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const providers_json_1 = __importDefault(require("../providers.json"));
7
7
  const fs_1 = __importDefault(require("fs"));
8
- const axios_1 = __importDefault(require("axios"));
8
+ const generalUtil_1 = require("../generalUtil");
9
9
  const providerList = providers_json_1.default;
10
10
  async function getChainData() {
11
11
  try {
12
- const { data: chainData } = await (0, axios_1.default)('https://chainlist.org/rpcs.json');
12
+ const chainData = await (0, generalUtil_1.fetchJson)('https://chainlist.org/rpcs.json');
13
13
  return chainData;
14
14
  }
15
15
  catch (e) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTransactions = void 0;
3
+ exports.getTransactions = getTransactions;
4
4
  const debugLog_1 = require("./debugLog");
5
5
  const indexer_1 = require("./indexer");
6
6
  async function getTransactions(params) {
@@ -20,4 +20,3 @@ async function getTransactions(params) {
20
20
  }
21
21
  return null;
22
22
  }
23
- exports.getTransactions = getTransactions;
@@ -5,13 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const providers_json_1 = __importDefault(require("../providers.json"));
7
7
  const fs_1 = __importDefault(require("fs"));
8
- const axios_1 = __importDefault(require("axios"));
9
8
  const debugLog_1 = require("./debugLog");
10
9
  const promise_pool_1 = __importDefault(require("@supercharge/promise-pool"));
10
+ const generalUtil_1 = require("../generalUtil");
11
11
  const providerList = providers_json_1.default;
12
12
  async function getChainData() {
13
13
  try {
14
- const { data: chainData } = await (0, axios_1.default)('https://chainlist.org/rpcs.json');
14
+ const chainData = await (0, generalUtil_1.fetchJson)('https://chainlist.org/rpcs.json');
15
15
  // fix for zksync era name clash
16
16
  const eteriaListing = chainData.find((i) => i.chainId === 140);
17
17
  if (eteriaListing)
@@ -25,7 +25,7 @@ async function getChainData() {
25
25
  }
26
26
  }
27
27
  async function main() {
28
- const { data: oldProviders } = await (0, axios_1.default)(`https://unpkg.com/@defillama/sdk@latest/build/providers.json`);
28
+ const oldProviders = await (0, generalUtil_1.fetchJson)(`https://unpkg.com/@defillama/sdk@latest/build/providers.json`);
29
29
  let chainData = await getChainData();
30
30
  const providerIDMap = {};
31
31
  Object.values(providerList).forEach((i) => providerIDMap[i.chainId] = i.rpc);
@@ -36,7 +36,7 @@ async function main() {
36
36
  // shuffle the array
37
37
  chainData.sort(() => Math.random() - 0.5);
38
38
  await promise_pool_1.default
39
- .withConcurrency(7)
39
+ .withConcurrency(5)
40
40
  .for(chainData)
41
41
  .process(async (i) => {
42
42
  var _a, _b;
@@ -134,7 +134,7 @@ async function filterForWorkingRPCs(rpc, chain, chainId) {
134
134
  rpc = filterRPCs(rpc);
135
135
  const promises = await Promise.all(rpc.map(async (i) => {
136
136
  try {
137
- const { data } = await axios_1.default.post(i, {
137
+ const data = await (0, generalUtil_1.postJson)(i, {
138
138
  jsonrpc: '2.0',
139
139
  method: 'eth_blockNumber',
140
140
  params: [],
@@ -146,7 +146,7 @@ async function filterForWorkingRPCs(rpc, chain, chainId) {
146
146
  return i;
147
147
  }
148
148
  catch (e) {
149
- console.log(e === null || e === void 0 ? void 0 : e.message, i, chain);
149
+ console.log(chain, e === null || e === void 0 ? void 0 : e.message);
150
150
  }
151
151
  }));
152
152
  return rpc.filter((_i, index) => promises[index]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "5.0.173",
3
+ "version": "5.0.177",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -9,6 +9,8 @@
9
9
  "watch": "tsc --watch",
10
10
  "load-providers": "wget https://unpkg.com/@defillama/sdk@latest/build/providers.json -O build/providers.json",
11
11
  "test": "npm run load-providers && TEST_MODE=true LLAMA_DEBUG_MODE='' SDK_DEBUG='' LLAMA_DEBUG_LEVEL2='' jest",
12
+ "test-only": "echo 'skipped building providers.json' && TEST_MODE=true LLAMA_DEBUG_MODE='' SDK_DEBUG='' LLAMA_DEBUG_LEVEL2='' jest",
13
+ "test-debug": "TEST_MODE=true jest",
12
14
  "update-providers": "ts-node src/util/updateProviderList.ts",
13
15
  "remove-rpcs": "ts-node src/util/removeRedundantRPCs.ts",
14
16
  "format": "prettier --write \"src/**/*.ts\"",
@@ -1,9 +0,0 @@
1
- export interface TokenPrices {
2
- [token: string]: {
3
- usd: number;
4
- } | undefined;
5
- }
6
- export type GetCoingeckoLog = () => Promise<any>;
7
- export declare function makeCoingeckoCall(url: string, coingeckoMaxRetries: number, getCoingeckoLock: GetCoingeckoLog): Promise<any>;
8
- export declare function getTokenPrices(originalIds: string[], url: string, knownTokenPrices: TokenPrices, getCoingeckoLock: GetCoingeckoLog, coingeckoMaxRetries: number, prefix?: string): Promise<TokenPrices>;
9
- export declare function getHistoricalTokenPrices(ids: string[], url: string, timestamp: number, getCoingeckoLock: GetCoingeckoLog, coingeckoMaxRetries: number): Promise<TokenPrices>;
@@ -1,73 +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.getHistoricalTokenPrices = exports.getTokenPrices = exports.makeCoingeckoCall = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- function fetchJson(url) {
9
- return (0, axios_1.default)(url).then((res) => res.data);
10
- }
11
- async function makeCoingeckoCall(url, coingeckoMaxRetries, getCoingeckoLock) {
12
- for (let j = 0; j < coingeckoMaxRetries; j++) {
13
- try {
14
- await getCoingeckoLock();
15
- const values = await fetchJson(url);
16
- return values;
17
- }
18
- catch (e) {
19
- if (j >= coingeckoMaxRetries - 1) {
20
- throw e;
21
- }
22
- }
23
- }
24
- }
25
- exports.makeCoingeckoCall = makeCoingeckoCall;
26
- async function getTokenPrices(originalIds, url, knownTokenPrices, getCoingeckoLock, coingeckoMaxRetries, prefix = "") {
27
- const tokenPrices = {};
28
- const newIds = originalIds.slice(); // Copy
29
- for (let i = 0; i < newIds.length; i++) {
30
- const knownPrice = knownTokenPrices[prefix + newIds[i]];
31
- if (knownPrice !== undefined) {
32
- tokenPrices[newIds[i]] = knownPrice;
33
- newIds.splice(i, 1);
34
- i--;
35
- }
36
- }
37
- // The url can only contain up to 100 addresses (otherwise we'll get 'URI too large' errors)
38
- for (let i = 0; i < newIds.length; i += 100) {
39
- const tempTokenPrices = await makeCoingeckoCall(`https://api.coingecko.com/api/${url}=${newIds
40
- .slice(i, i + 100)
41
- .join(",")}&vs_currencies=usd`, coingeckoMaxRetries, getCoingeckoLock);
42
- Object.assign(tokenPrices, tempTokenPrices);
43
- Object.entries(tempTokenPrices).forEach((tokenPrice) => {
44
- knownTokenPrices[prefix + tokenPrice[0]] = tokenPrice[1];
45
- });
46
- }
47
- return tokenPrices;
48
- }
49
- exports.getTokenPrices = getTokenPrices;
50
- const secondsPerHalfDay = Math.round((24 * 3600) / 2);
51
- async function getHistoricalTokenPrices(ids, url, timestamp, getCoingeckoLock, coingeckoMaxRetries) {
52
- var _a;
53
- const tokenPrices = {};
54
- for (const id of ids) {
55
- const range = await makeCoingeckoCall(`${url}/${id.toLowerCase()}/market_chart/range?vs_currency=usd&from=${timestamp - secondsPerHalfDay}&to=${timestamp + secondsPerHalfDay}`, coingeckoMaxRetries, getCoingeckoLock);
56
- if (range.error === undefined && ((_a = range.prices) === null || _a === void 0 ? void 0 : _a.length) > 0) {
57
- let closest = range.prices[0];
58
- for (const price of range.prices) {
59
- if (Math.abs(price[0] - timestamp) < Math.abs(closest[0] - timestamp)) {
60
- closest = price;
61
- }
62
- }
63
- tokenPrices[id.toLowerCase()] = {
64
- usd: closest[1],
65
- };
66
- }
67
- else {
68
- tokenPrices[id.toLowerCase()] = undefined;
69
- }
70
- }
71
- return tokenPrices;
72
- }
73
- exports.getHistoricalTokenPrices = getHistoricalTokenPrices;