@metamask-previews/assets-controller 20.4.1-preview-730f5d72e → 20.4.1-preview-e9ac9ffe1

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist/AssetsController.d.ts +3 -2
  3. package/dist/AssetsController.d.ts.map +1 -1
  4. package/dist/AssetsController.js +28 -394
  5. package/dist/AssetsController.js.map +1 -1
  6. package/dist/data-sources/AccountActivityDataSource.js +2 -2
  7. package/dist/data-sources/AccountActivityDataSource.js.map +1 -1
  8. package/dist/data-sources/AccountsApiDataSource.d.ts +3 -26
  9. package/dist/data-sources/AccountsApiDataSource.d.ts.map +1 -1
  10. package/dist/data-sources/AccountsApiDataSource.js +2 -203
  11. package/dist/data-sources/AccountsApiDataSource.js.map +1 -1
  12. package/dist/data-sources/RpcDataSource.d.ts +0 -6
  13. package/dist/data-sources/RpcDataSource.d.ts.map +1 -1
  14. package/dist/data-sources/RpcDataSource.js +4 -179
  15. package/dist/data-sources/RpcDataSource.js.map +1 -1
  16. package/dist/data-sources/SnapDataSource.d.ts +0 -2
  17. package/dist/data-sources/SnapDataSource.d.ts.map +1 -1
  18. package/dist/data-sources/SnapDataSource.js +1 -67
  19. package/dist/data-sources/SnapDataSource.js.map +1 -1
  20. package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.ts.map +1 -1
  21. package/dist/data-sources/evm-rpc-services/clients/MulticallClient.js +0 -1
  22. package/dist/data-sources/evm-rpc-services/clients/MulticallClient.js.map +1 -1
  23. package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.ts +0 -12
  24. package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.ts.map +1 -1
  25. package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.js +9 -70
  26. package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.js.map +1 -1
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/middlewares/RpcFallbackMiddleware.d.ts +4 -18
  32. package/dist/middlewares/RpcFallbackMiddleware.d.ts.map +1 -1
  33. package/dist/middlewares/RpcFallbackMiddleware.js +5 -163
  34. package/dist/middlewares/RpcFallbackMiddleware.js.map +1 -1
  35. package/dist/middlewares/index.d.ts +0 -2
  36. package/dist/middlewares/index.d.ts.map +1 -1
  37. package/dist/middlewares/index.js +0 -1
  38. package/dist/middlewares/index.js.map +1 -1
  39. package/dist/pipeline/buildFastFetchSources.d.ts +6 -13
  40. package/dist/pipeline/buildFastFetchSources.d.ts.map +1 -1
  41. package/dist/pipeline/buildFastFetchSources.js +7 -15
  42. package/dist/pipeline/buildFastFetchSources.js.map +1 -1
  43. package/dist/pipeline/buildUpdateSources.d.ts +0 -3
  44. package/dist/pipeline/buildUpdateSources.d.ts.map +1 -1
  45. package/dist/pipeline/buildUpdateSources.js +1 -5
  46. package/dist/pipeline/buildUpdateSources.js.map +1 -1
  47. package/dist/pipeline/buildWsUpdateSources.d.ts +2 -5
  48. package/dist/pipeline/buildWsUpdateSources.d.ts.map +1 -1
  49. package/dist/pipeline/buildWsUpdateSources.js +9 -14
  50. package/dist/pipeline/buildWsUpdateSources.js.map +1 -1
  51. package/dist/types.d.ts +0 -8
  52. package/dist/types.d.ts.map +1 -1
  53. package/dist/types.js.map +1 -1
  54. package/dist/utils/native-assets.d.ts.map +1 -1
  55. package/dist/utils/native-assets.js +0 -1
  56. package/dist/utils/native-assets.js.map +1 -1
  57. package/package.json +2 -2
  58. package/dist/middlewares/CustomAssetGraduationMiddleware.d.ts +0 -34
  59. package/dist/middlewares/CustomAssetGraduationMiddleware.d.ts.map +0 -1
  60. package/dist/middlewares/CustomAssetGraduationMiddleware.js +0 -117
  61. package/dist/middlewares/CustomAssetGraduationMiddleware.js.map +0 -1
  62. package/dist/utils/customAssetsRpcSupplement.d.ts +0 -60
  63. package/dist/utils/customAssetsRpcSupplement.d.ts.map +0 -1
  64. package/dist/utils/customAssetsRpcSupplement.js +0 -68
  65. package/dist/utils/customAssetsRpcSupplement.js.map +0 -1
@@ -1,26 +1,12 @@
1
- import type { AssetsControllerState, AssetsDataSource, Middleware } from '../types.js';
1
+ import type { AssetsDataSource, Middleware } from '../types.js';
2
2
  export type RpcFallbackMiddlewareOptions = {
3
3
  /** The RPC data source to use as a fallback. */
4
4
  rpcDataSource: AssetsDataSource;
5
- /**
6
- * When true, recover failed and unprocessed chains with a full RPC refetch
7
- * (Accounts API v6). When false, re-read stale tracked assets the v5 API
8
- * omitted (legacy path).
9
- */
10
- isBalanceV6Enabled?: () => boolean;
11
- /** Current AssetsController state. Used to find tracked assets the response left empty. */
12
- getAssetsState: () => AssetsControllerState;
13
5
  };
14
6
  /**
15
- * RpcFallbackMiddleware recovers what upstream sources left outstanding on RPC.
16
- *
17
- * Accounts API v5: chains in `response.errors`, plus EVM assets tracked in
18
- * state that this response left empty (the API omits tokens it does not index).
19
- *
20
- * Accounts API v6: one RPC retry on the chain axis. Chains in
21
- * `response.errors` are refetched in full (native + existing balances + pins +
22
- * default tracked assets). RPC reads those from state; the request is not
23
- * scoped via `customAssets`.
7
+ * RpcFallbackMiddleware recovers chains upstream sources left in `errors`
8
+ * with one RPC refetch. RPC reads native, existing balances, pins, and
9
+ * default tracked assets from controller state.
24
10
  */
