@metamask-previews/assets-controller 20.0.1-preview-9fd631f7d → 20.0.1-preview-6fbab7311

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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Changed
11
+
12
+ - Use hand-rolled Multicall3 `aggregate3` codecs for balance batches, while retaining the Ethers codecs for byte-identical comparison ([#11078](https://github.com/MetaMask/core/pull/11078))
13
+
10
14
  ## [20.0.1]
11
15
 
12
16
  ### Changed
@@ -1,28 +1,40 @@
1
1
  import type { Hex } from '@metamask/utils';
2
- import type { Address, BalanceOfRequest, BalanceOfResponse, ChainId, GetProviderFunction } from '../types/index.js';
2
+ import type { BalanceOfRequest, BalanceOfResponse, ChainId, GetProviderFunction } from '../types/index.js';
3
+ import type { Aggregate3Call } from './aggregate3Codec.js';
3
4
  /**
4
- * Encode a Multicall3 aggregate3 call.
5
+ * Encode a Multicall3 aggregate3 call with the Ethers ABI coder.
6
+ *
7
+ * `MulticallClient` calls `encodeAggregate3` from `aggregate3Codec.ts`.
8
+ * This function stays so those tests can compare the two encodings.
5
9
  *
6
10
  * @param calls - Array of calls with target, allowFailure, and callData.
7
11
  * @returns The encoded aggregate3 call data.
8
12
  */
9
- export declare function encodeAggregate3(calls: readonly {
10
- target: Address;
11
- allowFailure: boolean;
12
- callData: Hex;
13
- }[]): Hex;
13
+ export declare function encodeAggregate3WithEthers(calls: readonly Aggregate3Call[]): Hex;
14
14
  /**
15
- * Decode the response from aggregate3.
16
- * Returns array of (success, returnData) tuples.
15
+ * Decode the response from aggregate3 with the Ethers ABI coder.
16
+ *
17
+ * `MulticallClient` calls `decodeAggregate3Response` from `aggregate3Codec.ts`.
18
+ * This function stays so those tests can compare the two decodings.
17
19
  *
18
20
  * @param data - The raw response data.
19
21
  * @param callCount - Number of calls made (used for validation).
20
22
  * @returns Array of success and return data.
21
23
  */
22
- export declare function decodeAggregate3Response(data: Hex, callCount: number): {
24
+ export declare function decodeAggregate3ResponseWithEthers(data: Hex, callCount: number): {
23
25
  success: boolean;
24
26
  returnData: Hex;
25
27
  }[];
28
+ /**
29
+ * Decode a uint256 balance with the Ethers ABI coder.
30
+ *
31
+ * `MulticallClient` calls `decodeUint256` from `aggregate3Codec.ts`.
32
+ * This function stays so those tests can compare the two decodings.
33
+ *
34
+ * @param data - The hex return data.
35
+ * @returns The decoded balance as a string.
36
+ */
37
+ export declare function decodeUint256WithEthers(data: Hex): string;
26
38
  export type MulticallClientConfig = {
27
39
  maxCallsPerBatch?: number;
28
40
  timeoutMs?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"MulticallClient.d.ts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/clients/MulticallClient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,KAAK,EACV,OAAO,EACP,gBAAgB,EAChB,iBAAiB,EACjB,OAAO,EACP,mBAAmB,EAEpB,MAAM,mBAAmB,CAAC;AAyc3B;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,YAAY,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,GAAG,CAAA;CAAE,EAAE,GAC1E,GAAG,CAQL;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,GAAG,EACT,SAAS,EAAE,MAAM,GAChB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,GAAG,CAAA;CAAE,EAAE,CAiBzC;AAwBD,MAAM,MAAM,qBAAqB,GAAG;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oCAAoC,GAAG,CACjD,OAAO,EAAE,OAAO,KACb,GAAG,GAAG,SAAS,CAAC;AAErB;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,EAAE,mBAAmB,CAAC;IACjC,4BAA4B,EAAE,oCAAoC,CAAC;IACnE,MAAM,CAAC,EAAE,qBAAqB,CAAC;CAChC,CAAC;AAEF;;;GAGG;AACH,qBAAa,eAAe;;IAO1B,YAAY,EACV,WAAW,EACX,4BAA4B,EAC5B,MAAM,GACP,EAAE,sBAAsB,EAiBxB;IAED;;;;;;;;OAQG;IACG,cAAc,CAClB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,OAAO;QAAK,qBAAqB;KAAS,GACzC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAuB9B;CA4LF"}
1
+ {"version":3,"file":"MulticallClient.d.ts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/clients/MulticallClient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,KAAK,EAEV,gBAAgB,EAChB,iBAAiB,EACjB,OAAO,EACP,mBAAmB,EAEpB,MAAM,mBAAmB,CAAC;AAO3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAwc3D;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,SAAS,cAAc,EAAE,GAC/B,GAAG,CAQL;AAED;;;;;;;;;GASG;AACH,wBAAgB,kCAAkC,CAChD,IAAI,EAAE,GAAG,EACT,SAAS,EAAE,MAAM,GAChB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,GAAG,CAAA;CAAE,EAAE,CAiBzC;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAOzD;AASD,MAAM,MAAM,qBAAqB,GAAG;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oCAAoC,GAAG,CACjD,OAAO,EAAE,OAAO,KACb,GAAG,GAAG,SAAS,CAAC;AAErB;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,WAAW,EAAE,mBAAmB,CAAC;IACjC,4BAA4B,EAAE,oCAAoC,CAAC;IACnE,MAAM,CAAC,EAAE,qBAAqB,CAAC;CAChC,CAAC;AAEF;;;GAGG;AACH,qBAAa,eAAe;;IAO1B,YAAY,EACV,WAAW,EACX,4BAA4B,EAC5B,MAAM,GACP,EAAE,sBAAsB,EAiBxB;IAED;;;;;;;;OAQG;IACG,cAAc,CAClB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,OAAO;QAAK,qBAAqB;KAAS,GACzC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAuB9B;CA4LF"}
@@ -2,6 +2,7 @@ import { Interface } from '@ethersproject/abi';
2
2
  import { createServicePolicy, encodeFunctionData, } from '@metamask/controller-utils';
3
3
  import { ZERO_ADDRESS } from '../../../utils/constants.js';
4
4
  import { reduceInBatchesSerially } from '../utils/index.js';
5
+ import { decodeAggregate3Response, decodeUint256, encodeAggregate3, } from './aggregate3Codec.js';
5
6
  // =============================================================================
6
7
  // ABI DEFINITIONS
7
8
  // =============================================================================
@@ -436,12 +437,15 @@ function buildAggregate3BalanceCalls(batch, multicallAddress) {
436
437
  });
437
438
  }
438
439
  /**
439
- * Encode a Multicall3 aggregate3 call.
440
+ * Encode a Multicall3 aggregate3 call with the Ethers ABI coder.
441
+ *
442
+ * `MulticallClient` calls `encodeAggregate3` from `aggregate3Codec.ts`.
443
+ * This function stays so those tests can compare the two encodings.
440
444
  *
441
445
  * @param calls - Array of calls with target, allowFailure, and callData.
442
446
  * @returns The encoded aggregate3 call data.
443
447
  */
444
- export function encodeAggregate3(calls) {
448
+ export function encodeAggregate3WithEthers(calls) {
445
449
  return encodeFunctionData(multicall3Interface, 'aggregate3', [
446
450
  calls.map((call) => ({
447
451
  target: call.target,
@@ -451,14 +455,16 @@ export function encodeAggregate3(calls) {
451
455
  ]);
452
456
  }
453
457
  /**
454
- * Decode the response from aggregate3.
455
- * Returns array of (success, returnData) tuples.
458
+ * Decode the response from aggregate3 with the Ethers ABI coder.
459
+ *
460
+ * `MulticallClient` calls `decodeAggregate3Response` from `aggregate3Codec.ts`.
461
+ * This function stays so those tests can compare the two decodings.
456
462
  *
457
463
  * @param data - The raw response data.
458
464
  * @param callCount - Number of calls made (used for validation).
459
465
  * @returns Array of success and return data.
460
466
  */
461
- export function decodeAggregate3Response(data, callCount) {
467
+ export function decodeAggregate3ResponseWithEthers(data, callCount) {
462
468
  const decoded = multicall3Interface.decodeFunctionResult('aggregate3', data);
463
469
  // decoded[0] is the array of (success, returnData) tuples
464
470
  const results = decoded[0];
@@ -471,12 +477,15 @@ export function decodeAggregate3Response(data, callCount) {
471
477
  }));
472
478
  }
473
479
  /**
474
- * Decode a uint256 balance from return data.
480
+ * Decode a uint256 balance with the Ethers ABI coder.
481
+ *
482
+ * `MulticallClient` calls `decodeUint256` from `aggregate3Codec.ts`.
483
+ * This function stays so those tests can compare the two decodings.
475
484
  *
476
485
  * @param data - The hex return data.
477
486
  * @returns The decoded balance as a string.
478
487
  */
479
- function decodeUint256(data) {
488
+ export function decodeUint256WithEthers(data) {
480
489
  if (data === '0x' || data.length < 66) {
481
490
  // Empty or invalid data; treat as 0
482
491
  return '0';
@@ -1 +1 @@
1
- {"version":3,"file":"MulticallClient.js","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/clients/MulticallClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;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C;YAC/D,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC;gBACjC,EAAE,EAAE,YAAY;gBAChB,IAAI,EAAE,QAAQ;aACf,CAAC,CAAC;YAEH,MAAM,OAAO,GAAG,aAAa,CAAC,MAAa,CAAC,CAAC;YAC7C,OAAO;gBACL,YAAY;gBACZ,cAAc;gBACd,OAAO,EAAE,IAAI;gBACb,OAAO;aACR,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,sBAAsB,CAAC,QAA4B;QACjD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,qBAAqB,CAAC,OAAyB;QAC7C,OAAO;YACL,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,OAAO,EAAE,KAAK;SACf,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport {\n createServicePolicy,\n encodeFunctionData,\n} from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { ZERO_ADDRESS } from '../../../utils/constants.js';\nimport type {\n Address,\n BalanceOfRequest,\n BalanceOfResponse,\n ChainId,\n GetProviderFunction,\n Provider,\n} from '../types/index.js';\nimport { reduceInBatchesSerially } from '../utils/index.js';\n\n// =============================================================================\n// ABI DEFINITIONS\n// =============================================================================\n\n/**\n * Multicall3 contract ABI (subset for aggregate3 and getEthBalance).\n *\n * @see https://github.com/mds1/multicall\n */\nconst MULTICALL3_ABI = [\n {\n name: 'aggregate3',\n type: 'function',\n stateMutability: 'payable',\n inputs: [\n {\n name: 'calls',\n type: 'tuple[]',\n components: [\n { name: 'target', type: 'address' },\n { name: 'allowFailure', type: 'bool' },\n { name: 'callData', type: 'bytes' },\n ],\n },\n ],\n outputs: [\n {\n name: 'returnData',\n type: 'tuple[]',\n components: [\n { name: 'success', type: 'bool' },\n { name: 'returnData', type: 'bytes' },\n ],\n },\n ],\n },\n {\n name: 'getEthBalance',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'addr', type: 'address' }],\n outputs: [{ name: 'balance', type: 'uint256' }],\n },\n];\n\n/**\n * ERC-20 ABI (subset for balanceOf).\n */\nconst ERC20_ABI = [\n {\n name: 'balanceOf',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'account', type: 'address' }],\n outputs: [{ name: 'balance', type: 'uint256' }],\n },\n];\n\n/**\n * Interface instances for ABI encoding/decoding.\n */\nconst multicall3Interface = new Interface(MULTICALL3_ABI);\nconst erc20Interface = new Interface(ERC20_ABI);\n\n// =============================================================================\n// CONSTANTS\n// =============================================================================\n\n/**\n * Multicall3 contract addresses by chain ID.\n * Source: https://github.com/mds1/multicall/blob/main/deployments.json\n *\n * TODO: try to find service to use here instead of hardcoding the addresses\n */\nconst MULTICALL3_ADDRESS_BY_CHAIN: Record<Hex, Hex> = {\n '0x1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xaa36a7': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4268': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5e9': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1b6e6': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x18fc4a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x45': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1a4': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xaa37dc': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa4b1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa4ba': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x66eed': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x66eee': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x66eeb': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15f2249': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x89': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x13881': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x13882': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x44d': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x5a2': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x98a': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x64': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x27d8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa86a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa869': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xfa2': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xfa': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xfaf0': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x38': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x61': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15eb': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xcc': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x504': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x505': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x507': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2a15c308d': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x2a15c3083': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x63564c40': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x19': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x152': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5535072': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x6c1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x7a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x13': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x10': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x72': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x120': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4e454152': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x250': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5c2359': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xec0': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x42': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x80': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x440': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x257': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe9fe': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xd3a0': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x84444': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1e': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2329': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2328': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x6c': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x12': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa516': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5afe': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa4ec': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xaef3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x116ea': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x116e9': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2019': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3e9': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x7d1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x141': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x6a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x28': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4d2': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1e14': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1e15': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1251': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x7f08': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8ae': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x138b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1389': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1388': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1f92': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x14a33': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x14a34': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2105': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x936': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xff': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x46a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x46b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x14f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xd2af': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe9ac0ce': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe705': '0xca11bde05977b3631167028862be2a173976ca11',\n '0xe704': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe708': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2b6f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x39': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x23a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1644': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xdea8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3af': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x171': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3e7': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x76adf1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3b9ac9ff': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2c': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x2e': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x15b3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x82751': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8274f': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x82750': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x96f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3cc5': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4571': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe99': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x7d0': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1297': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1d5e': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3a14269b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x561bf78b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x235ddd0': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3cd156dc': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5d456c62': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x79f99296': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x585eb4b1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x507aaa2a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1fc3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x32d': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8a73': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8a72': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8a71': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe9ac0d6': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x1069': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x7e5': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x53': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x52': '0xca11bde05977b3631167028862be2a173976ca11',\n '0xe298': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1a8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x94': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2c6': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2803': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2802': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa9': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x28c5f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x28c60': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x13a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4cb2f': '0xdbfa261cd7d17bb40479a0493ad6c0fee435859e',\n '0x7f93': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xb660': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xb02113d3f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xdad': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xdae': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15b38': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15b32': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x45c': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x45b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3d': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x41a6ace': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa729': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1f47b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1b59': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x1b58': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xc3': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x16fd8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xc7': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x405': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x334': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1ce': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x1cf': '0xca11bde05977b3631167028862be2a173976ca11',\n '0xa70e': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x868b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa0c71fd': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x13e31': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa1337': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1f2b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xf63': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x144': '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n '0x118': '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n '0x12c': '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n '0x18995f': '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n '0x2b74': '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n '0xfc': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x9da': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x137': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x13ed': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x24b1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xba9302': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x7c8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x138d5': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x6d': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x343b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x34a1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3109': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x91b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa96': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x22c3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2be3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xbf03': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1b254': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa7b14': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2276': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1b9e': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x6a63bb8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15af3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15af1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xae3f3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x531': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x28c61': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x28c58': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x1d88': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5b9b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4c7e1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa53b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1a2b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x406': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x2cef': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x18b2': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x182a9': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xc4': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xfdd': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xfde': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x99c0a0f': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x22cf': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x310c5': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x46f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x659': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x139c968f9': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xed88': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xd036': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1f3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x31bf8c3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1cbc67bfdc': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x98967f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4f588': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x16db': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x3a': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x59': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x1e0': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2eb': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x221': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x6f0': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa867': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2611': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa6': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15f900': '0x6B5eFbC0C82eBb26CA13a4F11836f36Fc6fdBC5D',\n '0x74c': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x407b': '0x90a2377F233E3461BACa6080d4837837d8762927',\n '0xa3c3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xab5': '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n '0x138de': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x18c6': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8173': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2ba': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x279f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xb67d2': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x18232': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x32': '0x0B1795ccA8E4eC4df02346a082df54D437F8D9aF',\n '0x18c7': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x10e6': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x10b3e': '0x99423C88EB5723A590b4C644426069042f137B9e',\n // Ink Mainnet\n '0xdef1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n // Stable (988)\n '0x3dc': '0xcA11bde05977b3631167028862bE2a173976CA11',\n // Tempo Mainnet\n '0x1079': '0xcA11bde05977b3631167028862bE2a173976CA11',\n // Tempo Testnet Moderato\n '0xa5bf': '0xcA11bde05977b3631167028862bE2a173976CA11',\n // Arc (5042)\n '0x13b2': '0xcA11bde05977b3631167028862bE2a173976CA11',\n // Robinhood Chain (4663)\n '0x1237': '0xcA11bde05977b3631167028862bE2a173976CA11',\n // Somnia (5031), MultiCallV3 per docs.somnia.network/developer/smart-contracts\n '0x13a7': '0x5e44F178E8cF9B2F5409B6f18ce936aB817C5a11',\n};\n\n// =============================================================================\n// ENCODING/DECODING UTILITIES (using @ethersproject/abi)\n// =============================================================================\n\n/**\n * Encode a balanceOf call for an ERC-20 token.\n *\n * @param accountAddress - The account address.\n * @returns The encoded call data.\n */\nfunction encodeBalanceOf(accountAddress: Address): Hex {\n return encodeFunctionData(erc20Interface, 'balanceOf', [accountAddress]);\n}\n\n/**\n * Encode a getEthBalance call for native token via Multicall3.\n *\n * @param accountAddress - The account address.\n * @returns The encoded call data.\n */\nfunction encodeGetEthBalance(accountAddress: Address): Hex {\n return encodeFunctionData(multicall3Interface, 'getEthBalance', [\n accountAddress,\n ]);\n}\n\ntype BalanceCallDataCache = {\n getErc20BalanceCallData: (accountAddress: Address) => Hex;\n getNativeBalanceCallData: (accountAddress: Address) => Hex;\n};\n\nfunction createBalanceCallDataCache(): BalanceCallDataCache {\n const erc20ByAccount = new Map<string, Hex>();\n const nativeByAccount = new Map<string, Hex>();\n\n return {\n getErc20BalanceCallData(accountAddress: Address): Hex {\n const key = accountAddress.toLowerCase();\n const existing = erc20ByAccount.get(key);\n if (existing !== undefined) {\n return existing;\n }\n const callData = encodeBalanceOf(accountAddress);\n erc20ByAccount.set(key, callData);\n return callData;\n },\n getNativeBalanceCallData(accountAddress: Address): Hex {\n const key = accountAddress.toLowerCase();\n const existing = nativeByAccount.get(key);\n if (existing !== undefined) {\n return existing;\n }\n const callData = encodeGetEthBalance(accountAddress);\n nativeByAccount.set(key, callData);\n return callData;\n },\n };\n}\n\n/**\n * Cache balance call encodings per account address.\n * ERC-20 `balanceOf` and native `getEthBalance` call data depend only on the\n * account being queried, not the token contract (which is the multicall target).\n */\nconst balanceCallDataCache = createBalanceCallDataCache();\n\n/**\n * Build Multicall3 aggregate3 calls for a batch of balance requests.\n *\n * @param batch - Balance requests in the current batch.\n * @param multicallAddress - Multicall3 contract address for native balance calls.\n * @returns Aggregate3 call descriptors.\n */\nfunction buildAggregate3BalanceCalls(\n batch: BalanceOfRequest[],\n multicallAddress: Hex,\n): { target: Address; allowFailure: boolean; callData: Hex }[] {\n return batch.map((req) => {\n const isNative = req.tokenAddress === ZERO_ADDRESS;\n const target = isNative ? multicallAddress : req.tokenAddress;\n return {\n target,\n allowFailure: true,\n callData: isNative\n ? balanceCallDataCache.getNativeBalanceCallData(req.accountAddress)\n : balanceCallDataCache.getErc20BalanceCallData(req.accountAddress),\n };\n });\n}\n\n/**\n * Encode a Multicall3 aggregate3 call.\n *\n * @param calls - Array of calls with target, allowFailure, and callData.\n * @returns The encoded aggregate3 call data.\n */\nexport function encodeAggregate3(\n calls: readonly { target: Address; allowFailure: boolean; callData: Hex }[],\n): Hex {\n return encodeFunctionData(multicall3Interface, 'aggregate3', [\n calls.map((call) => ({\n target: call.target,\n allowFailure: call.allowFailure,\n callData: call.callData,\n })),\n ]);\n}\n\n/**\n * Decode the response from aggregate3.\n * Returns array of (success, returnData) tuples.\n *\n * @param data - The raw response data.\n * @param callCount - Number of calls made (used for validation).\n * @returns Array of success and return data.\n */\nexport function decodeAggregate3Response(\n data: Hex,\n callCount: number,\n): { success: boolean; returnData: Hex }[] {\n const decoded = multicall3Interface.decodeFunctionResult('aggregate3', data);\n\n // decoded[0] is the array of (success, returnData) tuples\n const results = decoded[0] as readonly {\n success: boolean;\n returnData: string;\n }[];\n\n if (results.length !== callCount) {\n throw new Error(`Expected ${callCount} results, got ${results.length}`);\n }\n\n return results.map((result) => ({\n success: result.success,\n returnData: result.returnData as Hex,\n }));\n}\n\n/**\n * Decode a uint256 balance from return data.\n *\n * @param data - The hex return data.\n * @returns The decoded balance as a string.\n */\nfunction decodeUint256(data: Hex): string {\n if (data === '0x' || data.length < 66) {\n // Empty or invalid data; treat as 0\n return '0';\n }\n const decoded = erc20Interface.decodeFunctionResult('balanceOf', data);\n return decoded[0].toString();\n}\n\n// =============================================================================\n// MULTICALL CLIENT\n// =============================================================================\n\n/** Retries after the initial multicall attempt before returning failed responses. */\nconst MULTICALL_MAX_RETRIES = 2;\n\nexport type MulticallClientConfig = {\n maxCallsPerBatch?: number;\n timeoutMs?: number;\n};\n\n/**\n * Function for retrieving the Multicall3 contract address for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @returns The Multicall3 contract address, or undefined if not supported.\n */\nexport type GetMulticall3AddressForChainFunction = (\n chainId: ChainId,\n) => Hex | undefined;\n\n/**\n * Options for creating a MulticallClient.\n */\nexport type MulticallClientOptions = {\n getProvider: GetProviderFunction;\n getMulticall3AddressForChain: GetMulticall3AddressForChainFunction;\n config?: MulticallClientConfig;\n};\n\n/**\n * Client for batching RPC calls using Multicall3.\n * Falls back to individual calls on chains without Multicall3 support.\n */\nexport class MulticallClient {\n readonly #getProvider: GetProviderFunction;\n\n readonly #config: Required<MulticallClientConfig>;\n\n readonly #getMulticall3AddressForChain: GetMulticall3AddressForChainFunction;\n\n constructor({\n getProvider,\n getMulticall3AddressForChain,\n config,\n }: MulticallClientOptions) {\n this.#getProvider = getProvider;\n // Use default values for invalid (non-positive) batch sizes to prevent\n // infinite loops or errors in divideIntoBatches\n const maxCallsPerBatch =\n config?.maxCallsPerBatch !== undefined && config.maxCallsPerBatch > 0\n ? config.maxCallsPerBatch\n : 300;\n const timeoutMs =\n config?.timeoutMs !== undefined && config.timeoutMs > 0\n ? config.timeoutMs\n : 30000;\n this.#config = {\n maxCallsPerBatch,\n timeoutMs,\n };\n this.#getMulticall3AddressForChain = getMulticall3AddressForChain;\n }\n\n /**\n * Fetch ERC-20 and native token balances using Multicall3.\n * Falls back to individual RPC calls on unsupported chains.\n *\n * @param chainId - The chain ID.\n * @param requests - Array of balance requests.\n * @param options - Optional batch options (e.g. single-call fallback).\n * @returns Array of balance responses.\n */\n async batchBalanceOf(\n chainId: ChainId,\n requests: BalanceOfRequest[],\n options = { fallbackToSingleCalls: false },\n ): Promise<BalanceOfResponse[]> {\n if (requests.length === 0) {\n return [];\n }\n\n const multicallAddress =\n this.#getMulticall3AddressForChain(chainId) ??\n MULTICALL3_ADDRESS_BY_CHAIN[chainId];\n const provider = this.#getProvider(chainId);\n\n if (!multicallAddress) {\n return options.fallbackToSingleCalls\n ? this.#fallbackBatchBalanceOf(provider, requests)\n : this.#createFailedResponses(requests);\n }\n\n // Use Multicall3\n return this.#multicallBatchBalanceOf(\n provider,\n multicallAddress,\n requests,\n options.fallbackToSingleCalls,\n );\n }\n\n /**\n * Fetch balances using Multicall3 aggregate3.\n *\n * @param provider - The RPC provider.\n * @param multicallAddress - The Multicall3 contract address.\n * @param requests - Array of balance requests.\n * @param fallbackToSingleCalls - Whether to fall back to individual RPC calls on batch failure.\n * @returns Array of balance responses.\n */\n async #multicallBatchBalanceOf(\n provider: Provider,\n multicallAddress: Hex,\n requests: BalanceOfRequest[],\n fallbackToSingleCalls: boolean,\n ): Promise<BalanceOfResponse[]> {\n const batchSize = this.#config.maxCallsPerBatch;\n\n const responses = await reduceInBatchesSerially<\n BalanceOfRequest,\n BalanceOfResponse[]\n >({\n values: requests,\n batchSize,\n initialResult: [],\n eachBatch: async (workingResult, batch) => {\n const calls = buildAggregate3BalanceCalls(batch, multicallAddress);\n\n try {\n await createServicePolicy({\n maxRetries: MULTICALL_MAX_RETRIES,\n }).execute(async () => {\n // Encode and send aggregate3 call\n const callData = encodeAggregate3(calls);\n const result = await provider.call({\n to: multicallAddress,\n data: callData,\n });\n\n // Decode response\n const decoded = decodeAggregate3Response(\n result as Hex,\n batch.length,\n );\n\n // Map results back to responses\n for (let i = 0; i < batch.length; i++) {\n const { tokenAddress, accountAddress } = batch[i];\n const { success, returnData } = decoded[i];\n\n if (success && returnData && returnData.length > 2) {\n workingResult.push({\n tokenAddress,\n accountAddress,\n success: true,\n balance: decodeUint256(returnData),\n });\n } else {\n workingResult.push({\n tokenAddress,\n accountAddress,\n success: false,\n });\n }\n }\n });\n } catch {\n if (fallbackToSingleCalls) {\n // On aggregate3 error, fall back to individual calls for this batch.\n // #fetchSingleBalance never rejects - it catches all errors internally\n // and returns a failed response, so we use Promise.all here.\n const fallbackResults = await Promise.all(\n batch.map((req) => this.#fetchSingleBalance(provider, req)),\n );\n\n for (const result of fallbackResults) {\n workingResult.push(result);\n }\n } else {\n workingResult.push(...this.#createFailedResponses(batch));\n }\n }\n\n return workingResult;\n },\n });\n\n return responses;\n }\n\n /**\n * Fallback: fetch balances using individual RPC calls.\n *\n * @param provider - The RPC provider.\n * @param requests - Array of balance requests.\n * @returns Array of balance responses.\n */\n async #fallbackBatchBalanceOf(\n provider: Provider,\n requests: BalanceOfRequest[],\n ): Promise<BalanceOfResponse[]> {\n // Use smaller batch size for parallel individual calls to avoid overwhelming RPC\n const batchSize = Math.min(this.#config.maxCallsPerBatch, 50);\n\n const responses = await reduceInBatchesSerially<\n BalanceOfRequest,\n BalanceOfResponse[]\n >({\n values: requests,\n batchSize,\n initialResult: [],\n eachBatch: async (workingResult, batch) => {\n // #fetchSingleBalance never rejects - it catches all errors internally\n // and returns a failed response, so we use Promise.all here.\n const batchResults = await Promise.all(\n batch.map((req) => this.#fetchSingleBalance(provider, req)),\n );\n\n for (const result of batchResults) {\n workingResult.push(result);\n }\n\n return workingResult;\n },\n });\n\n return responses;\n }\n\n /**\n * Fetch a single token balance (fallback method).\n *\n * @param provider - The RPC provider.\n * @param request - The balance request.\n * @returns The balance response.\n */\n async #fetchSingleBalance(\n provider: Provider,\n request: BalanceOfRequest,\n ): Promise<BalanceOfResponse> {\n // Destructure inside try block to ensure any errors are caught\n // and don't cause promise rejections that bypass error handling\n try {\n const { tokenAddress, accountAddress } = request;\n\n // Native token (zero address)\n if (tokenAddress === ZERO_ADDRESS) {\n const balance = await provider.getBalance(accountAddress);\n return {\n tokenAddress,\n accountAddress,\n success: true,\n balance: balance.toString(),\n };\n }\n\n // ERC-20 token\n const callData =\n balanceCallDataCache.getErc20BalanceCallData(accountAddress);\n const result = await provider.call({\n to: tokenAddress,\n data: callData,\n });\n\n const balance = decodeUint256(result as Hex);\n return {\n tokenAddress,\n accountAddress,\n success: true,\n balance,\n };\n } catch {\n return this.#createFailedResponse(request);\n }\n }\n\n #createFailedResponses(requests: BalanceOfRequest[]): BalanceOfResponse[] {\n return requests.map((request) => this.#createFailedResponse(request));\n }\n\n #createFailedResponse(request: BalanceOfRequest): BalanceOfResponse {\n return {\n tokenAddress: request.tokenAddress,\n accountAddress: request.accountAddress,\n success: false,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"MulticallClient.js","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/clients/MulticallClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAS3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,aAAa,EACb,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAG9B,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,cAAc,GAAG;IACrB;QACE,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,SAAS;QAC1B,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,SAAS;gBACf,UAAU,EAAE;oBACV,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;oBACnC,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE;oBACtC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE;iBACpC;aACF;SACF;QACD,OAAO,EAAE;Y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AC7C,OAAO;YACL,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,cAAc,EAAE,OAAO,CAAC,cAAc;YACtC,OAAO,EAAE,KAAK;SACf,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport {\n createServicePolicy,\n encodeFunctionData,\n} from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { ZERO_ADDRESS } from '../../../utils/constants.js';\nimport type {\n Address,\n BalanceOfRequest,\n BalanceOfResponse,\n ChainId,\n GetProviderFunction,\n Provider,\n} from '../types/index.js';\nimport { reduceInBatchesSerially } from '../utils/index.js';\nimport {\n decodeAggregate3Response,\n decodeUint256,\n encodeAggregate3,\n} from './aggregate3Codec.js';\nimport type { Aggregate3Call } from './aggregate3Codec.js';\n\n// =============================================================================\n// ABI DEFINITIONS\n// =============================================================================\n\n/**\n * Multicall3 contract ABI (subset for aggregate3 and getEthBalance).\n *\n * @see https://github.com/mds1/multicall\n */\nconst MULTICALL3_ABI = [\n {\n name: 'aggregate3',\n type: 'function',\n stateMutability: 'payable',\n inputs: [\n {\n name: 'calls',\n type: 'tuple[]',\n components: [\n { name: 'target', type: 'address' },\n { name: 'allowFailure', type: 'bool' },\n { name: 'callData', type: 'bytes' },\n ],\n },\n ],\n outputs: [\n {\n name: 'returnData',\n type: 'tuple[]',\n components: [\n { name: 'success', type: 'bool' },\n { name: 'returnData', type: 'bytes' },\n ],\n },\n ],\n },\n {\n name: 'getEthBalance',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'addr', type: 'address' }],\n outputs: [{ name: 'balance', type: 'uint256' }],\n },\n];\n\n/**\n * ERC-20 ABI (subset for balanceOf).\n */\nconst ERC20_ABI = [\n {\n name: 'balanceOf',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'account', type: 'address' }],\n outputs: [{ name: 'balance', type: 'uint256' }],\n },\n];\n\n/**\n * Interface instances for ABI encoding/decoding.\n */\nconst multicall3Interface = new Interface(MULTICALL3_ABI);\nconst erc20Interface = new Interface(ERC20_ABI);\n\n// =============================================================================\n// CONSTANTS\n// =============================================================================\n\n/**\n * Multicall3 contract addresses by chain ID.\n * Source: https://github.com/mds1/multicall/blob/main/deployments.json\n *\n * TODO: try to find service to use here instead of hardcoding the addresses\n */\nconst MULTICALL3_ADDRESS_BY_CHAIN: Record<Hex, Hex> = {\n '0x1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xaa36a7': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4268': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5e9': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1b6e6': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x18fc4a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x45': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1a4': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xaa37dc': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa4b1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa4ba': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x66eed': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x66eee': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x66eeb': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15f2249': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x89': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x13881': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x13882': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x44d': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x5a2': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x98a': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x64': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x27d8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa86a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa869': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xfa2': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xfa': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xfaf0': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x38': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x61': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15eb': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xcc': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x504': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x505': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x507': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2a15c308d': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x2a15c3083': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x63564c40': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x19': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x152': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5535072': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x6c1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x7a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x13': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x10': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x72': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x120': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4e454152': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x250': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5c2359': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xec0': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x42': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x80': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x440': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x257': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe9fe': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xd3a0': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x84444': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1e': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2329': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2328': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x6c': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x12': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa516': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5afe': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa4ec': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xaef3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x116ea': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x116e9': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2019': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3e9': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x7d1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x141': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x6a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x28': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4d2': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1e14': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1e15': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1251': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x7f08': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8ae': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x138b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1389': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1388': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1f92': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x14a33': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x14a34': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2105': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x936': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xff': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x46a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x46b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x14f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xd2af': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe9ac0ce': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe705': '0xca11bde05977b3631167028862be2a173976ca11',\n '0xe704': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe708': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2b6f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x39': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x23a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1644': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xdea8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3af': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x171': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3e7': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x76adf1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3b9ac9ff': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2c': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x2e': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x15b3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x82751': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8274f': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x82750': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x96f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3cc5': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4571': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe99': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x7d0': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1297': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1d5e': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3a14269b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x561bf78b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x235ddd0': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3cd156dc': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5d456c62': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x79f99296': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x585eb4b1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x507aaa2a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1fc3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x32d': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8a73': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8a72': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8a71': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe9ac0d6': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x1069': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x7e5': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x53': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x52': '0xca11bde05977b3631167028862be2a173976ca11',\n '0xe298': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1a8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x94': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2c6': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2803': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2802': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa9': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x28c5f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x28c60': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x13a': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4cb2f': '0xdbfa261cd7d17bb40479a0493ad6c0fee435859e',\n '0x7f93': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xb660': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xb02113d3f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xdad': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xdae': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15b38': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15b32': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x45c': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x45b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3d': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x41a6ace': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa729': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1f47b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1b59': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x1b58': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xc3': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x16fd8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xc7': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x405': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x334': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1ce': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x1cf': '0xca11bde05977b3631167028862be2a173976ca11',\n '0xa70e': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x868b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa0c71fd': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x13e31': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa1337': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1f2b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xf63': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x144': '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n '0x118': '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n '0x12c': '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n '0x18995f': '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n '0x2b74': '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n '0xfc': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x9da': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x137': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x13ed': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x24b1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xba9302': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x7c8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x138d5': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x6d': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x343b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x34a1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x3109': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x91b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa96': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x22c3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2be3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xbf03': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1b254': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa7b14': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2276': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1b9e': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x6a63bb8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15af3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15af1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xae3f3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x531': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x28c61': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x28c58': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x1d88': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x5b9b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4c7e1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa53b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1a2b': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x406': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x2cef': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x18b2': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x182a9': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xc4': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xfdd': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xfde': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x99c0a0f': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x22cf': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x310c5': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x46f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x659': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x139c968f9': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xed88': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xd036': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1f3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x31bf8c3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x1cbc67bfdc': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x98967f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x4f588': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x16db': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x3a': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x59': '0xca11bde05977b3631167028862be2a173976ca11',\n '0x1e0': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2eb': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x221': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x6f0': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa867': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2611': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xa6': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x15f900': '0x6B5eFbC0C82eBb26CA13a4F11836f36Fc6fdBC5D',\n '0x74c': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x407b': '0x90a2377F233E3461BACa6080d4837837d8762927',\n '0xa3c3': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xab5': '0xF9cda624FBC7e059355ce98a31693d299FACd963',\n '0x138de': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x18c6': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8173': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x2ba': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x279f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xb67d2': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0xe8': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x18232': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x8f': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x32': '0x0B1795ccA8E4eC4df02346a082df54D437F8D9aF',\n '0x18c7': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x10e6': '0xcA11bde05977b3631167028862bE2a173976CA11',\n '0x10b3e': '0x99423C88EB5723A590b4C644426069042f137B9e',\n // Ink Mainnet\n '0xdef1': '0xcA11bde05977b3631167028862bE2a173976CA11',\n // Stable (988)\n '0x3dc': '0xcA11bde05977b3631167028862bE2a173976CA11',\n // Tempo Mainnet\n '0x1079': '0xcA11bde05977b3631167028862bE2a173976CA11',\n // Tempo Testnet Moderato\n '0xa5bf': '0xcA11bde05977b3631167028862bE2a173976CA11',\n // Arc (5042)\n '0x13b2': '0xcA11bde05977b3631167028862bE2a173976CA11',\n // Robinhood Chain (4663)\n '0x1237': '0xcA11bde05977b3631167028862bE2a173976CA11',\n // Somnia (5031), MultiCallV3 per docs.somnia.network/developer/smart-contracts\n '0x13a7': '0x5e44F178E8cF9B2F5409B6f18ce936aB817C5a11',\n};\n\n// =============================================================================\n// ENCODING/DECODING UTILITIES (using @ethersproject/abi)\n// =============================================================================\n\n/**\n * Encode a balanceOf call for an ERC-20 token.\n *\n * @param accountAddress - The account address.\n * @returns The encoded call data.\n */\nfunction encodeBalanceOf(accountAddress: Address): Hex {\n return encodeFunctionData(erc20Interface, 'balanceOf', [accountAddress]);\n}\n\n/**\n * Encode a getEthBalance call for native token via Multicall3.\n *\n * @param accountAddress - The account address.\n * @returns The encoded call data.\n */\nfunction encodeGetEthBalance(accountAddress: Address): Hex {\n return encodeFunctionData(multicall3Interface, 'getEthBalance', [\n accountAddress,\n ]);\n}\n\ntype BalanceCallDataCache = {\n getErc20BalanceCallData: (accountAddress: Address) => Hex;\n getNativeBalanceCallData: (accountAddress: Address) => Hex;\n};\n\nfunction createBalanceCallDataCache(): BalanceCallDataCache {\n const erc20ByAccount = new Map<string, Hex>();\n const nativeByAccount = new Map<string, Hex>();\n\n return {\n getErc20BalanceCallData(accountAddress: Address): Hex {\n const key = accountAddress.toLowerCase();\n const existing = erc20ByAccount.get(key);\n if (existing !== undefined) {\n return existing;\n }\n const callData = encodeBalanceOf(accountAddress);\n erc20ByAccount.set(key, callData);\n return callData;\n },\n getNativeBalanceCallData(accountAddress: Address): Hex {\n const key = accountAddress.toLowerCase();\n const existing = nativeByAccount.get(key);\n if (existing !== undefined) {\n return existing;\n }\n const callData = encodeGetEthBalance(accountAddress);\n nativeByAccount.set(key, callData);\n return callData;\n },\n };\n}\n\n/**\n * Cache balance call encodings per account address.\n * ERC-20 `balanceOf` and native `getEthBalance` call data depend only on the\n * account being queried, not the token contract (which is the multicall target).\n */\nconst balanceCallDataCache = createBalanceCallDataCache();\n\n/**\n * Build Multicall3 aggregate3 calls for a batch of balance requests.\n *\n * @param batch - Balance requests in the current batch.\n * @param multicallAddress - Multicall3 contract address for native balance calls.\n * @returns Aggregate3 call descriptors.\n */\nfunction buildAggregate3BalanceCalls(\n batch: BalanceOfRequest[],\n multicallAddress: Hex,\n): Aggregate3Call[] {\n return batch.map((req) => {\n const isNative = req.tokenAddress === ZERO_ADDRESS;\n const target = isNative ? multicallAddress : req.tokenAddress;\n return {\n target,\n allowFailure: true,\n callData: isNative\n ? balanceCallDataCache.getNativeBalanceCallData(req.accountAddress)\n : balanceCallDataCache.getErc20BalanceCallData(req.accountAddress),\n };\n });\n}\n\n/**\n * Encode a Multicall3 aggregate3 call with the Ethers ABI coder.\n *\n * `MulticallClient` calls `encodeAggregate3` from `aggregate3Codec.ts`.\n * This function stays so those tests can compare the two encodings.\n *\n * @param calls - Array of calls with target, allowFailure, and callData.\n * @returns The encoded aggregate3 call data.\n */\nexport function encodeAggregate3WithEthers(\n calls: readonly Aggregate3Call[],\n): Hex {\n return encodeFunctionData(multicall3Interface, 'aggregate3', [\n calls.map((call) => ({\n target: call.target,\n allowFailure: call.allowFailure,\n callData: call.callData,\n })),\n ]);\n}\n\n/**\n * Decode the response from aggregate3 with the Ethers ABI coder.\n *\n * `MulticallClient` calls `decodeAggregate3Response` from `aggregate3Codec.ts`.\n * This function stays so those tests can compare the two decodings.\n *\n * @param data - The raw response data.\n * @param callCount - Number of calls made (used for validation).\n * @returns Array of success and return data.\n */\nexport function decodeAggregate3ResponseWithEthers(\n data: Hex,\n callCount: number,\n): { success: boolean; returnData: Hex }[] {\n const decoded = multicall3Interface.decodeFunctionResult('aggregate3', data);\n\n // decoded[0] is the array of (success, returnData) tuples\n const results = decoded[0] as readonly {\n success: boolean;\n returnData: string;\n }[];\n\n if (results.length !== callCount) {\n throw new Error(`Expected ${callCount} results, got ${results.length}`);\n }\n\n return results.map((result) => ({\n success: result.success,\n returnData: result.returnData as Hex,\n }));\n}\n\n/**\n * Decode a uint256 balance with the Ethers ABI coder.\n *\n * `MulticallClient` calls `decodeUint256` from `aggregate3Codec.ts`.\n * This function stays so those tests can compare the two decodings.\n *\n * @param data - The hex return data.\n * @returns The decoded balance as a string.\n */\nexport function decodeUint256WithEthers(data: Hex): string {\n if (data === '0x' || data.length < 66) {\n // Empty or invalid data; treat as 0\n return '0';\n }\n const decoded = erc20Interface.decodeFunctionResult('balanceOf', data);\n return decoded[0].toString();\n}\n\n// =============================================================================\n// MULTICALL CLIENT\n// =============================================================================\n\n/** Retries after the initial multicall attempt before returning failed responses. */\nconst MULTICALL_MAX_RETRIES = 2;\n\nexport type MulticallClientConfig = {\n maxCallsPerBatch?: number;\n timeoutMs?: number;\n};\n\n/**\n * Function for retrieving the Multicall3 contract address for a given chain ID.\n *\n * @param chainId - The chain ID.\n * @returns The Multicall3 contract address, or undefined if not supported.\n */\nexport type GetMulticall3AddressForChainFunction = (\n chainId: ChainId,\n) => Hex | undefined;\n\n/**\n * Options for creating a MulticallClient.\n */\nexport type MulticallClientOptions = {\n getProvider: GetProviderFunction;\n getMulticall3AddressForChain: GetMulticall3AddressForChainFunction;\n config?: MulticallClientConfig;\n};\n\n/**\n * Client for batching RPC calls using Multicall3.\n * Falls back to individual calls on chains without Multicall3 support.\n */\nexport class MulticallClient {\n readonly #getProvider: GetProviderFunction;\n\n readonly #config: Required<MulticallClientConfig>;\n\n readonly #getMulticall3AddressForChain: GetMulticall3AddressForChainFunction;\n\n constructor({\n getProvider,\n getMulticall3AddressForChain,\n config,\n }: MulticallClientOptions) {\n this.#getProvider = getProvider;\n // Use default values for invalid (non-positive) batch sizes to prevent\n // infinite loops or errors in divideIntoBatches\n const maxCallsPerBatch =\n config?.maxCallsPerBatch !== undefined && config.maxCallsPerBatch > 0\n ? config.maxCallsPerBatch\n : 300;\n const timeoutMs =\n config?.timeoutMs !== undefined && config.timeoutMs > 0\n ? config.timeoutMs\n : 30000;\n this.#config = {\n maxCallsPerBatch,\n timeoutMs,\n };\n this.#getMulticall3AddressForChain = getMulticall3AddressForChain;\n }\n\n /**\n * Fetch ERC-20 and native token balances using Multicall3.\n * Falls back to individual RPC calls on unsupported chains.\n *\n * @param chainId - The chain ID.\n * @param requests - Array of balance requests.\n * @param options - Optional batch options (e.g. single-call fallback).\n * @returns Array of balance responses.\n */\n async batchBalanceOf(\n chainId: ChainId,\n requests: BalanceOfRequest[],\n options = { fallbackToSingleCalls: false },\n ): Promise<BalanceOfResponse[]> {\n if (requests.length === 0) {\n return [];\n }\n\n const multicallAddress =\n this.#getMulticall3AddressForChain(chainId) ??\n MULTICALL3_ADDRESS_BY_CHAIN[chainId];\n const provider = this.#getProvider(chainId);\n\n if (!multicallAddress) {\n return options.fallbackToSingleCalls\n ? this.#fallbackBatchBalanceOf(provider, requests)\n : this.#createFailedResponses(requests);\n }\n\n // Use Multicall3\n return this.#multicallBatchBalanceOf(\n provider,\n multicallAddress,\n requests,\n options.fallbackToSingleCalls,\n );\n }\n\n /**\n * Fetch balances using Multicall3 aggregate3.\n *\n * @param provider - The RPC provider.\n * @param multicallAddress - The Multicall3 contract address.\n * @param requests - Array of balance requests.\n * @param fallbackToSingleCalls - Whether to fall back to individual RPC calls on batch failure.\n * @returns Array of balance responses.\n */\n async #multicallBatchBalanceOf(\n provider: Provider,\n multicallAddress: Hex,\n requests: BalanceOfRequest[],\n fallbackToSingleCalls: boolean,\n ): Promise<BalanceOfResponse[]> {\n const batchSize = this.#config.maxCallsPerBatch;\n\n const responses = await reduceInBatchesSerially<\n BalanceOfRequest,\n BalanceOfResponse[]\n >({\n values: requests,\n batchSize,\n initialResult: [],\n eachBatch: async (workingResult, batch) => {\n const calls = buildAggregate3BalanceCalls(batch, multicallAddress);\n\n try {\n await createServicePolicy({\n maxRetries: MULTICALL_MAX_RETRIES,\n }).execute(async () => {\n // Encode and send aggregate3 call\n const callData = encodeAggregate3(calls);\n const result = await provider.call({\n to: multicallAddress,\n data: callData,\n });\n\n // Decode response\n const decoded = decodeAggregate3Response(\n result as Hex,\n batch.length,\n );\n\n // Map results back to responses\n for (let i = 0; i < batch.length; i++) {\n const { tokenAddress, accountAddress } = batch[i];\n const { success, returnData } = decoded[i];\n\n if (success && returnData && returnData.length > 2) {\n workingResult.push({\n tokenAddress,\n accountAddress,\n success: true,\n balance: decodeUint256(returnData),\n });\n } else {\n workingResult.push({\n tokenAddress,\n accountAddress,\n success: false,\n });\n }\n }\n });\n } catch {\n if (fallbackToSingleCalls) {\n // On aggregate3 error, fall back to individual calls for this batch.\n // #fetchSingleBalance never rejects - it catches all errors internally\n // and returns a failed response, so we use Promise.all here.\n const fallbackResults = await Promise.all(\n batch.map((req) => this.#fetchSingleBalance(provider, req)),\n );\n\n for (const result of fallbackResults) {\n workingResult.push(result);\n }\n } else {\n workingResult.push(...this.#createFailedResponses(batch));\n }\n }\n\n return workingResult;\n },\n });\n\n return responses;\n }\n\n /**\n * Fallback: fetch balances using individual RPC calls.\n *\n * @param provider - The RPC provider.\n * @param requests - Array of balance requests.\n * @returns Array of balance responses.\n */\n async #fallbackBatchBalanceOf(\n provider: Provider,\n requests: BalanceOfRequest[],\n ): Promise<BalanceOfResponse[]> {\n // Use smaller batch size for parallel individual calls to avoid overwhelming RPC\n const batchSize = Math.min(this.#config.maxCallsPerBatch, 50);\n\n const responses = await reduceInBatchesSerially<\n BalanceOfRequest,\n BalanceOfResponse[]\n >({\n values: requests,\n batchSize,\n initialResult: [],\n eachBatch: async (workingResult, batch) => {\n // #fetchSingleBalance never rejects - it catches all errors internally\n // and returns a failed response, so we use Promise.all here.\n const batchResults = await Promise.all(\n batch.map((req) => this.#fetchSingleBalance(provider, req)),\n );\n\n for (const result of batchResults) {\n workingResult.push(result);\n }\n\n return workingResult;\n },\n });\n\n return responses;\n }\n\n /**\n * Fetch a single token balance (fallback method).\n *\n * @param provider - The RPC provider.\n * @param request - The balance request.\n * @returns The balance response.\n */\n async #fetchSingleBalance(\n provider: Provider,\n request: BalanceOfRequest,\n ): Promise<BalanceOfResponse> {\n // Destructure inside try block to ensure any errors are caught\n // and don't cause promise rejections that bypass error handling\n try {\n const { tokenAddress, accountAddress } = request;\n\n // Native token (zero address)\n if (tokenAddress === ZERO_ADDRESS) {\n const balance = await provider.getBalance(accountAddress);\n return {\n tokenAddress,\n accountAddress,\n success: true,\n balance: balance.toString(),\n };\n }\n\n // ERC-20 token\n const callData =\n balanceCallDataCache.getErc20BalanceCallData(accountAddress);\n const result = await provider.call({\n to: tokenAddress,\n data: callData,\n });\n\n const balance = decodeUint256(result as Hex);\n return {\n tokenAddress,\n accountAddress,\n success: true,\n balance,\n };\n } catch {\n return this.#createFailedResponse(request);\n }\n }\n\n #createFailedResponses(requests: BalanceOfRequest[]): BalanceOfResponse[] {\n return requests.map((request) => this.#createFailedResponse(request));\n }\n\n #createFailedResponse(request: BalanceOfRequest): BalanceOfResponse {\n return {\n tokenAddress: request.tokenAddress,\n accountAddress: request.accountAddress,\n success: false,\n };\n }\n}\n"]}
@@ -0,0 +1,57 @@
1
+ import type { Hex } from '@metamask/utils';
2
+ import type { Address } from '../types/index.js';
3
+ /**
4
+ * One Multicall3 `aggregate3` call.
5
+ *
6
+ * `target` is the contract to call. `allowFailure` lets that call revert
7
+ * without failing the batch. `callData` is the ABI-encoded call.
8
+ */
9
+ export type Aggregate3Call = {
10
+ target: Address;
11
+ allowFailure: boolean;
12
+ callData: Hex;
13
+ };
14
+ /**
15
+ * Encode `aggregate3((address,bool,bytes)[])`.
16
+ *
17
+ * The bytes are the 4-byte selector `82ad56cb`, then one ABI argument:
18
+ *
19
+ * 1. A word holding the offset of the calls array, always `0x20`.
20
+ * 2. A word holding the number of calls.
21
+ * 3. One offset word per call. See `getAggregate3Parts`.
22
+ * 4. The call bodies, in order. See `encodeAggregate3Call`.
23
+ *
24
+ * @param calls - Aggregate3 call descriptors.
25
+ * @returns Call data that matches `encodeAggregate3WithEthers` for the same input.
26
+ * @throws When a target or call data value is not hex the Ethers coder would accept.
27
+ */
28
+ export declare function encodeAggregate3(calls: readonly Aggregate3Call[]): Hex;
29
+ /**
30
+ * Decode an `aggregate3` return value.
31
+ *
32
+ * The outer shape is one dynamic array of `(bool success, bytes returnData)`
33
+ * tuples. `callCount` is checked against the length word so a short response
34
+ * cannot be paired with the wrong batch.
35
+ *
36
+ * @param data - The raw `eth_call` return data.
37
+ * @param callCount - The expected result count.
38
+ * @returns One decoded result per call, in call order.
39
+ * @throws When `data` is not hex, a word is out of range, or the length word
40
+ * does not equal `callCount`.
41
+ */
42
+ export declare function decodeAggregate3Response(data: Hex, callCount: number): {
43
+ success: boolean;
44
+ returnData: Hex;
45
+ }[];
46
+ /**
47
+ * Read a uint256 from the first ABI word of return data.
48
+ *
49
+ * `balanceOf` and `getEthBalance` each return a single 32-byte word. Empty
50
+ * data and anything shorter than one word decode as `'0'`, matching
51
+ * `decodeUint256WithEthers`.
52
+ *
53
+ * @param data - Hex return data.
54
+ * @returns The integer as a decimal string.
55
+ */
56
+ export declare function decodeUint256(data: Hex): string;
57
+ //# sourceMappingURL=aggregate3Codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregate3Codec.d.ts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/clients/aggregate3Codec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAajD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,GAAG,CAAC;CACf,CAAC;AA4IF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,GAAG,GAAG,CAUtE;AAqFD;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,GAAG,EACT,SAAS,EAAE,MAAM,GAChB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,GAAG,CAAA;CAAE,EAAE,CASzC;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAK/C"}
@@ -0,0 +1,241 @@
1
+ /** `aggregate3((address,bool,bytes)[])` selector, without a `0x` prefix. */
2
+ const AGGREGATE3_SELECTOR = '82ad56cb';
3
+ /**
4
+ * 32-byte words written as 64 hex characters, with no `0x` prefix.
5
+ * The encoder concatenates them after the selector.
6
+ *
7
+ * - `WORD_ARRAY_OFFSET` is `0x20`: the calls array begins at the next word.
8
+ * - `WORD_CALLDATA_OFFSET` is `0x60`: `callData` begins three words into a tuple.
9
+ * - `WORD_ZERO` / `WORD_ONE` are the ABI bool values.
10
+ */
11
+ const WORD_ARRAY_OFFSET = `0${'0'.repeat(61)}20`;
12
+ const WORD_CALLDATA_OFFSET = `0${'0'.repeat(61)}60`;
13
+ const WORD_ZERO = '0'.repeat(64);
14
+ const WORD_ONE = `0${'0'.repeat(62)}1`;
15
+ const LOWERCASE_HEX_RE = /^[0-9a-f]*$/u;
16
+ /**
17
+ * Write a byte count as a 32-byte hex word.
18
+ *
19
+ * @param value - A byte length or an element count.
20
+ * @returns 64 lowercase hex characters, with no `0x` prefix.
21
+ */
22
+ function encodeWord(value) {
23
+ return value.toString(16).padStart(64, '0');
24
+ }
25
+ /**
26
+ * Check a call and return the hex bodies the encoder pads.
27
+ *
28
+ * Addresses follow the Ethers coder: a `0x` prefix, hex digits, and at most
29
+ * 32 bytes. Lengths other than 20 bytes are left-padded, which is what keeps
30
+ * short and long targets byte-identical to Ethers. Call data must be
31
+ * even-length hex.
32
+ *
33
+ * @param call - One aggregate3 call.
34
+ * @returns Lowercase hex bodies with the `0x` prefix removed.
35
+ * @throws When `target` or `callData` is not hex the Ethers coder would accept.
36
+ */
37
+ function normalizeAggregate3Call(call) {
38
+ const { target, callData } = call;
39
+ if (!target.startsWith('0x')) {
40
+ throw new Error(`invalid address value: ${target}`);
41
+ }
42
+ const targetHex = target.slice(2).toLowerCase();
43
+ if (!LOWERCASE_HEX_RE.test(targetHex) || targetHex.length > 64) {
44
+ throw new Error(`invalid address value: ${target}`);
45
+ }
46
+ if (!callData.startsWith('0x')) {
47
+ throw new Error(`invalid bytes value: ${callData}`);
48
+ }
49
+ const dataHex = callData.slice(2).toLowerCase();
50
+ if (dataHex.length % 2 !== 0 || !LOWERCASE_HEX_RE.test(dataHex)) {
51
+ throw new Error(`invalid bytes value: ${callData}`);
52
+ }
53
+ return { targetHex, dataHex };
54
+ }
55
+ /**
56
+ * Encode one `(address, bool, bytes)` tuple.
57
+ *
58
+ * The body is five pieces, concatenated:
59
+ *
60
+ * - `target`, left-padded to 32 bytes
61
+ * - `allowFailure` as a 0 or 1 word
62
+ * - the offset of `callData`, always `0x60` (three words into the tuple)
63
+ * - the `callData` length in bytes
64
+ * - `callData`, right-padded with zeros to a multiple of 32 bytes
65
+ *
66
+ * @param call - One aggregate3 call.
67
+ * @returns The tuple body and its padded length in bytes.
68
+ */
69
+ function encodeAggregate3Call(call) {
70
+ const { targetHex, dataHex } = normalizeAggregate3Call(call);
71
+ const paddedData = dataHex.padEnd(dataHex.length + ((64 - (dataHex.length % 64)) % 64), '0');
72
+ // Three static words (96 bytes) plus the 32-byte length prefix.
73
+ return {
74
+ bodyParts: [
75
+ targetHex.padStart(64, '0'),
76
+ call.allowFailure ? WORD_ONE : WORD_ZERO,
77
+ WORD_CALLDATA_OFFSET,
78
+ encodeWord(dataHex.length / 2),
79
+ paddedData,
80
+ ],
81
+ byteLength: 128 + paddedData.length / 2,
82
+ };
83
+ }
84
+ /**
85
+ * Build the array head and the concatenated tuple bodies.
86
+ *
87
+ * Each head word is a byte offset measured from the first head word. The
88
+ * first call therefore starts at `32 * calls.length`, the size of the head
89
+ * itself, and every later call starts at the previous offset plus that
90
+ * call's padded body length.
91
+ *
92
+ * @param calls - Aggregate3 call descriptors.
93
+ * @returns Hex words for the head and the body, with no `0x` prefixes.
94
+ */
95
+ function getAggregate3Parts(calls) {
96
+ const parts = calls.reduce((accumulator, call) => {
97
+ const encodedCall = encodeAggregate3Call(call);
98
+ accumulator.headParts.push(encodeWord(accumulator.nextTupleOffset));
99
+ accumulator.bodyParts.push(...encodedCall.bodyParts);
100
+ accumulator.nextTupleOffset += encodedCall.byteLength;
101
+ return accumulator;
102
+ }, {
103
+ headParts: [],
104
+ bodyParts: [],
105
+ nextTupleOffset: calls.length * 32,
106
+ });
107
+ return parts;
108
+ }
109
+ /**
110
+ * Encode `aggregate3((address,bool,bytes)[])`.
111
+ *
112
+ * The bytes are the 4-byte selector `82ad56cb`, then one ABI argument:
113
+ *
114
+ * 1. A word holding the offset of the calls array, always `0x20`.
115
+ * 2. A word holding the number of calls.
116
+ * 3. One offset word per call. See `getAggregate3Parts`.
117
+ * 4. The call bodies, in order. See `encodeAggregate3Call`.
118
+ *
119
+ * @param calls - Aggregate3 call descriptors.
120
+ * @returns Call data that matches `encodeAggregate3WithEthers` for the same input.
121
+ * @throws When a target or call data value is not hex the Ethers coder would accept.
122
+ */
123
+ export function encodeAggregate3(calls) {
124
+ const { headParts, bodyParts } = getAggregate3Parts(calls);
125
+ return [
126
+ `0x${AGGREGATE3_SELECTOR}`,
127
+ WORD_ARRAY_OFFSET,
128
+ encodeWord(calls.length),
129
+ ...headParts,
130
+ ...bodyParts,
131
+ ].join('');
132
+ }
133
+ /**
134
+ * Read one 32-byte word from an aggregate3 response body.
135
+ *
136
+ * Offsets and lengths in this response are byte counts. The uint256 payload
137
+ * inside `returnData` is decoded separately by `decodeUint256`.
138
+ *
139
+ * @param body - Response hex with the `0x` prefix removed.
140
+ * @param charIndex - Index of the first hex character of the word.
141
+ * @returns The word as an integer.
142
+ * @throws When the word is missing or is not hex.
143
+ */
144
+ function readResponseWord(body, charIndex) {
145
+ if (charIndex < 0 || charIndex + 64 > body.length) {
146
+ throw new Error('aggregate3 response data length out-of-bounds');
147
+ }
148
+ const value = parseInt(body.slice(charIndex, charIndex + 64), 16);
149
+ if (!Number.isFinite(value)) {
150
+ throw new Error('aggregate3 response contains a non-hex word');
151
+ }
152
+ return value;
153
+ }
154
+ /**
155
+ * Locate the array head of an aggregate3 return value.
156
+ *
157
+ * `eth_call` return data has no function selector. Word 0 is the byte offset
158
+ * of the result array. At that offset sits the length word, then one offset
159
+ * word per result. `headStart` is the hex index of the first of those
160
+ * offset words.
161
+ *
162
+ * @param body - Response hex with the `0x` prefix removed.
163
+ * @param callCount - How many results the caller expects.
164
+ * @returns The head position and the length stored in the response.
165
+ * @throws When the stored length is not `callCount`.
166
+ */
167
+ function getAggregate3ResponseHead(body, callCount) {
168
+ const headStart = readResponseWord(body, 0) * 2 + 64;
169
+ const resultCount = readResponseWord(body, headStart - 64);
170
+ if (resultCount !== callCount) {
171
+ throw new Error(`Expected ${callCount} results, got ${resultCount}`);
172
+ }
173
+ return { headStart, resultCount };
174
+ }
175
+ /**
176
+ * Decode one `(bool success, bytes returnData)` result.
177
+ *
178
+ * The tuple starts at the head plus that result's offset. Its first word is
179
+ * `success` (`0` or `1`). Its second word is the offset of `returnData`,
180
+ * measured from the start of the tuple. The payload at that offset is a
181
+ * length word followed by the raw bytes, which this returns without padding.
182
+ *
183
+ * @param body - Response hex with the `0x` prefix removed.
184
+ * @param headStart - Hex index of the first result-offset word.
185
+ * @param resultIndex - Index of the result to decode.
186
+ * @returns The success flag and the unpadded return data.
187
+ * @throws When the return data runs past the end of `body`.
188
+ */
189
+ function decodeAggregate3Result(body, headStart, resultIndex) {
190
+ const tupleStart = headStart + readResponseWord(body, headStart + resultIndex * 64) * 2;
191
+ const returnDataStart = tupleStart + readResponseWord(body, tupleStart + 64) * 2;
192
+ const returnDataBytes = readResponseWord(body, returnDataStart);
193
+ const dataStart = returnDataStart + 64;
194
+ if (dataStart + returnDataBytes * 2 > body.length) {
195
+ throw new Error('aggregate3 response data length out-of-bounds');
196
+ }
197
+ return {
198
+ success: readResponseWord(body, tupleStart) !== 0,
199
+ returnData: `0x${body
200
+ .slice(dataStart, dataStart + returnDataBytes * 2)
201
+ .toLowerCase()}`,
202
+ };
203
+ }
204
+ /**
205
+ * Decode an `aggregate3` return value.
206
+ *
207
+ * The outer shape is one dynamic array of `(bool success, bytes returnData)`
208
+ * tuples. `callCount` is checked against the length word so a short response
209
+ * cannot be paired with the wrong batch.
210
+ *
211
+ * @param data - The raw `eth_call` return data.
212
+ * @param callCount - The expected result count.
213
+ * @returns One decoded result per call, in call order.
214
+ * @throws When `data` is not hex, a word is out of range, or the length word
215
+ * does not equal `callCount`.
216
+ */
217
+ export function decodeAggregate3Response(data, callCount) {
218
+ if (!data.startsWith('0x')) {
219
+ throw new Error(`invalid response data value: ${data}`);
220
+ }
221
+ const body = data.slice(2);
222
+ const { headStart, resultCount } = getAggregate3ResponseHead(body, callCount);
223
+ return Array.from({ length: resultCount }, (_, resultIndex) => decodeAggregate3Result(body, headStart, resultIndex));
224
+ }
225
+ /**
226
+ * Read a uint256 from the first ABI word of return data.
227
+ *
228
+ * `balanceOf` and `getEthBalance` each return a single 32-byte word. Empty
229
+ * data and anything shorter than one word decode as `'0'`, matching
230
+ * `decodeUint256WithEthers`.
231
+ *
232
+ * @param data - Hex return data.
233
+ * @returns The integer as a decimal string.
234
+ */
235
+ export function decodeUint256(data) {
236
+ if (data === '0x' || data.length < 66) {
237
+ return '0';
238
+ }
239
+ return BigInt(data.slice(0, 66)).toString();
240
+ }
241
+ //# sourceMappingURL=aggregate3Codec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregate3Codec.js","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/clients/aggregate3Codec.ts"],"names":[],"mappings":"AAqCA,4EAA4E;AAC5E,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;AACjD,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;AACpD,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACjC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC;AACvC,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAExC;;;;;GAKG;AACH,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,uBAAuB,CAAC,IAAoB;IAInD,MAAM,EA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AAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC9C,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { Address } from '../types/index.js';\n\n// Hand-rolled Multicall3 `aggregate3` codecs.\n//\n// Balance refreshes pack many `balanceOf` and `getEthBalance` calls into one\n// `aggregate3`. This module writes and reads that fixed ABI shape directly.\n// `MulticallClient` still has the Ethers codecs (`encodeAggregate3WithEthers`,\n// `decodeAggregate3ResponseWithEthers`, `decodeUint256WithEthers`) so tests\n// can require the same bytes.\n//\n// Why this is split out, and what it costs, is recorded in\n// `packages/assets-controller/docs/decisions/2026-10-26-hand-rolled-aggregate3-codecs.md`.\n\n/**\n * One Multicall3 `aggregate3` call.\n *\n * `target` is the contract to call. `allowFailure` lets that call revert\n * without failing the batch. `callData` is the ABI-encoded call.\n */\nexport type Aggregate3Call = {\n target: Address;\n allowFailure: boolean;\n callData: Hex;\n};\n\n/**\n * One encoded `(address, bool, bytes)` tuple, before it is placed in the\n * array. `bodyParts` are 32-byte hex words with no `0x` prefix. `byteLength`\n * is the padded size of that body and is what the next call's offset adds.\n */\ntype EncodedAggregate3Call = {\n bodyParts: string[];\n byteLength: number;\n};\n\n/** `aggregate3((address,bool,bytes)[])` selector, without a `0x` prefix. */\nconst AGGREGATE3_SELECTOR = '82ad56cb';\n\n/**\n * 32-byte words written as 64 hex characters, with no `0x` prefix.\n * The encoder concatenates them after the selector.\n *\n * - `WORD_ARRAY_OFFSET` is `0x20`: the calls array begins at the next word.\n * - `WORD_CALLDATA_OFFSET` is `0x60`: `callData` begins three words into a tuple.\n * - `WORD_ZERO` / `WORD_ONE` are the ABI bool values.\n */\nconst WORD_ARRAY_OFFSET = `0${'0'.repeat(61)}20`;\nconst WORD_CALLDATA_OFFSET = `0${'0'.repeat(61)}60`;\nconst WORD_ZERO = '0'.repeat(64);\nconst WORD_ONE = `0${'0'.repeat(62)}1`;\nconst LOWERCASE_HEX_RE = /^[0-9a-f]*$/u;\n\n/**\n * Write a byte count as a 32-byte hex word.\n *\n * @param value - A byte length or an element count.\n * @returns 64 lowercase hex characters, with no `0x` prefix.\n */\nfunction encodeWord(value: number): string {\n return value.toString(16).padStart(64, '0');\n}\n\n/**\n * Check a call and return the hex bodies the encoder pads.\n *\n * Addresses follow the Ethers coder: a `0x` prefix, hex digits, and at most\n * 32 bytes. Lengths other than 20 bytes are left-padded, which is what keeps\n * short and long targets byte-identical to Ethers. Call data must be\n * even-length hex.\n *\n * @param call - One aggregate3 call.\n * @returns Lowercase hex bodies with the `0x` prefix removed.\n * @throws When `target` or `callData` is not hex the Ethers coder would accept.\n */\nfunction normalizeAggregate3Call(call: Aggregate3Call): {\n targetHex: string;\n dataHex: string;\n} {\n const { target, callData } = call;\n if (!target.startsWith('0x')) {\n throw new Error(`invalid address value: ${target}`);\n }\n const targetHex = target.slice(2).toLowerCase();\n if (!LOWERCASE_HEX_RE.test(targetHex) || targetHex.length > 64) {\n throw new Error(`invalid address value: ${target}`);\n }\n\n if (!callData.startsWith('0x')) {\n throw new Error(`invalid bytes value: ${callData}`);\n }\n const dataHex = callData.slice(2).toLowerCase();\n if (dataHex.length % 2 !== 0 || !LOWERCASE_HEX_RE.test(dataHex)) {\n throw new Error(`invalid bytes value: ${callData}`);\n }\n return { targetHex, dataHex };\n}\n\n/**\n * Encode one `(address, bool, bytes)` tuple.\n *\n * The body is five pieces, concatenated:\n *\n * - `target`, left-padded to 32 bytes\n * - `allowFailure` as a 0 or 1 word\n * - the offset of `callData`, always `0x60` (three words into the tuple)\n * - the `callData` length in bytes\n * - `callData`, right-padded with zeros to a multiple of 32 bytes\n *\n * @param call - One aggregate3 call.\n * @returns The tuple body and its padded length in bytes.\n */\nfunction encodeAggregate3Call(call: Aggregate3Call): EncodedAggregate3Call {\n const { targetHex, dataHex } = normalizeAggregate3Call(call);\n const paddedData = dataHex.padEnd(\n dataHex.length + ((64 - (dataHex.length % 64)) % 64),\n '0',\n );\n\n // Three static words (96 bytes) plus the 32-byte length prefix.\n return {\n bodyParts: [\n targetHex.padStart(64, '0'),\n call.allowFailure ? WORD_ONE : WORD_ZERO,\n WORD_CALLDATA_OFFSET,\n encodeWord(dataHex.length / 2),\n paddedData,\n ],\n byteLength: 128 + paddedData.length / 2,\n };\n}\n\n/**\n * Build the array head and the concatenated tuple bodies.\n *\n * Each head word is a byte offset measured from the first head word. The\n * first call therefore starts at `32 * calls.length`, the size of the head\n * itself, and every later call starts at the previous offset plus that\n * call's padded body length.\n *\n * @param calls - Aggregate3 call descriptors.\n * @returns Hex words for the head and the body, with no `0x` prefixes.\n */\nfunction getAggregate3Parts(calls: readonly Aggregate3Call[]): {\n headParts: string[];\n bodyParts: string[];\n} {\n const parts = calls.reduce(\n (accumulator, call) => {\n const encodedCall = encodeAggregate3Call(call);\n accumulator.headParts.push(encodeWord(accumulator.nextTupleOffset));\n accumulator.bodyParts.push(...encodedCall.bodyParts);\n accumulator.nextTupleOffset += encodedCall.byteLength;\n return accumulator;\n },\n {\n headParts: [] as string[],\n bodyParts: [] as string[],\n nextTupleOffset: calls.length * 32,\n },\n );\n return parts;\n}\n\n/**\n * Encode `aggregate3((address,bool,bytes)[])`.\n *\n * The bytes are the 4-byte selector `82ad56cb`, then one ABI argument:\n *\n * 1. A word holding the offset of the calls array, always `0x20`.\n * 2. A word holding the number of calls.\n * 3. One offset word per call. See `getAggregate3Parts`.\n * 4. The call bodies, in order. See `encodeAggregate3Call`.\n *\n * @param calls - Aggregate3 call descriptors.\n * @returns Call data that matches `encodeAggregate3WithEthers` for the same input.\n * @throws When a target or call data value is not hex the Ethers coder would accept.\n */\nexport function encodeAggregate3(calls: readonly Aggregate3Call[]): Hex {\n const { headParts, bodyParts } = getAggregate3Parts(calls);\n\n return [\n `0x${AGGREGATE3_SELECTOR}`,\n WORD_ARRAY_OFFSET,\n encodeWord(calls.length),\n ...headParts,\n ...bodyParts,\n ].join('') as Hex;\n}\n\n/**\n * Read one 32-byte word from an aggregate3 response body.\n *\n * Offsets and lengths in this response are byte counts. The uint256 payload\n * inside `returnData` is decoded separately by `decodeUint256`.\n *\n * @param body - Response hex with the `0x` prefix removed.\n * @param charIndex - Index of the first hex character of the word.\n * @returns The word as an integer.\n * @throws When the word is missing or is not hex.\n */\nfunction readResponseWord(body: string, charIndex: number): number {\n if (charIndex < 0 || charIndex + 64 > body.length) {\n throw new Error('aggregate3 response data length out-of-bounds');\n }\n const value = parseInt(body.slice(charIndex, charIndex + 64), 16);\n if (!Number.isFinite(value)) {\n throw new Error('aggregate3 response contains a non-hex word');\n }\n return value;\n}\n\n/**\n * Locate the array head of an aggregate3 return value.\n *\n * `eth_call` return data has no function selector. Word 0 is the byte offset\n * of the result array. At that offset sits the length word, then one offset\n * word per result. `headStart` is the hex index of the first of those\n * offset words.\n *\n * @param body - Response hex with the `0x` prefix removed.\n * @param callCount - How many results the caller expects.\n * @returns The head position and the length stored in the response.\n * @throws When the stored length is not `callCount`.\n */\nfunction getAggregate3ResponseHead(\n body: string,\n callCount: number,\n): { headStart: number; resultCount: number } {\n const headStart = readResponseWord(body, 0) * 2 + 64;\n const resultCount = readResponseWord(body, headStart - 64);\n if (resultCount !== callCount) {\n throw new Error(`Expected ${callCount} results, got ${resultCount}`);\n }\n return { headStart, resultCount };\n}\n\n/**\n * Decode one `(bool success, bytes returnData)` result.\n *\n * The tuple starts at the head plus that result's offset. Its first word is\n * `success` (`0` or `1`). Its second word is the offset of `returnData`,\n * measured from the start of the tuple. The payload at that offset is a\n * length word followed by the raw bytes, which this returns without padding.\n *\n * @param body - Response hex with the `0x` prefix removed.\n * @param headStart - Hex index of the first result-offset word.\n * @param resultIndex - Index of the result to decode.\n * @returns The success flag and the unpadded return data.\n * @throws When the return data runs past the end of `body`.\n */\nfunction decodeAggregate3Result(\n body: string,\n headStart: number,\n resultIndex: number,\n): { success: boolean; returnData: Hex } {\n const tupleStart =\n headStart + readResponseWord(body, headStart + resultIndex * 64) * 2;\n const returnDataStart =\n tupleStart + readResponseWord(body, tupleStart + 64) * 2;\n const returnDataBytes = readResponseWord(body, returnDataStart);\n const dataStart = returnDataStart + 64;\n if (dataStart + returnDataBytes * 2 > body.length) {\n throw new Error('aggregate3 response data length out-of-bounds');\n }\n return {\n success: readResponseWord(body, tupleStart) !== 0,\n returnData: `0x${body\n .slice(dataStart, dataStart + returnDataBytes * 2)\n .toLowerCase()}`,\n };\n}\n\n/**\n * Decode an `aggregate3` return value.\n *\n * The outer shape is one dynamic array of `(bool success, bytes returnData)`\n * tuples. `callCount` is checked against the length word so a short response\n * cannot be paired with the wrong batch.\n *\n * @param data - The raw `eth_call` return data.\n * @param callCount - The expected result count.\n * @returns One decoded result per call, in call order.\n * @throws When `data` is not hex, a word is out of range, or the length word\n * does not equal `callCount`.\n */\nexport function decodeAggregate3Response(\n data: Hex,\n callCount: number,\n): { success: boolean; returnData: Hex }[] {\n if (!data.startsWith('0x')) {\n throw new Error(`invalid response data value: ${data}`);\n }\n const body = data.slice(2);\n const { headStart, resultCount } = getAggregate3ResponseHead(body, callCount);\n return Array.from({ length: resultCount }, (_, resultIndex) =>\n decodeAggregate3Result(body, headStart, resultIndex),\n );\n}\n\n/**\n * Read a uint256 from the first ABI word of return data.\n *\n * `balanceOf` and `getEthBalance` each return a single 32-byte word. Empty\n * data and anything shorter than one word decode as `'0'`, matching\n * `decodeUint256WithEthers`.\n *\n * @param data - Hex return data.\n * @returns The integer as a decimal string.\n */\nexport function decodeUint256(data: Hex): string {\n if (data === '0x' || data.length < 66) {\n return '0';\n }\n return BigInt(data.slice(0, 66)).toString();\n}\n"]}
@@ -1,3 +1,4 @@
1
- export { decodeAggregate3Response, encodeAggregate3, MulticallClient, type MulticallClientConfig, } from './MulticallClient.js';
1
+ export { decodeAggregate3Response, encodeAggregate3, } from './aggregate3Codec.js';
2
+ export { MulticallClient, type MulticallClientConfig, } from './MulticallClient.js';
2
3
  export type { GetProviderFunction, Provider } from '../types/index.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/clients/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,eAAe,EACf,KAAK,qBAAqB,GAC3B,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/clients/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,KAAK,qBAAqB,GAC3B,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC"}
@@ -1,2 +1,3 @@
1
- export { decodeAggregate3Response, encodeAggregate3, MulticallClient, } from './MulticallClient.js';
1
+ export { decodeAggregate3Response, encodeAggregate3, } from './aggregate3Codec.js';
2
+ export { MulticallClient, } from './MulticallClient.js';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/clients/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,eAAe,GAEhB,MAAM,sBAAsB,CAAC","sourcesContent":["export {\n decodeAggregate3Response,\n encodeAggregate3,\n MulticallClient,\n type MulticallClientConfig,\n} from './MulticallClient.js';\n\n// Re-export provider types from types module\nexport type { GetProviderFunction, Provider } from '../types/index.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/data-sources/evm-rpc-services/clients/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,GAEhB,MAAM,sBAAsB,CAAC","sourcesContent":["export {\n decodeAggregate3Response,\n encodeAggregate3,\n} from './aggregate3Codec.js';\nexport {\n MulticallClient,\n type MulticallClientConfig,\n} from './MulticallClient.js';\n\n// Re-export provider types from types module\nexport type { GetProviderFunction, Provider } from '../types/index.js';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/assets-controller",
3
- "version": "20.0.1-preview-9fd631f7d",
3
+ "version": "20.0.1-preview-6fbab7311",
4
4
  "description": "Tracks assets balances/prices and handles token detection across all digital assets",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -89,7 +89,7 @@
89
89
  "@metamask/eth-json-rpc-provider": "^7.0.0",
90
90
  "@types/lodash-es": "^4.17.12",
91
91
  "@typescript/native": "npm:typescript@^7.0.2",
92
- "nock": "^13.5.6",
92
+ "nock": "^15.0.5",
93
93
  "rimraf": "^6.1.3",
94
94
  "typedoc": "^0.28.20",
95
95
  "typedoc-plugin-missing-exports": "^4.1.4",