@defillama/sdk 5.0.149 → 5.0.151

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.
@@ -1,30 +1,32 @@
1
1
  import { Balances as BalancesV1 } from "./types";
2
2
  import { Chain } from "./general";
3
+ type BalancesOptions = {
4
+ skipChain?: boolean;
5
+ label?: string;
6
+ };
7
+ type BalancesOptionsWithLabel = BalancesOptions | string;
3
8
  export declare class Balances {
4
9
  chain: Chain | string;
5
10
  timestamp?: number;
6
11
  _balances: BalancesV1;
12
+ _breakdownBalances: {
13
+ [key: string]: Balances;
14
+ };
7
15
  constructor(params: {
8
16
  chain?: Chain | string;
9
17
  timestamp?: number;
10
18
  });
11
- _add(token: string, balance: any, { skipChain }?: {
12
- skipChain?: boolean | undefined;
13
- }): void;
14
- add(token: string | string[], balance: any, { skipChain }?: {
15
- skipChain?: boolean | undefined;
16
- }): void;
17
- addToken(token: string, balance: any, { skipChain }?: {
18
- skipChain?: boolean | undefined;
19
- }): void;
20
- addGasToken(balance: any): void;
21
- addCGToken(token: string, balance: any): void;
22
- addTokenVannila(token: string, balance: any): void;
23
- addUSDValue(balance: any): void;
24
- addTokens(tokens: string[], balances: any[], { skipChain }?: {
25
- skipChain?: boolean | undefined;
26
- }): void;
27
- addBalances(balances: BalancesV1 | Balances): void;
19
+ _add(token: string, balance: any, optionsOrLabel?: BalancesOptionsWithLabel, options?: BalancesOptions): void;
20
+ add(token: string | string[] | Balances, balance?: any, optionsOrLabel?: BalancesOptionsWithLabel, options?: BalancesOptions): void;
21
+ addToken(token: string, balance: any, optionsOrLabel?: BalancesOptionsWithLabel, options?: BalancesOptions): void;
22
+ addGasToken(balance: any, optionsOrLabel?: BalancesOptionsWithLabel, options?: BalancesOptions): void;
23
+ addCGToken(token: string, balance: any, optionsOrLabel?: BalancesOptionsWithLabel, options?: BalancesOptions): void;
24
+ addTokenVannila(token: string, balance: any, optionsOrLabel?: BalancesOptionsWithLabel, options?: BalancesOptions): void;
25
+ addUSDValue(balance: any, optionsOrLabel?: BalancesOptionsWithLabel, options?: BalancesOptions): void;
26
+ addTokens(tokens: string[], balances: any[], optionsOrLabel?: BalancesOptionsWithLabel, options?: BalancesOptions): void;
27
+ addBalances(balances: BalancesV1 | Balances, optionsOrLabel?: BalancesOptionsWithLabel, options?: (BalancesOptions & {
28
+ skipBreakdown?: boolean;
29
+ })): void;
28
30
  getBalances(): BalancesV1;
29
31
  removeTokenBalance(token: string): void;
30
32
  getUSDValue(): Promise<number>;
@@ -46,11 +48,16 @@ export declare class Balances {
46
48
  usdTokenBalances: BalancesV1;
47
49
  rawTokenBalances: BalancesV1;
48
50
  }>;
49
- clone(ratio?: number): Balances;
50
- subtract(balances: BalancesV1 | Balances): void;
51
- subtractToken(token: string, balance: any, { skipChain }?: {
52
- skipChain?: boolean | undefined;
53
- }): void;
51
+ clone(ratio?: number, optionsOrLabel?: BalancesOptionsWithLabel, options?: BalancesOptions): Balances;
52
+ subtract(balances: BalancesV1 | Balances, optionsOrLabel?: BalancesOptionsWithLabel, options?: BalancesOptions): void;
53
+ subtractToken(token: string, balance: any, optionsOrLabel?: BalancesOptionsWithLabel, options?: BalancesOptions): void;
54
54
  removeNegativeBalances(): void;
55
+ _breakdownBalancesAction(action: string, args?: any[]): Promise<{
56
+ [key: string]: any;
57
+ }>;
58
+ hasBreakdownBalances(): boolean;
59
+ getBreakdownBalances(): {
60
+ [key: string]: Balances;
61
+ };
55
62
  }