25
11
  export declare class RpcFallbackMiddleware {
26
12
  #private;
@@ -1 +1 @@
1
- {"version":3,"file":"RpcFallbackMiddleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/RpcFallbackMiddleware.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,qBAAqB,EACrB,gBAAgB,EAKhB,UAAU,EAEX,MAAM,aAAa,CAAC;AAQrB,MAAM,MAAM,4BAA4B,GAAG;IACzC,gDAAgD;IAChD,aAAa,EAAE,gBAAgB,CAAC;IAChC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,OAAO,CAAC;IACnC,2FAA2F;IAC3F,cAAc,EAAE,MAAM,qBAAqB,CAAC;CAC7C,CAAC;AAIF;;;;;;;;;;GAUG;AACH,qBAAa,qBAAqB;;IAChC,QAAQ,CAAC,IAAI,2BAAmB;IAQhC,YAAY,OAAO,EAAE,4BAA4B,EAKhD;IAED,OAAO,IAAI,MAAM,CAEhB;IAED,IAAI,gBAAgB,IAAI,UAAU,CAOjC;CA0JF"}
1
+ {"version":3,"file":"RpcFallbackMiddleware.d.ts","sourceRoot":"","sources":["../../src/middlewares/RpcFallbackMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAGhB,UAAU,EAEX,MAAM,aAAa,CAAC;AAMrB,MAAM,MAAM,4BAA4B,GAAG;IACzC,gDAAgD;IAChD,aAAa,EAAE,gBAAgB,CAAC;CACjC,CAAC;AAIF;;;;GAIG;AACH,qBAAa,qBAAqB;;IAChC,QAAQ,CAAC,IAAI,2BAAmB;IAIhC,YAAY,OAAO,EAAE,4BAA4B,EAEhD;IAED,OAAO,IAAI,MAAM,CAEhB;IAED,IAAI,gBAAgB,IAAI,UAAU,CAIjC;CAuDF"}
@@ -1,46 +1,28 @@
1
- import { KnownCaipNamespace } from '@metamask/utils';
2
- import { isStakingContractAssetId } from '../data-sources/evm-rpc-services/index.js';
3
- import { projectLogger, createModuleLogger } from '../logger.js';
4
1
  import { forDataTypes } from '../types.js';
5
2
  import { filterFailedChainBalances } from '../utils/filterFailedChainBalances.js';
6
3
  import { mergeDataResponses } from './ParallelMiddleware.js';
7
4
  const CONTROLLER_NAME = 'RpcFallbackMiddleware';
8
- const log = createModuleLogger(projectLogger, CONTROLLER_NAME);
9
5
  const noopNext = async (ctx) => ctx;
10
6
  /**
11
- * RpcFallbackMiddleware recovers what upstream sources left outstanding on RPC.
12
- *
13
- * Accounts API v5: chains in `response.errors`, plus EVM assets tracked in
14
- * state that this response left empty (the API omits tokens it does not index).
15
- *
16
- * Accounts API v6: one RPC retry on the chain axis. Chains in
17
- * `response.errors` are refetched in full (native + existing balances + pins +
18
- * default tracked assets). RPC reads those from state; the request is not
19
- * scoped via `customAssets`.
7
+ * RpcFallbackMiddleware recovers chains upstream sources left in `errors`
8
+ * with one RPC refetch. RPC reads native, existing balances, pins, and
9
+ * default tracked assets from controller state.
20
10
  */
21
11
  export class RpcFallbackMiddleware {
22
12
  name = CONTROLLER_NAME;
23
13
  #rpcDataSource;
24
- #isBalanceV6Enabled;
25
- #getAssetsState;
26
14
  constructor(options) {
27
15
  this.#rpcDataSource = options.rpcDataSource;
28
- this.#isBalanceV6Enabled =
29
- options.isBalanceV6Enabled ?? (() => false);
30
- this.#getAssetsState = options.getAssetsState;
31
16
  }
32
17
  getName() {
33
18
  return this.name;
34
19
  }
35
20
  get assetsMiddleware() {
36
21
  return forDataTypes(['balance'], async (ctx, next) => {
37
- if (this.#isBalanceV6Enabled()) {
38
- return this.#recoverV6(ctx, next);
39
- }
40
- return this.#recoverV5(ctx, next);
22
+ return this.#recover(ctx, next);
41
23
  });
42
24
  }
43
- async #recoverV6(ctx, next) {
25
+ async #recover(ctx, next) {
44
26
  const erroredChains = new Set(Object.keys(ctx.response.errors ?? {}));
45
27
  const chainsToFetch = ctx.request.chainIds.filter((id) => erroredChains.has(id));
46
28
  if (chainsToFetch.length === 0) {
@@ -75,145 +57,5 @@ export class RpcFallbackMiddleware {
75
57
  }
76
58
  return next({ ...ctx, response: merged });
77
59
  }
78
- async #recoverV5(ctx, next) {
79
- const erroredChains = new Set(Object.keys(ctx.response.errors ?? {}));
80
- const staleAssets = collectStaleTrackedAssets(ctx, this.#getAssetsState());
81
- const chainsToFetch = [
82
- ...new Set([
83
- ...ctx.request.chainIds.filter((id) => erroredChains.has(id)),
84
- // Already restricted to requested chains. Their chain may not be
85
- // errored: the Accounts API can answer for a chain while omitting a
86
- // token it does not index.
87
- ...staleAssets.map((assetId) => assetId.split('/')[0]),
88
- ]),
89
- ];
90
- if (chainsToFetch.length === 0) {
91
- return next(ctx);
92
- }
93
- log('Re-reading balances on RPC', {
94
- erroredChains: [...erroredChains],
95
- staleAssets,
96
- chains: chainsToFetch,
97
- });
98
- const filteredRequest = {
99
- ...ctx.request,
100
- chainIds: chainsToFetch,
101
- customAssets: [
102
- ...new Set([...(ctx.request.customAssets ?? []), ...staleAssets]),
103
- ],
104
- };
105
- const rpcResult = await this.#rpcDataSource.assetsMiddleware({
106
- ...ctx,
107
- request: filteredRequest,
108
- response: {},
109
- }, noopNext);
110
- // A chain RPC itself failed on contributed nothing trustworthy: its
111
- // balances are failure stubs (native 0) that would overwrite correct
112
- // upstream amounts and, with replaceCoveredChainBalances, wipe the
113
- // chain's token slice from state. Drop them before merging — this also
114
- // keeps failed chains from counting as "recovered" below.
115
- const rpcFailedChains = new Set(Object.keys(rpcResult.response.errors ?? {}));
116
- const rpcAssetsBalance = filterFailedChainBalances(rpcResult.response.assetsBalance, rpcFailedChains);
117
- // RPC errors are kept only for chains that were already errored
118
- // upstream. For chains fetched solely for stale tracked assets the
119
- // upstream response succeeded and stays authoritative — the stale asset
120
- // keeps its previous amount and is retried on the next pass.
121
- const rpcErrors = Object.fromEntries(Object.entries(rpcResult.response.errors ?? {}).filter(([chainId]) => erroredChains.has(chainId)));
122
- const merged = mergeDataResponses([
123
- ctx.response,
124
- {
125
- ...rpcResult.response,
126
- assetsBalance: rpcAssetsBalance,
127
- errors: rpcErrors,
128
- },
129
- ]);
130
- // Clear errors only for chains RPC actually recovered a balance for.
131
- // We must inspect the (filtered) RPC balances — NOT merged — because
132
- // merged also contains balances from the upstream sources (AccountsApi /
133
- // Websocket / Staked). If those sources returned partial data for
134
- // a chain that they also flagged as errored (e.g. via
135
- // unprocessedNetworks), and RPC then failed for that same chain,
136
- // looking at merged would incorrectly mark the error as recovered.
137
- if (merged.errors && rpcAssetsBalance) {
138
- const chainsRecoveredByRpc = new Set();
139
- for (const accountBalances of Object.values(rpcAssetsBalance)) {
140
- for (const assetId of Object.keys(accountBalances)) {
141
- chainsRecoveredByRpc.add(assetId.split('/')[0]);
142
- }
143
- }
144
- for (const chainId of erroredChains) {
145
- if (chainsRecoveredByRpc.has(chainId)) {
146
- delete merged.errors[chainId];
147
- }
148
- }
149
- }
150
- return next({ ...ctx, response: merged });
151
- }
152
- }
153
- /**
154
- * EVM assets tracked in state that this balance response left empty and RPC
155
- * should re-read.
156
- *
157
- * Limited to chains both requested and supported by the owning account:
158
- * RpcDataSource fetches per account and skips chains outside its supported
159
- * set, so anything else would be queued and then silently dropped.
160
- *
161
- * @param ctx - Pipeline context.
162
- * @param state - Current AssetsController state.
163
- * @returns Asset IDs to hand to the RPC data source.
164
- */
165
- function collectStaleTrackedAssets(ctx, state) {
166
- const { assetsBalance: stateAssetsBalance, customAssets: stateCustomAssets } = state;
167
- const staleAssets = new Set();
168
- for (const { account, supportedChains } of ctx.request
169
- .accountsWithSupportedChains) {
170
- const accountId = account.id;
171
- const trackedAssetIds = new Set([
172
- ...Object.keys(stateAssetsBalance[accountId] ?? {}),
173
- ...(stateCustomAssets?.[accountId] ?? []),
174
- ]);
175
- const chainsForAccount = supportedChains.filter((chainId) => ctx.request.chainIds.includes(chainId));
176
- for (const assetId of trackedAssetIds) {
177
- if (isEvmAssetOnChains(assetId, chainsForAccount) &&
178
- // Staked vault balances belong to StakedBalanceDataSource; an RPC
179
- // ERC-20 read of the share token would clobber them.
180
- !isStakingContractAssetId(assetId) &&
181
- isBalanceEmpty(ctx.response.assetsBalance?.[accountId], assetId)) {
182
- staleAssets.add(assetId);
183
- }
184
- }
185
- }
186
- return [...staleAssets];
187
- }
188
- /**
189
- * Whether a balance response carries no positive amount for an asset. A
190
- * returned `0` cannot be distinguished from "not indexed", so both count as
191
- * empty. Asset IDs are matched case-insensitively: state keys ERC-20 assets by
192
- * checksummed address, while some data sources return them lower-cased.
193
- *
194
- * @param balances - Balance map for a single account from the response.
195
- * @param assetId - Asset ID to check.
196
- * @returns True when the response holds no positive amount for the asset.
197
- */
198
- function isBalanceEmpty(balances, assetId) {
199
- let amount = balances?.[assetId]?.amount;
200
- if (amount === undefined && balances) {
201
- const lowerCasedAssetId = assetId.toLowerCase();
202
- amount = Object.entries(balances).find(([id]) => id.toLowerCase() === lowerCasedAssetId)?.[1]?.amount;
203
- }
204
- return !(Number(amount) > 0);
205
- }
206
- /**
207
- * Whether an asset is an EVM asset on one of the given chains.
208
- *
209
- * @param assetId - CAIP-19 asset ID.
210
- * @param chainIds - Chains to match against.
211
- * @returns True for EVM assets whose chain is in `chainIds`.
212
- */
213
- function isEvmAssetOnChains(assetId, chainIds) {
214
- if (!assetId.startsWith(`${KnownCaipNamespace.Eip155}:`)) {
215
- return false;
216
- }
217
- return chainIds.includes(assetId.split('/')[0]);
218
60
  }
