@defillama/sdk 5.0.198 → 5.0.206

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.
@@ -111,6 +111,7 @@ export declare class ChainApi {
111
111
  getBalancesV2(): Balances;
112
112
  getTransactions(params: GetTransactionOptions): Promise<any>;
113
113
  getTransactionReceipt(tx: string): Promise<import("ethers").TransactionReceipt | null>;
114
+ getStats(): DebugStats;
114
115
  }
115
116
  export default ChainApi;
116
117
  export declare function getDebugStats(): Record<string, DebugStats>;
package/build/ChainApi.js CHANGED
@@ -29,7 +29,7 @@ class ChainApi {
29
29
  this.chainId = (_b = providers_json_1.default[this.chain]) === null || _b === void 0 ? void 0 : _b.chainId;
30
30
  this.storedKey = params.storedKey;
31
31
  this.api = this;
32
- const uKey = `${params.protocol}:${this.storedKey}`;
32
+ const uKey = this.storedKey ? `${params.protocol}:${this.storedKey}` : (params.protocol ? `${params.protocol}` : `chain-${this.chain}`);
33
33
  const stats = {
34
34
  meta: {
35
35
  chain: this.chain,
@@ -98,7 +98,8 @@ class ChainApi {
98
98
  });
99
99
  }
100
100
  async getBlock() {
101
- this.addStat('getBlock');
101
+ if (!this.block)
102
+ this.addStat('getBlock');
102
103
  if (!this.block)
103
104
  this.block = await (0, blocks_1.getBlockNumber)(this.chain, this.timestamp);
104
105
  return this.block;
@@ -277,6 +278,9 @@ class ChainApi {
277
278
  this.addStat('getTransactionReceipt');
278
279
  return this.provider.getTransactionReceipt(tx);
279
280
  }
281
+ getStats() {
282
+ return this.stats;
283
+ }
280
284
  }
281
285
  exports.ChainApi = ChainApi;
282
286
  exports.default = ChainApi;
package/build/abi/abi2.js CHANGED
@@ -39,8 +39,10 @@ exports.fetchList = fetchList;
39
39
  exports.bytecodeCall = bytecodeCall;
40
40
  const abi1 = __importStar(require("./index"));
41
41
  async function call(params) {
42
+ if (params.abis)
43
+ return callWithAlternateAbis();
42
44
  try {
43
- const response = await abi1.call(params);
45
+ const response = await abi1.call(params); // abi v1 doesnt have support for 'abis' param
44
46
  if (params.field)
45
47
  response.output = response.output[params.field];
46
48
  if (params.withMetadata)
@@ -54,10 +56,25 @@ async function call(params) {
54
56
  return { success: false, error: e };
55
57
  return null;
56
58
  }
59
+ async function callWithAlternateAbis() {
60
+ const { abis, ...restParams } = params;
61
+ if (!abis || abis.length === 0)
62
+ throw new Error('No alternate ABIs provided!');
63
+ for (let i = 0; i < abis.length - 1; i++) {
64
+ const res = await call({ ...restParams, abi: abis[i], permitFailure: true, withMetadata: true });
65
+ const response = params.withMetadata ? res : res.output;
66
+ if (res.success)
67
+ return response;
68
+ }
69
+ const lastAbi = abis[abis.length - 1];
70
+ return call({ ...restParams, abi: lastAbi, });
71
+ }
57
72
  }
58
73
  async function multiCall(params) {
59
74
  if (params.excludeFailed)
60
75
  params.permitFailure = true;
76
+ if (params.abis)
77
+ return multiCallWithAlternateAbis();
61
78
  params.calls = params.calls.map(i => {
62
79
  if (typeof i === 'object')
63
80
  return i;
@@ -76,6 +93,40 @@ async function multiCall(params) {
76
93
  if (params.withMetadata)
77
94
  return output;
78
95
  return output.map((i) => i.output);
96
+ async function multiCallWithAlternateAbis() {
97
+ const { abis, ...restParams } = params;
98
+ if (!abis || abis.length === 0)
99
+ throw new Error('No alternate ABIs provided!');
100
+ const outputs = [];
101
+ for (let i = 0; i < abis.length; i++) {
102
+ const res = await multiCall({ ...restParams, abi: abis[i], permitFailure: true, withMetadata: true, excludeFailed: false, });
103
+ outputs.push(res);
104
+ }
105
+ let finalOutput;
106
+ const permitFailure = params.permitFailure || params.excludeFailed;
107
+ outputs.forEach((res) => {
108
+ if (!finalOutput) { // First iteration
109
+ finalOutput = res;
110
+ return;
111
+ }
112
+ res.forEach((callRes, idx) => {
113
+ var _a;
114
+ if ((_a = finalOutput[idx]) === null || _a === void 0 ? void 0 : _a.success)
115
+ return; // Already succeeded with an earlier ABI
116
+ finalOutput[idx] = callRes;
117
+ });
118
+ });
119
+ if (!permitFailure)
120
+ finalOutput.forEach((data) => {
121
+ if (!(data === null || data === void 0 ? void 0 : data.success))
122
+ throw new Error(`All ABI alternatives failed for multiCall! Last error: ${data === null || data === void 0 ? void 0 : data.error}`);
123
+ });
124
+ if (params.excludeFailed)
125
+ finalOutput = finalOutput.filter((i) => i === null || i === void 0 ? void 0 : i.success);
126
+ if (params.withMetadata)
127
+ return finalOutput;
128
+ return finalOutput.map((i) => i.output);
129
+ }
79
130
  }
80
131
  async function fetchList(params) {
81
132
  // itemAbi2 is used when we need to make a second call to get the final result
@@ -84,6 +84,8 @@ function isValidTarget(target, chain) {
84
84
  }
85
85
  async function call(params) {
86
86
  var _a;
87
+ if (!params.abi)
88
+ throw new Error('Missing ABI parameter ("abis" is supported only in abi2/ChainApi)!');
87
89
  if (params.chain === 'tron')
88
90
  (0, common_1.fixTronCallParams)(params);
89
91
  if (!isValidTarget(params.target, params.chain))
@@ -145,6 +147,8 @@ async function bytecodeCall(params) {
145
147
  }
146
148
  async function multiCall(params) {
147
149
  var _a;
150
+ if (!params.abi)
151
+ throw new Error('Missing ABI parameter ("abis" is supported only in abi2/ChainApi)!');
148
152
  fixBlockTag(params);
149
153
  if (params.chain === 'tron')
150
154
  (0, common_1.fixTronCallParams)(params);
@@ -206,6 +206,9 @@ const DEPLOYMENT_BLOCK = {
206
206
  doma: 1,
207
207
  capx: 30800,
208
208
  stable: 2423647,
209
+ megaeth: 1858081,
210
+ injective: 1,
211
+ occ: 1,
209
212
  };
210
213
  async function makeMultiCall(functionABI, calls, chain, block) {
211
214
  if (!functionABI)
package/build/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export * as types from "./types";
17
17
  export * as tron from "./abi/tron";
18
18
  export * as erc20 from "./erc20";
19
19
  export * as coins from "./util/coins";
20
+ export * as chainUtils from "./util/chainUtils";
20
21
  export declare const log: typeof debugLog;
21
22
  export declare const logTable: typeof debugTable;
22
23
  export declare const humanizeNumber: typeof humanN.humanizeNumber;
package/build/index.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.humanizeNumber = exports.logTable = exports.log = exports.coins = exports.erc20 = exports.tron = exports.types = exports.indexer = exports.graph = exports.blocks = exports.api2 = exports.elastic = exports.api = exports.sdkCache = exports.getEventLogs = exports.cache = exports.util = exports.setProvider = exports.getProvider = exports.Balances = exports.ChainApi = void 0;
36
+ exports.humanizeNumber = exports.logTable = exports.log = exports.chainUtils = exports.coins = exports.erc20 = exports.tron = exports.types = exports.indexer = exports.graph = exports.blocks = exports.api2 = exports.elastic = exports.api = exports.sdkCache = exports.getEventLogs = exports.cache = exports.util = exports.setProvider = exports.getProvider = exports.Balances = exports.ChainApi = void 0;
37
37
  const debugLog_1 = require("./util/debugLog");
38
38
  var ChainApi_1 = require("./ChainApi");
39
39
  Object.defineProperty(exports, "ChainApi", { enumerable: true, get: function () { return ChainApi_1.ChainApi; } });
@@ -58,6 +58,7 @@ exports.types = __importStar(require("./types"));
58
58
  exports.tron = __importStar(require("./abi/tron"));
59
59
  exports.erc20 = __importStar(require("./erc20"));
60
60
  exports.coins = __importStar(require("./util/coins"));
61
+ exports.chainUtils = __importStar(require("./util/chainUtils"));
61
62
  exports.log = debugLog_1.debugLog;
62
63
  exports.logTable = debugLog_1.debugTable;
63
64
  exports.humanizeNumber = humanN.humanizeNumber;