@defillama/sdk 5.0.195 → 5.0.204

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);
@@ -369,6 +369,7 @@ function multicallAddress(chainId) {
369
369
  case 11820: return '0x6d761c3fe633c67b1d3a55678b04eb4ad11c4642'; // artela
370
370
  case 2355: return '0x566da61a4D0841a67bA8F2c7e5975885fa0Af4DA'; // silicon_zk
371
371
  case 728126428: return 'TEazPvZwDjDtFeJupyo7QunvnrnUjPH8ED'; // silicon_zk
372
+ case 1110: return '0x114575812CF34299cd65BD251C798608fa805433'; // grx
372
373
  default:
373
374
  return null;
374
375
  }
@@ -199,6 +199,14 @@ const DEPLOYMENT_BLOCK = {
199
199
  '0g': 6546802,
200
200
  besc: 1,
201
201
  monad: 9248132,
202
+ incentiv: 1036482,
203
+ bsquared: 1,
204
+ mantra: 1,
205
+ cross: 1,
206
+ doma: 1,
207
+ capx: 30800,
208
+ stable: 2423647,
209
+ megaeth: 1858081,
202
210
  };
203
211
  async function makeMultiCall(functionABI, calls, chain, block) {
204
212
  if (!functionABI)
@@ -325,4 +333,5 @@ const CUSTOM_MULTICALL_ADDRESSES = {
325
333
  'eteria': '0x8cC688B1F99b651ee00bB0Cb0aae61F416F8384b',
326
334
  'xone': '0xe39d7BCDdaBBD0526D143185Fb7b459099Fd40c9',
327
335
  'besc': '0xBcdb671cBC7711fE533E8B46E52EbC1470145F67',
336
+ 'capx': '0x8E1cd29c79dD1Dd4966Cd6A05EeC7d25B5f47f2b',
328
337
  };