219
61
  //# sourceMappingURL=RpcFallbackMiddleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RpcFallbackMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/RpcFallbackMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAY3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEhD,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;AAe/D,MAAM,QAAQ,GAAG,KAAK,EAAE,GAAY,EAAoB,EAAE,CAAC,GAAG,CAAC;AAE/D;;;;;;;;;;GAUG;AACH,MAAM,OAAO,qBAAqB;IACvB,IAAI,GAAG,eAAe,CAAC;IAEvB,cAAc,CAAmB;IAEjC,mBAAmB,CAAgB;IAEnC,eAAe,CAA8B;IAEtD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CAAC,aAAa,EAAE,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,EAChE,CAAC;gBACD,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,WAAW,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,cAAc,CACrB,QAAkD,EAClD,OAAsB;IAEtB,IAAI,MAAM,GAAG,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IACzC,IAAI,MAAM,KAAK,SAAS,IAAI,QAAQ,EAAE,CAAC;QACrC,MAAM,iBAAiB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QAChD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CACpC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,iBAAiB,CACjD,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC;IACD,OAAO,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,OAAsB,EACtB,QAAmB;IAEnB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAY,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["import { KnownCaipNamespace } from '@metamask/utils';\n\nimport { isStakingContractAssetId } from '../data-sources/evm-rpc-services/index.js';\nimport { projectLogger, createModuleLogger } from '../logger.js';\nimport { forDataTypes } from '../types.js';\nimport type {\n AssetBalance,\n AssetsControllerState,\n AssetsDataSource,\n Caip19AssetId,\n ChainId,\n Context,\n DataResponse,\n Middleware,\n NextFunction,\n} from '../types.js';\nimport { filterFailedChainBalances } from '../utils/filterFailedChainBalances.js';\nimport { mergeDataResponses } from './ParallelMiddleware.js';\n\nconst CONTROLLER_NAME = 'RpcFallbackMiddleware';\n\nconst log = createModuleLogger(projectLogger, CONTROLLER_NAME);\n\nexport type RpcFallbackMiddlewareOptions = {\n /** The RPC data source to use as a fallback. */\n rpcDataSource: AssetsDataSource;\n /**\n * When true, recover failed and unprocessed chains with a full RPC refetch\n * (Accounts API v6). When false, re-read stale tracked assets the v5 API\n * omitted (legacy path).\n */\n isBalanceV6Enabled?: () => boolean;\n /** Current AssetsController state. Used to find tracked assets the response left empty. */\n getAssetsState: () => AssetsControllerState;\n};\n\nconst noopNext = async (ctx: Context): Promise<Context> => ctx;\n\n/**\n * RpcFallbackMiddleware recovers what upstream sources left outstanding on RPC.\n *\n * Accounts API v5: chains in `response.errors`, plus EVM assets tracked in\n * state that this response left empty (the API omits tokens it does not index).\n *\n * Accounts API v6: one RPC retry on the chain axis. Chains in\n * `response.errors` are refetched in full (native + existing balances + pins +\n * default tracked assets). RPC reads those from state; the request is not\n * scoped via `customAssets`.\n */\nexport class RpcFallbackMiddleware {\n readonly name = CONTROLLER_NAME;\n\n readonly #rpcDataSource: AssetsDataSource;\n\n readonly #isBalanceV6Enabled: () => boolean;\n\n readonly #getAssetsState: () => AssetsControllerState;\n\n constructor(options: RpcFallbackMiddlewareOptions) {\n this.#rpcDataSource = options.rpcDataSource;\n this.#isBalanceV6Enabled =\n options.isBalanceV6Enabled ?? ((): boolean => false);\n this.#getAssetsState = options.getAssetsState;\n }\n\n getName(): string {\n return this.name;\n }\n\n get assetsMiddleware(): Middleware {\n return forDataTypes(['balance'], async (ctx, next) => {\n if (this.#isBalanceV6Enabled()) {\n return this.#recoverV6(ctx, next);\n }\n return this.#recoverV5(ctx, next);\n });\n }\n\n async #recoverV6(ctx: Context, next: NextFunction): Promise<Context> {\n const erroredChains = new Set<ChainId>(\n Object.keys(ctx.response.errors ?? {}) as ChainId[],\n );\n const chainsToFetch = ctx.request.chainIds.filter((id) =>\n erroredChains.has(id),\n );\n\n if (chainsToFetch.length === 0) {\n return next(ctx);\n }\n\n const rpcResult = await this.#rpcDataSource.assetsMiddleware(\n {\n ...ctx,\n request: { ...ctx.request, chainIds: chainsToFetch },\n response: {},\n },\n noopNext,\n );\n\n const rpcFailedChains = new Set<ChainId>(\n Object.keys(rpcResult.response.errors ?? {}) as ChainId[],\n );\n const rpcAssetsBalance = filterFailedChainBalances(\n rpcResult.response.assetsBalance,\n rpcFailedChains,\n );\n\n const merged = mergeDataResponses([\n ctx.response,\n {\n ...rpcResult.response,\n assetsBalance: rpcAssetsBalance,\n },\n ]);\n\n if (merged.errors && rpcAssetsBalance) {\n const chainsRecoveredByRpc = new Set<string>();\n for (const accountBalances of Object.values(rpcAssetsBalance)) {\n for (const assetId of Object.keys(accountBalances)) {\n chainsRecoveredByRpc.add(assetId.split('/')[0]);\n }\n }\n for (const chainId of erroredChains) {\n if (chainsRecoveredByRpc.has(chainId)) {\n delete merged.errors[chainId];\n }\n }\n }\n\n return next({ ...ctx, response: merged });\n }\n\n async #recoverV5(ctx: Context, next: NextFunction): Promise<Context> {\n const erroredChains = new Set<ChainId>(\n Object.keys(ctx.response.errors ?? {}) as ChainId[],\n );\n const staleAssets = collectStaleTrackedAssets(ctx, this.#getAssetsState());\n\n const chainsToFetch = [\n ...new Set([\n ...ctx.request.chainIds.filter((id) => erroredChains.has(id)),\n // Already restricted to requested chains. Their chain may not be\n // errored: the Accounts API can answer for a chain while omitting a\n // token it does not index.\n ...staleAssets.map((assetId) => assetId.split('/')[0] as ChainId),\n ]),\n ];\n\n if (chainsToFetch.length === 0) {\n return next(ctx);\n }\n\n log('Re-reading balances on RPC', {\n erroredChains: [...erroredChains],\n staleAssets,\n chains: chainsToFetch,\n });\n\n const filteredRequest = {\n ...ctx.request,\n chainIds: chainsToFetch,\n customAssets: [\n ...new Set([...(ctx.request.customAssets ?? []), ...staleAssets]),\n ],\n };\n\n const rpcResult = await this.#rpcDataSource.assetsMiddleware(\n {\n ...ctx,\n request: filteredRequest,\n response: {},\n },\n noopNext,\n );\n\n // A chain RPC itself failed on contributed nothing trustworthy: its\n // balances are failure stubs (native 0) that would overwrite correct\n // upstream amounts and, with replaceCoveredChainBalances, wipe the\n // chain's token slice from state. Drop them before merging — this also\n // keeps failed chains from counting as \"recovered\" below.\n const rpcFailedChains = new Set<ChainId>(\n Object.keys(rpcResult.response.errors ?? {}) as ChainId[],\n );\n const rpcAssetsBalance = filterFailedChainBalances(\n rpcResult.response.assetsBalance,\n rpcFailedChains,\n );\n\n // RPC errors are kept only for chains that were already errored\n // upstream. For chains fetched solely for stale tracked assets the\n // upstream response succeeded and stays authoritative — the stale asset\n // keeps its previous amount and is retried on the next pass.\n const rpcErrors = Object.fromEntries(\n Object.entries(rpcResult.response.errors ?? {}).filter(([chainId]) =>\n erroredChains.has(chainId as ChainId),\n ),\n );\n\n const merged: DataResponse = mergeDataResponses([\n ctx.response,\n {\n ...rpcResult.response,\n assetsBalance: rpcAssetsBalance,\n errors: rpcErrors,\n },\n ]);\n\n // Clear errors only for chains RPC actually recovered a balance for.\n // We must inspect the (filtered) RPC balances — NOT merged — because\n // merged also contains balances from the upstream sources (AccountsApi /\n // Websocket / Staked). If those sources returned partial data for\n // a chain that they also flagged as errored (e.g. via\n // unprocessedNetworks), and RPC then failed for that same chain,\n // looking at merged would incorrectly mark the error as recovered.\n if (merged.errors && rpcAssetsBalance) {\n const chainsRecoveredByRpc = new Set<string>();\n for (const accountBalances of Object.values(rpcAssetsBalance)) {\n for (const assetId of Object.keys(accountBalances)) {\n chainsRecoveredByRpc.add(assetId.split('/')[0]);\n }\n }\n for (const chainId of erroredChains) {\n if (chainsRecoveredByRpc.has(chainId)) {\n delete merged.errors[chainId];\n }\n }\n }\n\n return next({ ...ctx, response: merged });\n }\n}\n\n/**\n * EVM assets tracked in state that this balance response left empty and RPC\n * should re-read.\n *\n * Limited to chains both requested and supported by the owning account:\n * RpcDataSource fetches per account and skips chains outside its supported\n * set, so anything else would be queued and then silently dropped.\n *\n * @param ctx - Pipeline context.\n * @param state - Current AssetsController state.\n * @returns Asset IDs to hand to the RPC data source.\n */\nfunction collectStaleTrackedAssets(\n ctx: Context,\n state: AssetsControllerState,\n): Caip19AssetId[] {\n const { assetsBalance: stateAssetsBalance, customAssets: stateCustomAssets } =\n state;\n\n const staleAssets = new Set<Caip19AssetId>();\n\n for (const { account, supportedChains } of ctx.request\n .accountsWithSupportedChains) {\n const accountId = account.id;\n const trackedAssetIds = new Set<Caip19AssetId>([\n ...(Object.keys(stateAssetsBalance[accountId] ?? {}) as Caip19AssetId[]),\n ...(stateCustomAssets?.[accountId] ?? []),\n ]);\n\n const chainsForAccount = supportedChains.filter((chainId) =>\n ctx.request.chainIds.includes(chainId),\n );\n\n for (const assetId of trackedAssetIds) {\n if (\n isEvmAssetOnChains(assetId, chainsForAccount) &&\n // Staked vault balances belong to StakedBalanceDataSource; an RPC\n // ERC-20 read of the share token would clobber them.\n !isStakingContractAssetId(assetId) &&\n isBalanceEmpty(ctx.response.assetsBalance?.[accountId], assetId)\n ) {\n staleAssets.add(assetId);\n }\n }\n }\n\n return [...staleAssets];\n}\n\n/**\n * Whether a balance response carries no positive amount for an asset. A\n * returned `0` cannot be distinguished from \"not indexed\", so both count as\n * empty. Asset IDs are matched case-insensitively: state keys ERC-20 assets by\n * checksummed address, while some data sources return them lower-cased.\n *\n * @param balances - Balance map for a single account from the response.\n * @param assetId - Asset ID to check.\n * @returns True when the response holds no positive amount for the asset.\n */\nfunction isBalanceEmpty(\n balances: Record<string, AssetBalance> | undefined,\n assetId: Caip19AssetId,\n): boolean {\n let amount = balances?.[assetId]?.amount;\n if (amount === undefined && balances) {\n const lowerCasedAssetId = assetId.toLowerCase();\n amount = Object.entries(balances).find(\n ([id]) => id.toLowerCase() === lowerCasedAssetId,\n )?.[1]?.amount;\n }\n return !(Number(amount) > 0);\n}\n\n/**\n * Whether an asset is an EVM asset on one of the given chains.\n *\n * @param assetId - CAIP-19 asset ID.\n * @param chainIds - Chains to match against.\n * @returns True for EVM assets whose chain is in `chainIds`.\n */\nfunction isEvmAssetOnChains(\n assetId: Caip19AssetId,\n chainIds: ChainId[],\n): boolean {\n if (!assetId.startsWith(`${KnownCaipNamespace.Eip155}:`)) {\n return false;\n }\n return chainIds.includes(assetId.split('/')[0] as ChainId);\n}\n"]}
