@defillama/sdk 3.0.1 → 3.0.3

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.
@@ -13,7 +13,7 @@ export declare function call(params: {
13
13
  export declare function multiCall(params: {
14
14
  abi: string | any;
15
15
  calls: {
16
- target: Address;
16
+ target?: Address;
17
17
  params?: CallParams;
18
18
  }[];
19
19
  block?: number;
@@ -108,14 +108,22 @@ function call(params) {
108
108
  }
109
109
  exports.call = call;
110
110
  function multiCall(params) {
111
+ var _a;
111
112
  return __awaiter(this, void 0, void 0, function () {
112
- var abi, contractCalls, chunkSize, contractChunks, i, _a, results, errors, flatResults, failedQueries, failed, newResults_1;
113
+ var abi, contractCalls, chunkSize, contractChunks, i, _b, results, errors, flatResults, failedQueries, failed, newResults_1;
113
114
  var _this = this;
114
- return __generator(this, function (_b) {
115
- switch (_b.label) {
115
+ return __generator(this, function (_c) {
116
+ switch (_c.label) {
116
117
  case 0:
118
+ if (!params.calls)
119
+ throw new Error('Missing calls parameter');
120
+ if (params.target && !params.target.startsWith('0x'))
121
+ throw new Error('Invalid target: ' + params.target);
122
+ if (!params.calls.length) {
123
+ return [2 /*return*/, { output: [] }];
124
+ }
117
125
  abi = resolveABI(params.abi);
118
- contractCalls = params.calls.map(function (call, index) {
126
+ contractCalls = (params.calls).map(function (call) {
119
127
  var _a;
120
128
  var callParams = normalizeParams(call.params);
121
129
  return {
@@ -137,7 +145,7 @@ function multiCall(params) {
137
145
  });
138
146
  }); })];
139
147
  case 1:
140
- _a = _b.sent(), results = _a.results, errors = _a.errors;
148
+ _b = _c.sent(), results = _b.results, errors = _b.errors;
141
149
  if (errors.length)
142
150
  throw errors[0];
143
151
  flatResults = [].concat.apply([], results
@@ -151,7 +159,7 @@ function multiCall(params) {
151
159
  }));
152
160
  failedQueries = flatResults.filter(function (r) { return !r.success; });
153
161
  if (failedQueries.length)
154
- (0, debugLog_1.debugLog)("Failed multicalls:", failedQueries.map(function (r) { return r.input; }));
162
+ (0, debugLog_1.debugLog)("[chain: ".concat((_a = params.chain) !== null && _a !== void 0 ? _a : "ethereum", "] Failed multicalls:"), failedQueries.map(function (r) { return r.input; }));
155
163
  if (!(params.requery === true && flatResults.some(function (r) { return !r.success; }))) return [3 /*break*/, 3];
156
164
  failed = flatResults.map(function (r, i) { return [r, i]; }).filter(function (r) { return !r[0].success; });
157
165
  return [4 /*yield*/, multiCall({
@@ -165,11 +173,11 @@ function multiCall(params) {
165
173
  return output;
166
174
  })];
167
175
  case 2:
168
- newResults_1 = _b.sent();
176
+ newResults_1 = _c.sent();
169
177
  failed.forEach(function (f, i) {
170
178
  flatResults[f[1]] = newResults_1[i];
171
179
  });
172
- _b.label = 3;
180
+ _c.label = 3;
173
181
  case 3: return [2 /*return*/, {
174
182
  output: flatResults, // flatten array
175
183
  }];
@@ -39,7 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.call = void 0;
40
40
  var events_1 = require("events");
41
41
  var debugLog_1 = require("../util/debugLog");
42
- var maxParallelCalls = !!process.env.LLAMA_SDK_MAX_PARALLEL ? +process.env.LLAMA_SDK_MAX_PARALLEL : 100;
42
+ var maxParallelCalls = !!process.env.LLAMA_SDK_MAX_PARALLEL ? +process.env.LLAMA_SDK_MAX_PARALLEL : 30;
43
43
  var COUNTERS = {};
44
44
  var emitter = new events_1.EventEmitter();
45
45
  emitter.setMaxListeners(500000);
@@ -0,0 +1,25 @@
1
+ import { Address } from "./types";
2
+ import { Chain } from "./general";
3
+ type CallParams = string | number | (string | number)[] | undefined;
4
+ type CallsParams = {
5
+ target?: Address;
6
+ params?: CallParams;
7
+ };
8
+ export declare function call(params: {
9
+ target: Address;
10
+ abi: string | any;
11
+ block?: number;
12
+ params?: CallParams;
13
+ chain?: Chain;
14
+ withMetadata?: boolean;
15
+ }): Promise<any>;
16
+ export declare function multiCall(params: {
17
+ abi: string | any;
18
+ calls: CallsParams[] | (string | number)[];
19
+ block?: number;
20
+ target?: Address;
21
+ chain?: Chain;
22
+ requery?: boolean;
23
+ withMetadata?: boolean;
24
+ }): Promise<any[]>;
25
+ export {};
package/build/abi2.js ADDED
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ 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;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ exports.multiCall = exports.call = void 0;
63
+ var abi1 = __importStar(require("./abi"));
64
+ function call(params) {
65
+ return __awaiter(this, void 0, void 0, function () {
66
+ var response;
67
+ return __generator(this, function (_a) {
68
+ switch (_a.label) {
69
+ case 0: return [4 /*yield*/, abi1.call(params)];
70
+ case 1:
71
+ response = _a.sent();
72
+ if (!params.withMetadata)
73
+ return [2 /*return*/, response];
74
+ return [2 /*return*/, response.output];
75
+ }
76
+ });
77
+ });
78
+ }
79
+ exports.call = call;
80
+ function multiCall(params) {
81
+ return __awaiter(this, void 0, void 0, function () {
82
+ var output;
83
+ return __generator(this, function (_a) {
84
+ switch (_a.label) {
85
+ case 0:
86
+ params.calls = params.calls.map(function (i) {
87
+ if (typeof i === 'object')
88
+ return i;
89
+ if (typeof i === 'string') {
90
+ if (params.target)
91
+ return { params: i };
92
+ return { target: i };
93
+ }
94
+ return { params: i };
95
+ });
96
+ if (!params.target) {
97
+ if (params.calls.some(function (i) { return !i.target; }))
98
+ throw new Error('Missing target parameter');
99
+ }
100
+ return [4 /*yield*/, abi1.multiCall(params)];
101
+ case 1:
102
+ output = (_a.sent()).output;
103
+ if (!params.withMetadata)
104
+ return [2 /*return*/, output];
105
+ return [2 /*return*/, output.map(function (i) { return i.output; })];
106
+ }
107
+ });
108
+ });
109
+ }
110
+ exports.multiCall = multiCall;
package/build/general.js CHANGED
@@ -55,7 +55,7 @@ exports.providers = {
55
55
  xdaiarb: createProvider("xdaiarb", "https://arbitrum.xdaichain.com", 200),
56
56
  kardia: createProvider("kardia", "https://rpc.kardiachain.io/", 24),
57
57
  fuse: createProvider("fuse", "https://rpc.fuse.io", 122),
58
- smartbch: createProvider("smartbch", "https://smartbch.fountainhead.cash/mainnet", 10000),
58
+ smartbch: createProvider("smartbch", "https://global.uat.cash,https://smartbch.greyh.at,https://smartbch.fountainhead.cash/mainnet", 10000),
59
59
  elastos: createProvider("elastos", "https://api.elastos.io/eth,https://api.trinity-tech.cn/eth", 20),
60
60
  hoo: createProvider("hoo", "https://http-mainnet.hoosmartchain.com", 70),
61
61
  fusion: createProvider("fusion", "https://mainnet.anyswap.exchange,https://mainway.freemoon.xyz/gate", 32659),
@@ -118,7 +118,7 @@ exports.providers = {
118
118
  ontology_evm: createProvider("ontology_evm", "https://dappnode1.ont.io:10339", 58),
119
119
  jfin: createProvider("jfin", "https://rpc.jfinchain.com/", 3501),
120
120
  bitkub: createProvider("bitkub", "https://rpc.bitkubchain.io/", 96),
121
- bitgert: createProvider("bitgert", "https://rpc.icecreamswap.com,https://serverrpc.com,https://chainrpc.com,https://mainnet-rpc.brisescan.com", 32520),
121
+ bitgert: createProvider("bitgert", "https://nodes.vefinetwork.org/bitgert,https://serverrpc.com,https://chainrpc.com,https://mainnet-rpc.brisescan.com", 32520),
122
122
  canto: createProvider("canto", "https://jsonrpc.canto.nodestake.top,https://canto.evm.chandrastation.com/", 7700),
123
123
  dogechain: createProvider("dogechain", "https://dogechain.ankr.com,https://rpc.dogechain.dog,https://rpc01-sg.dogechain.dog,https://rpc02-sg.dogechain.dog,https://rpc03-sg.dogechain.dog", 2000),
124
124
  posi: createProvider("posi", "https://api.posichain.org,https://api.s0.posichain.org", 900000),
package/build/index.d.ts CHANGED
@@ -1,2 +1,8 @@
1
+ import { debugLog } from "./util/debugLog";
1
2
  export * as util from "./generalUtil";
2
3
  export * as api from "./api";
4
+ export * as api2 from "./abi2";
5
+ export * as blocks from "./computeTVL/blocks";
6
+ import * as humanN from "./computeTVL/humanizeNumber";
7
+ export declare const log: typeof debugLog;
8
+ export declare const humanizeNumber: typeof humanN.humanizeNumber;
package/build/index.js CHANGED
@@ -23,6 +23,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.api = exports.util = void 0;
26
+ exports.humanizeNumber = exports.log = exports.blocks = exports.api2 = exports.api = exports.util = void 0;
27
+ var debugLog_1 = require("./util/debugLog");
27
28
  exports.util = __importStar(require("./generalUtil"));
28
29
  exports.api = __importStar(require("./api"));
30
+ exports.api2 = __importStar(require("./abi2"));
31
+ exports.blocks = __importStar(require("./computeTVL/blocks"));
32
+ var humanN = __importStar(require("./computeTVL/humanizeNumber"));
33
+ exports.log = debugLog_1.debugLog;
34
+ exports.humanizeNumber = humanN.humanizeNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defillama/sdk",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "SDK for calculating TVL",
5
5
  "main": "build/index.js",
6
6
  "scripts": {