@metamask/assets-controller 6.0.0 → 6.2.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.
Files changed (156) hide show
  1. package/CHANGELOG.md +50 -4
  2. package/dist/AssetsController.cjs +205 -29
  3. package/dist/AssetsController.cjs.map +1 -1
  4. package/dist/AssetsController.d.cts +8 -1
  5. package/dist/AssetsController.d.cts.map +1 -1
  6. package/dist/AssetsController.d.mts +8 -1
  7. package/dist/AssetsController.d.mts.map +1 -1
  8. package/dist/AssetsController.mjs +206 -30
  9. package/dist/AssetsController.mjs.map +1 -1
  10. package/dist/data-sources/AccountsApiDataSource.cjs +6 -3
  11. package/dist/data-sources/AccountsApiDataSource.cjs.map +1 -1
  12. package/dist/data-sources/AccountsApiDataSource.d.cts +6 -0
  13. package/dist/data-sources/AccountsApiDataSource.d.cts.map +1 -1
  14. package/dist/data-sources/AccountsApiDataSource.d.mts +6 -0
  15. package/dist/data-sources/AccountsApiDataSource.d.mts.map +1 -1
  16. package/dist/data-sources/AccountsApiDataSource.mjs +7 -4
  17. package/dist/data-sources/AccountsApiDataSource.mjs.map +1 -1
  18. package/dist/data-sources/BackendWebsocketDataSource.cjs +5 -3
  19. package/dist/data-sources/BackendWebsocketDataSource.cjs.map +1 -1
  20. package/dist/data-sources/BackendWebsocketDataSource.d.cts +3 -1
  21. package/dist/data-sources/BackendWebsocketDataSource.d.cts.map +1 -1
  22. package/dist/data-sources/BackendWebsocketDataSource.d.mts +3 -1
  23. package/dist/data-sources/BackendWebsocketDataSource.d.mts.map +1 -1
  24. package/dist/data-sources/BackendWebsocketDataSource.mjs +5 -3
  25. package/dist/data-sources/BackendWebsocketDataSource.mjs.map +1 -1
  26. package/dist/data-sources/PriceDataSource.cjs +12 -8
  27. package/dist/data-sources/PriceDataSource.cjs.map +1 -1
  28. package/dist/data-sources/PriceDataSource.d.cts +5 -0
  29. package/dist/data-sources/PriceDataSource.d.cts.map +1 -1
  30. package/dist/data-sources/PriceDataSource.d.mts +5 -0
  31. package/dist/data-sources/PriceDataSource.d.mts.map +1 -1
  32. package/dist/data-sources/PriceDataSource.mjs +12 -8
  33. package/dist/data-sources/PriceDataSource.mjs.map +1 -1
  34. package/dist/data-sources/RpcDataSource.cjs +25 -10
  35. package/dist/data-sources/RpcDataSource.cjs.map +1 -1
  36. package/dist/data-sources/RpcDataSource.d.cts +4 -3
  37. package/dist/data-sources/RpcDataSource.d.cts.map +1 -1
  38. package/dist/data-sources/RpcDataSource.d.mts +4 -3
  39. package/dist/data-sources/RpcDataSource.d.mts.map +1 -1
  40. package/dist/data-sources/RpcDataSource.mjs +25 -10
  41. package/dist/data-sources/RpcDataSource.mjs.map +1 -1
  42. package/dist/data-sources/TokenDataSource.cjs +24 -14
  43. package/dist/data-sources/TokenDataSource.cjs.map +1 -1
  44. package/dist/data-sources/TokenDataSource.d.cts +5 -0
  45. package/dist/data-sources/TokenDataSource.d.cts.map +1 -1
  46. package/dist/data-sources/TokenDataSource.d.mts +5 -0
  47. package/dist/data-sources/TokenDataSource.d.mts.map +1 -1
  48. package/dist/data-sources/TokenDataSource.mjs +24 -14
  49. package/dist/data-sources/TokenDataSource.mjs.map +1 -1
  50. package/dist/data-sources/evm-rpc-services/clients/MulticallClient.cjs +8 -0
  51. package/dist/data-sources/evm-rpc-services/clients/MulticallClient.cjs.map +1 -1
  52. package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.cts.map +1 -1
  53. package/dist/data-sources/evm-rpc-services/clients/MulticallClient.d.mts.map +1 -1
  54. package/dist/data-sources/evm-rpc-services/clients/MulticallClient.mjs +8 -0
  55. package/dist/data-sources/evm-rpc-services/clients/MulticallClient.mjs.map +1 -1
  56. package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.cjs +45 -25
  57. package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.cjs.map +1 -1
  58. package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.cts +11 -2
  59. package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.cts.map +1 -1
  60. package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.mts +11 -2
  61. package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.d.mts.map +1 -1
  62. package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.mjs +45 -25
  63. package/dist/data-sources/evm-rpc-services/services/BalanceFetcher.mjs.map +1 -1
  64. package/dist/data-sources/evm-rpc-services/types/state.cjs.map +1 -1
  65. package/dist/data-sources/evm-rpc-services/types/state.d.cts +6 -0
  66. package/dist/data-sources/evm-rpc-services/types/state.d.cts.map +1 -1
  67. package/dist/data-sources/evm-rpc-services/types/state.d.mts +6 -0
  68. package/dist/data-sources/evm-rpc-services/types/state.d.mts.map +1 -1
  69. package/dist/data-sources/evm-rpc-services/types/state.mjs.map +1 -1
  70. package/dist/errors.cjs +25 -0
  71. package/dist/errors.cjs.map +1 -0
  72. package/dist/errors.d.cts +25 -0
  73. package/dist/errors.d.cts.map +1 -0
  74. package/dist/errors.d.mts +25 -0
  75. package/dist/errors.d.mts.map +1 -0
  76. package/dist/errors.mjs +21 -0
  77. package/dist/errors.mjs.map +1 -0
  78. package/dist/index.cjs +5 -1
  79. package/dist/index.cjs.map +1 -1
  80. package/dist/index.d.cts +3 -1
  81. package/dist/index.d.cts.map +1 -1
  82. package/dist/index.d.mts +3 -1
  83. package/dist/index.d.mts.map +1 -1
  84. package/dist/index.mjs +2 -1
  85. package/dist/index.mjs.map +1 -1
  86. package/dist/middlewares/CustomAssetGraduationMiddleware.cjs +121 -0
  87. package/dist/middlewares/CustomAssetGraduationMiddleware.cjs.map +1 -0
  88. package/dist/middlewares/CustomAssetGraduationMiddleware.d.cts +25 -0
  89. package/dist/middlewares/CustomAssetGraduationMiddleware.d.cts.map +1 -0
  90. package/dist/middlewares/CustomAssetGraduationMiddleware.d.mts +25 -0
  91. package/dist/middlewares/CustomAssetGraduationMiddleware.d.mts.map +1 -0
  92. package/dist/middlewares/CustomAssetGraduationMiddleware.mjs +117 -0
  93. package/dist/middlewares/CustomAssetGraduationMiddleware.mjs.map +1 -0
  94. package/dist/middlewares/RpcFallbackMiddleware.cjs +90 -0
  95. package/dist/middlewares/RpcFallbackMiddleware.cjs.map +1 -0
  96. package/dist/middlewares/RpcFallbackMiddleware.d.cts +23 -0
  97. package/dist/middlewares/RpcFallbackMiddleware.d.cts.map +1 -0
  98. package/dist/middlewares/RpcFallbackMiddleware.d.mts +23 -0
  99. package/dist/middlewares/RpcFallbackMiddleware.d.mts.map +1 -0
  100. package/dist/middlewares/RpcFallbackMiddleware.mjs +86 -0
  101. package/dist/middlewares/RpcFallbackMiddleware.mjs.map +1 -0
  102. package/dist/middlewares/index.cjs +5 -1
  103. package/dist/middlewares/index.cjs.map +1 -1
  104. package/dist/middlewares/index.d.cts +4 -0
  105. package/dist/middlewares/index.d.cts.map +1 -1
  106. package/dist/middlewares/index.d.mts +4 -0
  107. package/dist/middlewares/index.d.mts.map +1 -1
  108. package/dist/middlewares/index.mjs +2 -0
  109. package/dist/middlewares/index.mjs.map +1 -1
  110. package/dist/types.cjs.map +1 -1
  111. package/dist/types.d.cts +7 -0
  112. package/dist/types.d.cts.map +1 -1
  113. package/dist/types.d.mts +7 -0
  114. package/dist/types.d.mts.map +1 -1
  115. package/dist/types.mjs.map +1 -1
  116. package/dist/utils/fetchWithTimeout.cjs +30 -0
  117. package/dist/utils/fetchWithTimeout.cjs.map +1 -0
  118. package/dist/utils/fetchWithTimeout.d.cts +11 -0
  119. package/dist/utils/fetchWithTimeout.d.cts.map +1 -0
  120. package/dist/utils/fetchWithTimeout.d.mts +11 -0
  121. package/dist/utils/fetchWithTimeout.d.mts.map +1 -0
  122. package/dist/utils/fetchWithTimeout.mjs +26 -0
  123. package/dist/utils/fetchWithTimeout.mjs.map +1 -0
  124. package/dist/utils/formatExchangeRatesForBridge.cjs +10 -8
  125. package/dist/utils/formatExchangeRatesForBridge.cjs.map +1 -1
  126. package/dist/utils/formatExchangeRatesForBridge.d.cts +5 -3
  127. package/dist/utils/formatExchangeRatesForBridge.d.cts.map +1 -1
  128. package/dist/utils/formatExchangeRatesForBridge.d.mts +5 -3
  129. package/dist/utils/formatExchangeRatesForBridge.d.mts.map +1 -1
  130. package/dist/utils/formatExchangeRatesForBridge.mjs +11 -9
  131. package/dist/utils/formatExchangeRatesForBridge.mjs.map +1 -1
  132. package/dist/utils/formatStateForTransactionPay.cjs +8 -6
  133. package/dist/utils/formatStateForTransactionPay.cjs.map +1 -1
  134. package/dist/utils/formatStateForTransactionPay.d.cts +2 -2
  135. package/dist/utils/formatStateForTransactionPay.d.cts.map +1 -1
  136. package/dist/utils/formatStateForTransactionPay.d.mts +2 -2
  137. package/dist/utils/formatStateForTransactionPay.d.mts.map +1 -1
  138. package/dist/utils/formatStateForTransactionPay.mjs +8 -6
  139. package/dist/utils/formatStateForTransactionPay.mjs.map +1 -1
  140. package/dist/utils/index.cjs +6 -1
  141. package/dist/utils/index.cjs.map +1 -1
  142. package/dist/utils/index.d.cts +2 -0
  143. package/dist/utils/index.d.cts.map +1 -1
  144. package/dist/utils/index.d.mts +2 -0
  145. package/dist/utils/index.d.mts.map +1 -1
  146. package/dist/utils/index.mjs +2 -0
  147. package/dist/utils/index.mjs.map +1 -1
  148. package/dist/utils/native-assets.cjs +63 -0
  149. package/dist/utils/native-assets.cjs.map +1 -0
  150. package/dist/utils/native-assets.d.cts +19 -0
  151. package/dist/utils/native-assets.d.cts.map +1 -0
  152. package/dist/utils/native-assets.d.mts +19 -0
  153. package/dist/utils/native-assets.d.mts.map +1 -0
  154. package/dist/utils/native-assets.mjs +58 -0
  155. package/dist/utils/native-assets.mjs.map +1 -0
  156. package/package.json +8 -8
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Thrown and/or passed to `captureException` when one or more assets data
3
+ * source middlewares fail during a fetch. Use Sentry's "error type" / title
4
+ * filter on `AssetsDataSourceError` to build issue alerts.
5
+ */
6
+ export declare class AssetsDataSourceError extends Error {
7
+ /** Comma-separated data source names that failed. */
8
+ readonly failedSources: string;
9
+ /** Number of failed middlewares in the request. */
10
+ readonly errorCount: number;
11
+ /** Chains included in the request (for context). */
12
+ readonly chainCount: number;
13
+ /**
14
+ * @param details - Which sources failed and request size hints.
15
+ * @param details.failedSources - Comma-separated data source names that failed.
16
+ * @param details.errorCount - Number of failed middlewares in the request.
17
+ * @param details.chainCount - Chains included in the request (for context).
18
+ */
19
+ constructor(details: {
20
+ failedSources: string;
21
+ errorCount: number;
22
+ chainCount: number;
23
+ });
24
+ }
25
+ //# sourceMappingURL=errors.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.cts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,qDAAqD;IACrD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAE/B,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,oDAAoD;IACpD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;;;;OAKG;gBACS,OAAO,EAAE;QACnB,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;KACpB;CASF"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Thrown and/or passed to `captureException` when one or more assets data
3
+ * source middlewares fail during a fetch. Use Sentry's "error type" / title
4
+ * filter on `AssetsDataSourceError` to build issue alerts.
5
+ */
6
+ export declare class AssetsDataSourceError extends Error {
7
+ /** Comma-separated data source names that failed. */
8
+ readonly failedSources: string;
9
+ /** Number of failed middlewares in the request. */
10
+ readonly errorCount: number;
11
+ /** Chains included in the request (for context). */
12
+ readonly chainCount: number;
13
+ /**
14
+ * @param details - Which sources failed and request size hints.
15
+ * @param details.failedSources - Comma-separated data source names that failed.
16
+ * @param details.errorCount - Number of failed middlewares in the request.
17
+ * @param details.chainCount - Chains included in the request (for context).
18
+ */
19
+ constructor(details: {
20
+ failedSources: string;
21
+ errorCount: number;
22
+ chainCount: number;
23
+ });
24
+ }
25
+ //# sourceMappingURL=errors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.mts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,qDAAqD;IACrD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAE/B,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,oDAAoD;IACpD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;;;;OAKG;gBACS,OAAO,EAAE;QACnB,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;KACpB;CASF"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Thrown and/or passed to `captureException` when one or more assets data
3
+ * source middlewares fail during a fetch. Use Sentry's "error type" / title
4
+ * filter on `AssetsDataSourceError` to build issue alerts.
5
+ */
6
+ export class AssetsDataSourceError extends Error {
7
+ /**
8
+ * @param details - Which sources failed and request size hints.
9
+ * @param details.failedSources - Comma-separated data source names that failed.
10
+ * @param details.errorCount - Number of failed middlewares in the request.
11
+ * @param details.chainCount - Chains included in the request (for context).
12
+ */
13
+ constructor(details) {
14
+ super(`Assets data source middleware failures (${details.errorCount}): ${details.failedSources}`);
15
+ this.name = 'AssetsDataSourceError';
16
+ this.failedSources = details.failedSources;
17
+ this.errorCount = details.errorCount;
18
+ this.chainCount = details.chainCount;
19
+ }
20
+ }
21
+ //# sourceMappingURL=errors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.mjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAU9C;;;;;OAKG;IACH,YAAY,OAIX;QACC,KAAK,CACH,2CAA2C,OAAO,CAAC,UAAU,MAAM,OAAO,CAAC,aAAa,EAAE,CAC3F,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACvC,CAAC;CACF","sourcesContent":["/**\n * Thrown and/or passed to `captureException` when one or more assets data\n * source middlewares fail during a fetch. Use Sentry's \"error type\" / title\n * filter on `AssetsDataSourceError` to build issue alerts.\n */\nexport class AssetsDataSourceError extends Error {\n /** Comma-separated data source names that failed. */\n readonly failedSources: string;\n\n /** Number of failed middlewares in the request. */\n readonly errorCount: number;\n\n /** Chains included in the request (for context). */\n readonly chainCount: number;\n\n /**\n * @param details - Which sources failed and request size hints.\n * @param details.failedSources - Comma-separated data source names that failed.\n * @param details.errorCount - Number of failed middlewares in the request.\n * @param details.chainCount - Chains included in the request (for context).\n */\n constructor(details: {\n failedSources: string;\n errorCount: number;\n chainCount: number;\n }) {\n super(\n `Assets data source middleware failures (${details.errorCount}): ${details.failedSources}`,\n );\n this.name = 'AssetsDataSourceError';\n this.failedSources = details.failedSources;\n this.errorCount = details.errorCount;\n this.chainCount = details.chainCount;\n }\n}\n"]}
package/dist/index.cjs CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getInternalAccountsForGroup = exports.getGroupIdForAccount = exports.getAggregatedBalanceForAccount = exports.formatStateForTransactionPay = exports.formatExchangeRatesForBridge = exports.normalizeAssetId = exports.DetectionMiddleware = exports.PriceDataSource = exports.TokenDataSource = exports.extractChainFromAssetId = exports.getChainIdsCaveat = exports.KEYRING_PERMISSION = exports.SNAP_DATA_SOURCE_NAME = exports.createSnapDataSource = exports.SnapDataSource = exports.createRpcDataSource = exports.RpcDataSource = exports.createBackendWebsocketDataSource = exports.BackendWebsocketDataSource = exports.AccountsApiDataSource = exports.AbstractDataSource = exports.getDefaultAssetsControllerState = exports.AssetsController = void 0;
3
+ exports.getInternalAccountsForGroup = exports.getGroupIdForAccount = exports.getAggregatedBalanceForAccount = exports.formatStateForTransactionPay = exports.formatExchangeRatesForBridge = exports.normalizeAssetId = exports.RpcFallbackMiddleware = exports.DetectionMiddleware = exports.CustomAssetGraduationMiddleware = exports.PriceDataSource = exports.TokenDataSource = exports.extractChainFromAssetId = exports.getChainIdsCaveat = exports.KEYRING_PERMISSION = exports.SNAP_DATA_SOURCE_NAME = exports.createSnapDataSource = exports.SnapDataSource = exports.createRpcDataSource = exports.RpcDataSource = exports.createBackendWebsocketDataSource = exports.BackendWebsocketDataSource = exports.AccountsApiDataSource = exports.AbstractDataSource = exports.AssetsDataSourceError = exports.getDefaultAssetsControllerState = exports.AssetsController = void 0;
4
4
  // Main controller export