1
+ {"version":3,"file":"RpcFallbackMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/RpcFallbackMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAOhD,MAAM,QAAQ,GAAG,KAAK,EAAE,GAAY,EAAoB,EAAE,CAAC,GAAG,CAAC;AAE/D;;;;GAIG;AACH,MAAM,OAAO,qBAAqB;IACvB,IAAI,GAAG,eAAe,CAAC;IAEvB,cAAc,CAAmB;IAE1C,YAAY,OAAqC;QAC/C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAC9C,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,YAAY,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACnD,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,GAAY,EAAE,IAAkB;QAC7C,MAAM,aAAa,GAAG,IAAI,GAAG,CAC3B,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AG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClD,CAAC;YACH,CAAC;YACD,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;gBACpC,IAAI,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;oBACtC,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBAChC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,EAAE,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5C,CAAC;CACF","sourcesContent":["import { forDataTypes } from '../types.js';\nimport type {\n AssetsDataSource,\n ChainId,\n Context,\n Middleware,\n NextFunction,\n} from '../types.js';\nimport { filterFailedChainBalances } from '../utils/filterFailedChainBalances.js';\nimport { mergeDataResponses } from './ParallelMiddleware.js';\n\nconst CONTROLLER_NAME = 'RpcFallbackMiddleware';\n\nexport type RpcFallbackMiddlewareOptions = {\n /** The RPC data source to use as a fallback. */\n rpcDataSource: AssetsDataSource;\n};\n\nconst noopNext = async (ctx: Context): Promise<Context> => ctx;\n\n/**\n * RpcFallbackMiddleware recovers chains upstream sources left in `errors`\n * with one RPC refetch. RPC reads native, existing balances, pins, and\n * default tracked assets from controller state.\n */\nexport class RpcFallbackMiddleware {\n readonly name = CONTROLLER_NAME;\n\n readonly #rpcDataSource: AssetsDataSource;\n\n constructor(options: RpcFallbackMiddlewareOptions) {\n this.#rpcDataSource = options.rpcDataSource;\n }\n\n getName(): string {\n return this.name;\n }\n\n get assetsMiddleware(): Middleware {\n return forDataTypes(['balance'], async (ctx, next) => {\n return this.#recover(ctx, next);\n });\n }\n\n async #recover(ctx: Context, next: NextFunction): Promise<Context> {\n const erroredChains = new Set<ChainId>(\n Object.keys(ctx.response.errors ?? {}) as ChainId[],\n );\n const chainsToFetch = ctx.request.chainIds.filter((id) =>\n erroredChains.has(id),\n );\n\n if (chainsToFetch.length === 0) {\n return next(ctx);\n }\n\n const rpcResult = await this.#rpcDataSource.assetsMiddleware(\n {\n ...ctx,\n request: { ...ctx.request, chainIds: chainsToFetch },\n response: {},\n },\n noopNext,\n );\n\n const rpcFailedChains = new Set<ChainId>(\n Object.keys(rpcResult.response.errors ?? {}) as ChainId[],\n );\n const rpcAssetsBalance = filterFailedChainBalances(\n rpcResult.response.assetsBalance,\n rpcFailedChains,\n );\n\n const merged = mergeDataResponses([\n ctx.response,\n {\n ...rpcResult.response,\n assetsBalance: rpcAssetsBalance,\n },\n ]);\n\n if (merged.errors && rpcAssetsBalance) {\n const chainsRecoveredByRpc = new Set<string>();\n for (const accountBalances of Object.values(rpcAssetsBalance)) {\n for (const assetId of Object.keys(accountBalances)) {\n chainsRecoveredByRpc.add(assetId.split('/')[0]);\n }\n }\n for (const chainId of erroredChains) {\n if (chainsRecoveredByRpc.has(chainId)) {\n delete merged.errors[chainId];\n }\n }\n }\n\n return next({ ...ctx, response: merged });\n }\n}\n"]}
@@ -1,5 +1,3 @@
1
- export { CustomAssetGraduationMiddleware } from './CustomAssetGraduationMiddleware.js';
2
- export type { CustomAssetGraduationMiddlewareOptions } from './CustomAssetGraduationMiddleware.js';
3
1
  export { RpcFallbackMiddleware } from './RpcFallbackMiddleware.js';
