@metamask/assets-controllers 73.1.0 → 73.3.0
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 +43 -1
- package/dist/AccountTrackerController.cjs +51 -1
- package/dist/AccountTrackerController.cjs.map +1 -1
- package/dist/AccountTrackerController.d.cts +40 -1
- package/dist/AccountTrackerController.d.cts.map +1 -1
- package/dist/AccountTrackerController.d.mts +40 -1
- package/dist/AccountTrackerController.d.mts.map +1 -1
- package/dist/AccountTrackerController.mjs +51 -1
- package/dist/AccountTrackerController.mjs.map +1 -1
- package/dist/TokenBalancesController.cjs +278 -319
- package/dist/TokenBalancesController.cjs.map +1 -1
- package/dist/TokenBalancesController.d.cts +51 -93
- package/dist/TokenBalancesController.d.cts.map +1 -1
- package/dist/TokenBalancesController.d.mts +51 -93
- package/dist/TokenBalancesController.d.mts.map +1 -1
- package/dist/TokenBalancesController.mjs +277 -317
- package/dist/TokenBalancesController.mjs.map +1 -1
- package/dist/assetsUtil.cjs +13 -1
- package/dist/assetsUtil.cjs.map +1 -1
- package/dist/assetsUtil.d.cts +8 -0
- package/dist/assetsUtil.d.cts.map +1 -1
- package/dist/assetsUtil.d.mts +8 -0
- package/dist/assetsUtil.d.mts.map +1 -1
- package/dist/assetsUtil.mjs +12 -1
- package/dist/assetsUtil.mjs.map +1 -1
- package/dist/balances.cjs +447 -0
- package/dist/balances.cjs.map +1 -0
- package/dist/balances.d.cts +88 -0
- package/dist/balances.d.cts.map +1 -0
- package/dist/balances.d.mts +88 -0
- package/dist/balances.d.mts.map +1 -0
- package/dist/balances.mjs +441 -0
- package/dist/balances.mjs.map +1 -0
- package/dist/constants.cjs +13 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +1 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +1 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +12 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs +6 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs +286 -0
- package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs.map +1 -0
- package/dist/multi-chain-accounts-service/api-balance-fetcher.d.cts +30 -0
- package/dist/multi-chain-accounts-service/api-balance-fetcher.d.cts.map +1 -0
- package/dist/multi-chain-accounts-service/api-balance-fetcher.d.mts +30 -0
- package/dist/multi-chain-accounts-service/api-balance-fetcher.d.mts.map +1 -0
- package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs +286 -0
- package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs.map +1 -0
- package/dist/multi-chain-accounts-service/multi-chain-accounts.cjs +35 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.cjs.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.cts +16 -0
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.cts.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.mts +16 -0
- package/dist/multi-chain-accounts-service/multi-chain-accounts.d.mts.map +1 -1
- package/dist/multi-chain-accounts-service/multi-chain-accounts.mjs +33 -0
- package/dist/multi-chain-accounts-service/multi-chain-accounts.mjs.map +1 -1
- package/dist/multi-chain-accounts-service/types.cjs.map +1 -1
- package/dist/multi-chain-accounts-service/types.d.cts +8 -0
- package/dist/multi-chain-accounts-service/types.d.cts.map +1 -1
- package/dist/multi-chain-accounts-service/types.d.mts +8 -0
- package/dist/multi-chain-accounts-service/types.d.mts.map +1 -1
- package/dist/multi-chain-accounts-service/types.mjs.map +1 -1
- package/dist/multicall.cjs +457 -1
- package/dist/multicall.cjs.map +1 -1
- package/dist/multicall.d.cts +51 -0
- package/dist/multicall.d.cts.map +1 -1
- package/dist/multicall.d.mts +51 -0
- package/dist/multicall.d.mts.map +1 -1
- package/dist/multicall.mjs +457 -0
- package/dist/multicall.mjs.map +1 -1
- package/dist/rpc-service/rpc-balance-fetcher.cjs +184 -0
- package/dist/rpc-service/rpc-balance-fetcher.cjs.map +1 -0
- package/dist/rpc-service/rpc-balance-fetcher.d.cts +34 -0
- package/dist/rpc-service/rpc-balance-fetcher.d.cts.map +1 -0
- package/dist/rpc-service/rpc-balance-fetcher.d.mts +34 -0
- package/dist/rpc-service/rpc-balance-fetcher.d.mts.map +1 -0
- package/dist/rpc-service/rpc-balance-fetcher.mjs +184 -0
- package/dist/rpc-service/rpc-balance-fetcher.mjs.map +1 -0
- package/package.json +11 -11
- package/dist/selectors/balanceSelectors.cjs +0 -328
- package/dist/selectors/balanceSelectors.cjs.map +0 -1
- package/dist/selectors/balanceSelectors.d.cts +0 -1676
- package/dist/selectors/balanceSelectors.d.cts.map +0 -1
- package/dist/selectors/balanceSelectors.d.mts +0 -1676
- package/dist/selectors/balanceSelectors.d.mts.map +0 -1
- package/dist/selectors/balanceSelectors.mjs +0 -321
- package/dist/selectors/balanceSelectors.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/types.ts"],"names":[],"mappings":"","sourcesContent":["export type GetSupportedNetworksResponse = {\n fullSupport: number[];\n partialSupport: {\n balances: number[];\n };\n};\n\nexport type GetBalancesQueryParams = {\n /** Comma-separated network/chain IDs */\n networks?: string;\n /** Whether or not to filter the assets to contain only the tokens existing in the Token API */\n filterSupportedTokens?: boolean;\n /** Specific token addresses to fetch balances for across specified network(s) */\n includeTokenAddresses?: string;\n /** Whether to include balances of the account's staked asset balances */\n includeStakedAssets?: boolean;\n};\n\nexport type GetBalancesResponse = {\n count: number;\n balances: {\n /** Underlying object type. Seems to be always `token` */\n object: string;\n /** Token Type: This is only supplied as `native` to native chain tokens (e.g. - ETH, POL) */\n type?: string;\n /** Timestamp is only provided for `native` chain tokens */\n timestamp?: string;\n address: string;\n symbol: string;\n name: string;\n decimals: number;\n chainId: number;\n /** string representation of the balance in decimal format (decimals adjusted). e.g. - 123.456789 */\n balance: string;\n }[];\n /** networks that failed to process, if no network is processed, returns HTTP 422 */\n unprocessedNetworks: number[];\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/types.ts"],"names":[],"mappings":"","sourcesContent":["export type GetSupportedNetworksResponse = {\n fullSupport: number[];\n partialSupport: {\n balances: number[];\n };\n};\n\nexport type GetBalancesQueryParams = {\n /** Comma-separated network/chain IDs */\n networks?: string;\n /** Whether or not to filter the assets to contain only the tokens existing in the Token API */\n filterSupportedTokens?: boolean;\n /** Specific token addresses to fetch balances for across specified network(s) */\n includeTokenAddresses?: string;\n /** Whether to include balances of the account's staked asset balances */\n includeStakedAssets?: boolean;\n};\n\nexport type GetBalancesQueryParamsV4 = {\n /** Comma-separated network/chain IDs */\n networks?: string;\n\n /** Comma-separated account addresses */\n accountAddresses?: string;\n};\n\nexport type GetBalancesResponse = {\n count: number;\n balances: {\n /** Underlying object type. Seems to be always `token` */\n object: string;\n /** Token Type: This is only supplied as `native` to native chain tokens (e.g. - ETH, POL) */\n type?: string;\n /** Timestamp is only provided for `native` chain tokens */\n timestamp?: string;\n address: string;\n symbol: string;\n name: string;\n decimals: number;\n chainId: number;\n /** string representation of the balance in decimal format (decimals adjusted). e.g. - 123.456789 */\n balance: string;\n /** Account address for V4 API responses */\n accountAddress?: string;\n }[];\n /** networks that failed to process, if no network is processed, returns HTTP 422 */\n unprocessedNetworks: number[];\n};\n"]}
|
|
@@ -14,6 +14,12 @@ export type GetBalancesQueryParams = {
|
|
|
14
14
|
/** Whether to include balances of the account's staked asset balances */
|
|
15
15
|
includeStakedAssets?: boolean;
|
|
16
16
|
};
|
|
17
|
+
export type GetBalancesQueryParamsV4 = {
|
|
18
|
+
/** Comma-separated network/chain IDs */
|
|
19
|
+
networks?: string;
|
|
20
|
+
/** Comma-separated account addresses */
|
|
21
|
+
accountAddresses?: string;
|
|
22
|
+
};
|
|
17
23
|
export type GetBalancesResponse = {
|
|
18
24
|
count: number;
|
|
19
25
|
balances: {
|
|
@@ -30,6 +36,8 @@ export type GetBalancesResponse = {
|
|
|
30
36
|
chainId: number;
|
|
31
37
|
/** string representation of the balance in decimal format (decimals adjusted). e.g. - 123.456789 */
|
|
32
38
|
balance: string;
|
|
39
|
+
/** Account address for V4 API responses */
|
|
40
|
+
accountAddress?: string;
|
|
33
41
|
}[];
|
|
34
42
|
/** networks that failed to process, if no network is processed, returns HTTP 422 */
|
|
35
43
|
unprocessedNetworks: number[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,4BAA4B,GAAG;IACzC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE;QACd,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+FAA+F;IAC/F,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,iFAAiF;IACjF,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,yEAAyE;IACzE,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,yDAAyD;QACzD,MAAM,EAAE,MAAM,CAAC;QACf,6FAA6F;QAC7F,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,2DAA2D;QAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,oGAAoG;QACpG,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,4BAA4B,GAAG;IACzC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE;QACd,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+FAA+F;IAC/F,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,iFAAiF;IACjF,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,yEAAyE;IACzE,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,wCAAwC;IACxC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,yDAAyD;QACzD,MAAM,EAAE,MAAM,CAAC;QACf,6FAA6F;QAC7F,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,2DAA2D;QAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,oGAAoG;QACpG,OAAO,EAAE,MAAM,CAAC;QAChB,2CAA2C;QAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,EAAE,CAAC;IACJ,qFAAqF;IACrF,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC/B,CAAC"}
|
|
@@ -14,6 +14,12 @@ export type GetBalancesQueryParams = {
|
|
|
14
14
|
/** Whether to include balances of the account's staked asset balances */
|
|
15
15
|
includeStakedAssets?: boolean;
|
|
16
16
|
};
|
|
17
|
+
export type GetBalancesQueryParamsV4 = {
|
|
18
|
+
/** Comma-separated network/chain IDs */
|
|
19
|
+
networks?: string;
|
|
20
|
+
/** Comma-separated account addresses */
|
|
21
|
+
accountAddresses?: string;
|
|
22
|
+
};
|
|
17
23
|
export type GetBalancesResponse = {
|
|
18
24
|
count: number;
|
|
19
25
|
balances: {
|
|
@@ -30,6 +36,8 @@ export type GetBalancesResponse = {
|
|
|
30
36
|
chainId: number;
|
|
31
37
|
/** string representation of the balance in decimal format (decimals adjusted). e.g. - 123.456789 */
|
|
32
38
|
balance: string;
|
|
39
|
+
/** Account address for V4 API responses */
|
|
40
|
+
accountAddress?: string;
|
|
33
41
|
}[];
|
|
34
42
|
/** networks that failed to process, if no network is processed, returns HTTP 422 */
|
|
35
43
|
unprocessedNetworks: number[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,4BAA4B,GAAG;IACzC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE;QACd,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+FAA+F;IAC/F,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,iFAAiF;IACjF,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,yEAAyE;IACzE,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,yDAAyD;QACzD,MAAM,EAAE,MAAM,CAAC;QACf,6FAA6F;QAC7F,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,2DAA2D;QAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,oGAAoG;QACpG,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,4BAA4B,GAAG;IACzC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,EAAE;QACd,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+FAA+F;IAC/F,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,iFAAiF;IACjF,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,yEAAyE;IACzE,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,wCAAwC;IACxC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,yDAAyD;QACzD,MAAM,EAAE,MAAM,CAAC;QACf,6FAA6F;QAC7F,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,2DAA2D;QAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,oGAAoG;QACpG,OAAO,EAAE,MAAM,CAAC;QAChB,2CAA2C;QAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,EAAE,CAAC;IACJ,qFAAqF;IACrF,mBAAmB,EAAE,MAAM,EAAE,CAAC;CAC/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/types.ts"],"names":[],"mappings":"","sourcesContent":["export type GetSupportedNetworksResponse = {\n fullSupport: number[];\n partialSupport: {\n balances: number[];\n };\n};\n\nexport type GetBalancesQueryParams = {\n /** Comma-separated network/chain IDs */\n networks?: string;\n /** Whether or not to filter the assets to contain only the tokens existing in the Token API */\n filterSupportedTokens?: boolean;\n /** Specific token addresses to fetch balances for across specified network(s) */\n includeTokenAddresses?: string;\n /** Whether to include balances of the account's staked asset balances */\n includeStakedAssets?: boolean;\n};\n\nexport type GetBalancesResponse = {\n count: number;\n balances: {\n /** Underlying object type. Seems to be always `token` */\n object: string;\n /** Token Type: This is only supplied as `native` to native chain tokens (e.g. - ETH, POL) */\n type?: string;\n /** Timestamp is only provided for `native` chain tokens */\n timestamp?: string;\n address: string;\n symbol: string;\n name: string;\n decimals: number;\n chainId: number;\n /** string representation of the balance in decimal format (decimals adjusted). e.g. - 123.456789 */\n balance: string;\n }[];\n /** networks that failed to process, if no network is processed, returns HTTP 422 */\n unprocessedNetworks: number[];\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/multi-chain-accounts-service/types.ts"],"names":[],"mappings":"","sourcesContent":["export type GetSupportedNetworksResponse = {\n fullSupport: number[];\n partialSupport: {\n balances: number[];\n };\n};\n\nexport type GetBalancesQueryParams = {\n /** Comma-separated network/chain IDs */\n networks?: string;\n /** Whether or not to filter the assets to contain only the tokens existing in the Token API */\n filterSupportedTokens?: boolean;\n /** Specific token addresses to fetch balances for across specified network(s) */\n includeTokenAddresses?: string;\n /** Whether to include balances of the account's staked asset balances */\n includeStakedAssets?: boolean;\n};\n\nexport type GetBalancesQueryParamsV4 = {\n /** Comma-separated network/chain IDs */\n networks?: string;\n\n /** Comma-separated account addresses */\n accountAddresses?: string;\n};\n\nexport type GetBalancesResponse = {\n count: number;\n balances: {\n /** Underlying object type. Seems to be always `token` */\n object: string;\n /** Token Type: This is only supplied as `native` to native chain tokens (e.g. - ETH, POL) */\n type?: string;\n /** Timestamp is only provided for `native` chain tokens */\n timestamp?: string;\n address: string;\n symbol: string;\n name: string;\n decimals: number;\n chainId: number;\n /** string representation of the balance in decimal format (decimals adjusted). e.g. - 123.456789 */\n balance: string;\n /** Account address for V4 API responses */\n accountAddress?: string;\n }[];\n /** networks that failed to process, if no network is processed, returns HTTP 422 */\n unprocessedNetworks: number[];\n};\n"]}
|
package/dist/multicall.cjs
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.multicallOrFallback = void 0;
|
|
6
|
+
exports.getTokenBalancesForMultipleAddresses = exports.getStakedBalancesForAddresses = exports.aggregate3 = exports.multicallOrFallback = void 0;
|
|
4
7
|
const contracts_1 = require("@ethersproject/contracts");
|
|
8
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
9
|
+
const AssetsContractController_1 = require("./AssetsContractController.cjs");
|
|
5
10
|
const assetsUtil_1 = require("./assetsUtil.cjs");
|
|
6
11
|
// https://github.com/mds1/multicall/blob/main/deployments.json
|
|
7
12
|
const MULTICALL_CONTRACT_BY_CHAINID = {
|
|
@@ -285,6 +290,78 @@ const multicallAbi = [
|
|
|
285
290
|
],
|
|
286
291
|
},
|
|
287
292
|
];
|
|
293
|
+
// Multicall3 ABI for aggregate3 function
|
|
294
|
+
const multicall3Abi = [
|
|
295
|
+
{
|
|
296
|
+
name: 'aggregate3',
|
|
297
|
+
type: 'function',
|
|
298
|
+
stateMutability: 'payable',
|
|
299
|
+
inputs: [
|
|
300
|
+
{
|
|
301
|
+
name: 'calls',
|
|
302
|
+
type: 'tuple[]',
|
|
303
|
+
components: [
|
|
304
|
+
{ name: 'target', type: 'address' },
|
|
305
|
+
{ name: 'allowFailure', type: 'bool' },
|
|
306
|
+
{ name: 'callData', type: 'bytes' },
|
|
307
|
+
],
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
outputs: [
|
|
311
|
+
{
|
|
312
|
+
name: 'returnData',
|
|
313
|
+
type: 'tuple[]',
|
|
314
|
+
components: [
|
|
315
|
+
{ name: 'success', type: 'bool' },
|
|
316
|
+
{ name: 'returnData', type: 'bytes' },
|
|
317
|
+
],
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
},
|
|
321
|
+
];
|
|
322
|
+
// Constants for encoded strings and addresses
|
|
323
|
+
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
324
|
+
const BALANCE_OF_FUNCTION = 'balanceOf(address)';
|
|
325
|
+
const GET_ETH_BALANCE_FUNCTION = 'getEthBalance';
|
|
326
|
+
const GET_SHARES_FUNCTION = 'getShares';
|
|
327
|
+
const CONVERT_TO_ASSETS_FUNCTION = 'convertToAssets';
|
|
328
|
+
// ERC20 balanceOf ABI
|
|
329
|
+
const ERC20_BALANCE_OF_ABI = [
|
|
330
|
+
{
|
|
331
|
+
name: 'balanceOf',
|
|
332
|
+
type: 'function',
|
|
333
|
+
inputs: [{ name: 'account', type: 'address' }],
|
|
334
|
+
outputs: [{ name: '', type: 'uint256' }],
|
|
335
|
+
stateMutability: 'view',
|
|
336
|
+
},
|
|
337
|
+
];
|
|
338
|
+
// Multicall3 getEthBalance ABI
|
|
339
|
+
const MULTICALL3_GET_ETH_BALANCE_ABI = [
|
|
340
|
+
{
|
|
341
|
+
name: 'getEthBalance',
|
|
342
|
+
type: 'function',
|
|
343
|
+
inputs: [{ name: 'addr', type: 'address' }],
|
|
344
|
+
outputs: [{ name: 'balance', type: 'uint256' }],
|
|
345
|
+
stateMutability: 'view',
|
|
346
|
+
},
|
|
347
|
+
];
|
|
348
|
+
// Staking contract ABI with both getShares and convertToAssets
|
|
349
|
+
const STAKING_CONTRACT_ABI = [
|
|
350
|
+
{
|
|
351
|
+
inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
|
|
352
|
+
name: 'getShares',
|
|
353
|
+
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
354
|
+
stateMutability: 'view',
|
|
355
|
+
type: 'function',
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
inputs: [{ internalType: 'uint256', name: 'shares', type: 'uint256' }],
|
|
359
|
+
name: 'convertToAssets',
|
|
360
|
+
outputs: [{ internalType: 'uint256', name: 'assets', type: 'uint256' }],
|
|
361
|
+
stateMutability: 'view',
|
|
362
|
+
type: 'function',
|
|
363
|
+
},
|
|
364
|
+
];
|
|
288
365
|
const multicall = async (calls, multicallAddress, provider, maxCallsPerMulticall) => {
|
|
289
366
|
const multicallContract = new contracts_1.Contract(multicallAddress, multicallAbi, provider);
|
|
290
367
|
return await (0, assetsUtil_1.reduceInBatchesSerially)({
|
|
@@ -330,6 +407,7 @@ const fallback = async (calls, maxCallsParallel) => {
|
|
|
330
407
|
* Executes an array of contract calls. If the chain supports multicalls,
|
|
331
408
|
* the calls will be executed in single RPC requests (up to maxCallsPerMulticall).
|
|
332
409
|
* Otherwise the calls will be executed separately in parallel (up to maxCallsParallel).
|
|
410
|
+
*
|
|
333
411
|
* @param calls - An array of contract calls to execute.
|
|
334
412
|
* @param chainId - The hexadecimal chain id.
|
|
335
413
|
* @param provider - An ethers rpc provider.
|
|
@@ -360,4 +438,382 @@ const multicallOrFallback = async (calls, chainId, provider, maxCallsPerMultical
|
|
|
360
438
|
return await fallback(calls, maxCallsParallel);
|
|
361
439
|
};
|
|
362
440
|
exports.multicallOrFallback = multicallOrFallback;
|
|
441
|
+
/**
|
|
442
|
+
* Execute multiple contract calls using Multicall3's aggregate3 function.
|
|
443
|
+
* This allows for more efficient batch calls with individual failure handling.
|
|
444
|
+
*
|
|
445
|
+
* @param calls - Array of calls to execute via aggregate3
|
|
446
|
+
* @param chainId - The hexadecimal chain id
|
|
447
|
+
* @param provider - An ethers rpc provider
|
|
448
|
+
* @returns Promise resolving to array of results from aggregate3
|
|
449
|
+
*/
|
|
450
|
+
const aggregate3 = async (calls, chainId, provider) => {
|
|
451
|
+
if (calls.length === 0) {
|
|
452
|
+
return [];
|
|
453
|
+
}
|
|
454
|
+
const multicall3Address = MULTICALL_CONTRACT_BY_CHAINID[chainId];
|
|
455
|
+
const multicall3Contract = new contracts_1.Contract(multicall3Address, multicall3Abi, provider);
|
|
456
|
+
return await multicall3Contract.callStatic.aggregate3(calls);
|
|
457
|
+
};
|
|
458
|
+
exports.aggregate3 = aggregate3;
|
|
459
|
+
/**
|
|
460
|
+
* Processes and decodes balance results from aggregate3 calls
|
|
461
|
+
*
|
|
462
|
+
* @param results - Array of results from aggregate3 calls
|
|
463
|
+
* @param callMapping - Array mapping call indices to token and user addresses
|
|
464
|
+
* @param chainId - The hexadecimal chain id
|
|
465
|
+
* @param provider - An ethers rpc provider
|
|
466
|
+
* @param includeStaked - Whether to include staked balances
|
|
467
|
+
* @returns Map of token address to map of user address to balance
|
|
468
|
+
*/
|
|
469
|
+
const processBalanceResults = (results, callMapping, chainId, provider, includeStaked) => {
|
|
470
|
+
const balanceMap = {};
|
|
471
|
+
const stakedBalanceMap = {};
|
|
472
|
+
// Create contract instances for decoding
|
|
473
|
+
const erc20Contract = new contracts_1.Contract(ZERO_ADDRESS, ERC20_BALANCE_OF_ABI, provider);
|
|
474
|
+
const multicall3Address = MULTICALL_CONTRACT_BY_CHAINID[chainId];
|
|
475
|
+
const multicall3Contract = new contracts_1.Contract(multicall3Address, MULTICALL3_GET_ETH_BALANCE_ABI, provider);
|
|
476
|
+
// Staking contracts are now handled separately in two-step process
|
|
477
|
+
results.forEach((result, index) => {
|
|
478
|
+
if (result.success) {
|
|
479
|
+
const { tokenAddress, userAddress, callType } = callMapping[index];
|
|
480
|
+
let balance;
|
|
481
|
+
if (callType === 'native') {
|
|
482
|
+
// For native token, decode the getEthBalance result
|
|
483
|
+
balance = multicall3Contract.interface.decodeFunctionResult(GET_ETH_BALANCE_FUNCTION, result.returnData)[0];
|
|
484
|
+
if (!balanceMap[tokenAddress]) {
|
|
485
|
+
balanceMap[tokenAddress] = {};
|
|
486
|
+
}
|
|
487
|
+
balanceMap[tokenAddress][userAddress] = balance;
|
|
488
|
+
}
|
|
489
|
+
else if (callType === 'staking') {
|
|
490
|
+
// Staking is now handled separately in two-step process
|
|
491
|
+
// This case should not occur anymore
|
|
492
|
+
console.warn('Staking callType found in main processing - this should not happen');
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
// For ERC20 tokens, decode the balanceOf result
|
|
496
|
+
balance = erc20Contract.interface.decodeFunctionResult(BALANCE_OF_FUNCTION, result.returnData)[0];
|
|
497
|
+
if (!balanceMap[tokenAddress]) {
|
|
498
|
+
balanceMap[tokenAddress] = {};
|
|
499
|
+
}
|
|
500
|
+
balanceMap[tokenAddress][userAddress] = balance;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
const result = { tokenBalances: balanceMap };
|
|
505
|
+
if (includeStaked && Object.keys(stakedBalanceMap).length > 0) {
|
|
506
|
+
result.stakedBalances = stakedBalanceMap;
|
|
507
|
+
}
|
|
508
|
+
return result;
|
|
509
|
+
};
|
|
510
|
+
/**
|
|
511
|
+
* Fallback function to get native token balances using individual eth_getBalance calls
|
|
512
|
+
* when Multicall3 is not supported on the chain.
|
|
513
|
+
*
|
|
514
|
+
* @param userAddresses - Array of user addresses to check balances for
|
|
515
|
+
* @param provider - An ethers rpc provider
|
|
516
|
+
* @param maxCallsParallel - Maximum number of parallel calls (default: 20)
|
|
517
|
+
* @returns Promise resolving to map of user address to balance
|
|
518
|
+
*/
|
|
519
|
+
const getNativeBalancesFallback = async (userAddresses, provider, maxCallsParallel = 20) => {
|
|
520
|
+
const balanceMap = {};
|
|
521
|
+
await (0, assetsUtil_1.reduceInBatchesSerially)({
|
|
522
|
+
values: userAddresses,
|
|
523
|
+
batchSize: maxCallsParallel,
|
|
524
|
+
initialResult: undefined,
|
|
525
|
+
eachBatch: async (_, batch) => {
|
|
526
|
+
const results = await Promise.allSettled(batch.map(async (userAddress) => {
|
|
527
|
+
const balance = await provider.getBalance(userAddress);
|
|
528
|
+
return {
|
|
529
|
+
success: true,
|
|
530
|
+
balance: new bn_js_1.default(balance.toString()),
|
|
531
|
+
userAddress,
|
|
532
|
+
};
|
|
533
|
+
}));
|
|
534
|
+
results.forEach((result) => {
|
|
535
|
+
if (result.status === 'fulfilled' &&
|
|
536
|
+
result.value.success &&
|
|
537
|
+
result.value.balance !== null) {
|
|
538
|
+
balanceMap[result.value.userAddress] = result.value.balance;
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
},
|
|
542
|
+
});
|
|
543
|
+
return balanceMap;
|
|
544
|
+
};
|
|
545
|
+
/**
|
|
546
|
+
* Fallback function to get token balances using individual calls
|
|
547
|
+
* when Multicall3 is not supported or when aggregate3 calls fail.
|
|
548
|
+
*
|
|
549
|
+
* @param tokenAddresses - Array of ERC20 token contract addresses
|
|
550
|
+
* @param userAddresses - Array of user addresses to check balances for
|
|
551
|
+
* @param provider - An ethers rpc provider
|
|
552
|
+
* @param includeNative - Whether to include native token balances (default: true)
|
|
553
|
+
* @param maxCallsParallel - Maximum number of parallel calls (default: 20)
|
|
554
|
+
* @returns Promise resolving to map of token address to map of user address to balance
|
|
555
|
+
*/
|
|
556
|
+
const getTokenBalancesFallback = async (tokenAddresses, userAddresses, provider, includeNative, maxCallsParallel) => {
|
|
557
|
+
const balanceMap = {};
|
|
558
|
+
// Handle ERC20 token balances using the existing fallback function
|
|
559
|
+
if (tokenAddresses.length > 0) {
|
|
560
|
+
const erc20Calls = [];
|
|
561
|
+
const callMapping = [];
|
|
562
|
+
tokenAddresses.forEach((tokenAddress) => {
|
|
563
|
+
userAddresses.forEach((userAddress) => {
|
|
564
|
+
const contract = new contracts_1.Contract(tokenAddress, ERC20_BALANCE_OF_ABI, provider);
|
|
565
|
+
erc20Calls.push({
|
|
566
|
+
contract,
|
|
567
|
+
functionSignature: BALANCE_OF_FUNCTION,
|
|
568
|
+
arguments: [userAddress],
|
|
569
|
+
});
|
|
570
|
+
callMapping.push({ tokenAddress, userAddress });
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
const erc20Results = await fallback(erc20Calls, maxCallsParallel);
|
|
574
|
+
erc20Results.forEach((result, index) => {
|
|
575
|
+
if (result.success) {
|
|
576
|
+
const { tokenAddress, userAddress } = callMapping[index];
|
|
577
|
+
if (!balanceMap[tokenAddress]) {
|
|
578
|
+
balanceMap[tokenAddress] = {};
|
|
579
|
+
}
|
|
580
|
+
balanceMap[tokenAddress][userAddress] = result.value;
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
// Handle native token balances using the native fallback function
|
|
585
|
+
if (includeNative) {
|
|
586
|
+
const nativeBalances = await getNativeBalancesFallback(userAddresses, provider, maxCallsParallel);
|
|
587
|
+
if (Object.keys(nativeBalances).length > 0) {
|
|
588
|
+
balanceMap[ZERO_ADDRESS] = nativeBalances;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return balanceMap;
|
|
592
|
+
};
|
|
593
|
+
/**
|
|
594
|
+
* Fallback function to get staked balances using individual calls
|
|
595
|
+
* when Multicall3 is not supported or when aggregate3 calls fail.
|
|
596
|
+
*
|
|
597
|
+
* @param userAddresses - Array of user addresses to check staked balances for
|
|
598
|
+
* @param chainId - The hexadecimal chain id
|
|
599
|
+
* @param provider - An ethers rpc provider
|
|
600
|
+
* @param maxCallsParallel - Maximum number of parallel calls (default: 20)
|
|
601
|
+
* @returns Promise resolving to map of user address to staked balance
|
|
602
|
+
*/
|
|
603
|
+
const getStakedBalancesFallback = async (userAddresses, chainId, provider, maxCallsParallel) => {
|
|
604
|
+
const stakedBalanceMap = {};
|
|
605
|
+
const stakingContractAddress = AssetsContractController_1.STAKING_CONTRACT_ADDRESS_BY_CHAINID[chainId];
|
|
606
|
+
if (!stakingContractAddress) {
|
|
607
|
+
// No staking support for this chain
|
|
608
|
+
return stakedBalanceMap;
|
|
609
|
+
}
|
|
610
|
+
const stakingCalls = [];
|
|
611
|
+
const callMapping = [];
|
|
612
|
+
userAddresses.forEach((userAddress) => {
|
|
613
|
+
const contract = new contracts_1.Contract(stakingContractAddress, STAKING_CONTRACT_ABI, provider);
|
|
614
|
+
stakingCalls.push({
|
|
615
|
+
contract,
|
|
616
|
+
functionSignature: GET_SHARES_FUNCTION,
|
|
617
|
+
arguments: [userAddress],
|
|
618
|
+
});
|
|
619
|
+
callMapping.push({ userAddress });
|
|
620
|
+
});
|
|
621
|
+
const stakingResults = await fallback(stakingCalls, maxCallsParallel);
|
|
622
|
+
stakingResults.forEach((result, index) => {
|
|
623
|
+
if (result.success) {
|
|
624
|
+
const { userAddress } = callMapping[index];
|
|
625
|
+
stakedBalanceMap[userAddress] = result.value;
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
return stakedBalanceMap;
|
|
629
|
+
};
|
|
630
|
+
/**
|
|
631
|
+
* Get staked balances for multiple addresses using two-step process:
|
|
632
|
+
* 1. Get shares for all addresses
|
|
633
|
+
* 2. Convert non-zero shares to assets
|
|
634
|
+
*
|
|
635
|
+
* @param userAddresses - Array of user addresses to check
|
|
636
|
+
* @param chainId - Chain ID as hex string
|
|
637
|
+
* @param provider - Ethers provider
|
|
638
|
+
* @returns Promise resolving to map of user address to staked balance
|
|
639
|
+
*/
|
|
640
|
+
const getStakedBalancesForAddresses = async (userAddresses, chainId, provider) => {
|
|
641
|
+
const stakingContractAddress = AssetsContractController_1.STAKING_CONTRACT_ADDRESS_BY_CHAINID[chainId];
|
|
642
|
+
if (!stakingContractAddress) {
|
|
643
|
+
return {};
|
|
644
|
+
}
|
|
645
|
+
const stakingContract = new contracts_1.Contract(stakingContractAddress, STAKING_CONTRACT_ABI, provider);
|
|
646
|
+
try {
|
|
647
|
+
// Step 1: Get shares for all addresses
|
|
648
|
+
const shareCalls = userAddresses.map((userAddress) => ({
|
|
649
|
+
target: stakingContractAddress,
|
|
650
|
+
allowFailure: true,
|
|
651
|
+
callData: stakingContract.interface.encodeFunctionData(GET_SHARES_FUNCTION, [userAddress]),
|
|
652
|
+
}));
|
|
653
|
+
const shareResults = await (0, exports.aggregate3)(shareCalls, chainId, provider);
|
|
654
|
+
// Step 2: For addresses with non-zero shares, convert to assets
|
|
655
|
+
const nonZeroSharesData = [];
|
|
656
|
+
shareResults.forEach((result, index) => {
|
|
657
|
+
if (result.success) {
|
|
658
|
+
const sharesRaw = stakingContract.interface.decodeFunctionResult(GET_SHARES_FUNCTION, result.returnData)[0];
|
|
659
|
+
const shares = new bn_js_1.default(sharesRaw.toString());
|
|
660
|
+
if (shares.gt(new bn_js_1.default(0))) {
|
|
661
|
+
nonZeroSharesData.push({
|
|
662
|
+
address: userAddresses[index],
|
|
663
|
+
shares,
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
if (nonZeroSharesData.length === 0) {
|
|
669
|
+
return {};
|
|
670
|
+
}
|
|
671
|
+
// Step 3: Convert shares to assets for addresses with non-zero shares
|
|
672
|
+
const assetCalls = nonZeroSharesData.map(({ shares }) => ({
|
|
673
|
+
target: stakingContractAddress,
|
|
674
|
+
allowFailure: true,
|
|
675
|
+
callData: stakingContract.interface.encodeFunctionData(CONVERT_TO_ASSETS_FUNCTION, [shares.toString()]),
|
|
676
|
+
}));
|
|
677
|
+
const assetResults = await (0, exports.aggregate3)(assetCalls, chainId, provider);
|
|
678
|
+
// Step 4: Build final result mapping
|
|
679
|
+
const result = {};
|
|
680
|
+
assetResults.forEach((assetResult, index) => {
|
|
681
|
+
if (assetResult.success) {
|
|
682
|
+
const assetsRaw = stakingContract.interface.decodeFunctionResult(CONVERT_TO_ASSETS_FUNCTION, assetResult.returnData)[0];
|
|
683
|
+
const assets = new bn_js_1.default(assetsRaw.toString());
|
|
684
|
+
const { address } = nonZeroSharesData[index];
|
|
685
|
+
result[address] = assets;
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
return result;
|
|
689
|
+
}
|
|
690
|
+
catch (error) {
|
|
691
|
+
console.error('Error fetching staked balances:', error);
|
|
692
|
+
return {};
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
exports.getStakedBalancesForAddresses = getStakedBalancesForAddresses;
|
|
696
|
+
/**
|
|
697
|
+
* Get token balances (both ERC20 and native) for multiple addresses using aggregate3.
|
|
698
|
+
* This is more efficient than individual balanceOf calls for multiple addresses and tokens.
|
|
699
|
+
* Native token balances are mapped to the zero address (0x0000000000000000000000000000000000000000).
|
|
700
|
+
*
|
|
701
|
+
* @param accountTokenGroups - Array of objects containing account addresses and their associated token addresses
|
|
702
|
+
* @param chainId - The hexadecimal chain id
|
|
703
|
+
* @param provider - An ethers rpc provider
|
|
704
|
+
* @param includeNative - Whether to include native token balances (default: true)
|
|
705
|
+
* @param includeStaked - Whether to include staked balances from supported staking contracts (default: false)
|
|
706
|
+
* @returns Promise resolving to object containing tokenBalances map and optional stakedBalances map
|
|
707
|
+
*/
|
|
708
|
+
const getTokenBalancesForMultipleAddresses = async (accountTokenGroups, chainId, provider, includeNative, includeStaked) => {
|
|
709
|
+
// Return early if no groups provided
|
|
710
|
+
if (accountTokenGroups.length === 0 && !includeNative && !includeStaked) {
|
|
711
|
+
return { tokenBalances: {} };
|
|
712
|
+
}
|
|
713
|
+
// Extract unique token addresses and user addresses from groups
|
|
714
|
+
const uniqueTokenAddresses = Array.from(new Set(accountTokenGroups.flatMap((group) => group.tokenAddresses))).filter((tokenAddress) => tokenAddress !== ZERO_ADDRESS); // Exclude native token from ERC20 calls
|
|
715
|
+
const uniqueUserAddresses = Array.from(new Set(accountTokenGroups.map((group) => group.accountAddress)));
|
|
716
|
+
// Check if Multicall3 is supported on this chain
|
|
717
|
+
if (!MULTICALL_CONTRACT_BY_CHAINID[chainId]) {
|
|
718
|
+
// Fallback to individual balance calls when Multicall3 is not supported
|
|
719
|
+
const tokenBalances = await getTokenBalancesFallback(uniqueTokenAddresses, uniqueUserAddresses, provider, includeNative, 20);
|
|
720
|
+
const result = { tokenBalances };
|
|
721
|
+
// Handle staked balances fallback if requested
|
|
722
|
+
if (includeStaked) {
|
|
723
|
+
const stakedBalances = await getStakedBalancesFallback(uniqueUserAddresses, chainId, provider, 20);
|
|
724
|
+
if (Object.keys(stakedBalances).length > 0) {
|
|
725
|
+
result.stakedBalances = stakedBalances;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return result;
|
|
729
|
+
}
|
|
730
|
+
try {
|
|
731
|
+
// Create calls directly from pairs
|
|
732
|
+
const allCalls = [];
|
|
733
|
+
const allCallMapping = [];
|
|
734
|
+
// Create a temporary ERC20 contract for encoding
|
|
735
|
+
const tempERC20Contract = new contracts_1.Contract(ZERO_ADDRESS, ERC20_BALANCE_OF_ABI, provider);
|
|
736
|
+
// Create ERC20 balance calls for all account-token combinations
|
|
737
|
+
accountTokenGroups.forEach((group) => {
|
|
738
|
+
group.tokenAddresses
|
|
739
|
+
.filter((tokenAddress) => tokenAddress !== ZERO_ADDRESS)
|
|
740
|
+
.forEach((tokenAddress) => {
|
|
741
|
+
allCalls.push({
|
|
742
|
+
target: tokenAddress,
|
|
743
|
+
allowFailure: true,
|
|
744
|
+
callData: tempERC20Contract.interface.encodeFunctionData(BALANCE_OF_FUNCTION, [group.accountAddress]),
|
|
745
|
+
});
|
|
746
|
+
allCallMapping.push({
|
|
747
|
+
tokenAddress,
|
|
748
|
+
userAddress: group.accountAddress,
|
|
749
|
+
callType: 'erc20',
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
});
|
|
753
|
+
// Add native token balance calls if requested
|
|
754
|
+
if (includeNative) {
|
|
755
|
+
const multicall3Address = MULTICALL_CONTRACT_BY_CHAINID[chainId];
|
|
756
|
+
const multicall3TempContract = new contracts_1.Contract(multicall3Address, MULTICALL3_GET_ETH_BALANCE_ABI, provider);
|
|
757
|
+
uniqueUserAddresses.forEach((userAddress) => {
|
|
758
|
+
allCalls.push({
|
|
759
|
+
target: multicall3Address,
|
|
760
|
+
allowFailure: true,
|
|
761
|
+
callData: multicall3TempContract.interface.encodeFunctionData(GET_ETH_BALANCE_FUNCTION, [userAddress]),
|
|
762
|
+
});
|
|
763
|
+
allCallMapping.push({
|
|
764
|
+
tokenAddress: ZERO_ADDRESS,
|
|
765
|
+
userAddress,
|
|
766
|
+
callType: 'native',
|
|
767
|
+
});
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
// Note: Staking balances will be handled separately in two steps after token/native calls
|
|
771
|
+
// Execute all calls in batches
|
|
772
|
+
const maxCallsPerBatch = 300; // Limit calls per batch to avoid gas/size limits
|
|
773
|
+
const allResults = [];
|
|
774
|
+
await (0, assetsUtil_1.reduceInBatchesSerially)({
|
|
775
|
+
values: allCalls,
|
|
776
|
+
batchSize: maxCallsPerBatch,
|
|
777
|
+
initialResult: undefined,
|
|
778
|
+
eachBatch: async (_, batch) => {
|
|
779
|
+
const batchResults = await (0, exports.aggregate3)(batch, chainId, provider);
|
|
780
|
+
allResults.push(...batchResults);
|
|
781
|
+
},
|
|
782
|
+
});
|
|
783
|
+
// Handle staking balances in two steps if requested
|
|
784
|
+
let stakedBalances = {};
|
|
785
|
+
if (includeStaked) {
|
|
786
|
+
stakedBalances = await (0, exports.getStakedBalancesForAddresses)(uniqueUserAddresses, chainId, provider);
|
|
787
|
+
}
|
|
788
|
+
// Process and return results
|
|
789
|
+
const result = processBalanceResults(allResults, allCallMapping, chainId, provider, false);
|
|
790
|
+
// Add staked balances to result
|
|
791
|
+
if (includeStaked && Object.keys(stakedBalances).length > 0) {
|
|
792
|
+
result.stakedBalances = stakedBalances;
|
|
793
|
+
}
|
|
794
|
+
return result;
|
|
795
|
+
}
|
|
796
|
+
catch (error) {
|
|
797
|
+
// Fallback only on revert
|
|
798
|
+
// https://docs.ethers.org/v5/troubleshooting/errors/#help-CALL_EXCEPTION
|
|
799
|
+
if (!error ||
|
|
800
|
+
typeof error !== 'object' ||
|
|
801
|
+
!('code' in error) ||
|
|
802
|
+
error.code !== 'CALL_EXCEPTION') {
|
|
803
|
+
throw error;
|
|
804
|
+
}
|
|
805
|
+
// Fallback to individual balance calls when aggregate3 fails
|
|
806
|
+
const tokenBalances = await getTokenBalancesFallback(uniqueTokenAddresses, uniqueUserAddresses, provider, includeNative, 20);
|
|
807
|
+
const result = { tokenBalances };
|
|
808
|
+
// Handle staked balances fallback if requested
|
|
809
|
+
if (includeStaked) {
|
|
810
|
+
const stakedBalances = await getStakedBalancesFallback(uniqueUserAddresses, chainId, provider, 20);
|
|
811
|
+
if (Object.keys(stakedBalances).length > 0) {
|
|
812
|
+
result.stakedBalances = stakedBalances;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
return result;
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
exports.getTokenBalancesForMultipleAddresses = getTokenBalancesForMultipleAddresses;
|
|
363
819
|
//# sourceMappingURL=multicall.cjs.map
|