@defillama/sdk 5.0.71 → 5.0.74

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.
@@ -3,6 +3,14 @@ import Balances from "./Balances";
3
3
  import { Chain } from "./general";
4
4
  import { Provider } from "ethers";
5
5
  import { GetLogsOptions } from "./util/logs";
6
+ type Erc4626SumOptions = {
7
+ calls: string[];
8
+ tokenAbi?: string;
9
+ balanceAbi?: string;
10
+ balanceCalls?: any[];
11
+ permitFailure?: boolean;
12
+ isOG4626?: boolean;
13
+ };
6
14
  export declare class ChainApi {
7
15
  block?: Block;
8
16
  chain: Chain | string;
@@ -21,7 +29,7 @@ export declare class ChainApi {
21
29
  call(params: CallOptions): Promise<any>;
22
30
  batchCall(params: CallOptions[]): Promise<any[]>;
23
31
  multiCall(params: MulticallOptions): Promise<any[]>;
24
- fetchList(params: FetchListOptions): Promise<any[]>;
32
+ fetchList(params: FetchListOptions): Promise<any>;
25
33
  bytecodeCall(params: ByteCodeCallOptions): Promise<any>;
26
34
  getBlock(): Promise<number>;
27
35
  log(...args: any): void;
@@ -44,14 +52,8 @@ export declare class ChainApi {
44
52
  removeTokenBalance(token: string): void;
45
53
  deleteToken(token: string): void;
46
54
  deleteTokens(tokens: string[]): void;
47
- erc4626Sum({ calls, tokenAbi, balanceAbi, balanceCalls, permitFailure, isOG4626 }: {
48
- calls: string[];
49
- tokenAbi?: string;
50
- balanceAbi?: string;
51
- balanceCalls?: any[];
52
- permitFailure?: boolean;
53
- isOG4626?: boolean;
54
- }): Promise<BalancesV1>;
55
+ erc4626Sum2(options: Erc4626SumOptions): Promise<BalancesV1>;
56
+ erc4626Sum({ calls, tokenAbi, balanceAbi, balanceCalls, permitFailure, isOG4626 }: Erc4626SumOptions): Promise<BalancesV1>;
55
57
  sumTokens({ token, tokens, owners, owner, tokensAndOwners, tokensAndOwners2, blacklistedTokens, blacklistedOwners, ownerTokens, }: {
56
58
  token?: string;
57
59
  tokens?: string[];
package/build/ChainApi.js CHANGED
@@ -106,11 +106,20 @@ class ChainApi {
106
106
  deleteTokens(tokens) {
107
107
  tokens.forEach(i => this.deleteToken(i));
108
108
  }
109
- async erc4626Sum({ calls, tokenAbi = 'address:token', balanceAbi = 'uint256:balance', balanceCalls, permitFailure = false, isOG4626 = false }) {
110
- if (isOG4626) {
109
+ async erc4626Sum2(options) {
110
+ if (options.isOG4626 !== false)
111
+ options.isOG4626 = true;
112
+ return this.erc4626Sum(options);
113
+ }
114
+ async erc4626Sum({ calls, tokenAbi, balanceAbi, balanceCalls, permitFailure = false, isOG4626 = false }) {
115
+ if (isOG4626 && !tokenAbi && !balanceAbi) {
111
116
  tokenAbi = 'asset';
112
117
  balanceAbi = 'totalAssets';
113
118
  }
119
+ if (!tokenAbi)
120
+ tokenAbi = 'address:token';
121
+ if (!balanceAbi)
122
+ balanceAbi = 'uint256:balance';
114
123
  if (typeof tokenAbi === 'string' && (!tokenAbi.includes(':') && !tokenAbi.includes('(')))
115
124
  tokenAbi = `address:${tokenAbi}`;
116
125
  if (typeof balanceAbi === 'string' && (!balanceAbi.includes(':') && !balanceAbi.includes('(')))
@@ -1,5 +1,5 @@
1
1
  import { CallOptions, MulticallOptions, FetchListOptions, ByteCodeCallOptions } from "../types";
2
2
  export declare function call(params: CallOptions): Promise<any>;
3
3
  export declare function multiCall(params: MulticallOptions): Promise<any[]>;
4
- export declare function fetchList(params: FetchListOptions): Promise<any[]>;
4
+ export declare function fetchList(params: FetchListOptions): Promise<any>;
5
5
  export declare function bytecodeCall(params: ByteCodeCallOptions): Promise<any>;
package/build/abi/abi2.js CHANGED
@@ -27,13 +27,24 @@ exports.bytecodeCall = exports.fetchList = exports.multiCall = exports.call = vo
27
27
  const abi1 = __importStar(require("./index"));
28
28
  const debugLog_1 = require("../util/debugLog");
29
29
  async function call(params) {
30
- const response = await abi1.call(params);
31
- if (params.withMetadata)
32
- return response;
33
- return response.output;
30
+ try {
31
+ const response = await abi1.call(params);
32
+ if (params.withMetadata)
33
+ return response;
34
+ return response.output;
35
+ }
36
+ catch (e) {
37
+ if (!params.permitFailure)
38
+ throw e;
39
+ if (params.withMetadata)
40
+ return { success: false, error: e };
41
+ return null;
42
+ }
34
43
  }
35
44
  exports.call = call;
36
45
  async function multiCall(params) {
46
+ if (params.excludeFailed)
47
+ params.permitFailure = true;
37
48
  params.calls = params.calls.map(i => {
38
49
  if (typeof i === 'object')
39
50
  return i;
@@ -44,33 +55,72 @@ async function multiCall(params) {
44
55
  }
45
56
  return { params: i };
46
57
  });
47
- const { output } = await abi1.multiCall(params);
58
+ let { output } = await abi1.multiCall(params);
59
+ if (params.excludeFailed)
60
+ output = output.filter((i) => i.success);
48
61
  if (params.withMetadata)
49
62
  return output;
50
63
  return output.map((i) => i.output);
51
64
  }
52
65
  exports.multiCall = multiCall;
53
66
  async function fetchList(params) {
54
- let { startFrom = 0, lengthAbi, itemAbi, withMetadata, startFromOne = false, itemCount, ...commonParams } = params;
67
+ let { startFrom = 0, lengthAbi, itemAbi, withMetadata, startFromOne = false, itemCount, target, targets, calls: _targets, chain, block, permitFailure, groupedByInput, excludeFailed, } = params;
68
+ if (!targets)
69
+ targets = _targets;
70
+ permitFailure = permitFailure || excludeFailed;
71
+ if (excludeFailed && groupedByInput)
72
+ throw new Error('excludeFailed and groupedByInput cannot be used together!');
73
+ if (withMetadata && groupedByInput)
74
+ throw new Error('withMetadata and groupedByInput cannot be used together!');
55
75
  if (typeof lengthAbi === 'string' && (!lengthAbi.includes(':') && !lengthAbi.includes('(')))
56
76
  lengthAbi = `uint256:${lengthAbi}`;
57
77
  if (typeof itemAbi === 'string' && (!itemAbi.includes(':') && !itemAbi.includes('(')))
58
78
  itemAbi = `function ${itemAbi}(uint256) view returns (address)`;
59
- let itemLength;
79
+ let itemLength, itemLengths;
80
+ const calls = [];
81
+ if (!target && !targets)
82
+ throw new Error('Need to provide either target or targets parameter!');
83
+ if (target) {
84
+ if (itemCount)
85
+ itemLength = itemCount;
86
+ else
87
+ itemLength = await call({ chain, block, target, abi: lengthAbi, });
88
+ (0, debugLog_1.debugLog)('length: ', itemLength);
89
+ if (startFromOne) {
90
+ itemLength++;
91
+ if (startFrom === 0)
92
+ startFrom = 1;
93
+ }
94
+ for (let i = startFrom; i < itemLength; i++)
95
+ calls.push({ target, params: [i] });
96
+ return multiCall({ chain, block, permitFailure, abi: itemAbi, calls, withMetadata, excludeFailed, });
97
+ }
60
98
  if (itemCount)
61
- itemLength = itemCount;
99
+ itemLengths = targets.map(() => itemCount);
62
100
  else
63
- itemLength = await call({ ...commonParams, abi: lengthAbi, });
64
- (0, debugLog_1.debugLog)('length: ', itemLength);
65
- if (startFromOne) {
66
- itemLength++;
67
- if (startFrom === 0)
68
- startFrom = 1;
101
+ itemLengths = await multiCall({ chain, block, calls: targets, abi: lengthAbi, });
102
+ (0, debugLog_1.debugLog)('itemLengths: ', itemLengths);
103
+ const groupedByRes = itemLengths.map(() => []);
104
+ const indexToTargetMapping = {};
105
+ let k = 0;
106
+ for (let i = 0; i < itemLengths.length; i++) {
107
+ let itemLength = itemLengths[i];
108
+ if (startFromOne) {
109
+ itemLength++;
110
+ if (startFrom === 0)
111
+ startFrom = 1;
112
+ }
113
+ for (let j = startFrom; j < itemLength; j++) {
114
+ calls.push({ target: targets[i], params: [j] });
115
+ indexToTargetMapping[k] = i;
116
+ k++;
117
+ }
69
118
  }
70
- const calls = [];
71
- for (let i = startFrom; i < itemLength; i++)
72
- calls.push(i);
73
- return multiCall({ ...commonParams, abi: itemAbi, calls, withMetadata });
119
+ const res = await multiCall({ chain, block, permitFailure, abi: itemAbi, calls, withMetadata, excludeFailed, });
120
+ if (!groupedByInput)
121
+ return res;
122
+ res.forEach((i, idx) => groupedByRes[indexToTargetMapping[idx]].push(i));
123
+ return groupedByRes;
74
124
  }
75
125
  exports.fetchList = fetchList;
76
126
  async function bytecodeCall(params) {
@@ -374,6 +374,12 @@ function multicallAddress(chainId) {
374
374
  return '0x493d616f5F9a64e5B3D527120E406439bdF29272';
375
375
  case 810180: // zklink
376
376
  return '0xa8738F57538E3Bb73872d1133F2358c7Fe56FD35';
377
+ case 5112: // ham
378
+ return '0xB7c3Ea932649fBD594C881aDCb3F19415e2EA2d5';
379
+ case 1996: // sanko
380
+ return '0xB32d192e07727A0F6f48e721791aa4e02cd292e1';
381
+ case 185: // mint
382
+ return '0xf8ac4BEB2F75d2cFFb588c63251347fdD629B92c';
377
383
  default:
378
384
  return null;
379
385
  }
@@ -140,7 +140,11 @@ const DEPLOYMENT_BLOCK = {
140
140
  bitr: 1045566,
141
141
  dreyerx: 163720,
142
142
  cyeth: 1,
143
- taiko: 938,
143
+ taiko: 11269,
144
+ sei: 79351444,
145
+ aura: 6731307,
146
+ conflux: 97705330,
147
+ etlk: 1,
144
148
  };
145
149
  async function makeMultiCall(functionABI, calls, chain, block) {
146
150
  if (chain === 'tron')