4
2
  export type { RpcFallbackMiddlewareOptions } from './RpcFallbackMiddleware.js';
5
3
  export { createParallelBalanceMiddleware, createParallelMiddleware, mergeDataResponses, } from './ParallelMiddleware.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,YAAY,EAAE,sCAAsC,EAAE,MAAM,sCAAsC,CAAC;AACnG,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,YAAY,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EACL,+BAA+B,EAC/B,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,YAAY,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EACL,+BAA+B,EAC/B,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
@@ -1,4 +1,3 @@
1
- export { CustomAssetGraduationMiddleware } from './CustomAssetGraduationMiddleware.js';
2
1
  export { RpcFallbackMiddleware } from './RpcFallbackMiddleware.js';
3
2
  export { createParallelBalanceMiddleware, createParallelMiddleware, mergeDataResponses, } from './ParallelMiddleware.js';
4
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AAEvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EACL,+BAA+B,EAC/B,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC","sourcesContent":["export { CustomAssetGraduationMiddleware } from './CustomAssetGraduationMiddleware.js';\nexport type { CustomAssetGraduationMiddlewareOptions } from './CustomAssetGraduationMiddleware.js';\nexport { RpcFallbackMiddleware } from './RpcFallbackMiddleware.js';\nexport type { RpcFallbackMiddlewareOptions } from './RpcFallbackMiddleware.js';\nexport {\n createParallelBalanceMiddleware,\n createParallelMiddleware,\n mergeDataResponses,\n} from './ParallelMiddleware.js';\nexport type { BalanceSource } from './ParallelMiddleware.js';\nexport type { AssetsDataSource } from '../types.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EACL,+BAA+B,EAC/B,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC","sourcesContent":["export { RpcFallbackMiddleware } from './RpcFallbackMiddleware.js';\nexport type { RpcFallbackMiddlewareOptions } from './RpcFallbackMiddleware.js';\nexport {\n createParallelBalanceMiddleware,\n createParallelMiddleware,\n mergeDataResponses,\n} from './ParallelMiddleware.js';\nexport type { BalanceSource } from './ParallelMiddleware.js';\nexport type { AssetsDataSource } from '../types.js';\n"]}
@@ -8,37 +8,30 @@ import type { AssetsDataSource } from '../types.js';
8
8
  */
9
9
  export type FastFetchSources = {
10
10
  accountsApiDataSource: AssetsDataSource;
11
- customAssetGraduationMiddleware: AssetsDataSource;
12
11
  rpcFallbackMiddleware: AssetsDataSource;
13
12
  tokenDataSource: AssetsDataSource;
14
13
  priceDataSource: AssetsDataSource;
15
14
  };
16
15
  /**
17
- * Compose the fast fetch lane: balances in parallel → custom-asset graduation →
18
- * RPC fallback → token metadata and prices in parallel.
16
+ * Compose the fast fetch lane: balances → RPC fallback → token metadata and
17
+ * prices in parallel.
19
18
  *
20
19
  * Snap and RPC balance sources are deliberately absent — the controller runs
21
20
  * those in a background lane because of their latency.
22
21
  *
23
- * Ordering carries one invariant: graduation runs BEFORE the RPC fallback so
24
- * it only ever sees Accounts API / websocket balances. RPC intentionally
25
- * carries custom assets and must never trigger graduation. Token and price
26
- * enrichment each choose their own asset sets from the request and controller
27
- * state.
22
+ * Pins stay in `customAssets` and travel as `includeAssetIds`. A chain that
23
+ * comes back without all of them is reported as errored so the RPC fallback
24
+ * refetches it. Token and price enrichment each choose their own asset sets
25
+ * from the request and controller state.
28
26
  *
29
27
  * @param sources - The sources to place into the lane.
30
28
  * @param options - Lane options.
31
29
  * @param options.isBasicFunctionality - When false, the lane is empty. No
32
30
  * balance source runs here, so there is no token or price source to feed.
33
31
  * The RPC background lane fetches balances and then runs token and price.
34
- * @param options.includeCustomAssetGraduation - `true` on the Accounts API v5
35
- * lane. The v6 lane never graduates custom assets: it sends the pins to the
36
- * endpoint as `includeAssetIds`, and a chain that comes back without all of
37
- * them is reported as errored so the RPC fallback refetches it.
38
32
  * @returns The composed source list, ready for `executeAssetsPipeline`.
39
33
  */
40
34
  export declare function buildFastFetchSources(sources: FastFetchSources, options: {
41
35
  isBasicFunctionality: boolean;
42
- includeCustomAssetGraduation: boolean;
43
36
  }): AssetsDataSource[];
44
37
  //# sourceMappingURL=buildFastFetchSources.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildFastFetchSources.d.ts","sourceRoot":"","sources":["../../src/pipeline/buildFastFetchSources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,qBAAqB,EAAE,gBAAgB,CAAC;IACxC,+BAA+B,EAAE,gBAAgB,CAAC;IAClD,qBAAqB,EAAE,gBAAgB,CAAC;IACxC,eAAe,EAAE,gBAAgB,CAAC;IAClC,eAAe,EAAE,gBAAgB,CAAC;CACnC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE;IACP,oBAAoB,EAAE,OAAO,CAAC;IAC9B,4BAA4B,EAAE,OAAO,CAAC;CACvC,GACA,gBAAgB,EAAE,CAqBpB"}