56
63
  export default Balances;
package/build/Balances.js CHANGED
@@ -7,14 +7,36 @@ exports.Balances = void 0;
7
7
  const generalUtil_1 = require("./generalUtil");
8
8
  const computeTVL_1 = __importDefault(require("./util/computeTVL"));
9
9
  const nullAddress = '0x0000000000000000000000000000000000000000';
10
+ // the last parameter of add function can be either a string or an object with options (or both as last two parameters)
11
+ function getOptions({ optionsOrLabel = {}, options = {} } = {}) {
12
+ var _a;
13
+ let label;
14
+ if (optionsOrLabel) {
15
+ if (typeof optionsOrLabel === 'string') {
16
+ label = optionsOrLabel;
17
+ }
18
+ else {
19
+ options = optionsOrLabel;
20
+ label = options.label;
21
+ }
22
+ }
23
+ return {
24
+ ...options,
25
+ skipChain: (_a = options === null || options === void 0 ? void 0 : options.skipChain) !== null && _a !== void 0 ? _a : false,
26
+ label,
27
+ };
28
+ }
10
29
  class Balances {
11
30
  constructor(params) {
12
31
  var _a;
13
32
  this.chain = (_a = params.chain) !== null && _a !== void 0 ? _a : 'ethereum';
14
33
  this.timestamp = params.timestamp;
15
34
  this._balances = {};
35
+ this._breakdownBalances = {};
16
36
  }
17
- _add(token, balance, { skipChain = false } = {}) {
37
+ _add(token, balance, optionsOrLabel, options) {
38
+ var _a;
39
+ const { label, skipChain } = getOptions({ optionsOrLabel, options });
18
40
  token = token.replace(/\//g, ':');
19
41
  const isIBCToken = token.startsWith('ibc:');
20
42
  let chain = this.chain;
@@ -30,59 +52,88 @@ class Balances {
30
52
  token = token.replace('0x', '0x0');
31
53
  }
32
54
  (0, generalUtil_1.sumSingleBalance)(this._balances, token, balance, chain);
55
+ if (label) {
56
+ this._breakdownBalances[label] = (_a = this._breakdownBalances[label]) !== null && _a !== void 0 ? _a : new Balances({ chain: this.chain, timestamp: this.timestamp });
57
+ this._breakdownBalances[label]._add(token, balance, { skipChain });
58
+ }
33
59
  }
34
- add(token, balance, { skipChain = false } = {}) {
60
+ add(token, balance, optionsOrLabel, options) {
61
+ if (token instanceof Balances) {
62
+ if (typeof optionsOrLabel === 'string')
63
+ throw new Error('When adding a Balances instance, optionsOrLabel must be an object with options, not a string');
64
+ this.addBalances(token, balance, optionsOrLabel);
65
+ return;
66
+ }
67
+ options = getOptions({ optionsOrLabel, options });
35
68
  if (!token)
36
69
  throw new Error('token is required');
37
70
  if (!balance)
38
71
  return;
39
72
  if (Array.isArray(balance)) {
40
73
  if (Array.isArray(token)) {
41
- this.addTokens(token, balance, { skipChain });
74
+ this.addTokens(token, balance, options);
42
75
  return;
43
76
  }
44
77
  else if (typeof token === 'string') {
45
- balance.forEach((v) => this._add(token, v, { skipChain }));
78
+ balance.forEach((v) => this._add(token, v, options));
46
79
  return;
47
80
  }
48
81
  }
49
82
  if (typeof token !== 'string')
50
83
  throw new Error('token must be a string');
51
- this._add(token, balance, { skipChain });
84
+ this._add(token, balance, options);
52
85
  }
53
- addToken(token, balance, { skipChain = false } = {}) {
54
- this._add(token, balance, { skipChain });
86
+ addToken(token, balance, optionsOrLabel, options) {
87
+ options = getOptions({ optionsOrLabel, options });
88
+ this._add(token, balance, options);
55
89
  }
56
- addGasToken(balance) {
57
- this._add(nullAddress, balance);
90
+ addGasToken(balance, optionsOrLabel, options) {
91
+ options = getOptions({ optionsOrLabel, options });
92
+ this._add(nullAddress, balance, options);
58
93
  }
59
- addCGToken(token, balance) {
60
- this.addTokenVannila('coingecko:' + token, balance);
94
+ addCGToken(token, balance, optionsOrLabel, options) {
95
+ options = getOptions({ optionsOrLabel, options });
96
+ this.addTokenVannila('coingecko:' + token, balance, options);
61
97
  }
62
- addTokenVannila(token, balance) {
63
- this._add(token, balance, { skipChain: true });
98
+ addTokenVannila(token, balance, optionsOrLabel, options) {
99
+ options = getOptions({ optionsOrLabel, options });
100
+ this._add(token, balance, { ...options, skipChain: true });
64
101
  }
65
- addUSDValue(balance) {
66
- this.addCGToken('tether', balance);
102
+ addUSDValue(balance, optionsOrLabel, options) {
103
+ options = getOptions({ optionsOrLabel, options });
104
+ this.addCGToken('tether', balance, { ...options, skipChain: true });
67
105
  }
68
- addTokens(tokens, balances, { skipChain = false } = {}) {
106
+ addTokens(tokens, balances, optionsOrLabel, options) {
107
+ options = getOptions({ optionsOrLabel, options });
69
108
  if (!Array.isArray(tokens))
70
109
  throw new Error('tokens must be an array');
71
110
  if (!Array.isArray(balances))
72
111
  throw new Error('balances must be an array');
73
112
  if (tokens.length !== balances.length)
74
113
  throw new Error('token and balance must have the same length');
75
- tokens.forEach((v, i) => this._add(v, balances[i], { skipChain }));
114
+ tokens.forEach((v, i) => this._add(v, balances[i], options));
76
115
  }
77
- addBalances(balances) {
116
+ addBalances(balances, optionsOrLabel, options) {
117
+ var _a;
118
+ options = getOptions({ optionsOrLabel, options });
78
119
  if (balances instanceof Balances) {
79
120
  if (balances === this)
80
121
  return;
122
+ // if balances object has breakdown by label, and overall label is not set, we copy existing breakdown balances into this instance
123
+ if (balances.hasBreakdownBalances() && !options.skipBreakdown && !options.label) {
124
+ this._breakdownBalances = (_a = this._breakdownBalances) !== null && _a !== void 0 ? _a : {};
125
+ const { label, ...restOptions } = options;
126
+ Object.entries(balances.getBreakdownBalances()).forEach(([label, breakdown]) => {
127
+ var _a;
128
+ this._breakdownBalances[label] = (_a = this._breakdownBalances[label]) !== null && _a !== void 0 ? _a : new Balances({ chain: this.chain, timestamp: this.timestamp });
129
+ this._breakdownBalances[label].addBalances(breakdown, restOptions);
130
+ });
131
+ }
81
132
  balances = balances.getBalances();
82
133
  }
83
134
  if (balances === this._balances)
84
135
  return;
85
- Object.entries(balances).forEach(([token, balance]) => this._add(token, balance, { skipChain: true }));
136
+ Object.entries(balances).forEach(([token, balance]) => this._add(token, balance, { ...options, skipChain: true }));
86
137
  }
87
138
  getBalances() {
88
139
  return this._balances;
@@ -93,6 +144,7 @@ class Balances {
93
144
  if (regex.test(i))
94
145
  delete this._balances[i];
95
146
  });
147
+ this._breakdownBalancesAction('removeTokenBalance', [token]);
96
148
  }
97
149
  async getUSDValue() {
98
150
  const { usdTvl } = await (0, computeTVL_1.default)(this.getBalances(), this.timestamp);
@@ -109,6 +161,7 @@ class Balances {
109
161
  Object.keys(this._balances).forEach((token) => {
110
162
  this._balances[token] = Number(this._balances[token]) * ratio;
111
163
  });
164
+ this._breakdownBalancesAction('resizeBy', [ratio]);
112
165
  return this;
113
166
  }
114
167
  static async getUSDValue(balances, timestamp) {
@@ -124,31 +177,58 @@ class Balances {
124
177
  const { usdTvl, usdTokenBalances } = await (0, computeTVL_1.default)(balances, timestamp);
125
178
  return { usdTvl, usdTokenBalances, rawTokenBalances: balances };
126
179
  }
127
- clone(ratio = 1) {
180
+ clone(ratio = 1, optionsOrLabel, options) {
181
+ options = getOptions({ optionsOrLabel, options });
128
182
  const newBalances = new Balances({ chain: this.chain, timestamp: this.timestamp });
129
- newBalances.addBalances(this);
183
+ newBalances.addBalances(this, options);
130
184
  if (ratio !== 1)
131
185
  newBalances.resizeBy(ratio);
132
186
  return newBalances;
133
187
  }
134
- subtract(balances) {
188
+ subtract(balances, optionsOrLabel, options) {
189
+ options = getOptions({ optionsOrLabel, options });
135
190
  if (balances instanceof Balances) {
136
191
  if (balances === this)
137
192
  return;
138
193
  balances = balances.getBalances();
139
194
  }
140
195
  Object.entries(balances).forEach(([token, balance]) => {
141
- this._add(token, Number(balance) * -1, { skipChain: true });
196
+ this._add(token, Number(balance) * -1, { skipChain: true, label: options.label });
142
197
  });
143
198
  }
144
- subtractToken(token, balance, { skipChain = false } = {}) {
145
- this._add(token, Number(balance) * -1, { skipChain });
199
+ subtractToken(token, balance, optionsOrLabel, options) {
200
+ options = getOptions({ optionsOrLabel, options });
201
+ this._add(token, Number(balance) * -1, options);
146
202
  }
147
203
  removeNegativeBalances() {
148
204
  Object.keys(this._balances).forEach((token) => {
149
205
  if (Number(this._balances[token]) <= 0)
150
206
  delete this._balances[token];
151
207
  });
208
+ if (this._breakdownBalances) {
209
+ Object.values(this._breakdownBalances).forEach((breakdown) => breakdown.removeNegativeBalances());
210
+ }
211
+ }
212
+ async _breakdownBalancesAction(action, args = []) {
213
+ if (!this._breakdownBalances)
214
+ return {};
215
+ const response = {};
216
+ const entries = Object.entries(this._breakdownBalances);
217
+ for (const [label, breakdown] of entries) {
218
+ if (typeof breakdown[action] === 'function') {
219
+ response[label] = breakdown[action](...args);
220
+ if (response[label] instanceof Promise) {
221
+ response[label] = await response[label];
222
+ }
223
+ }
224
+ }
225
+ return response;
226
+ }
227
+ hasBreakdownBalances() {
228
+ return Object.keys(this._breakdownBalances).length > 0;
229
+ }
230
+ getBreakdownBalances() {
231
+ return this._breakdownBalances;
152
232
  }
153
233
  }
154
234
  exports.Balances = Balances;
@@ -12,6 +12,14 @@ type Erc4626SumOptions = {
12
12
  permitFailure?: boolean;
13
13
  isOG4626?: boolean;
14
14
  };
15
+ type DebugStats = {
16
+ total: number;
17
+ [key: string]: any;
18
+ };
19
+ type BalancesV2Options = {
20
+ skipChain?: boolean;
21
+ label?: string;
22
+ };
15
23
  export declare class ChainApi {
16
24
  block?: Block;
17
25
  chain: Chain | string;
@@ -20,13 +28,16 @@ export declare class ChainApi {
20
28
  provider: Provider;
21
29
  _balances: Balances;
22
30
  storedKey?: string;
31
+ stats: DebugStats;
23
32
  api: ChainApi;
24
33
  constructor(params: {
25
34
  block?: Block;
26
35
  chain?: Chain | string;
27
36
  storedKey?: string;
28
37
  timestamp?: number;
38
+ protocol?: string;
29
39
  });
40
+ addStat(method: string, value?: any, skipTotal?: boolean): void;
30
41
  call(params: CallOptions): Promise<any>;
31
42
  batchCall(params: CallOptions[]): Promise<any[]>;
32
43
  multiCall(params: MulticallOptions): Promise<any[]>;
@@ -35,20 +46,14 @@ export declare class ChainApi {
35
46
  getBlock(): Promise<number>;
36
47
  log(...args: any): void;
37
48
  logTable(...args: any): void;
38
- add(token: any, balance: any, { skipChain }?: {
39
- skipChain?: boolean | undefined;
40
- }): void;
41
- addToken(token: string, balance: any, { skipChain }?: {
42
- skipChain?: boolean | undefined;
43
- }): void;
44
- addGasToken(balance: any): void;
45
- addUSDValue(balance: any): void;
46
- addTokens(tokens: string[], balances: any[], { skipChain }?: {
47
- skipChain?: boolean | undefined;
48
- }): void;
49
- addBalances(balances: Balances | BalancesV1): void;
50
- addCGToken(token: string, balance: any): void;
51
- addTokenVannila(token: string, balance: any): void;
49
+ add(token: any, balance: any, options?: BalancesV2Options): void;
50
+ addToken(token: string, balance: any, options?: BalancesV2Options): void;
51
+ addGasToken(balance: any, options?: BalancesV2Options): void;
52
+ addUSDValue(balance: any, options?: BalancesV2Options): void;
53
+ addTokens(tokens: string[], balances: any[], options?: BalancesV2Options): void;
54
+ addBalances(balances: Balances | BalancesV1, options?: BalancesV2Options): void;
55
+ addCGToken(token: string, balance: any, options?: BalancesV2Options): void;
56
+ addTokenVannila(token: string, balance: any, options?: BalancesV2Options): void;
52
57
  getBalances(): BalancesV1;
53
58
  getChainId(): number | undefined;
54
59
  removeTokenBalance(token: string): void;
@@ -56,7 +61,7 @@ export declare class ChainApi {
56
61
  deleteTokens(tokens: string[]): void;
57
62
  erc4626Sum2(options: Erc4626SumOptions): Promise<BalancesV1>;
58
63
  erc4626Sum({ calls, tokenAbi, balanceAbi, balanceCalls, permitFailure, isOG4626 }: Erc4626SumOptions): Promise<BalancesV1>;
59
- sumTokens({ token, tokens, owners, owner, tokensAndOwners, tokensAndOwners2, blacklistedTokens, blacklistedOwners, ownerTokens, }: {
64
+ sumTokens({ token, tokens, owners, owner, tokensAndOwners, tokensAndOwners2, blacklistedTokens, blacklistedOwners, ownerTokens, balancesV2Options, }: {
60
65
  token?: string;
61
66
  tokens?: string[];
62
67
  owner?: string;
@@ -66,6 +71,7 @@ export declare class ChainApi {
66
71
  ownerTokens?: any[];
67
72
  blacklistedTokens?: string[];
68
73
  blacklistedOwners?: string[];
74
+ balancesV2Options?: BalancesV2Options;
69
75
  }): Promise<BalancesV1>;
70
76
  getUSDValue(): Promise<number>;
71
77
  getUSDString(): Promise<string>;
@@ -80,3 +86,4 @@ export declare class ChainApi {
80
86
  getTransactionReceipt(tx: string): Promise<import("ethers").TransactionReceipt | null>;
81
87
  }
82
88
  export default ChainApi;
89
+ export declare function getDebugStats(): Record<string, DebugStats>;
package/build/ChainApi.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ChainApi = void 0;
6
+ exports.getDebugStats = exports.ChainApi = void 0;
7
7
  const abi2_1 = require("./abi/abi2");
8
8
  const Balances_1 = __importDefault(require("./Balances"));
9
9
  const blocks_1 = require("./computeTVL/blocks");
@@ -15,6 +15,7 @@ const generalUtil_1 = require("./generalUtil");
15
15
  const debugLog_1 = require("./util/debugLog");
16
16
  const logs_1 = __importDefault(require("./util/logs"));
17
17
  const transactions_1 = require("./util/transactions");
18
+ const callStatsByProject = {};
18
19
  const nullAddress = '0x0000000000000000000000000000000000000000';
19
20
  class ChainApi {
20
21
  constructor(params) {
@@ -28,8 +29,28 @@ class ChainApi {
28
29
  this.chainId = (_b = providers_json_1.default[this.chain]) === null || _b === void 0 ? void 0 : _b.chainId;
29
30
  this.storedKey = params.storedKey;
30
31
  this.api = this;
32
+ const uKey = `${params.protocol}:${this.storedKey}`;
33
+ const stats = {
34
+ meta: {
35
+ chain: this.chain,
36
+ storedKey: this.storedKey,
37
+ protocol: params.protocol,
38
+ },
39
+ label: uKey,
40
+ total: 0,
41
+ };
42
+ callStatsByProject[uKey] = stats;
43
+ this.stats = stats;
44
+ }
45
+ addStat(method, value = 1, skipTotal = false) {
46
+ if (!skipTotal)
47
+ this.stats.total += value;
48
+ if (!this.stats[method])
49
+ this.stats[method] = 0;
50
+ this.stats[method] += value;
31
51
  }
32
52
  call(params) {
53
+ this.addStat('call');
33
54
  return (0, abi2_1.call)({
34
55
  ...params,
35
56
  block: this.block,
@@ -40,6 +61,8 @@ class ChainApi {
40
61
  return Promise.all(params.map(i => this.call(i)));
41
62
  }
42
63
  multiCall(params) {
64
+ this.addStat('multiCall', params.calls.length, true);
65
+ this.addStat('call');
43
66
  return (0, abi2_1.multiCall)({
44
67
  ...params,
45
68
  block: this.block,
@@ -47,6 +70,7 @@ class ChainApi {
47
70
  });
48
71
  }
49
72
  fetchList(params) {
73
+ this.addStat('fetchList');
50
74
  return (0, abi2_1.fetchList)({
51
75
  ...params,
52
76
  block: this.block,
@@ -61,6 +85,7 @@ class ChainApi {
61
85
  });
62
86
  }
63
87
  async getBlock() {
88
+ this.addStat('getBlock');
64
89
  if (!this.block)
65
90
  this.block = await (0, blocks_1.getBlockNumber)(this.chain, this.timestamp);
66
91
  return this.block;
@@ -71,29 +96,29 @@ class ChainApi {
71
96
  logTable(...args) {
72
97
  (0, debugLog_1.debugTable)(...args);
73
98
  }
74
- add(token, balance, { skipChain = false } = {}) {
75
- this._balances.add(token, balance, { skipChain });
99
+ add(token, balance, options = {}) {
100
+ this._balances.add(token, balance, options);
76
101
  }
77
- addToken(token, balance, { skipChain = false } = {}) {
78
- this.add(token, balance, { skipChain });
102
+ addToken(token, balance, options = {}) {
103
+ this.add(token, balance, options);
79
104
  }
80
- addGasToken(balance) {
81
- this.add(nullAddress, balance);
105
+ addGasToken(balance, options = {}) {
106
+ this.add(nullAddress, balance, options);
82
107
  }
83
- addUSDValue(balance) {
84
- this._balances.addUSDValue(balance);
108
+ addUSDValue(balance, options = {}) {
109
+ this._balances.addUSDValue(balance, options);
85
110
  }
86
- addTokens(tokens, balances, { skipChain = false } = {}) {
87
- this.add(tokens, balances, { skipChain });
111
+ addTokens(tokens, balances, options = {}) {
112
+ this.add(tokens, balances, options);
88
113
  }
89
- addBalances(balances) {
90
- this._balances.addBalances(balances);
114
+ addBalances(balances, options = {}) {
115
+ this._balances.addBalances(balances, options);
91
116
  }
92
- addCGToken(token, balance) {
93
- this._balances.addCGToken(token, balance);
117
+ addCGToken(token, balance, options = {}) {
118
+ this._balances.addCGToken(token, balance, options);
94
119
  }
95
- addTokenVannila(token, balance) {
96
- this._balances.addTokenVannila(token, balance);
120
+ addTokenVannila(token, balance, options = {}) {
121
+ this._balances.addTokenVannila(token, balance, options);
97
122
  }
98
123
  getBalances() {
99
124
  return this._balances.getBalances();
@@ -139,7 +164,7 @@ class ChainApi {
139
164
  });
140
165
  return this.getBalances();
141
166
  }
142
- async sumTokens({ token, tokens = [], owners = [], owner, tokensAndOwners = [], tokensAndOwners2 = [], blacklistedTokens = [], blacklistedOwners = [], ownerTokens = [], }) {
167
+ async sumTokens({ token, tokens = [], owners = [], owner, tokensAndOwners = [], tokensAndOwners2 = [], blacklistedTokens = [], blacklistedOwners = [], ownerTokens = [], balancesV2Options = {}, }) {
143
168
  if (tokensAndOwners2.length)
144
169
  tokensAndOwners.push(...tokensAndOwners2[0].map((i, j) => [i, tokensAndOwners2[1][j]]));
145
170
  if (token)
@@ -157,11 +182,12 @@ class ChainApi {
157
182
  tokensAndOwners = tokensAndOwners.filter(i => !blacklistedTokens.includes(i[0]) && !blacklistedOwners.includes(i[1]));
158
183
  const ethBalOwners = tokensAndOwners.filter(i => i[0] === nullAddress).map(i => i[1]);
159
184
  tokensAndOwners = tokensAndOwners.filter(i => i[0] !== nullAddress);
185
+ this.addStat('sumTokens', tokensAndOwners.length + ethBalOwners.length, true);
160
186
  const bals = await this.multiCall({
161
187
  calls: tokensAndOwners.map(i => ({ target: i[0], params: [i[1]] })),
162
188
  abi: 'erc20:balanceOf',
163
189
  });
164
- this.addTokens(tokensAndOwners.map(i => i[0]), bals);
190
+ this.addTokens(tokensAndOwners.map(i => i[0]), bals, balancesV2Options);
165
191
  if (ethBalOwners.length) {
166
192
  let ethBals = [];
167
193
  const multicallAddress = (0, multicall3_1.getMulticallAddress)(this.chain, this.block);
@@ -176,7 +202,7 @@ class ChainApi {
176
202
  const res = await (0, eth_1.getBalances)({ chain: this.chain, targets: ethBalOwners, block: this.block });
177
203
  ethBals = res.output.map((i) => i.balance);
178
204
  }
179
- ethBals.map(i => this.addToken(nullAddress, i));
205
+ ethBals.map(i => this.addToken(nullAddress, i, balancesV2Options));
180
206
  }
181
207
  return this.getBalances();
182
208
  }
@@ -190,6 +216,8 @@ class ChainApi {
190
216
  return this._balances.getUSDJSONs();
191
217
  }
192
218
  async getLogs(params) {
219
+ var _a;
220
+ this.addStat('getLogs', ((_a = params.targets) === null || _a === void 0 ? void 0 : _a.length) || 1);
193
221
  params.chain = this.chain;
194
222
  return (0, logs_1.default)(params);
195
223
  }
@@ -197,9 +225,11 @@ class ChainApi {
197
225
  return this._balances;
198
226
  }
199
227
  async getTransactions(params) {
228
+ this.addStat('getTransactions');
200
229
  return (0, transactions_1.getTransactions)({ ...params, chain: this.chain });
201
230
  }
202
231
  async getTransactionReceipt(tx) {
232
+ this.addStat('getTransactionReceipt');
203
233
  return this.provider.getTransactionReceipt(tx);
204
234
  }
205
235
  }
@@ -212,3 +242,7 @@ function getUniqueTokensAndOwners(toa, chain) {
212
242
  const uniqueMerged = (0, generalUtil_1.getUniqueAddresses)(mergedToa, chain);
213
243
  return uniqueMerged.map(i => i.split('~'));
214
244
  }
245
+ function getDebugStats() {
246
+ return callStatsByProject;
247
+ }
248
+ exports.getDebugStats = getDebugStats;
@@ -201,6 +201,12 @@ const DEPLOYMENT_BLOCK = {
201
201
  lens: 1,
202
202
  basecamp: 1,
203
203
  platon: 1,
204
+ xrplevm: 1,
205
+ katana: 1,
206
+ mint: 1,
207
+ btnx: 1,
208
+ vechain: 22103870,
209
+ tac: 1,
204
210
  };
205
211
  async function makeMultiCall(functionABI, calls, chain, block) {
206
212
  if (chain === 'tron')
@@ -344,6 +350,12 @@ function getMulticallAddress(chain, block) {
344
350
  case 'hedera':
345
351
  multicallAddress = '0x18fa376d92511dd04090566ab6144847c03557d8';
346
352
  break;
353
+ case 'xrplevm':
354
+ multicallAddress = '0xaB3a12b26e72F4D6D9B579aCb5027a0918eF1114';
355
+ break;
356
+ case 'vechain':
357
+ multicallAddress = '0x8B2fF167683c5e1DFD6717d934B560F20cf9F2a3';
358
+ break;
347
359
  }
348
360
  return multicallAddress;
349
361
  }