5
5
  var AssetsController_1 = require("./AssetsController.cjs");
6
6
  Object.defineProperty(exports, "AssetsController", { enumerable: true, get: function () { return AssetsController_1.AssetsController; } });
7
7
  Object.defineProperty(exports, "getDefaultAssetsControllerState", { enumerable: true, get: function () { return AssetsController_1.getDefaultAssetsControllerState; } });
8
+ var errors_1 = require("./errors.cjs");
9
+ Object.defineProperty(exports, "AssetsDataSourceError", { enumerable: true, get: function () { return errors_1.AssetsDataSourceError; } });
8
10
  // Data sources - base class and types
9
11
  var data_sources_1 = require("./data-sources/index.cjs");
10
12
  Object.defineProperty(exports, "AbstractDataSource", { enumerable: true, get: function () { return data_sources_1.AbstractDataSource; } });
@@ -35,7 +37,9 @@ Object.defineProperty(exports, "TokenDataSource", { enumerable: true, get: funct
35
37
  Object.defineProperty(exports, "PriceDataSource", { enumerable: true, get: function () { return data_sources_6.PriceDataSource; } });
36
38
  // Middlewares
37
39
  var middlewares_1 = require("./middlewares/index.cjs");
40
+ Object.defineProperty(exports, "CustomAssetGraduationMiddleware", { enumerable: true, get: function () { return middlewares_1.CustomAssetGraduationMiddleware; } });
38
41
  Object.defineProperty(exports, "DetectionMiddleware", { enumerable: true, get: function () { return middlewares_1.DetectionMiddleware; } });
42
+ Object.defineProperty(exports, "RpcFallbackMiddleware", { enumerable: true, get: function () { return middlewares_1.RpcFallbackMiddleware; } });
39
43
  // Utilities
40
44
  var utils_1 = require("./utils/index.cjs");
41
45
  Object.defineProperty(exports, "normalizeAssetId", { enumerable: true, get: function () { return utils_1.normalizeAssetId; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,2DAG4B;AAF1B,oHAAA,gBAAgB,OAAA;AAChB,mIAAA,+BAA+B,OAAA;AAqFjC,sCAAsC;AACtC,yDAAoD;AAA3C,kHAAA,kBAAkB,OAAA;AAI3B,6BAA6B;AAC7B,yDAAuD;AAA9C,qHAAA,qBAAqB,OAAA;AAQ9B,kCAAkC;AAClC,yDAGwB;AAFtB,0HAAA,0BAA0B,OAAA;AAC1B,gIAAA,gCAAgC,OAAA;AAQlC,qBAAqB;AACrB,yDAAoE;AAA3D,6GAAA,aAAa,OAAA;AAAE,mHAAA,mBAAmB,OAAA;AAS3C,gFAAgF;AAChF,yDASwB;AARtB,8GAAA,cAAc,OAAA;AACd,oHAAA,oBAAoB,OAAA;AACpB,qHAAA,qBAAqB,OAAA;AACrB,YAAY;AACZ,kHAAA,kBAAkB,OAAA;AAClB,oBAAoB;AACpB,iHAAA,iBAAiB,OAAA;AACjB,uHAAA,uBAAuB,OAAA;AAQzB,0BAA0B;AAC1B,yDAAkE;AAAzD,+GAAA,eAAe,OAAA;AAAE,+GAAA,eAAe,OAAA;AAQzC,cAAc;AACd,uDAAoD;AAA3C,kHAAA,mBAAmB,OAAA;AAE5B,YAAY;AACZ,2CAIiB;AAHf,yGAAA,gBAAgB,OAAA;AAChB,qHAAA,4BAA4B,OAAA;AAC5B,qHAAA,4BAA4B,OAAA;AAS9B,YAAY;AACZ,mDAI6B;AAH3B,yHAAA,8BAA8B,OAAA;AAC9B,+GAAA,oBAAoB,OAAA;AACpB,sHAAA,2BAA2B,OAAA","sourcesContent":["// Main controller export\nexport {\n AssetsController,\n getDefaultAssetsControllerState,\n} from './AssetsController';\nexport type { PendingTokenMetadata } from './AssetsController';\n\n// State and messenger types\nexport type {\n AssetsControllerState,\n AssetsControllerMessenger,\n AssetsControllerOptions,\n AssetsControllerGetStateAction,\n AssetsControllerActions,\n AssetsControllerStateChangeEvent,\n AssetsControllerBalanceChangedEvent,\n AssetsControllerPriceChangedEvent,\n AssetsControllerAssetsDetectedEvent,\n AssetsControllerEvents,\n} from './AssetsController';\nexport type {\n AssetsControllerGetAssetsAction,\n AssetsControllerGetAssetsBalanceAction,\n AssetsControllerGetAssetMetadataAction,\n AssetsControllerGetAssetsPriceAction,\n AssetsControllerAddCustomAssetAction,\n AssetsControllerRemoveCustomAssetAction,\n AssetsControllerGetCustomAssetsAction,\n AssetsControllerHideAssetAction,\n AssetsControllerUnhideAssetAction,\n AssetsControllerGetExchangeRatesForBridgeAction,\n AssetsControllerGetStateForTransactionPayAction,\n} from './AssetsController-method-action-types';\n\n// Core types\nexport type {\n // CAIP types\n Caip19AssetId,\n AccountId,\n ChainId,\n // Asset types\n AssetType,\n TokenStandard,\n // Contract data types\n TokenFees,\n HoneypotStatus,\n StorageSlots,\n LocalizedDescription,\n // Metadata types\n BaseAssetMetadata,\n FungibleAssetMetadata,\n ERC721AssetMetadata,\n ERC1155AssetMetadata,\n AssetMetadata,\n // Price types\n BaseAssetPrice,\n FungibleAssetPrice,\n NFTAssetPrice,\n AssetPrice,\n // Balance types\n FungibleAssetBalance,\n ERC721AssetBalance,\n ERC1155AssetBalance,\n AssetBalance,\n // Data source types\n AccountWithSupportedChains,\n DataType,\n DataRequest,\n DataResponse,\n AssetsUpdateMode,\n // Middleware types\n Context,\n NextFunction,\n Middleware,\n AssetsDataSource,\n FetchContext,\n FetchNextFunction,\n FetchMiddleware,\n SubscriptionResponse,\n // Combined asset type\n Asset,\n // Event types\n BalanceChangeEvent,\n PriceChangeEvent,\n MetadataChangeEvent,\n AssetsDetectedEvent,\n} from './types';\n\n// Data sources - base class and types\nexport { AbstractDataSource } from './data-sources';\n\nexport type { DataSourceState, SubscriptionRequest } from './data-sources';\n\n// Data sources - AccountsApi\nexport { AccountsApiDataSource } from './data-sources';\n\nexport type {\n AccountsApiDataSourceConfig,\n AccountsApiDataSourceOptions,\n AccountsApiDataSourceState,\n} from './data-sources';\n\n// Data sources - BackendWebsocket\nexport {\n BackendWebsocketDataSource,\n createBackendWebsocketDataSource,\n} from './data-sources';\n\nexport type {\n BackendWebsocketDataSourceOptions,\n BackendWebsocketDataSourceState,\n} from './data-sources';\n\n// Data sources - RPC\nexport { RpcDataSource, createRpcDataSource } from './data-sources';\n\nexport type {\n RpcDataSourceConfig,\n RpcDataSourceOptions,\n RpcDataSourceState,\n ChainStatus,\n} from './data-sources';\n\n// Data sources - Unified Snap Data Source (dynamically discovers keyring snaps)\nexport {\n SnapDataSource,\n createSnapDataSource,\n SNAP_DATA_SOURCE_NAME,\n // Constants\n KEYRING_PERMISSION,\n // Utility functions\n getChainIdsCaveat,\n extractChainFromAssetId,\n} from './data-sources';\n\nexport type {\n SnapDataSourceState,\n SnapDataSourceOptions,\n} from './data-sources';\n\n// Enrichment data sources\nexport { TokenDataSource, PriceDataSource } from './data-sources';\n\nexport type {\n TokenDataSourceOptions,\n PriceDataSourceConfig,\n PriceDataSourceOptions,\n} from './data-sources';\n\n// Middlewares\nexport { DetectionMiddleware } from './middlewares';\n\n// Utilities\nexport {\n normalizeAssetId,\n formatExchangeRatesForBridge,\n formatStateForTransactionPay,\n} from './utils';\nexport type {\n AccountForLegacyFormat,\n BridgeExchangeRatesFormat,\n LegacyToken,\n TransactionPayLegacyFormat,\n} from './utils';\n\n// Selectors\nexport {\n getAggregatedBalanceForAccount,\n getGroupIdForAccount,\n getInternalAccountsForGroup,\n} from './selectors/balance';\n\nexport type {\n AccountsById,\n AggregatedBalanceEntry,\n AggregatedBalanceForAccount,\n EnabledNetworkMap,\n} from './selectors/balance';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,2DAG4B;AAF1B,oHAAA,gBAAgB,OAAA;AAChB,mIAAA,+BAA+B,OAAA;AAEjC,uCAAiD;AAAxC,+GAAA,qBAAqB,OAAA;AAoF9B,sCAAsC;AACtC,yDAAoD;AAA3C,kHAAA,kBAAkB,OAAA;AAI3B,6BAA6B;AAC7B,yDAAuD;AAA9C,qHAAA,qBAAqB,OAAA;AAQ9B,kCAAkC;AAClC,yDAGwB;AAFtB,0HAAA,0BAA0B,OAAA;AAC1B,gIAAA,gCAAgC,OAAA;AAQlC,qBAAqB;AACrB,yDAAoE;AAA3D,6GAAA,aAAa,OAAA;AAAE,mHAAA,mBAAmB,OAAA;AAS3C,gFAAgF;AAChF,yDASwB;AARtB,8GAAA,cAAc,OAAA;AACd,oHAAA,oBAAoB,OAAA;AACpB,qHAAA,qBAAqB,OAAA;AACrB,YAAY;AACZ,kHAAA,kBAAkB,OAAA;AAClB,oBAAoB;AACpB,iHAAA,iBAAiB,OAAA;AACjB,uHAAA,uBAAuB,OAAA;AAQzB,0BAA0B;AAC1B,yDAAkE;AAAzD,+GAAA,eAAe,OAAA;AAAE,+GAAA,eAAe,OAAA;AAQzC,cAAc;AACd,uDAIuB;AAHrB,8HAAA,+BAA+B,OAAA;AAC/B,kHAAA,mBAAmB,OAAA;AACnB,oHAAA,qBAAqB,OAAA;AAOvB,YAAY;AACZ,2CAIiB;AAHf,yGAAA,gBAAgB,OAAA;AAChB,qHAAA,4BAA4B,OAAA;AAC5B,qHAAA,4BAA4B,OAAA;AAS9B,YAAY;AACZ,mDAI6B;AAH3B,yHAAA,8BAA8B,OAAA;AAC9B,+GAAA,oBAAoB,OAAA;AACpB,sHAAA,2BAA2B,OAAA","sourcesContent":["// Main controller export\nexport {\n AssetsController,\n getDefaultAssetsControllerState,\n} from './AssetsController';\nexport { AssetsDataSourceError } from './errors';\nexport type { PendingTokenMetadata } from './AssetsController';\n\n// State and messenger types\nexport type {\n AssetsControllerState,\n AssetsControllerMessenger,\n AssetsControllerOptions,\n AssetsControllerGetStateAction,\n AssetsControllerActions,\n AssetsControllerStateChangeEvent,\n AssetsControllerBalanceChangedEvent,\n AssetsControllerPriceChangedEvent,\n AssetsControllerAssetsDetectedEvent,\n AssetsControllerEvents,\n} from './AssetsController';\nexport type {\n AssetsControllerGetAssetsAction,\n AssetsControllerGetAssetsBalanceAction,\n AssetsControllerGetAssetMetadataAction,\n AssetsControllerGetAssetsPriceAction,\n AssetsControllerAddCustomAssetAction,\n AssetsControllerRemoveCustomAssetAction,\n AssetsControllerGetCustomAssetsAction,\n AssetsControllerHideAssetAction,\n AssetsControllerUnhideAssetAction,\n AssetsControllerGetExchangeRatesForBridgeAction,\n AssetsControllerGetStateForTransactionPayAction,\n} from './AssetsController-method-action-types';\n\n// Core types\nexport type {\n // CAIP types\n Caip19AssetId,\n AccountId,\n ChainId,\n // Asset types\n AssetType,\n TokenStandard,\n // Contract data types\n TokenFees,\n HoneypotStatus,\n StorageSlots,\n LocalizedDescription,\n // Metadata types\n BaseAssetMetadata,\n FungibleAssetMetadata,\n ERC721AssetMetadata,\n ERC1155AssetMetadata,\n AssetMetadata,\n // Price types\n BaseAssetPrice,\n FungibleAssetPrice,\n NFTAssetPrice,\n AssetPrice,\n // Balance types\n FungibleAssetBalance,\n ERC721AssetBalance,\n ERC1155AssetBalance,\n AssetBalance,\n // Data source types\n AccountWithSupportedChains,\n DataType,\n DataRequest,\n DataResponse,\n AssetsUpdateMode,\n // Middleware types\n Context,\n NextFunction,\n Middleware,\n AssetsDataSource,\n FetchContext,\n FetchNextFunction,\n FetchMiddleware,\n SubscriptionResponse,\n // Combined asset type\n Asset,\n // Event types\n BalanceChangeEvent,\n PriceChangeEvent,\n MetadataChangeEvent,\n AssetsDetectedEvent,\n} from './types';\n\n// Data sources - base class and types\nexport { AbstractDataSource } from './data-sources';\n\nexport type { DataSourceState, SubscriptionRequest } from './data-sources';\n\n// Data sources - AccountsApi\nexport { AccountsApiDataSource } from './data-sources';\n\nexport type {\n AccountsApiDataSourceConfig,\n AccountsApiDataSourceOptions,\n AccountsApiDataSourceState,\n} from './data-sources';\n\n// Data sources - BackendWebsocket\nexport {\n BackendWebsocketDataSource,\n createBackendWebsocketDataSource,\n} from './data-sources';\n\nexport type {\n BackendWebsocketDataSourceOptions,\n BackendWebsocketDataSourceState,\n} from './data-sources';\n\n// Data sources - RPC\nexport { RpcDataSource, createRpcDataSource } from './data-sources';\n\nexport type {\n RpcDataSourceConfig,\n RpcDataSourceOptions,\n RpcDataSourceState,\n ChainStatus,\n} from './data-sources';\n\n// Data sources - Unified Snap Data Source (dynamically discovers keyring snaps)\nexport {\n SnapDataSource,\n createSnapDataSource,\n SNAP_DATA_SOURCE_NAME,\n // Constants\n KEYRING_PERMISSION,\n // Utility functions\n getChainIdsCaveat,\n extractChainFromAssetId,\n} from './data-sources';\n\nexport type {\n SnapDataSourceState,\n SnapDataSourceOptions,\n} from './data-sources';\n\n// Enrichment data sources\nexport { TokenDataSource, PriceDataSource } from './data-sources';\n\nexport type {\n TokenDataSourceOptions,\n PriceDataSourceConfig,\n PriceDataSourceOptions,\n} from './data-sources';\n\n// Middlewares\nexport {\n CustomAssetGraduationMiddleware,\n DetectionMiddleware,\n RpcFallbackMiddleware,\n} from './middlewares';\nexport type {\n CustomAssetGraduationMiddlewareOptions,\n RpcFallbackMiddlewareOptions,\n} from './middlewares';\n\n// Utilities\nexport {\n normalizeAssetId,\n formatExchangeRatesForBridge,\n formatStateForTransactionPay,\n} from './utils';\nexport type {\n AccountForLegacyFormat,\n BridgeExchangeRatesFormat,\n LegacyToken,\n TransactionPayLegacyFormat,\n} from './utils';\n\n// Selectors\nexport {\n getAggregatedBalanceForAccount,\n getGroupIdForAccount,\n getInternalAccountsForGroup,\n} from './selectors/balance';\n\nexport type {\n AccountsById,\n AggregatedBalanceEntry,\n AggregatedBalanceForAccount,\n EnabledNetworkMap,\n} from './selectors/balance';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { AssetsController, getDefaultAssetsControllerState, } from "./AssetsController.cjs";
2
+ export { AssetsDataSourceError } from "./errors.cjs";
2
3
  export type { PendingTokenMetadata } from "./AssetsController.cjs";
3
4
  export type { AssetsControllerState, AssetsControllerMessenger, AssetsControllerOptions, AssetsControllerGetStateAction, AssetsControllerActions, AssetsControllerStateChangeEvent, AssetsControllerBalanceChangedEvent, AssetsControllerPriceChangedEvent, AssetsControllerAssetsDetectedEvent, AssetsControllerEvents, } from "./AssetsController.cjs";
4
5
  export type { AssetsControllerGetAssetsAction, AssetsControllerGetAssetsBalanceAction, AssetsControllerGetAssetMetadataAction, AssetsControllerGetAssetsPriceAction, AssetsControllerAddCustomAssetAction, AssetsControllerRemoveCustomAssetAction, AssetsControllerGetCustomAssetsAction, AssetsControllerHideAssetAction, AssetsControllerUnhideAssetAction, AssetsControllerGetExchangeRatesForBridgeAction, AssetsControllerGetStateForTransactionPayAction, } from "./AssetsController-method-action-types.cjs";
@@ -15,7 +16,8 @@ export { SnapDataSource, createSnapDataSource, SNAP_DATA_SOURCE_NAME, KEYRING_PE
15
16
  export type { SnapDataSourceState, SnapDataSourceOptions, } from "./data-sources/index.cjs";
16
17
  export { TokenDataSource, PriceDataSource } from "./data-sources/index.cjs";
17
18
  export type { TokenDataSourceOptions, PriceDataSourceConfig, PriceDataSourceOptions, } from "./data-sources/index.cjs";
18
- export { DetectionMiddleware } from "./middlewares/index.cjs";
19
+ export { CustomAssetGraduationMiddleware, DetectionMiddleware, RpcFallbackMiddleware, } from "./middlewares/index.cjs";
20
+ export type { CustomAssetGraduationMiddlewareOptions, RpcFallbackMiddlewareOptions, } from "./middlewares/index.cjs";
19
21
  export { normalizeAssetId, formatExchangeRatesForBridge, formatStateForTransactionPay, } from "./utils/index.cjs";
20
22
  export type { AccountForLegacyFormat, BridgeExchangeRatesFormat, LegacyToken, TransactionPayLegacyFormat, } from "./utils/index.cjs";
21
23
  export { getAggregatedBalanceForAccount, getGroupIdForAccount, getInternalAccountsForGroup, } from "./selectors/balance.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAC5B,YAAY,EAAE,oBAAoB,EAAE,+BAA2B;AAG/D,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,8BAA8B,EAC9B,uBAAuB,EACvB,gCAAgC,EAChC,mCAAmC,EACnC,iCAAiC,EACjC,mCAAmC,EACnC,sBAAsB,GACvB,+BAA2B;AAC5B,YAAY,EACV,+BAA+B,EAC/B,sCAAsC,EACtC,sCAAsC,EACtC,oCAAoC,EACpC,oCAAoC,EACpC,uCAAuC,EACvC,qCAAqC,EACrC,+BAA+B,EAC/B,iCAAiC,EACjC,+CAA+C,EAC/C,+CAA+C,GAChD,mDAA+C;AAGhD,YAAY,EAEV,aAAa,EACb,SAAS,EACT,OAAO,EAEP,SAAS,EACT,aAAa,EAEb,SAAS,EACT,cAAc,EACd,YAAY,EACZ,oBAAoB,EAEpB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EAEb,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,UAAU,EAEV,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EAEZ,0BAA0B,EAC1B,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,gBAAgB,EAEhB,OAAO,EACP,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EAEpB,KAAK,EAEL,kBA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3B,iCAAuB;AAGxB,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,GACjC,iCAAuB;AAExB,YAAY,EACV,iCAAiC,EACjC,+BAA+B,GAChC,iCAAuB;AAGxB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,iCAAuB;AAEpE,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,GACZ,iCAAuB;AAGxB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EAErB,kBAAkB,EAElB,iBAAiB,EACjB,uBAAuB,GACxB,iCAAuB;AAExB,YAAY,EACV,mBAAmB,EACnB,qBAAqB,GACtB,iCAAuB;AAGxB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,iCAAuB;AAElE,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,GACvB,iCAAuB;AAGxB,OAAO,EACL,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,GACtB,gCAAsB;AACvB,YAAY,EACV,sCAAsC,EACtC,4BAA4B,GAC7B,gCAAsB;AAGvB,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,GAC7B,0BAAgB;AACjB,YAAY,EACV,sBAAsB,EACtB,yBAAyB,EACzB,WAAW,EACX,0BAA0B,GAC3B,0BAAgB;AAGjB,OAAO,EACL,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,GAC5B,gCAA4B;AAE7B,YAAY,EACV,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,GAClB,gCAA4B"}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { AssetsController, getDefaultAssetsControllerState, } from "./AssetsController.mjs";
2
+ export { AssetsDataSourceError } from "./errors.mjs";
2
3
  export type { PendingTokenMetadata } from "./AssetsController.mjs";
3
4
  export type { AssetsControllerState, AssetsControllerMessenger, AssetsControllerOptions, AssetsControllerGetStateAction, AssetsControllerActions, AssetsControllerStateChangeEvent, AssetsControllerBalanceChangedEvent, AssetsControllerPriceChangedEvent, AssetsControllerAssetsDetectedEvent, AssetsControllerEvents, } from "./AssetsController.mjs";
4
5
  export type { AssetsControllerGetAssetsAction, AssetsControllerGetAssetsBalanceAction, AssetsControllerGetAssetMetadataAction, AssetsControllerGetAssetsPriceAction, AssetsControllerAddCustomAssetAction, AssetsControllerRemoveCustomAssetAction, AssetsControllerGetCustomAssetsAction, AssetsControllerHideAssetAction, AssetsControllerUnhideAssetAction, AssetsControllerGetExchangeRatesForBridgeAction, AssetsControllerGetStateForTransactionPayAction, } from "./AssetsController-method-action-types.mjs";
@@ -15,7 +16,8 @@ export { SnapDataSource, createSnapDataSource, SNAP_DATA_SOURCE_NAME, KEYRING_PE
15
16
  export type { SnapDataSourceState, SnapDataSourceOptions, } from "./data-sources/index.mjs";
16
17
  export { TokenDataSource, PriceDataSource } from "./data-sources/index.mjs";
17
18
  export type { TokenDataSourceOptions, PriceDataSourceConfig, PriceDataSourceOptions, } from "./data-sources/index.mjs";
18
- export { DetectionMiddleware } from "./middlewares/index.mjs";
19
+ export { CustomAssetGraduationMiddleware, DetectionMiddleware, RpcFallbackMiddleware, } from "./middlewares/index.mjs";
20
+ export type { CustomAssetGraduationMiddlewareOptions, RpcFallbackMiddlewareOptions, } from "./middlewares/index.mjs";
19
21
  export { normalizeAssetId, formatExchangeRatesForBridge, formatStateForTransactionPay, } from "./utils/index.mjs";
20
22
  export type { AccountForLegacyFormat, BridgeExchangeRatesFormat, LegacyToken, TransactionPayLegacyFormat, } from "./utils/index.mjs";
21
23
  export { getAggregatedBalanceForAccount, getGroupIdForAccount, getInternalAccountsForGroup, } from "./selectors/balance.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAC5B,YAAY,EAAE,oBAAoB,EAAE,+BAA2B;AAG/D,YAAY,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E,aAAa,EAAE,mBAAmB,EAAE,iCAAuB;AAEpE,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,GACZ,iCAAuB;AAGxB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EAErB,kBAAkB,EAElB,iBAAiB,EACjB,uBAAuB,GACxB,iCAAuB;AAExB,YAAY,EACV,mBAAmB,EACnB,qBAAqB,GACtB,iCAAuB;AAGxB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,iCAAuB;AAElE,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,GACvB,iCAAuB;AAGxB,OAAO,EAAE,mBAAmB,EAAE,gCAAsB;AAGpD,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,GAC7B,0BAAgB;AACjB,YAAY,EACV,sBAAsB,EACtB,yBAAyB,EACzB,WAAW,EACX,0BAA0B,GAC3B,0BAAgB;AAGjB,OAAO,EACL,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,GAC5B,gCAA4B;AAE7B,YAAY,EACV,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,GAClB,gCAA4B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,+BAA+B,GAChC,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AACjD,YAAY,EAAE,oBAAoB,EAAE,+BAA2B;AAG/D,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,8BAA8B,EAC9B,uBAAuB,EACvB,gCAAgC,EAChC,mCAAmC,EACnC,iCAAiC,EACjC,mCAAmC,EACnC,sBAAsB,GACvB,+BAA2B;AAC5B,YAAY,EACV,+BAA+B,EAC/B,sCAAsC,EACtC,sCAAsC,EACtC,oCAAoC,EACpC,oCAAoC,EACpC,uCAAuC,EACv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AAqB,GACtB,iCAAuB;AAGxB,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,iCAAuB;AAElE,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,GACvB,iCAAuB;AAGxB,OAAO,EACL,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,GACtB,gCAAsB;AACvB,YAAY,EACV,sCAAsC,EACtC,4BAA4B,GAC7B,gCAAsB;AAGvB,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,GAC7B,0BAAgB;AACjB,YAAY,EACV,sBAAsB,EACtB,yBAAyB,EACzB,WAAW,EACX,0BAA0B,GAC3B,0BAAgB;AAGjB,OAAO,EACL,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,GAC5B,gCAA4B;AAE7B,YAAY,EACV,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,GAClB,gCAA4B"}
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  // Main controller export
2
2
  export { AssetsController, getDefaultAssetsControllerState } from "./AssetsController.mjs";
3
+ export { AssetsDataSourceError } from "./errors.mjs";
3
4
  // Data sources - base class and types
4
5
  export { AbstractDataSource } from "./data-sources/index.mjs";
5
6
  // Data sources - AccountsApi
@@ -17,7 +18,7 @@ getChainIdsCaveat, extractChainFromAssetId } from "./data-sources/index.mjs";
17
18
  // Enrichment data sources
18
19
  export { TokenDataSource, PriceDataSource } from "./data-sources/index.mjs";
19
20
  // Middlewares
20
- export { DetectionMiddleware } from "./middlewares/index.mjs";
21
+ export { CustomAssetGraduationMiddleware, DetectionMiddleware, RpcFallbackMiddleware } from "./middlewares/index.mjs";
21
22
  // Utilities
22
23
  export { normalizeAssetId, formatExchangeRatesForBridge, formatStateForTransactionPay } from "./utils/index.mjs";
23
24
  // Selectors
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EACL,gBAAgB,EAChB,+BAA+B,EAChC,+BAA2B;AAoF5B,sCAAsC;AACtC,OAAO,EAAE,kBAAkB,EAAE,iCAAuB;AAIpD,6BAA6B;AAC7B,OAAO,EAAE,qBAAqB,EAAE,iCAAuB;AAQvD,kCAAkC;AAClC,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EACjC,iCAAuB;AAOxB,qBAAqB;AACrB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,iCAAuB;AASpE,gFAAgF;AAChF,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB;AACrB,YAAY;AACZ,kBAAkB;AAClB,oBAAoB;AACpB,iBAAiB,EACjB,uBAAuB,EACxB,iCAAuB;AAOxB,0BAA0B;AAC1B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,iCAAuB;AAQlE,cAAc;AACd,OAAO,EAAE,mBAAmB,EAAE,gCAAsB;AAEpD,YAAY;AACZ,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,EAC7B,0BAAgB;AAQjB,YAAY;AACZ,OAAO,EACL,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,EAC5B,gCAA4B","sourcesContent":["// Main controller export\nexport {\n AssetsController,\n getDefaultAssetsControllerState,\n} from './AssetsController';\nexport type { PendingTokenMetadata } from './AssetsController';\n\n// State and messenger types\nexport type {\n AssetsControllerState,\n AssetsControllerMessenger,\n AssetsControllerOptions,\n AssetsControllerGetStateAction,\n AssetsControllerActions,\n AssetsControllerStateChangeEvent,\n AssetsControllerBalanceChangedEvent,\n AssetsControllerPriceChangedEvent,\n AssetsControllerAssetsDetectedEvent,\n AssetsControllerEvents,\n} from './AssetsController';\nexport type {\n AssetsControllerGetAssetsAction,\n AssetsControllerGetAssetsBalanceAction,\n AssetsControllerGetAssetMetadataAction,\n AssetsControllerGetAssetsPriceAction,\n AssetsControllerAddCustomAssetAction,\n AssetsControllerRemoveCustomAssetAction,\n AssetsControllerGetCustomAssetsAction,\n AssetsControllerHideAssetAction,\n AssetsControllerUnhideAssetAction,\n AssetsControllerGetExchangeRatesForBridgeAction,\n AssetsControllerGetStateForTransactionPayAction,\n} from './AssetsController-method-action-types';\n\n// Core types\nexport type {\n // CAIP types\n Caip19AssetId,\n AccountId,\n ChainId,\n // Asset types\n AssetType,\n TokenStandard,\n // Contract data types\n TokenFees,\n HoneypotStatus,\n StorageSlots,\n LocalizedDescription,\n // Metadata types\n BaseAssetMetadata,\n FungibleAssetMetadata,\n ERC721AssetMetadata,\n ERC1155AssetMetadata,\n AssetMetadata,\n // Price types\n BaseAssetPrice,\n FungibleAssetPrice,\n NFTAssetPrice,\n AssetPrice,\n // Balance types\n FungibleAssetBalance,\n ERC721AssetBalance,\n ERC1155AssetBalance,\n AssetBalance,\n // Data source types\n AccountWithSupportedChains,\n DataType,\n DataRequest,\n DataResponse,\n AssetsUpdateMode,\n // Middleware types\n Context,\n NextFunction,\n Middleware,\n AssetsDataSource,\n FetchContext,\n FetchNextFunction,\n FetchMiddleware,\n SubscriptionResponse,\n // Combined asset type\n Asset,\n // Event types\n BalanceChangeEvent,\n PriceChangeEvent,\n MetadataChangeEvent,\n AssetsDetectedEvent,\n} from './types';\n\n// Data sources - base class and types\nexport { AbstractDataSource } from './data-sources';\n\nexport type { DataSourceState, SubscriptionRequest } from './data-sources';\n\n// Data sources - AccountsApi\nexport { AccountsApiDataSource } from './data-sources';\n\nexport type {\n AccountsApiDataSourceConfig,\n AccountsApiDataSourceOptions,\n AccountsApiDataSourceState,\n} from './data-sources';\n\n// Data sources - BackendWebsocket\nexport {\n BackendWebsocketDataSource,\n createBackendWebsocketDataSource,\n} from './data-sources';\n\nexport type {\n BackendWebsocketDataSourceOptions,\n BackendWebsocketDataSourceState,\n} from './data-sources';\n\n// Data sources - RPC\nexport { RpcDataSource, createRpcDataSource } from './data-sources';\n\nexport type {\n RpcDataSourceConfig,\n RpcDataSourceOptions,\n RpcDataSourceState,\n ChainStatus,\n} from './data-sources';\n\n// Data sources - Unified Snap Data Source (dynamically discovers keyring snaps)\nexport {\n SnapDataSource,\n createSnapDataSource,\n SNAP_DATA_SOURCE_NAME,\n // Constants\n KEYRING_PERMISSION,\n // Utility functions\n getChainIdsCaveat,\n extractChainFromAssetId,\n} from './data-sources';\n\nexport type {\n SnapDataSourceState,\n SnapDataSourceOptions,\n} from './data-sources';\n\n// Enrichment data sources\nexport { TokenDataSource, PriceDataSource } from './data-sources';\n\nexport type {\n TokenDataSourceOptions,\n PriceDataSourceConfig,\n PriceDataSourceOptions,\n} from './data-sources';\n\n// Middlewares\nexport { DetectionMiddleware } from './middlewares';\n\n// Utilities\nexport {\n normalizeAssetId,\n formatExchangeRatesForBridge,\n formatStateForTransactionPay,\n} from './utils';\nexport type {\n AccountForLegacyFormat,\n BridgeExchangeRatesFormat,\n LegacyToken,\n TransactionPayLegacyFormat,\n} from './utils';\n\n// Selectors\nexport {\n getAggregatedBalanceForAccount,\n getGroupIdForAccount,\n getInternalAccountsForGroup,\n} from './selectors/balance';\n\nexport type {\n AccountsById,\n AggregatedBalanceEntry,\n AggregatedBalanceForAccount,\n EnabledNetworkMap,\n} from './selectors/balance';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EACL,gBAAgB,EAChB,+BAA+B,EAChC,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AAoFjD,sCAAsC;AACtC,OAAO,EAAE,kBAAkB,EAAE,iCAAuB;AAIpD,6BAA6B;AAC7B,OAAO,EAAE,qBAAqB,EAAE,iCAAuB;AAQvD,kCAAkC;AAClC,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EACjC,iCAAuB;AAOxB,qBAAqB;AACrB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,iCAAuB;AASpE,gFAAgF;AAChF,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB;AACrB,YAAY;AACZ,kBAAkB;AAClB,oBAAoB;AACpB,iBAAiB,EACjB,uBAAuB,EACxB,iCAAuB;AAOxB,0BAA0B;AAC1B,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,iCAAuB;AAQlE,cAAc;AACd,OAAO,EACL,+BAA+B,EAC/B,mBAAmB,EACnB,qBAAqB,EACtB,gCAAsB;AAMvB,YAAY;AACZ,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,4BAA4B,EAC7B,0BAAgB;AAQjB,YAAY;AACZ,OAAO,EACL,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,EAC5B,gCAA4B","sourcesContent":["// Main controller export\nexport {\n AssetsController,\n getDefaultAssetsControllerState,\n} from './AssetsController';\nexport { AssetsDataSourceError } from './errors';\nexport type { PendingTokenMetadata } from './AssetsController';\n\n// State and messenger types\nexport type {\n AssetsControllerState,\n AssetsControllerMessenger,\n AssetsControllerOptions,\n AssetsControllerGetStateAction,\n AssetsControllerActions,\n AssetsControllerStateChangeEvent,\n AssetsControllerBalanceChangedEvent,\n AssetsControllerPriceChangedEvent,\n AssetsControllerAssetsDetectedEvent,\n AssetsControllerEvents,\n} from './AssetsController';\nexport type {\n AssetsControllerGetAssetsAction,\n AssetsControllerGetAssetsBalanceAction,\n AssetsControllerGetAssetMetadataAction,\n AssetsControllerGetAssetsPriceAction,\n AssetsControllerAddCustomAssetAction,\n AssetsControllerRemoveCustomAssetAction,\n AssetsControllerGetCustomAssetsAction,\n AssetsControllerHideAssetAction,\n AssetsControllerUnhideAssetAction,\n AssetsControllerGetExchangeRatesForBridgeAction,\n AssetsControllerGetStateForTransactionPayAction,\n} from './AssetsController-method-action-types';\n\n// Core types\nexport type {\n // CAIP types\n Caip19AssetId,\n AccountId,\n ChainId,\n // Asset types\n AssetType,\n TokenStandard,\n // Contract data types\n TokenFees,\n HoneypotStatus,\n StorageSlots,\n LocalizedDescription,\n // Metadata types\n BaseAssetMetadata,\n FungibleAssetMetadata,\n ERC721AssetMetadata,\n ERC1155AssetMetadata,\n AssetMetadata,\n // Price types\n BaseAssetPrice,\n FungibleAssetPrice,\n NFTAssetPrice,\n AssetPrice,\n // Balance types\n FungibleAssetBalance,\n ERC721AssetBalance,\n ERC1155AssetBalance,\n AssetBalance,\n // Data source types\n AccountWithSupportedChains,\n DataType,\n DataRequest,\n DataResponse,\n AssetsUpdateMode,\n // Middleware types\n Context,\n NextFunction,\n Middleware,\n AssetsDataSource,\n FetchContext,\n FetchNextFunction,\n FetchMiddleware,\n SubscriptionResponse,\n // Combined asset type\n Asset,\n // Event types\n BalanceChangeEvent,\n PriceChangeEvent,\n MetadataChangeEvent,\n AssetsDetectedEvent,\n} from './types';\n\n// Data sources - base class and types\nexport { AbstractDataSource } from './data-sources';\n\nexport type { DataSourceState, SubscriptionRequest } from './data-sources';\n\n// Data sources - AccountsApi\nexport { AccountsApiDataSource } from './data-sources';\n\nexport type {\n AccountsApiDataSourceConfig,\n AccountsApiDataSourceOptions,\n AccountsApiDataSourceState,\n} from './data-sources';\n\n// Data sources - BackendWebsocket\nexport {\n BackendWebsocketDataSource,\n createBackendWebsocketDataSource,\n} from './data-sources';\n\nexport type {\n BackendWebsocketDataSourceOptions,\n BackendWebsocketDataSourceState,\n} from './data-sources';\n\n// Data sources - RPC\nexport { RpcDataSource, createRpcDataSource } from './data-sources';\n\nexport type {\n RpcDataSourceConfig,\n RpcDataSourceOptions,\n RpcDataSourceState,\n ChainStatus,\n} from './data-sources';\n\n// Data sources - Unified Snap Data Source (dynamically discovers keyring snaps)\nexport {\n SnapDataSource,\n createSnapDataSource,\n SNAP_DATA_SOURCE_NAME,\n // Constants\n KEYRING_PERMISSION,\n // Utility functions\n getChainIdsCaveat,\n extractChainFromAssetId,\n} from './data-sources';\n\nexport type {\n SnapDataSourceState,\n SnapDataSourceOptions,\n} from './data-sources';\n\n// Enrichment data sources\nexport { TokenDataSource, PriceDataSource } from './data-sources';\n\nexport type {\n TokenDataSourceOptions,\n PriceDataSourceConfig,\n PriceDataSourceOptions,\n} from './data-sources';\n\n// Middlewares\nexport {\n CustomAssetGraduationMiddleware,\n DetectionMiddleware,\n RpcFallbackMiddleware,\n} from './middlewares';\nexport type {\n CustomAssetGraduationMiddlewareOptions,\n RpcFallbackMiddlewareOptions,\n} from './middlewares';\n\n// Utilities\nexport {\n normalizeAssetId,\n formatExchangeRatesForBridge,\n formatStateForTransactionPay,\n} from './utils';\nexport type {\n AccountForLegacyFormat,\n BridgeExchangeRatesFormat,\n LegacyToken,\n TransactionPayLegacyFormat,\n} from './utils';\n\n// Selectors\nexport {\n getAggregatedBalanceForAccount,\n getGroupIdForAccount,\n getInternalAccountsForGroup,\n} from './selectors/balance';\n\nexport type {\n AccountsById,\n AggregatedBalanceEntry,\n AggregatedBalanceForAccount,\n EnabledNetworkMap,\n} from './selectors/balance';\n"]}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _CustomAssetGraduationMiddleware_getSelectedAccountId, _CustomAssetGraduationMiddleware_removeCustomAsset;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CustomAssetGraduationMiddleware = void 0;
16
+ const utils_1 = require("@metamask/utils");
17
+ const logger_1 = require("../logger.cjs");
18
+ const types_1 = require("../types.cjs");
19
+ const utils_2 = require("../utils/index.cjs");
20
+ const CONTROLLER_NAME = 'CustomAssetGraduationMiddleware';
21
+ const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, CONTROLLER_NAME);
22
+ /**
23
+ * CustomAssetGraduationMiddleware removes EVM assets from `customAssets` when
24
+ * an upstream balance source (AccountsAPI / Websocket) reports a balance for
25
+ * them. Once a detector sees the asset, it no longer needs to be tracked as
26
+ * "custom" — the regular detection flow will keep it fresh.
27
+ *
28
+ * Rules:
29
+ * - Only the selected account's custom assets are considered.
30
+ * - Only EVM (CAIP-2 namespace `eip155`) assets graduate. Non-EVM custom
31
+ * assets (Solana, BTC, Tron, etc. — served by Snap data sources) are left
32
+ * alone.
33
+ */
34
+ class CustomAssetGraduationMiddleware {
35
+ constructor(options) {
36
+ this.name = CONTROLLER_NAME;
37
+ _CustomAssetGraduationMiddleware_getSelectedAccountId.set(this, void 0);
38
+ _CustomAssetGraduationMiddleware_removeCustomAsset.set(this, void 0);
39
+ __classPrivateFieldSet(this, _CustomAssetGraduationMiddleware_getSelectedAccountId, options.getSelectedAccountId, "f");
40
+ __classPrivateFieldSet(this, _CustomAssetGraduationMiddleware_removeCustomAsset, options.removeCustomAsset, "f");
41
+ }
42
+ getName() {
43
+ return this.name;
44
+ }
45
+ get assetsMiddleware() {
46
+ return (0, types_1.forDataTypes)(['balance'], async (ctx, next) => {
47
+ // Inspect the response BEFORE calling next() so we only consider
48
+ // balances populated by upstream middleware (AccountsApi / Websocket /
49
+ // Staked). This middleware is positioned in the pipeline before the
50
+ // RPC fallback — RPC intentionally carries custom assets and must
51
+ // never trigger graduation.
52
+ const accountId = __classPrivateFieldGet(this, _CustomAssetGraduationMiddleware_getSelectedAccountId, "f").call(this);
53
+ if (!accountId) {
54
+ return next(ctx);
55
+ }
56
+ const state = ctx.getAssetsState();
57
+ const customForAccount = state.customAssets?.[accountId] ?? [];
58
+ if (customForAccount.length === 0) {
59
+ return next(ctx);
60
+ }
61
+ const returnedBalances = ctx.response.assetsBalance?.[accountId] ?? {};
62
+ const returnedAssetIds = Object.keys(returnedBalances);
63
+ if (returnedAssetIds.length === 0) {
64
+ return next(ctx);
65
+ }
66
+ // customAssets state is stored with checksummed/normalized asset IDs.
67
+ // AccountsApiDataSource normalizes its response IDs, but
68
+ // BackendWebsocketDataSource does not — so we normalize the response
69
+ // side here to make the comparison robust to lower-case addresses
70
+ // delivered over the websocket.
71
+ const customSet = new Set(customForAccount);
72
+ for (const rawAssetId of returnedAssetIds) {
73
+ if (!isEvmAssetId(rawAssetId)) {
74
+ continue;
75
+ }
76
+ const normalizedAssetId = safeNormalize(rawAssetId);
77
+ if (!customSet.has(normalizedAssetId)) {
78
+ continue;
79
+ }
80
+ log('Graduating custom asset', {
81
+ accountId,
82
+ assetId: normalizedAssetId,
83
+ });
84
+ __classPrivateFieldGet(this, _CustomAssetGraduationMiddleware_removeCustomAsset, "f").call(this, accountId, normalizedAssetId);
85
+ }
86
+ return next(ctx);
87
+ });
88
+ }
89
+ }
90
+ exports.CustomAssetGraduationMiddleware = CustomAssetGraduationMiddleware;
91
+ _CustomAssetGraduationMiddleware_getSelectedAccountId = new WeakMap(), _CustomAssetGraduationMiddleware_removeCustomAsset = new WeakMap();
92
+ /**
93
+ * Check whether a CAIP-19 asset ID belongs to an EVM chain.
94
+ *
95
+ * @param assetId - The CAIP-19 asset ID to inspect.
96
+ * @returns `true` when the asset's chain namespace is `eip155`.
97
+ */
98
+ function isEvmAssetId(assetId) {
99
+ // CAIP-19 format: <namespace>:<chainRef>/<assetNamespace>:<assetRef>
100
+ // The chain namespace is always the segment before the first colon.
101
+ const namespace = assetId.split(':')[0];
102
+ return namespace === utils_1.KnownCaipNamespace.Eip155;
103
+ }
104
+ /**
105
+ * Normalize a CAIP-19 asset ID, returning the original on failure. Some
106
+ * malformed IDs (e.g. an asset reference that fails address checksumming)
107
+ * make `normalizeAssetId` throw — in that case we fall back to the raw ID
108
+ * so the graduation pass can still proceed for other assets.
109
+ *
110
+ * @param assetId - The CAIP-19 asset ID to normalize.
111
+ * @returns The normalized ID, or the original on failure.
112
+ */
113
+ function safeNormalize(assetId) {
114
+ try {
115
+ return (0, utils_2.normalizeAssetId)(assetId);
116
+ }
117
+ catch {
118
+ return assetId;
119
+ }
120
+ }
121
+ //# sourceMappingURL=CustomAssetGraduationMiddleware.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomAssetGraduationMiddleware.cjs","sourceRoot":"","sources":["../../src/middlewares/CustomAssetGraduationMiddleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAqD;AAErD,0CAA8D;AAC9D,wCAAwC;AAExC,8CAA4C;AAE5C,MAAM,eAAe,GAAG,iCAAiC,CAAC;AAE1D,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,eAAe,CAAC,CAAC;AAO/D;;;;;;;;;;;GAWG;AACH,MAAa,+BAA+B;IAU1C,YAAY,OAA+C;QATlD,SAAI,GAAG,eAAe,CAAC;QAEvB,wEAAmD;QAEnD,qEAGC;QAGR,uBAAA,IAAI,yDAAyB,OAAO,CAAC,oBAAoB,MAAA,CAAC;QAC1D,uBAAA,IAAI,sDAAsB,OAAO,CAAC,iBAAiB,MAAA,CAAC;IACtD,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,IAAA,oBAAY,EAAC,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACnD,iEAAiE;YACjE,uEAAuE;YACvE,oEAAoE;YACpE,kEAAkE;YAClE,4BAA4B;YAC5B,MAAM,SAAS,GAAG,uBAAA,IAAI,6DAAsB,MAA1B,IAAI,CAAwB,CAAC;YAC/C,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,OAAO,IAAI,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CAAC,CAAC;IACL,CAAC;CACF;AAnED,0EAmEC;;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,OAAsB;IAC1C,qEAAqE;IACrE,oEAAoE;IACpE,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,OAAO,SAAS,KAAK,0BAAkB,CAAC,MAAM,CAAC;AACjD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,aAAa,CAAC,OAAsB;IAC3C,IAAI,CAAC;QACH,OAAO,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC","sourcesContent":["import { KnownCaipNamespace } from '@metamask/utils';\n\nimport { projectLogger, createModuleLogger } from '../logger';\nimport { forDataTypes } from '../types';\nimport type { AccountId, Caip19AssetId, Middleware } from '../types';\nimport { normalizeAssetId } from '../utils';\n\nconst CONTROLLER_NAME = 'CustomAssetGraduationMiddleware';\n\nconst log = createModuleLogger(projectLogger, CONTROLLER_NAME);\n\nexport type CustomAssetGraduationMiddlewareOptions = {\n getSelectedAccountId: () => AccountId | undefined;\n removeCustomAsset: (accountId: AccountId, assetId: Caip19AssetId) => void;\n};\n\n/**\n * CustomAssetGraduationMiddleware removes EVM assets from `customAssets` when\n * an upstream balance source (AccountsAPI / Websocket) reports a balance for\n * them. Once a detector sees the asset, it no longer needs to be tracked as\n * \"custom\" — the regular detection flow will keep it fresh.\n *\n * Rules:\n * - Only the selected account's custom assets are considered.\n * - Only EVM (CAIP-2 namespace `eip155`) assets graduate. Non-EVM custom\n * assets (Solana, BTC, Tron, etc. — served by Snap data sources) are left\n * alone.\n */\nexport class CustomAssetGraduationMiddleware {\n readonly name = CONTROLLER_NAME;\n\n readonly #getSelectedAccountId: () => AccountId | undefined;\n\n readonly #removeCustomAsset: (\n accountId: AccountId,\n assetId: Caip19AssetId,\n ) => void;\n\n constructor(options: CustomAssetGraduationMiddlewareOptions) {\n this.#getSelectedAccountId = options.getSelectedAccountId;\n this.#removeCustomAsset = options.removeCustomAsset;\n }\n\n getName(): string {\n return this.name;\n }\n\n get assetsMiddleware(): Middleware {\n return forDataTypes(['balance'], async (ctx, next) => {\n // Inspect the response BEFORE calling next() so we only consider\n // balances populated by upstream middleware (AccountsApi / Websocket /\n // Staked). This middleware is positioned in the pipeline before the\n // RPC fallback — RPC intentionally carries custom assets and must\n // never trigger graduation.\n const accountId = this.#getSelectedAccountId();\n if (!accountId) {\n return next(ctx);\n }\n\n const state = ctx.getAssetsState();\n const customForAccount = state.customAssets?.[accountId] ?? [];\n if (customForAccount.length === 0) {\n return next(ctx);\n }\n\n const returnedBalances = ctx.response.assetsBalance?.[accountId] ?? {};\n const returnedAssetIds = Object.keys(returnedBalances) as Caip19AssetId[];\n if (returnedAssetIds.length === 0) {\n return next(ctx);\n }\n\n // customAssets state is stored with checksummed/normalized asset IDs.\n // AccountsApiDataSource normalizes its response IDs, but\n // BackendWebsocketDataSource does not — so we normalize the response\n // side here to make the comparison robust to lower-case addresses\n // delivered over the websocket.\n const customSet = new Set(customForAccount);\n for (const rawAssetId of returnedAssetIds) {\n if (!isEvmAssetId(rawAssetId)) {\n continue;\n }\n const normalizedAssetId = safeNormalize(rawAssetId);\n if (!customSet.has(normalizedAssetId)) {\n continue;\n }\n log('Graduating custom asset', {\n accountId,\n assetId: normalizedAssetId,\n });\n this.#removeCustomAsset(accountId, normalizedAssetId);\n }\n\n return next(ctx);\n });\n }\n}\n\n/**\n * Check whether a CAIP-19 asset ID belongs to an EVM chain.\n *\n * @param assetId - The CAIP-19 asset ID to inspect.\n * @returns `true` when the asset's chain namespace is `eip155`.\n */\nfunction isEvmAssetId(assetId: Caip19AssetId): boolean {\n // CAIP-19 format: <namespace>:<chainRef>/<assetNamespace>:<assetRef>\n // The chain namespace is always the segment before the first colon.\n const namespace = assetId.split(':')[0];\n return namespace === KnownCaipNamespace.Eip155;\n}\n\n/**\n * Normalize a CAIP-19 asset ID, returning the original on failure. Some\n * malformed IDs (e.g. an asset reference that fails address checksumming)\n * make `normalizeAssetId` throw — in that case we fall back to the raw ID\n * so the graduation pass can still proceed for other assets.\n *\n * @param assetId - The CAIP-19 asset ID to normalize.\n * @returns The normalized ID, or the original on failure.\n */\nfunction safeNormalize(assetId: Caip19AssetId): Caip19AssetId {\n try {\n return normalizeAssetId(assetId);\n } catch {\n return assetId;\n }\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import type { AccountId, Caip19AssetId, Middleware } from "../types.cjs";
2
+ export type CustomAssetGraduationMiddlewareOptions = {
3
+ getSelectedAccountId: () => AccountId | undefined;
4
+ removeCustomAsset: (accountId: AccountId, assetId: Caip19AssetId) => void;
5
+ };
6
+ /**
7
+ * CustomAssetGraduationMiddleware removes EVM assets from `customAssets` when
8
+ * an upstream balance source (AccountsAPI / Websocket) reports a balance for
9
+ * them. Once a detector sees the asset, it no longer needs to be tracked as
10
+ * "custom" — the regular detection flow will keep it fresh.
11
+ *
12
+ * Rules:
13
+ * - Only the selected account's custom assets are considered.
14
+ * - Only EVM (CAIP-2 namespace `eip155`) assets graduate. Non-EVM custom
15
+ * assets (Solana, BTC, Tron, etc. — served by Snap data sources) are left
16
+ * alone.
17
+ */
18
+ export declare class CustomAssetGraduationMiddleware {
19
+ #private;
20
+ readonly name = "CustomAssetGraduationMiddleware";
21
+ constructor(options: CustomAssetGraduationMiddlewareOptions);
22
+ getName(): string;
23
+ get assetsMiddleware(): Middleware;
24
+ }
25
+ //# sourceMappingURL=CustomAssetGraduationMiddleware.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomAssetGraduationMiddleware.d.cts","sourceRoot":"","sources":["../../src/middlewares/CustomAssetGraduationMiddleware.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,qBAAiB;AAOrE,MAAM,MAAM,sCAAsC,GAAG;IACnD,oBAAoB,EAAE,MAAM,SAAS,GAAG,SAAS,CAAC;IAClD,iBAAiB,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;CAC3E,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,qBAAa,+BAA+B;;IAC1C,QAAQ,CAAC,IAAI,qCAAmB;gBASpB,OAAO,EAAE,sCAAsC;IAK3D,OAAO,IAAI,MAAM;IAIjB,IAAI,gBAAgB,IAAI,UAAU,CA+CjC;CACF"}
@@ -0,0 +1,25 @@
1
+ import type { AccountId, Caip19AssetId, Middleware } from "../types.mjs";
2
+ export type CustomAssetGraduationMiddlewareOptions = {
3
+ getSelectedAccountId: () => AccountId | undefined;
4
+ removeCustomAsset: (accountId: AccountId, assetId: Caip19AssetId) => void;
5
+ };
6
+ /**
7
+ * CustomAssetGraduationMiddleware removes EVM assets from `customAssets` when
8
+ * an upstream balance source (AccountsAPI / Websocket) reports a balance for
9
+ * them. Once a detector sees the asset, it no longer needs to be tracked as
10
+ * "custom" — the regular detection flow will keep it fresh.
11
+ *
12
+ * Rules:
13
+ * - Only the selected account's custom assets are considered.
14
+ * - Only EVM (CAIP-2 namespace `eip155`) assets graduate. Non-EVM custom
15
+ * assets (Solana, BTC, Tron, etc. — served by Snap data sources) are left
16
+ * alone.
17
+ */
18
+ export declare class CustomAssetGraduationMiddleware {
19
+ #private;
20
+ readonly name = "CustomAssetGraduationMiddleware";
21
+ constructor(options: CustomAssetGraduationMiddlewareOptions);
22
+ getName(): string;
23
+ get assetsMiddleware(): Middleware;
24
+ }
25
+ //# sourceMappingURL=CustomAssetGraduationMiddleware.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomAssetGraduationMiddleware.d.mts","sourceRoot":"","sources":["../../src/middlewares/CustomAssetGraduationMiddleware.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,qBAAiB;AAOrE,MAAM,MAAM,sCAAsC,GAAG;IACnD,oBAAoB,EAAE,MAAM,SAAS,GAAG,SAAS,CAAC;IAClD,iBAAiB,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;CAC3E,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,qBAAa,+BAA+B;;IAC1C,QAAQ,CAAC,IAAI,qCAAmB;gBASpB,OAAO,EAAE,sCAAsC;IAK3D,OAAO,IAAI,MAAM;IAIjB,IAAI,gBAAgB,IAAI,UAAU,CA+CjC;CACF"}
@@ -0,0 +1,117 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _CustomAssetGraduationMiddleware_getSelectedAccountId, _CustomAssetGraduationMiddleware_removeCustomAsset;
13
+ import { KnownCaipNamespace } from "@metamask/utils";
14
+ import { projectLogger, createModuleLogger } from "../logger.mjs";
15
+ import { forDataTypes } from "../types.mjs";
16
+ import { normalizeAssetId } from "../utils/index.mjs";
17
+ const CONTROLLER_NAME = 'CustomAssetGraduationMiddleware';
18
+ const log = createModuleLogger(projectLogger, CONTROLLER_NAME);
19
+ /**
20
+ * CustomAssetGraduationMiddleware removes EVM assets from `customAssets` when
21
+ * an upstream balance source (AccountsAPI / Websocket) reports a balance for
22
+ * them. Once a detector sees the asset, it no longer needs to be tracked as
23
+ * "custom" — the regular detection flow will keep it fresh.
24
+ *
25
+ * Rules:
26
+ * - Only the selected account's custom assets are considered.
27
+ * - Only EVM (CAIP-2 namespace `eip155`) assets graduate. Non-EVM custom
28
+ * assets (Solana, BTC, Tron, etc. — served by Snap data sources) are left
29
+ * alone.
30
+ */
31
+ export class CustomAssetGraduationMiddleware {
32
+ constructor(options) {
33
+ this.name = CONTROLLER_NAME;
34
+ _CustomAssetGraduationMiddleware_getSelectedAccountId.set(this, void 0);
35
+ _CustomAssetGraduationMiddleware_removeCustomAsset.set(this, void 0);
36
+ __classPrivateFieldSet(this, _CustomAssetGraduationMiddleware_getSelectedAccountId, options.getSelectedAccountId, "f");
37
+ __classPrivateFieldSet(this, _CustomAssetGraduationMiddleware_removeCustomAsset, options.removeCustomAsset, "f");
38
+ }
39
+ getName() {
40
+ return this.name;
41
+ }
42
+ get assetsMiddleware() {
43
+ return forDataTypes(['balance'], async (ctx, next) => {
44
+ // Inspect the response BEFORE calling next() so we only consider
45
+ // balances populated by upstream middleware (AccountsApi / Websocket /
46
+ // Staked). This middleware is positioned in the pipeline before the
47
+ // RPC fallback — RPC intentionally carries custom assets and must
48
+ // never trigger graduation.
49
+ const accountId = __classPrivateFieldGet(this, _CustomAssetGraduationMiddleware_getSelectedAccountId, "f").call(this);
50
+ if (!accountId) {
51
+ return next(ctx);
52
+ }
53
+ const state = ctx.getAssetsState();
54
+ const customForAccount = state.customAssets?.[accountId] ?? [];
55
+ if (customForAccount.length === 0) {
56
+ return next(ctx);
57
+ }
58
+ const returnedBalances = ctx.response.assetsBalance?.[accountId] ?? {};
59
+ const returnedAssetIds = Object.keys(returnedBalances);
60
+ if (returnedAssetIds.length === 0) {
61
+ return next(ctx);
62
+ }
63
+ // customAssets state is stored with checksummed/normalized asset IDs.
64
+ // AccountsApiDataSource normalizes its response IDs, but
65
+ // BackendWebsocketDataSource does not — so we normalize the response
66
+ // side here to make the comparison robust to lower-case addresses
67
+ // delivered over the websocket.
68
+ const customSet = new Set(customForAccount);
69
+ for (const rawAssetId of returnedAssetIds) {
70
+ if (!isEvmAssetId(rawAssetId)) {
71
+ continue;
72
+ }
73
+ const normalizedAssetId = safeNormalize(rawAssetId);
74
+ if (!customSet.has(normalizedAssetId)) {
75
+ continue;
76
+ }
77
+ log('Graduating custom asset', {
78
+ accountId,
79
+ assetId: normalizedAssetId,
80
+ });
81
+ __classPrivateFieldGet(this, _CustomAssetGraduationMiddleware_removeCustomAsset, "f").call(this, accountId, normalizedAssetId);
82
+ }
83
+ return next(ctx);
84
+ });
85
+ }
86
+ }
87
+ _CustomAssetGraduationMiddleware_getSelectedAccountId = new WeakMap(), _CustomAssetGraduationMiddleware_removeCustomAsset = new WeakMap();
88
+ /**
89
+ * Check whether a CAIP-19 asset ID belongs to an EVM chain.
90
+ *
91
+ * @param assetId - The CAIP-19 asset ID to inspect.
92
+ * @returns `true` when the asset's chain namespace is `eip155`.
93
+ */
94
+ function isEvmAssetId(assetId) {
95
+ // CAIP-19 format: <namespace>:<chainRef>/<assetNamespace>:<assetRef>
96
+ // The chain namespace is always the segment before the first colon.
97
+ const namespace = assetId.split(':')[0];
98
+ return namespace === KnownCaipNamespace.Eip155;
99
+ }
100
+ /**
101
+ * Normalize a CAIP-19 asset ID, returning the original on failure. Some
102
+ * malformed IDs (e.g. an asset reference that fails address checksumming)
103
+ * make `normalizeAssetId` throw — in that case we fall back to the raw ID
104
+ * so the graduation pass can still proceed for other assets.
105
+ *
106
+ * @param assetId - The CAIP-19 asset ID to normalize.
107
+ * @returns The normalized ID, or the original on failure.
108
+ */
109
+ function safeNormalize(assetId) {
110
+ try {
111
+ return normalizeAssetId(assetId);
112
+ }
113
+ catch {
114
+ return assetId;
115
+ }
116
+ }
117
+ //# sourceMappingURL=CustomAssetGraduationMiddleware.mjs.map
@@ -0,0 +1 @@
1
+ {"version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,KAAK,kBAAkB,CAAC,MAAM,CAAC;AACjD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,aAAa,CAAC,OAAsB;IAC3C,IAAI,CAAC;QACH,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC","sourcesContent":["import { KnownCaipNamespace } from '@metamask/utils';\n\nimport { projectLogger, createModuleLogger } from '../logger';\nimport { forDataTypes } from '../types';\nimport type { AccountId, Caip19AssetId, Middleware } from '../types';\nimport { normalizeAssetId } from '../utils';\n\nconst CONTROLLER_NAME = 'CustomAssetGraduationMiddleware';\n\nconst log = createModuleLogger(projectLogger, CONTROLLER_NAME);\n\nexport type CustomAssetGraduationMiddlewareOptions = {\n getSelectedAccountId: () => AccountId | undefined;\n removeCustomAsset: (accountId: AccountId, assetId: Caip19AssetId) => void;\n};\n\n/**\n * CustomAssetGraduationMiddleware removes EVM assets from `customAssets` when\n * an upstream balance source (AccountsAPI / Websocket) reports a balance for\n * them. Once a detector sees the asset, it no longer needs to be tracked as\n * \"custom\" — the regular detection flow will keep it fresh.\n *\n * Rules:\n * - Only the selected account's custom assets are considered.\n * - Only EVM (CAIP-2 namespace `eip155`) assets graduate. Non-EVM custom\n * assets (Solana, BTC, Tron, etc. — served by Snap data sources) are left\n * alone.\n */\nexport class CustomAssetGraduationMiddleware {\n readonly name = CONTROLLER_NAME;\n\n readonly #getSelectedAccountId: () => AccountId | undefined;\n\n readonly #removeCustomAsset: (\n accountId: AccountId,\n assetId: Caip19AssetId,\n ) => void;\n\n constructor(options: CustomAssetGraduationMiddlewareOptions) {\n this.#getSelectedAccountId = options.getSelectedAccountId;\n this.#removeCustomAsset = options.removeCustomAsset;\n }\n\n getName(): string {\n return this.name;\n }\n\n get assetsMiddleware(): Middleware {\n return forDataTypes(['balance'], async (ctx, next) => {\n // Inspect the response BEFORE calling next() so we only consider\n // balances populated by upstream middleware (AccountsApi / Websocket /\n // Staked). This middleware is positioned in the pipeline before the\n // RPC fallback — RPC intentionally carries custom assets and must\n // never trigger graduation.\n const accountId = this.#getSelectedAccountId();\n if (!accountId) {\n return next(ctx);\n }\n\n const state = ctx.getAssetsState();\n const customForAccount = state.customAssets?.[accountId] ?? [];\n if (customForAccount.length === 0) {\n return next(ctx);\n }\n\n const returnedBalances = ctx.response.assetsBalance?.[accountId] ?? {};\n const returnedAssetIds = Object.keys(returnedBalances) as Caip19AssetId[];\n if (returnedAssetIds.length === 0) {\n return next(ctx);\n }\n\n // customAssets state is stored with checksummed/normalized asset IDs.\n // AccountsApiDataSource normalizes its response IDs, but\n // BackendWebsocketDataSource does not — so we normalize the response\n // side here to make the comparison robust to lower-case addresses\n // delivered over the websocket.\n const customSet = new Set(customForAccount);\n for (const rawAssetId of returnedAssetIds) {\n if (!isEvmAssetId(rawAssetId)) {\n continue;\n }\n const normalizedAssetId = safeNormalize(rawAssetId);\n if (!customSet.has(normalizedAssetId)) {\n continue;\n }\n log('Graduating custom asset', {\n accountId,\n assetId: normalizedAssetId,\n });\n this.#removeCustomAsset(accountId, normalizedAssetId);\n }\n\n return next(ctx);\n });\n }\n}\n\n/**\n * Check whether a CAIP-19 asset ID belongs to an EVM chain.\n *\n * @param assetId - The CAIP-19 asset ID to inspect.\n * @returns `true` when the asset's chain namespace is `eip155`.\n */\nfunction isEvmAssetId(assetId: Caip19AssetId): boolean {\n // CAIP-19 format: <namespace>:<chainRef>/<assetNamespace>:<assetRef>\n // The chain namespace is always the segment before the first colon.\n const namespace = assetId.split(':')[0];\n return namespace === KnownCaipNamespace.Eip155;\n}\n\n/**\n * Normalize a CAIP-19 asset ID, returning the original on failure. Some\n * malformed IDs (e.g. an asset reference that fails address checksumming)\n * make `normalizeAssetId` throw — in that case we fall back to the raw ID\n * so the graduation pass can still proceed for other assets.\n *\n * @param assetId - The CAIP-19 asset ID to normalize.\n * @returns The normalized ID, or the original on failure.\n */\nfunction safeNormalize(assetId: Caip19AssetId): Caip19AssetId {\n try {\n return normalizeAssetId(assetId);\n } catch {\n return assetId;\n }\n}\n"]}