1
+ {"version":3,"file":"buildFastFetchSources.d.ts","sourceRoot":"","sources":["../../src/pipeline/buildFastFetchSources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,qBAAqB,EAAE,gBAAgB,CAAC;IACxC,qBAAqB,EAAE,gBAAgB,CAAC;IACxC,eAAe,EAAE,gBAAgB,CAAC;IAClC,eAAe,EAAE,gBAAgB,CAAC;CACnC,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE;IACP,oBAAoB,EAAE,OAAO,CAAC;CAC/B,GACA,gBAAgB,EAAE,CAiBpB"}
@@ -1,38 +1,30 @@
1
1
  import { createParallelMiddleware } from '../middlewares/ParallelMiddleware.js';
2
2
  /**
3
- * Compose the fast fetch lane: balances in parallel → custom-asset graduation →
4
- * RPC fallback → token metadata and prices in parallel.
3
+ * Compose the fast fetch lane: balances → RPC fallback → token metadata and
4
+ * prices in parallel.
5
5
  *
6
6
  * Snap and RPC balance sources are deliberately absent — the controller runs
7
7
  * those in a background lane because of their latency.
8
8
  *
9
- * Ordering carries one invariant: graduation runs BEFORE the RPC fallback so
10
- * it only ever sees Accounts API / websocket balances. RPC intentionally
11
- * carries custom assets and must never trigger graduation. Token and price
12
- * enrichment each choose their own asset sets from the request and controller
13
- * state.
9
+ * Pins stay in `customAssets` and travel as `includeAssetIds`. A chain that
10
+ * comes back without all of them is reported as errored so the RPC fallback
11
+ * refetches it. Token and price enrichment each choose their own asset sets
12
+ * from the request and controller state.
14
13
  *
15
14
  * @param sources - The sources to place into the lane.
16
15
  * @param options - Lane options.
17
16
  * @param options.isBasicFunctionality - When false, the lane is empty. No
18
17
  * balance source runs here, so there is no token or price source to feed.
19
18
  * The RPC background lane fetches balances and then runs token and price.
20
- * @param options.includeCustomAssetGraduation - `true` on the Accounts API v5
21
- * lane. The v6 lane never graduates custom assets: it sends the pins to the
22
- * endpoint as `includeAssetIds`, and a chain that comes back without all of
23
- * them is reported as errored so the RPC fallback refetches it.
24
19
  * @returns The composed source list, ready for `executeAssetsPipeline`.
25
20
  */
26
21
  export function buildFastFetchSources(sources, options) {
27
- const { accountsApiDataSource, customAssetGraduationMiddleware, rpcFallbackMiddleware, tokenDataSource, priceDataSource, } = sources;
22
+ const { accountsApiDataSource, rpcFallbackMiddleware, tokenDataSource, priceDataSource, } = sources;
28
23
  if (!options.isBasicFunctionality) {
29
24
  return [];
30
25
  }
31
26
  return [
32
27
  accountsApiDataSource,
33
- ...(options.includeCustomAssetGraduation
34
- ? [customAssetGraduationMiddleware]
35
- : []),
36
28
  rpcFallbackMiddleware,
37
29
  createParallelMiddleware([tokenDataSource, priceDataSource]),
38
30
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"buildFastFetchSources.js","sourceRoot":"","sources":["../../src/pipeline/buildFastFetchSources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAkBhF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAyB,EACzB,OAGC;IAED,MAAM,EACJ,qBAAqB,EACrB,+BAA+B,EAC/B,qBAAqB,EACrB,eAAe,EACf,eAAe,GAChB,GAAG,OAAO,CAAC;IAEZ,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;QAClC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO;QACL,qBAAqB;QACrB,GAAG,CAAC,OAAO,CAAC,4BAA4B;YACtC,CAAC,CAAC,CAAC,+BAA+B,CAAC;YACnC,CAAC,CAAC,EAAE,CAAC;QACP,qBAAqB;QACrB,wBAAwB,CAAC,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;KAC7D,CAAC;AACJ,CAAC","sourcesContent":["import { createParallelMiddleware } from '../middlewares/ParallelMiddleware.js';\nimport type { AssetsDataSource } from '../types.js';\n\n/**\n * The sources the fast fetch lane composes, in the roles the lane assigns them.\n *\n * `AssetsController` constructs all of these unconditionally, so the lane can\n * assume every role is filled. `isBasicFunctionality` decides which of them\n * actually run, not which are supplied.\n */\nexport type FastFetchSources = {\n accountsApiDataSource: AssetsDataSource;\n customAssetGraduationMiddleware: AssetsDataSource;\n rpcFallbackMiddleware: AssetsDataSource;\n tokenDataSource: AssetsDataSource;\n priceDataSource: AssetsDataSource;\n};\n\n/**\n * Compose the fast fetch lane: balances in parallel → custom-asset graduation →\n * RPC fallback → token metadata and prices in parallel.\n *\n * Snap and RPC balance sources are deliberately absent — the controller runs\n * those in a background lane because of their latency.\n *\n * Ordering carries one invariant: graduation runs BEFORE the RPC fallback so\n * it only ever sees Accounts API / websocket balances. RPC intentionally\n * carries custom assets and must never trigger graduation. Token and price\n * enrichment each choose their own asset sets from the request and controller\n * state.\n *\n * @param sources - The sources to place into the lane.\n * @param options - Lane options.\n * @param options.isBasicFunctionality - When false, the lane is empty. No\n * balance source runs here, so there is no token or price source to feed.\n * The RPC background lane fetches balances and then runs token and price.\n * @param options.includeCustomAssetGraduation - `true` on the Accounts API v5\n * lane. The v6 lane never graduates custom assets: it sends the pins to the\n * endpoint as `includeAssetIds`, and a chain that comes back without all of\n * them is reported as errored so the RPC fallback refetches it.\n * @returns The composed source list, ready for `executeAssetsPipeline`.\n */\nexport function buildFastFetchSources(\n sources: FastFetchSources,\n options: {\n isBasicFunctionality: boolean;\n includeCustomAssetGraduation: boolean;\n },\n): AssetsDataSource[] {\n const {\n accountsApiDataSource,\n customAssetGraduationMiddleware,\n rpcFallbackMiddleware,\n tokenDataSource,\n priceDataSource,\n } = sources;\n\n if (!options.isBasicFunctionality) {\n return [];\n }\n\n return [\n accountsApiDataSource,\n ...(options.includeCustomAssetGraduation\n ? [customAssetGraduationMiddleware]\n : []),\n rpcFallbackMiddleware,\n createParallelMiddleware([tokenDataSource, priceDataSource]),\n ];\n}\n"]}
1
+ {"version":3,"file":"buildFastFetchSources.js","sourceRoot":"","sources":["../../src/pipeline/buildFastFetchSources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAiBhF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAyB,EACzB,OAEC;IAED,MAAM,EACJ,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,eAAe,GAChB,GAAG,OAAO,CAAC;IAEZ,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;QAClC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO;QACL,qBAAqB;QACrB,qBAAqB;QACrB,wBAAwB,CAAC,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;KAC7D,CAAC;AACJ,CAAC","sourcesContent":["import { createParallelMiddleware } from '../middlewares/ParallelMiddleware.js';\nimport type { AssetsDataSource } from '../types.js';\n\n/**\n * The sources the fast fetch lane composes, in the roles the lane assigns them.\n *\n * `AssetsController` constructs all of these unconditionally, so the lane can\n * assume every role is filled. `isBasicFunctionality` decides which of them\n * actually run, not which are supplied.\n */\nexport type FastFetchSources = {\n accountsApiDataSource: AssetsDataSource;\n rpcFallbackMiddleware: AssetsDataSource;\n tokenDataSource: AssetsDataSource;\n priceDataSource: AssetsDataSource;\n};\n\n/**\n * Compose the fast fetch lane: balances → RPC fallback → token metadata and\n * prices in parallel.\n *\n * Snap and RPC balance sources are deliberately absent — the controller runs\n * those in a background lane because of their latency.\n *\n * Pins stay in `customAssets` and travel as `includeAssetIds`. A chain that\n * comes back without all of them is reported as errored so the RPC fallback\n * refetches it. Token and price enrichment each choose their own asset sets\n * from the request and controller state.\n *\n * @param sources - The sources to place into the lane.\n * @param options - Lane options.\n * @param options.isBasicFunctionality - When false, the lane is empty. No\n * balance source runs here, so there is no token or price source to feed.\n * The RPC background lane fetches balances and then runs token and price.\n * @returns The composed source list, ready for `executeAssetsPipeline`.\n */\nexport function buildFastFetchSources(\n sources: FastFetchSources,\n options: {\n isBasicFunctionality: boolean;\n },\n): AssetsDataSource[] {\n const {\n accountsApiDataSource,\n rpcFallbackMiddleware,\n tokenDataSource,\n priceDataSource,\n } = sources;\n\n if (!options.isBasicFunctionality) {\n return [];\n }\n\n return [\n accountsApiDataSource,\n rpcFallbackMiddleware,\n createParallelMiddleware([tokenDataSource, priceDataSource]),\n ];\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  import type { AssetsDataSource } from '../types.js';
2
2
  /** The sources the standard update lane composes. */
3
3
  export type UpdateSources = {
4
- customAssetGraduationMiddleware: AssetsDataSource;
5
4
  rpcFallbackMiddleware: AssetsDataSource;
6
5
  tokenDataSource: AssetsDataSource;
7
6
  priceDataSource: AssetsDataSource;
@@ -12,13 +11,11 @@ export type UpdateSources = {
12
11
  * @param sources - The sources to place into the lane.
13
12
  * @param options - Lane options.
14
13
  * @param options.isBasicFunctionality - When false, no enrichment runs.
15
- * @param options.includeCustomAssetGraduation - When to include graduation.
16
14
  * @param options.includeRpcFallback - When to include the RPC fallback.
17
15
  * @returns The composed source list, ready for `executeAssetsPipeline`.
18
16
  */
19
17
  export declare function buildUpdateSources(sources: UpdateSources, options: {
20
18
  isBasicFunctionality: boolean;
21
- includeCustomAssetGraduation: boolean;
22
19
  includeRpcFallback: boolean;
23
20
  }): AssetsDataSource[];
24
21
  //# sourceMappingURL=buildUpdateSources.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildUpdateSources.d.ts","sourceRoot":"","sources":["../../src/pipeline/buildUpdateSources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,qDAAqD;AACrD,MAAM,MAAM,aAAa,GAAG;IAC1B,+BAA+B,EAAE,gBAAgB,CAAC;IAClD,qBAAqB,EAAE,gBAAgB,CAAC;IACxC,eAAe,EAAE,gBAAgB,CAAC;IAClC,eAAe,EAAE,gBAAgB,CAAC;CACnC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE;IACP,oBAAoB,EAAE,OAAO,CAAC;IAC9B,4BAA4B,EAAE,OAAO,CAAC;IACtC,kBAAkB,EAAE,OAAO,CAAC;CAC7B,GACA,gBAAgB,EAAE,CAiBpB"}
1
+ {"version":3,"file":"buildUpdateSources.d.ts","sourceRoot":"","sources":["../../src/pipeline/buildUpdateSources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,qDAAqD;AACrD,MAAM,MAAM,aAAa,GAAG;IAC1B,qBAAqB,EAAE,gBAAgB,CAAC;IACxC,eAAe,EAAE,gBAAgB,CAAC;IAClC,eAAe,EAAE,gBAAgB,CAAC;CACnC,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE;IACP,oBAAoB,EAAE,OAAO,CAAC;IAC9B,kBAAkB,EAAE,OAAO,CAAC;CAC7B,GACA,gBAAgB,EAAE,CASpB"}
@@ -5,16 +5,12 @@ import { createParallelMiddleware } from '../middlewares/ParallelMiddleware.js';
5
5
  * @param sources - The sources to place into the lane.
6
6
  * @param options - Lane options.
7
7
  * @param options.isBasicFunctionality - When false, no enrichment runs.
8
- * @param options.includeCustomAssetGraduation - When to include graduation.
9
8
  * @param options.includeRpcFallback - When to include the RPC fallback.
10
9
  * @returns The composed source list, ready for `executeAssetsPipeline`.
11
10
  */
12
11
  export function buildUpdateSources(sources, options) {
13
- const { customAssetGraduationMiddleware, rpcFallbackMiddleware, tokenDataSource, priceDataSource, } = sources;
12
+ const { rpcFallbackMiddleware, tokenDataSource, priceDataSource } = sources;
14
13
  return [
15
- ...(options.includeCustomAssetGraduation
16
- ? [customAssetGraduationMiddleware]
17
- : []),
18
14
  ...(options.includeRpcFallback ? [rpcFallbackMiddleware] : []),
19
15
  ...(options.isBasicFunctionality
20
16
  ? [createParallelMiddleware([tokenDataSource, priceDataSource])]
@@ -1 +1 @@
1
- {"version":3,"file":"buildUpdateSources.js","sourceRoot":"","sources":["../../src/pipeline/buildUpdateSources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAWhF;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAsB,EACtB,OAIC;IAED,MAAM,EACJ,+BAA+B,EAC/B,qBAAqB,EACrB,eAAe,EACf,eAAe,GAChB,GAAG,OAAO,CAAC;IAEZ,OAAO;QACL,GAAG,CAAC,OAAO,CAAC,4BAA4B;YACtC,CAAC,CAAC,CAAC,+BAA+B,CAAC;YACnC,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,GAAG,CAAC,OAAO,CAAC,oBAAoB;YAC9B,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC;YAChE,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC","sourcesContent":["import { createParallelMiddleware } from '../middlewares/ParallelMiddleware.js';\nimport type { AssetsDataSource } from '../types.js';\n\n/** The sources the standard update lane composes. */\nexport type UpdateSources = {\n customAssetGraduationMiddleware: AssetsDataSource;\n rpcFallbackMiddleware: AssetsDataSource;\n tokenDataSource: AssetsDataSource;\n priceDataSource: AssetsDataSource;\n};\n\n/**\n * Compose the update lane for the non-websocket sources.\n *\n * @param sources - The sources to place into the lane.\n * @param options - Lane options.\n * @param options.isBasicFunctionality - When false, no enrichment runs.\n * @param options.includeCustomAssetGraduation - When to include graduation.\n * @param options.includeRpcFallback - When to include the RPC fallback.\n * @returns The composed source list, ready for `executeAssetsPipeline`.\n */\nexport function buildUpdateSources(\n sources: UpdateSources,\n options: {\n isBasicFunctionality: boolean;\n includeCustomAssetGraduation: boolean;\n includeRpcFallback: boolean;\n },\n): AssetsDataSource[] {\n const {\n customAssetGraduationMiddleware,\n rpcFallbackMiddleware,\n tokenDataSource,\n priceDataSource,\n } = sources;\n\n return [\n ...(options.includeCustomAssetGraduation\n ? [customAssetGraduationMiddleware]\n : []),\n ...(options.includeRpcFallback ? [rpcFallbackMiddleware] : []),\n ...(options.isBasicFunctionality\n ? [createParallelMiddleware([tokenDataSource, priceDataSource])]\n : []),\n ];\n}\n"]}
1
+ {"version":3,"file":"buildUpdateSources.js","sourceRoot":"","sources":["../../src/pipeline/buildUpdateSources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAUhF;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAsB,EACtB,OAGC;IAED,MAAM,EAAE,qBAAqB,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAE5E,OAAO;QACL,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,GAAG,CAAC,OAAO,CAAC,oBAAoB;YAC9B,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC;YAChE,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC","sourcesContent":["import { createParallelMiddleware } from '../middlewares/ParallelMiddleware.js';\nimport type { AssetsDataSource } from '../types.js';\n\n/** The sources the standard update lane composes. */\nexport type UpdateSources = {\n rpcFallbackMiddleware: AssetsDataSource;\n tokenDataSource: AssetsDataSource;\n priceDataSource: AssetsDataSource;\n};\n\n/**\n * Compose the update lane for the non-websocket sources.\n *\n * @param sources - The sources to place into the lane.\n * @param options - Lane options.\n * @param options.isBasicFunctionality - When false, no enrichment runs.\n * @param options.includeRpcFallback - When to include the RPC fallback.\n * @returns The composed source list, ready for `executeAssetsPipeline`.\n */\nexport function buildUpdateSources(\n sources: UpdateSources,\n options: {\n isBasicFunctionality: boolean;\n includeRpcFallback: boolean;\n },\n): AssetsDataSource[] {\n const { rpcFallbackMiddleware, tokenDataSource, priceDataSource } = sources;\n\n return [\n ...(options.includeRpcFallback ? [rpcFallbackMiddleware] : []),\n ...(options.isBasicFunctionality\n ? [createParallelMiddleware([tokenDataSource, priceDataSource])]\n : []),\n ];\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  import type { AssetsDataSource, Middleware } from '../types.js';
2
2
  /** The sources the websocket update lane composes. */
3
3
  export type WsUpdateSources = {
4
- customAssetGraduationMiddleware: AssetsDataSource;
5
4
  rpcFallbackMiddleware: AssetsDataSource;
6
5
  /** Also supplies the occurrence-filter middleware used for websocket airdrops. */
7
6
  tokenDataSource: AssetsDataSource & {
@@ -10,18 +9,16 @@ export type WsUpdateSources = {
10
9
  priceDataSource: AssetsDataSource;
11
10
  };
12
11
  /**
13
- * Compose the websocket update lane.
12
+ * Compose the websocket update lane: occurrence filter → RPC fallback →
13
+ * token metadata and prices in parallel.
14
14
  *
15
15
  * @param sources - The sources to place into the lane.
16
16
  * @param options - Lane options.
17
17
  * @param options.isBasicFunctionality - When false, no network-backed source
18
18
  * runs.
19
- * @param options.includeCustomAssetGraduation - `true` on the v5 lane; the
20
- * v6 lane runs the RPC fallback instead of graduation.
21
19
  * @returns The composed source list, ready for `executeAssetsPipeline`.
22
20
  */
23
21
  export declare function buildWsUpdateSources(sources: WsUpdateSources, options: {
24
22
  isBasicFunctionality: boolean;
25
- includeCustomAssetGraduation: boolean;
26
23
  }): AssetsDataSource[];
27
24
  //# sourceMappingURL=buildWsUpdateSources.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildWsUpdateSources.d.ts","sourceRoot":"","sources":["../../src/pipeline/buildWsUpdateSources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEhE,sDAAsD;AACtD,MAAM,MAAM,eAAe,GAAG;IAC5B,+BAA+B,EAAE,gBAAgB,CAAC;IAClD,qBAAqB,EAAE,gBAAgB,CAAC;IACxC,kFAAkF;IAClF,eAAe,EAAE,gBAAgB,GAAG;QAClC,QAAQ,CAAC,0BAA0B,EAAE,UAAU,CAAC;KACjD,CAAC;IACF,eAAe,EAAE,gBAAgB,CAAC;CACnC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE;IACP,oBAAoB,EAAE,OAAO,CAAC;IAC9B,4BAA4B,EAAE,OAAO,CAAC;CACvC,GACA,gBAAgB,EAAE,CAyBpB"}
1
+ {"version":3,"file":"buildWsUpdateSources.d.ts","sourceRoot":"","sources":["../../src/pipeline/buildWsUpdateSources.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEhE,sDAAsD;AACtD,MAAM,MAAM,eAAe,GAAG;IAC5B,qBAAqB,EAAE,gBAAgB,CAAC;IACxC,kFAAkF;IAClF,eAAe,EAAE,gBAAgB,GAAG;QAClC,QAAQ,CAAC,0BAA0B,EAAE,UAAU,CAAC;KACjD,CAAC;IACF,eAAe,EAAE,gBAAgB,CAAC;CACnC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE;IACP,oBAAoB,EAAE,OAAO,CAAC;CAC/B,GACA,gBAAgB,EAAE,CAiBpB"}
@@ -1,32 +1,27 @@
1
1
  import { createParallelMiddleware } from '../middlewares/ParallelMiddleware.js';
2
2
  /**
3
- * Compose the websocket update lane.
3
+ * Compose the websocket update lane: occurrence filter → RPC fallback →
4
+ * token metadata and prices in parallel.
4
5
  *
5
6
  * @param sources - The sources to place into the lane.
6
7
  * @param options - Lane options.
7
8
  * @param options.isBasicFunctionality - When false, no network-backed source
8
9
  * runs.
9
- * @param options.includeCustomAssetGraduation - `true` on the v5 lane; the
10
- * v6 lane runs the RPC fallback instead of graduation.
11
10
  * @returns The composed source list, ready for `executeAssetsPipeline`.
12
11
  */
13
12
  export function buildWsUpdateSources(sources, options) {
14
- const { customAssetGraduationMiddleware, rpcFallbackMiddleware, tokenDataSource, priceDataSource, } = sources;
13
+ const { rpcFallbackMiddleware, tokenDataSource, priceDataSource } = sources;
14
+ if (!options.isBasicFunctionality) {
15
+ return [];
16
+ }
15
17
  const occurrenceFloorFilter = {
16
18
  getName: () => 'OccurrenceFloorFilter',
17
19
  assetsMiddleware: tokenDataSource.occurrenceFilterMiddleware,
18
20
  };
19
21
  return [
20
- ...(options.includeCustomAssetGraduation
21
- ? [customAssetGraduationMiddleware]
22
- : []),
23
- ...(options.isBasicFunctionality ? [occurrenceFloorFilter] : []),
24
- ...(!options.includeCustomAssetGraduation && options.isBasicFunctionality
25
- ? [rpcFallbackMiddleware]
26
- : []),
27
- ...(options.isBasicFunctionality
28
- ? [createParallelMiddleware([tokenDataSource, priceDataSource])]
29
- : []),
22
+ occurrenceFloorFilter,
23
+ rpcFallbackMiddleware,
24
+ createParallelMiddleware([tokenDataSource, priceDataSource]),
30
25
  ];
31
26
  }
32
27
  //# sourceMappingURL=buildWsUpdateSources.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"buildWsUpdateSources.js","sourceRoot":"","sources":["../../src/pipeline/buildWsUpdateSources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAchF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAwB,EACxB,OAGC;IAED,MAAM,EACJ,+BAA+B,EAC/B,qBAAqB,EACrB,eAAe,EACf,eAAe,GAChB,GAAG,OAAO,CAAC;IAEZ,MAAM,qBAAqB,GAAqB;QAC9C,OAAO,EAAE,GAAW,EAAE,CAAC,uBAAuB;QAC9C,gBAAgB,EAAE,eAAe,CAAC,0BAA0B;KAC7D,CAAC;IAEF,OAAO;QACL,GAAG,CAAC,OAAO,CAAC,4BAA4B;YACtC,CAAC,CAAC,CAAC,+BAA+B,CAAC;YACnC,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,GAAG,CAAC,CAAC,OAAO,CAAC,4BAA4B,IAAI,OAAO,CAAC,oBAAoB;YACvE,CAAC,CAAC,CAAC,qBAAqB,CAAC;YACzB,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,CAAC,oBAAoB;YAC9B,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC;YAChE,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC","sourcesContent":["import { createParallelMiddleware } from '../middlewares/ParallelMiddleware.js';\nimport type { AssetsDataSource, Middleware } from '../types.js';\n\n/** The sources the websocket update lane composes. */\nexport type WsUpdateSources = {\n customAssetGraduationMiddleware: AssetsDataSource;\n rpcFallbackMiddleware: AssetsDataSource;\n /** Also supplies the occurrence-filter middleware used for websocket airdrops. */\n tokenDataSource: AssetsDataSource & {\n readonly occurrenceFilterMiddleware: Middleware;\n };\n priceDataSource: AssetsDataSource;\n};\n\n/**\n * Compose the websocket update lane.\n *\n * @param sources - The sources to place into the lane.\n * @param options - Lane options.\n * @param options.isBasicFunctionality - When false, no network-backed source\n * runs.\n * @param options.includeCustomAssetGraduation - `true` on the v5 lane; the\n * v6 lane runs the RPC fallback instead of graduation.\n * @returns The composed source list, ready for `executeAssetsPipeline`.\n */\nexport function buildWsUpdateSources(\n sources: WsUpdateSources,\n options: {\n isBasicFunctionality: boolean;\n includeCustomAssetGraduation: boolean;\n },\n): AssetsDataSource[] {\n const {\n customAssetGraduationMiddleware,\n rpcFallbackMiddleware,\n tokenDataSource,\n priceDataSource,\n } = sources;\n\n const occurrenceFloorFilter: AssetsDataSource = {\n getName: (): string => 'OccurrenceFloorFilter',\n assetsMiddleware: tokenDataSource.occurrenceFilterMiddleware,\n };\n\n return [\n ...(options.includeCustomAssetGraduation\n ? [customAssetGraduationMiddleware]\n : []),\n ...(options.isBasicFunctionality ? [occurrenceFloorFilter] : []),\n ...(!options.includeCustomAssetGraduation && options.isBasicFunctionality\n ? [rpcFallbackMiddleware]\n : []),\n ...(options.isBasicFunctionality\n ? [createParallelMiddleware([tokenDataSource, priceDataSource])]\n : []),\n ];\n}\n"]}
1
+ {"version":3,"file":"buildWsUpdateSources.js","sourceRoot":"","sources":["../../src/pipeline/buildWsUpdateSources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAahF;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAwB,EACxB,OAEC;IAED,MAAM,EAAE,qBAAqB,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAE5E,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;QAClC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,qBAAqB,GAAqB;QAC9C,OAAO,EAAE,GAAW,EAAE,CAAC,uBAAuB;QAC9C,gBAAgB,EAAE,eAAe,CAAC,0BAA0B;KAC7D,CAAC;IAEF,OAAO;QACL,qBAAqB;QACrB,qBAAqB;QACrB,wBAAwB,CAAC,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;KAC7D,CAAC;AACJ,CAAC","sourcesContent":["import { createParallelMiddleware } from '../middlewares/ParallelMiddleware.js';\nimport type { AssetsDataSource, Middleware } from '../types.js';\n\n/** The sources the websocket update lane composes. */\nexport type WsUpdateSources = {\n rpcFallbackMiddleware: AssetsDataSource;\n /** Also supplies the occurrence-filter middleware used for websocket airdrops. */\n tokenDataSource: AssetsDataSource & {\n readonly occurrenceFilterMiddleware: Middleware;\n };\n priceDataSource: AssetsDataSource;\n};\n\n/**\n * Compose the websocket update lane: occurrence filter → RPC fallback →\n * token metadata and prices in parallel.\n *\n * @param sources - The sources to place into the lane.\n * @param options - Lane options.\n * @param options.isBasicFunctionality - When false, no network-backed source\n * runs.\n * @returns The composed source list, ready for `executeAssetsPipeline`.\n */\nexport function buildWsUpdateSources(\n sources: WsUpdateSources,\n options: {\n isBasicFunctionality: boolean;\n },\n): AssetsDataSource[] {\n const { rpcFallbackMiddleware, tokenDataSource, priceDataSource } = sources;\n\n if (!options.isBasicFunctionality) {\n return [];\n }\n\n const occurrenceFloorFilter: AssetsDataSource = {\n getName: (): string => 'OccurrenceFloorFilter',\n assetsMiddleware: tokenDataSource.occurrenceFilterMiddleware,\n };\n\n return [\n occurrenceFloorFilter,\n rpcFallbackMiddleware,\n createParallelMiddleware([tokenDataSource, priceDataSource]),\n ];\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -291,14 +291,6 @@ export type DataRequest = {
291
291
  * snapshot. RPC fallback additionally refetches existing balances.
292
292
  */
293
293
  customAssets?: Caip19AssetId[];
294
- /**
295
- * When true, the data source should poll only the user's `customAssets`
296
- * for the requested chains and skip refreshing the regular tracked
297
- * balances. Used by the AssetsController to issue a supplemental RPC
298
- * subscription on chains that another data source is already covering
299
- * (Accounts API v5 path). Ignored when Accounts API v6 is enabled.
300
- */
301
- customAssetsOnly?: boolean;
302
294
  /** Force fresh fetch, bypass cache */
303
295
  forceUpdate?: boolean;
304
296
  /**