@metamask/assets-controllers 110.0.0 → 110.0.1

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 (275) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/AccountTrackerController-method-action-types.cjs.map +1 -1
  3. package/dist/AccountTrackerController-method-action-types.d.cts.map +1 -1
  4. package/dist/AccountTrackerController-method-action-types.d.mts.map +1 -1
  5. package/dist/AccountTrackerController-method-action-types.mjs.map +1 -1
  6. package/dist/AccountTrackerController.cjs +8 -8
  7. package/dist/AccountTrackerController.cjs.map +1 -1
  8. package/dist/AccountTrackerController.d.cts.map +1 -1
  9. package/dist/AccountTrackerController.d.mts.map +1 -1
  10. package/dist/AccountTrackerController.mjs.map +1 -1
  11. package/dist/AssetsContractController-method-action-types.cjs.map +1 -1
  12. package/dist/AssetsContractController-method-action-types.d.cts.map +1 -1
  13. package/dist/AssetsContractController-method-action-types.d.mts.map +1 -1
  14. package/dist/AssetsContractController-method-action-types.mjs.map +1 -1
  15. package/dist/AssetsContractController.cjs +33 -33
  16. package/dist/AssetsContractController.cjs.map +1 -1
  17. package/dist/AssetsContractController.d.cts.map +1 -1
  18. package/dist/AssetsContractController.d.mts.map +1 -1
  19. package/dist/AssetsContractController.mjs.map +1 -1
  20. package/dist/CurrencyRateController-method-action-types.cjs.map +1 -1
  21. package/dist/CurrencyRateController-method-action-types.d.cts.map +1 -1
  22. package/dist/CurrencyRateController-method-action-types.d.mts.map +1 -1
  23. package/dist/CurrencyRateController-method-action-types.mjs.map +1 -1
  24. package/dist/CurrencyRateController.cjs +2 -2
  25. package/dist/CurrencyRateController.cjs.map +1 -1
  26. package/dist/CurrencyRateController.d.cts.map +1 -1
  27. package/dist/CurrencyRateController.d.mts.map +1 -1
  28. package/dist/CurrencyRateController.mjs.map +1 -1
  29. package/dist/DeFiPositionsController/DeFiPositionsController.cjs +6 -6
  30. package/dist/DeFiPositionsController/DeFiPositionsController.cjs.map +1 -1
  31. package/dist/DeFiPositionsController/DeFiPositionsController.d.cts.map +1 -1
  32. package/dist/DeFiPositionsController/DeFiPositionsController.d.mts.map +1 -1
  33. package/dist/DeFiPositionsController/DeFiPositionsController.mjs.map +1 -1
  34. package/dist/DeFiPositionsController/DeFiPositionsControllerV2-method-action-types.cjs.map +1 -1
  35. package/dist/DeFiPositionsController/DeFiPositionsControllerV2-method-action-types.d.cts.map +1 -1
  36. package/dist/DeFiPositionsController/DeFiPositionsControllerV2-method-action-types.d.mts.map +1 -1
  37. package/dist/DeFiPositionsController/DeFiPositionsControllerV2-method-action-types.mjs.map +1 -1
  38. package/dist/DeFiPositionsController/DeFiPositionsControllerV2.cjs +4 -4
  39. package/dist/DeFiPositionsController/DeFiPositionsControllerV2.cjs.map +1 -1
  40. package/dist/DeFiPositionsController/DeFiPositionsControllerV2.d.cts.map +1 -1
  41. package/dist/DeFiPositionsController/DeFiPositionsControllerV2.d.mts.map +1 -1
  42. package/dist/DeFiPositionsController/DeFiPositionsControllerV2.mjs.map +1 -1
  43. package/dist/DeFiPositionsController/calculate-defi-metrics.cjs.map +1 -1
  44. package/dist/DeFiPositionsController/calculate-defi-metrics.d.cts.map +1 -1
  45. package/dist/DeFiPositionsController/calculate-defi-metrics.d.mts.map +1 -1
  46. package/dist/DeFiPositionsController/calculate-defi-metrics.mjs.map +1 -1
  47. package/dist/DeFiPositionsController/fetch-positions.cjs +2 -2
  48. package/dist/DeFiPositionsController/fetch-positions.cjs.map +1 -1
  49. package/dist/DeFiPositionsController/fetch-positions.mjs.map +1 -1
  50. package/dist/DeFiPositionsController/group-defi-positions-v6.cjs +1 -1
  51. package/dist/DeFiPositionsController/group-defi-positions-v6.cjs.map +1 -1
  52. package/dist/DeFiPositionsController/group-defi-positions-v6.d.cts +1 -1
  53. package/dist/DeFiPositionsController/group-defi-positions-v6.d.cts.map +1 -1
  54. package/dist/DeFiPositionsController/group-defi-positions-v6.d.mts +1 -1
  55. package/dist/DeFiPositionsController/group-defi-positions-v6.d.mts.map +1 -1
  56. package/dist/DeFiPositionsController/group-defi-positions-v6.mjs +1 -1
  57. package/dist/DeFiPositionsController/group-defi-positions-v6.mjs.map +1 -1
  58. package/dist/DeFiPositionsController/group-defi-positions.cjs.map +1 -1
  59. package/dist/DeFiPositionsController/group-defi-positions.d.cts.map +1 -1
  60. package/dist/DeFiPositionsController/group-defi-positions.d.mts.map +1 -1
  61. package/dist/DeFiPositionsController/group-defi-positions.mjs.map +1 -1
  62. package/dist/DeFiPositionsController/merge-positions-for-accounts.cjs.map +1 -1
  63. package/dist/DeFiPositionsController/merge-positions-for-accounts.d.cts.map +1 -1
  64. package/dist/DeFiPositionsController/merge-positions-for-accounts.d.mts.map +1 -1
  65. package/dist/DeFiPositionsController/merge-positions-for-accounts.mjs.map +1 -1
  66. package/dist/MultichainAssetsController/MultichainAssetsController-method-action-types.cjs.map +1 -1
  67. package/dist/MultichainAssetsController/MultichainAssetsController-method-action-types.d.cts.map +1 -1
  68. package/dist/MultichainAssetsController/MultichainAssetsController-method-action-types.d.mts.map +1 -1
  69. package/dist/MultichainAssetsController/MultichainAssetsController-method-action-types.mjs.map +1 -1
  70. package/dist/MultichainAssetsController/MultichainAssetsController.cjs +2 -2
  71. package/dist/MultichainAssetsController/MultichainAssetsController.cjs.map +1 -1
  72. package/dist/MultichainAssetsController/MultichainAssetsController.d.cts.map +1 -1
  73. package/dist/MultichainAssetsController/MultichainAssetsController.d.mts.map +1 -1
  74. package/dist/MultichainAssetsController/MultichainAssetsController.mjs.map +1 -1
  75. package/dist/MultichainAssetsController/index.cjs +3 -3
  76. package/dist/MultichainAssetsController/index.cjs.map +1 -1
  77. package/dist/MultichainAssetsController/index.d.cts.map +1 -1
  78. package/dist/MultichainAssetsController/index.d.mts.map +1 -1
  79. package/dist/MultichainAssetsController/index.mjs.map +1 -1
  80. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController-method-action-types.cjs.map +1 -1
  81. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController-method-action-types.d.cts.map +1 -1
  82. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController-method-action-types.d.mts.map +1 -1
  83. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController-method-action-types.mjs.map +1 -1
  84. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.cjs +3 -3
  85. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.cjs.map +1 -1
  86. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.cts.map +1 -1
  87. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.d.mts.map +1 -1
  88. package/dist/MultichainAssetsRatesController/MultichainAssetsRatesController.mjs.map +1 -1
  89. package/dist/MultichainAssetsRatesController/index.cjs +5 -5
  90. package/dist/MultichainAssetsRatesController/index.cjs.map +1 -1
  91. package/dist/MultichainAssetsRatesController/index.d.cts.map +1 -1
  92. package/dist/MultichainAssetsRatesController/index.d.mts.map +1 -1
  93. package/dist/MultichainAssetsRatesController/index.mjs.map +1 -1
  94. package/dist/MultichainBalancesController/MultichainBalancesController.cjs.map +1 -1
  95. package/dist/MultichainBalancesController/MultichainBalancesController.d.cts.map +1 -1
  96. package/dist/MultichainBalancesController/MultichainBalancesController.d.mts.map +1 -1
  97. package/dist/MultichainBalancesController/MultichainBalancesController.mjs.map +1 -1
  98. package/dist/MultichainBalancesController/index.cjs +2 -2
  99. package/dist/MultichainBalancesController/index.cjs.map +1 -1
  100. package/dist/MultichainBalancesController/index.d.cts.map +1 -1
  101. package/dist/MultichainBalancesController/index.d.mts.map +1 -1
  102. package/dist/MultichainBalancesController/index.mjs.map +1 -1
  103. package/dist/NftController.cjs +14 -14
  104. package/dist/NftController.cjs.map +1 -1
  105. package/dist/NftController.d.cts.map +1 -1
  106. package/dist/NftController.d.mts.map +1 -1
  107. package/dist/NftController.mjs.map +1 -1
  108. package/dist/NftDetectionController.cjs +2 -2
  109. package/dist/NftDetectionController.cjs.map +1 -1
  110. package/dist/NftDetectionController.d.cts.map +1 -1
  111. package/dist/NftDetectionController.d.mts.map +1 -1
  112. package/dist/NftDetectionController.mjs.map +1 -1
  113. package/dist/RatesController/RatesController.cjs +2 -2
  114. package/dist/RatesController/RatesController.cjs.map +1 -1
  115. package/dist/RatesController/RatesController.d.cts.map +1 -1
  116. package/dist/RatesController/RatesController.d.mts.map +1 -1
  117. package/dist/RatesController/RatesController.mjs.map +1 -1
  118. package/dist/RatesController/index.cjs +3 -3
  119. package/dist/RatesController/index.cjs.map +1 -1
  120. package/dist/RatesController/index.d.cts.map +1 -1
  121. package/dist/RatesController/index.d.mts.map +1 -1
  122. package/dist/RatesController/index.mjs.map +1 -1
  123. package/dist/RatesController/types.cjs.map +1 -1
  124. package/dist/RatesController/types.d.cts.map +1 -1
  125. package/dist/RatesController/types.d.mts.map +1 -1
  126. package/dist/RatesController/types.mjs.map +1 -1
  127. package/dist/Standards/ERC20Standard.cjs +2 -2
  128. package/dist/Standards/ERC20Standard.cjs.map +1 -1
  129. package/dist/Standards/ERC20Standard.mjs.map +1 -1
  130. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.cjs +4 -4
  131. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.cjs.map +1 -1
  132. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.cts.map +1 -1
  133. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.d.mts.map +1 -1
  134. package/dist/Standards/NftStandards/ERC1155/ERC1155Standard.mjs.map +1 -1
  135. package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs +3 -3
  136. package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs.map +1 -1
  137. package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs.map +1 -1
  138. package/dist/TokenBalancesController-method-action-types.cjs.map +1 -1
  139. package/dist/TokenBalancesController-method-action-types.d.cts.map +1 -1
  140. package/dist/TokenBalancesController-method-action-types.d.mts.map +1 -1
  141. package/dist/TokenBalancesController-method-action-types.mjs.map +1 -1
  142. package/dist/TokenBalancesController.cjs +12 -12
  143. package/dist/TokenBalancesController.cjs.map +1 -1
  144. package/dist/TokenBalancesController.d.cts +1 -1
  145. package/dist/TokenBalancesController.d.cts.map +1 -1
  146. package/dist/TokenBalancesController.d.mts +1 -1
  147. package/dist/TokenBalancesController.d.mts.map +1 -1
  148. package/dist/TokenBalancesController.mjs.map +1 -1
  149. package/dist/TokenDetectionController-method-action-types.cjs.map +1 -1
  150. package/dist/TokenDetectionController-method-action-types.d.cts.map +1 -1
  151. package/dist/TokenDetectionController-method-action-types.d.mts.map +1 -1
  152. package/dist/TokenDetectionController-method-action-types.mjs.map +1 -1
  153. package/dist/TokenDetectionController.cjs +17 -17
  154. package/dist/TokenDetectionController.cjs.map +1 -1
  155. package/dist/TokenDetectionController.d.cts +1 -1
  156. package/dist/TokenDetectionController.d.cts.map +1 -1
  157. package/dist/TokenDetectionController.d.mts +1 -1
  158. package/dist/TokenDetectionController.d.mts.map +1 -1
  159. package/dist/TokenDetectionController.mjs.map +1 -1
  160. package/dist/TokenListController.cjs +6 -6
  161. package/dist/TokenListController.cjs.map +1 -1
  162. package/dist/TokenListController.d.cts.map +1 -1
  163. package/dist/TokenListController.d.mts.map +1 -1
  164. package/dist/TokenListController.mjs.map +1 -1
  165. package/dist/TokenListService.cjs +5 -5
  166. package/dist/TokenListService.cjs.map +1 -1
  167. package/dist/TokenListService.d.cts.map +1 -1
  168. package/dist/TokenListService.d.mts.map +1 -1
  169. package/dist/TokenListService.mjs.map +1 -1
  170. package/dist/TokenRatesController.cjs +6 -6
  171. package/dist/TokenRatesController.cjs.map +1 -1
  172. package/dist/TokenRatesController.d.cts.map +1 -1
  173. package/dist/TokenRatesController.d.mts.map +1 -1
  174. package/dist/TokenRatesController.mjs.map +1 -1
  175. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs +5 -5
  176. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.cjs.map +1 -1
  177. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.cts.map +1 -1
  178. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.d.mts.map +1 -1
  179. package/dist/TokenSearchDiscoveryDataController/TokenSearchDiscoveryDataController.mjs.map +1 -1
  180. package/dist/TokenSearchDiscoveryDataController/index.cjs.map +1 -1
  181. package/dist/TokenSearchDiscoveryDataController/index.d.cts.map +1 -1
  182. package/dist/TokenSearchDiscoveryDataController/index.d.mts.map +1 -1
  183. package/dist/TokenSearchDiscoveryDataController/index.mjs.map +1 -1
  184. package/dist/TokenSearchDiscoveryDataController/types.cjs.map +1 -1
  185. package/dist/TokenSearchDiscoveryDataController/types.d.cts.map +1 -1
  186. package/dist/TokenSearchDiscoveryDataController/types.d.mts.map +1 -1
  187. package/dist/TokenSearchDiscoveryDataController/types.mjs.map +1 -1
  188. package/dist/TokensController-method-action-types.cjs.map +1 -1
  189. package/dist/TokensController-method-action-types.d.cts.map +1 -1
  190. package/dist/TokensController-method-action-types.d.mts.map +1 -1
  191. package/dist/TokensController-method-action-types.mjs.map +1 -1
  192. package/dist/TokensController.cjs +10 -10
  193. package/dist/TokensController.cjs.map +1 -1
  194. package/dist/TokensController.d.cts.map +1 -1
  195. package/dist/TokensController.d.mts.map +1 -1
  196. package/dist/TokensController.mjs.map +1 -1
  197. package/dist/assetsUtil.cjs +2 -2
  198. package/dist/assetsUtil.cjs.map +1 -1
  199. package/dist/assetsUtil.d.cts.map +1 -1
  200. package/dist/assetsUtil.d.mts.map +1 -1
  201. package/dist/assetsUtil.mjs.map +1 -1
  202. package/dist/balances.cjs +4 -4
  203. package/dist/balances.cjs.map +1 -1
  204. package/dist/balances.d.cts.map +1 -1
  205. package/dist/balances.d.mts.map +1 -1
  206. package/dist/balances.mjs.map +1 -1
  207. package/dist/crypto-compare-service/crypto-compare.cjs +2 -2
  208. package/dist/crypto-compare-service/crypto-compare.cjs.map +1 -1
  209. package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -1
  210. package/dist/crypto-compare-service/index.cjs +3 -3
  211. package/dist/crypto-compare-service/index.cjs.map +1 -1
  212. package/dist/crypto-compare-service/index.d.cts.map +1 -1
  213. package/dist/crypto-compare-service/index.d.mts.map +1 -1
  214. package/dist/crypto-compare-service/index.mjs.map +1 -1
  215. package/dist/index.cjs +76 -76
  216. package/dist/index.cjs.map +1 -1
  217. package/dist/index.d.cts +1 -1
  218. package/dist/index.d.cts.map +1 -1
  219. package/dist/index.d.mts +1 -1
  220. package/dist/index.d.mts.map +1 -1
  221. package/dist/index.mjs.map +1 -1
  222. package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs +13 -13
  223. package/dist/multi-chain-accounts-service/api-balance-fetcher.cjs.map +1 -1
  224. package/dist/multi-chain-accounts-service/api-balance-fetcher.mjs.map +1 -1
  225. package/dist/multi-chain-accounts-service/index.cjs +3 -3
  226. package/dist/multi-chain-accounts-service/index.cjs.map +1 -1
  227. package/dist/multi-chain-accounts-service/index.d.cts.map +1 -1
  228. package/dist/multi-chain-accounts-service/index.d.mts.map +1 -1
  229. package/dist/multi-chain-accounts-service/index.mjs.map +1 -1
  230. package/dist/multi-chain-accounts-service/mocks/mock-get-balances.cjs.map +1 -1
  231. package/dist/multi-chain-accounts-service/mocks/mock-get-balances.d.cts.map +1 -1
  232. package/dist/multi-chain-accounts-service/mocks/mock-get-balances.d.mts.map +1 -1
  233. package/dist/multi-chain-accounts-service/mocks/mock-get-balances.mjs.map +1 -1
  234. package/dist/multi-chain-accounts-service/mocks/mock-get-supported-networks.cjs.map +1 -1
  235. package/dist/multi-chain-accounts-service/mocks/mock-get-supported-networks.d.cts.map +1 -1
  236. package/dist/multi-chain-accounts-service/mocks/mock-get-supported-networks.d.mts.map +1 -1
  237. package/dist/multi-chain-accounts-service/mocks/mock-get-supported-networks.mjs.map +1 -1
  238. package/dist/multi-chain-accounts-service/multi-chain-accounts.cjs.map +1 -1
  239. package/dist/multi-chain-accounts-service/multi-chain-accounts.d.cts.map +1 -1
  240. package/dist/multi-chain-accounts-service/multi-chain-accounts.d.mts.map +1 -1
  241. package/dist/multi-chain-accounts-service/multi-chain-accounts.mjs.map +1 -1
  242. package/dist/multicall.cjs +10 -10
  243. package/dist/multicall.cjs.map +1 -1
  244. package/dist/multicall.mjs.map +1 -1
  245. package/dist/rpc-service/rpc-balance-fetcher.cjs +6 -6
  246. package/dist/rpc-service/rpc-balance-fetcher.cjs.map +1 -1
  247. package/dist/rpc-service/rpc-balance-fetcher.d.cts.map +1 -1
  248. package/dist/rpc-service/rpc-balance-fetcher.d.mts.map +1 -1
  249. package/dist/rpc-service/rpc-balance-fetcher.mjs.map +1 -1
  250. package/dist/selectors/token-selectors.cjs +8 -8
  251. package/dist/selectors/token-selectors.cjs.map +1 -1
  252. package/dist/selectors/token-selectors.d.cts.map +1 -1
  253. package/dist/selectors/token-selectors.d.mts.map +1 -1
  254. package/dist/selectors/token-selectors.mjs.map +1 -1
  255. package/dist/token-prices-service/abstract-token-prices-service.cjs.map +1 -1
  256. package/dist/token-prices-service/abstract-token-prices-service.d.cts.map +1 -1
  257. package/dist/token-prices-service/abstract-token-prices-service.d.mts.map +1 -1
  258. package/dist/token-prices-service/abstract-token-prices-service.mjs.map +1 -1
  259. package/dist/token-prices-service/codefi-v2.cjs +1 -1
  260. package/dist/token-prices-service/codefi-v2.cjs.map +1 -1
  261. package/dist/token-prices-service/codefi-v2.d.cts +1 -1
  262. package/dist/token-prices-service/codefi-v2.d.cts.map +1 -1
  263. package/dist/token-prices-service/codefi-v2.d.mts +1 -1
  264. package/dist/token-prices-service/codefi-v2.d.mts.map +1 -1
  265. package/dist/token-prices-service/codefi-v2.mjs +1 -1
  266. package/dist/token-prices-service/codefi-v2.mjs.map +1 -1
  267. package/dist/token-prices-service/index.cjs +9 -9
  268. package/dist/token-prices-service/index.cjs.map +1 -1
  269. package/dist/token-prices-service/index.d.cts.map +1 -1
  270. package/dist/token-prices-service/index.d.mts.map +1 -1
  271. package/dist/token-prices-service/index.mjs.map +1 -1
  272. package/dist/token-service.cjs +2 -2
  273. package/dist/token-service.cjs.map +1 -1
  274. package/dist/token-service.mjs.map +1 -1
  275. package/package.json +9 -9
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildPositionFetcher = exports.DEFI_POSITIONS_API_URL = void 0;
4
- const timeout_with_retry_1 = require("../utils/timeout-with-retry.cjs");
4
+ const timeout_with_retry_js_1 = require("../utils/timeout-with-retry.cjs");
5
5
  // TODO: Update with prod API URL when available
6
6
  exports.DEFI_POSITIONS_API_URL = 'https://defiadapters.api.cx.metamask.io';
7
7
  const EIGHT_SECONDS_IN_MS = 8000;
@@ -13,7 +13,7 @@ const MAX_RETRIES = 1;
13
13
  */
14
14
  function buildPositionFetcher() {
15
15
  return async (accountAddress) => {
16
- const defiPositionsResponse = await (0, timeout_with_retry_1.timeoutWithRetry)(() => fetch(`${exports.DEFI_POSITIONS_API_URL}/positions/${accountAddress}`), EIGHT_SECONDS_IN_MS, MAX_RETRIES);
16
+ const defiPositionsResponse = await (0, timeout_with_retry_js_1.timeoutWithRetry)(() => fetch(`${exports.DEFI_POSITIONS_API_URL}/positions/${accountAddress}`), EIGHT_SECONDS_IN_MS, MAX_RETRIES);
17
17
  if (defiPositionsResponse.status !== 200) {
18
18
  throw new Error(`Unable to fetch defi positions - HTTP ${defiPositionsResponse.status}`);
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-positions.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/fetch-positions.ts"],"names":[],"mappings":";;;AAAA,wEAA+D;AA2D/D,gDAAgD;AACnC,QAAA,sBAAsB,GAAG,yCAAyC,CAAC;AAEhF,MAAM,mBAAmB,GAAG,IAAK,CAAC;AAClC,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB;;;;GAIG;AACH,SAAgB,oBAAoB;IAClC,OAAO,KAAK,EAAE,cAAsB,EAAmC,EAAE;QACvE,MAAM,qBAAqB,GAAG,MAAM,IAAA,qCAAgB,EAClD,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,8BAAsB,cAAc,cAAc,EAAE,CAAC,EACpE,mBAAmB,EACnB,WAAW,CACZ,CAAC;QAEF,IAAI,qBAAqB,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,qBAAqB,CAAC,MAAM,EAAE,CACxE,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC,CAAC;AACJ,CAAC;AAhBD,oDAgBC","sourcesContent":["import { timeoutWithRetry } from '../utils/timeout-with-retry';\n\nexport type DefiPositionResponse = AdapterResponse<{\n tokens: ProtocolToken[];\n}>;\n\ntype ProtocolDetails = {\n chainId: number;\n protocolId: string;\n productId: string;\n protocolDisplayName: string;\n name: string;\n description: string;\n iconUrl: string;\n siteUrl: string;\n positionType: PositionType;\n metadata?: {\n groupPositions?: boolean;\n };\n};\n\ntype AdapterResponse<ProtocolResponse> =\n | (ProtocolDetails & {\n chainName: string;\n } & (\n | (ProtocolResponse & { success: true })\n | (AdapterErrorResponse & { success: false })\n ))\n | (AdapterErrorResponse & { success: false });\n\ntype AdapterErrorResponse = {\n error: {\n message: string;\n };\n};\n\nexport type PositionType = 'supply' | 'borrow' | 'stake' | 'reward';\n\nexport type ProtocolToken = Balance & {\n type: 'protocol';\n tokenId?: string;\n};\n\nexport type Underlying = Balance & {\n type: 'underlying' | 'underlying-claimable';\n iconUrl: string;\n};\n\nexport type Balance = {\n address: string;\n name: string;\n symbol: string;\n decimals: number;\n balanceRaw: string;\n balance: number;\n price?: number;\n tokens?: Underlying[];\n};\n\n// TODO: Update with prod API URL when available\nexport const DEFI_POSITIONS_API_URL = 'https://defiadapters.api.cx.metamask.io';\n\nconst EIGHT_SECONDS_IN_MS = 8_000;\nconst MAX_RETRIES = 1;\n\n/**\n * Builds a function that fetches DeFi positions for a given account address\n *\n * @returns A function that fetches DeFi positions for a given account address\n */\nexport function buildPositionFetcher() {\n return async (accountAddress: string): Promise<DefiPositionResponse[]> => {\n const defiPositionsResponse = await timeoutWithRetry(\n () => fetch(`${DEFI_POSITIONS_API_URL}/positions/${accountAddress}`),\n EIGHT_SECONDS_IN_MS,\n MAX_RETRIES,\n );\n\n if (defiPositionsResponse.status !== 200) {\n throw new Error(\n `Unable to fetch defi positions - HTTP ${defiPositionsResponse.status}`,\n );\n }\n\n return (await defiPositionsResponse.json()).data;\n };\n}\n"]}
1
+ {"version":3,"file":"fetch-positions.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/fetch-positions.ts"],"names":[],"mappings":";;;AAAA,2EAAkE;AA2DlE,gDAAgD;AACnC,QAAA,sBAAsB,GAAG,yCAAyC,CAAC;AAEhF,MAAM,mBAAmB,GAAG,IAAK,CAAC;AAClC,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB;;;;GAIG;AACH,SAAgB,oBAAoB;IAClC,OAAO,KAAK,EAAE,cAAsB,EAAmC,EAAE;QACvE,MAAM,qBAAqB,GAAG,MAAM,IAAA,wCAAgB,EAClD,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,8BAAsB,cAAc,cAAc,EAAE,CAAC,EACpE,mBAAmB,EACnB,WAAW,CACZ,CAAC;QAEF,IAAI,qBAAqB,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,qBAAqB,CAAC,MAAM,EAAE,CACxE,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC,CAAC;AACJ,CAAC;AAhBD,oDAgBC","sourcesContent":["import { timeoutWithRetry } from '../utils/timeout-with-retry.js';\n\nexport type DefiPositionResponse = AdapterResponse<{\n tokens: ProtocolToken[];\n}>;\n\ntype ProtocolDetails = {\n chainId: number;\n protocolId: string;\n productId: string;\n protocolDisplayName: string;\n name: string;\n description: string;\n iconUrl: string;\n siteUrl: string;\n positionType: PositionType;\n metadata?: {\n groupPositions?: boolean;\n };\n};\n\ntype AdapterResponse<ProtocolResponse> =\n | (ProtocolDetails & {\n chainName: string;\n } & (\n | (ProtocolResponse & { success: true })\n | (AdapterErrorResponse & { success: false })\n ))\n | (AdapterErrorResponse & { success: false });\n\ntype AdapterErrorResponse = {\n error: {\n message: string;\n };\n};\n\nexport type PositionType = 'supply' | 'borrow' | 'stake' | 'reward';\n\nexport type ProtocolToken = Balance & {\n type: 'protocol';\n tokenId?: string;\n};\n\nexport type Underlying = Balance & {\n type: 'underlying' | 'underlying-claimable';\n iconUrl: string;\n};\n\nexport type Balance = {\n address: string;\n name: string;\n symbol: string;\n decimals: number;\n balanceRaw: string;\n balance: number;\n price?: number;\n tokens?: Underlying[];\n};\n\n// TODO: Update with prod API URL when available\nexport const DEFI_POSITIONS_API_URL = 'https://defiadapters.api.cx.metamask.io';\n\nconst EIGHT_SECONDS_IN_MS = 8_000;\nconst MAX_RETRIES = 1;\n\n/**\n * Builds a function that fetches DeFi positions for a given account address\n *\n * @returns A function that fetches DeFi positions for a given account address\n */\nexport function buildPositionFetcher() {\n return async (accountAddress: string): Promise<DefiPositionResponse[]> => {\n const defiPositionsResponse = await timeoutWithRetry(\n () => fetch(`${DEFI_POSITIONS_API_URL}/positions/${accountAddress}`),\n EIGHT_SECONDS_IN_MS,\n MAX_RETRIES,\n );\n\n if (defiPositionsResponse.status !== 200) {\n throw new Error(\n `Unable to fetch defi positions - HTTP ${defiPositionsResponse.status}`,\n );\n }\n\n return (await defiPositionsResponse.json()).data;\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-positions.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/fetch-positions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,wCAAoC;AA2D/D,gDAAgD;AAChD,MAAM,CAAC,MAAM,sBAAsB,GAAG,yCAAyC,CAAC;AAEhF,MAAM,mBAAmB,GAAG,IAAK,CAAC;AAClC,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB;;;;GAIG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,KAAK,EAAE,cAAsB,EAAmC,EAAE;QACvE,MAAM,qBAAqB,GAAG,MAAM,gBAAgB,CAClD,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,sBAAsB,cAAc,cAAc,EAAE,CAAC,EACpE,mBAAmB,EACnB,WAAW,CACZ,CAAC;QAEF,IAAI,qBAAqB,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,qBAAqB,CAAC,MAAM,EAAE,CACxE,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { timeoutWithRetry } from '../utils/timeout-with-retry';\n\nexport type DefiPositionResponse = AdapterResponse<{\n tokens: ProtocolToken[];\n}>;\n\ntype ProtocolDetails = {\n chainId: number;\n protocolId: string;\n productId: string;\n protocolDisplayName: string;\n name: string;\n description: string;\n iconUrl: string;\n siteUrl: string;\n positionType: PositionType;\n metadata?: {\n groupPositions?: boolean;\n };\n};\n\ntype AdapterResponse<ProtocolResponse> =\n | (ProtocolDetails & {\n chainName: string;\n } & (\n | (ProtocolResponse & { success: true })\n | (AdapterErrorResponse & { success: false })\n ))\n | (AdapterErrorResponse & { success: false });\n\ntype AdapterErrorResponse = {\n error: {\n message: string;\n };\n};\n\nexport type PositionType = 'supply' | 'borrow' | 'stake' | 'reward';\n\nexport type ProtocolToken = Balance & {\n type: 'protocol';\n tokenId?: string;\n};\n\nexport type Underlying = Balance & {\n type: 'underlying' | 'underlying-claimable';\n iconUrl: string;\n};\n\nexport type Balance = {\n address: string;\n name: string;\n symbol: string;\n decimals: number;\n balanceRaw: string;\n balance: number;\n price?: number;\n tokens?: Underlying[];\n};\n\n// TODO: Update with prod API URL when available\nexport const DEFI_POSITIONS_API_URL = 'https://defiadapters.api.cx.metamask.io';\n\nconst EIGHT_SECONDS_IN_MS = 8_000;\nconst MAX_RETRIES = 1;\n\n/**\n * Builds a function that fetches DeFi positions for a given account address\n *\n * @returns A function that fetches DeFi positions for a given account address\n */\nexport function buildPositionFetcher() {\n return async (accountAddress: string): Promise<DefiPositionResponse[]> => {\n const defiPositionsResponse = await timeoutWithRetry(\n () => fetch(`${DEFI_POSITIONS_API_URL}/positions/${accountAddress}`),\n EIGHT_SECONDS_IN_MS,\n MAX_RETRIES,\n );\n\n if (defiPositionsResponse.status !== 200) {\n throw new Error(\n `Unable to fetch defi positions - HTTP ${defiPositionsResponse.status}`,\n );\n }\n\n return (await defiPositionsResponse.json()).data;\n };\n}\n"]}
1
+ {"version":3,"file":"fetch-positions.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/fetch-positions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,wCAAuC;AA2DlE,gDAAgD;AAChD,MAAM,CAAC,MAAM,sBAAsB,GAAG,yCAAyC,CAAC;AAEhF,MAAM,mBAAmB,GAAG,IAAK,CAAC;AAClC,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB;;;;GAIG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,KAAK,EAAE,cAAsB,EAAmC,EAAE;QACvE,MAAM,qBAAqB,GAAG,MAAM,gBAAgB,CAClD,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,sBAAsB,cAAc,cAAc,EAAE,CAAC,EACpE,mBAAmB,EACnB,WAAW,CACZ,CAAC;QAEF,IAAI,qBAAqB,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CACb,yCAAyC,qBAAqB,CAAC,MAAM,EAAE,CACxE,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,MAAM,qBAAqB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { timeoutWithRetry } from '../utils/timeout-with-retry.js';\n\nexport type DefiPositionResponse = AdapterResponse<{\n tokens: ProtocolToken[];\n}>;\n\ntype ProtocolDetails = {\n chainId: number;\n protocolId: string;\n productId: string;\n protocolDisplayName: string;\n name: string;\n description: string;\n iconUrl: string;\n siteUrl: string;\n positionType: PositionType;\n metadata?: {\n groupPositions?: boolean;\n };\n};\n\ntype AdapterResponse<ProtocolResponse> =\n | (ProtocolDetails & {\n chainName: string;\n } & (\n | (ProtocolResponse & { success: true })\n | (AdapterErrorResponse & { success: false })\n ))\n | (AdapterErrorResponse & { success: false });\n\ntype AdapterErrorResponse = {\n error: {\n message: string;\n };\n};\n\nexport type PositionType = 'supply' | 'borrow' | 'stake' | 'reward';\n\nexport type ProtocolToken = Balance & {\n type: 'protocol';\n tokenId?: string;\n};\n\nexport type Underlying = Balance & {\n type: 'underlying' | 'underlying-claimable';\n iconUrl: string;\n};\n\nexport type Balance = {\n address: string;\n name: string;\n symbol: string;\n decimals: number;\n balanceRaw: string;\n balance: number;\n price?: number;\n tokens?: Underlying[];\n};\n\n// TODO: Update with prod API URL when available\nexport const DEFI_POSITIONS_API_URL = 'https://defiadapters.api.cx.metamask.io';\n\nconst EIGHT_SECONDS_IN_MS = 8_000;\nconst MAX_RETRIES = 1;\n\n/**\n * Builds a function that fetches DeFi positions for a given account address\n *\n * @returns A function that fetches DeFi positions for a given account address\n */\nexport function buildPositionFetcher() {\n return async (accountAddress: string): Promise<DefiPositionResponse[]> => {\n const defiPositionsResponse = await timeoutWithRetry(\n () => fetch(`${DEFI_POSITIONS_API_URL}/positions/${accountAddress}`),\n EIGHT_SECONDS_IN_MS,\n MAX_RETRIES,\n );\n\n if (defiPositionsResponse.status !== 200) {\n throw new Error(\n `Unable to fetch defi positions - HTTP ${defiPositionsResponse.status}`,\n );\n }\n\n return (await defiPositionsResponse.json()).data;\n };\n}\n"]}
@@ -14,7 +14,7 @@ exports.DEFI_POSITION_TYPES = core_backend_1.V6_DEFI_POSITION_TYPES;
14
14
  * Position types whose fiat value is a liability and is subtracted from the
15
15
  * protocol group's aggregated `marketValue`.
16
16
  */
17
- exports.DEFI_POSITION_LIABILITY_TYPES = new Set(['lending']);
17
+ exports.DEFI_POSITION_LIABILITY_TYPES = new Set(['loan']);
18
18
  // Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple
19
19
  // underlyings. Display-only.
20
20
  const SYMBOL_PRIORITY = ['ETH', 'WETH'];
@@ -1 +1 @@
1
- {"version":3,"file":"group-defi-positions-v6.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":";;;AAAA,yDAAgE;AAYhE,2CAKyB;AAEzB,+EAA+E;AAC/E,MAAM,wBAAwB,GAAG,+BAA+B,CAAC;AAEjE;;;GAGG;AACU,QAAA,mBAAmB,GAAG,qCAAsB,CAAC;AAQ1D;;;GAGG;AACU,QAAA,6BAA6B,GACxC,IAAI,GAAG,CAAmB,CAAC,SAAS,CAAC,CAAC,CAAC;AAuFzC,gFAAgF;AAChF,6BAA6B;AAC7B,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAIxC;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,OAAsB;IAClD,IAAI,CAAC;QACH,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,0BAAkB,EAAC,OAAO,CAAC,CAAC;QAChD,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;QAChD,MAAM,KAAK,GAAG,SAAS,KAAK,0BAAkB,CAAC,MAAM,CAAC;QACtD,MAAM,iBAAiB,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CACzE,KAAK,EACL,GAAG,CACJ,CAA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O,EAAE,CAAC;gBACb,OAAO,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;gBACzC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,kBAAkB,EAAE,CAAC;QAC1D,MAAM,MAAM,GAAG,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;QACzC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,cAAc,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAClC,CAAC;QACD,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAhGD,oDAgGC","sourcesContent":["import { V6_DEFI_POSITION_TYPES } from '@metamask/core-backend';\nimport type {\n V6BalanceItem,\n V6BalanceMetadata,\n V6BalancesResponse,\n V6DeFiPositionType,\n} from '@metamask/core-backend';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\nimport {\n KnownCaipNamespace,\n parseCaipAccountId,\n parseCaipAssetType,\n parseCaipChainId,\n} from '@metamask/utils';\n\n/** Static.cx host used to build CAIP-19 token icon URLs for DeFi positions. */\nconst STATIC_METAMASK_BASE_URL = 'https://static.cx.metamask.io';\n\n/**\n * Possible `positionType` values from Accounts API v6 DeFi metadata.\n * Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.\n */\nexport const DEFI_POSITION_TYPES = V6_DEFI_POSITION_TYPES;\n\n/**\n * The specific module or functionality within a DeFi protocol where a position\n * is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.\n */\nexport type DeFiPositionType = V6DeFiPositionType;\n\n/**\n * Position types whose fiat value is a liability and is subtracted from the\n * protocol group's aggregated `marketValue`.\n */\nexport const DEFI_POSITION_LIABILITY_TYPES: ReadonlySet<DeFiPositionType> =\n new Set<DeFiPositionType>(['lending']);\n\n/**\n * An icon-group entry shown next to a protocol in the DeFi tab list.\n */\nexport type DeFiPositionIconGroupItem = {\n /** Token icon URL, when one can be built for the asset. */\n avatarValue?: string;\n symbol: string;\n};\n\n/**\n * A single underlying position row shown on the DeFi details page.\n */\nexport type DeFiUnderlyingPosition = {\n assetId: CaipAssetType;\n chainId: CaipChainId;\n symbol: string;\n name: string;\n decimals: number;\n /** Raw balance string as returned by the API. */\n balance: string;\n /** Fiat market value in the requested currency, when a price is available. */\n marketValue?: number;\n /** Position type from protocol metadata. */\n positionType: DeFiPositionType;\n /** Address of the pool this position belongs to. */\n poolAddress: string;\n /**\n * Upstream grouping id from the API. Rows that share a `productName` can\n * still carry distinct `groupId`s (e.g. multiple Pendle YT markets).\n */\n groupId: string;\n /** Token icon URL, when one can be built for the asset. */\n tokenImage?: string;\n};\n\n/**\n * A section of the details page, grouping positions that share the same\n * API `productName`. A single `protocolId` can have multiple products\n * (different pools/markets under one protocol), so a group may contain\n * several sections.\n */\nexport type DeFiPositionDetailsSection = {\n /** Section label from the API (`metadata.productName`). */\n productName: string;\n positions: DeFiUnderlyingPosition[];\n};\n\n/**\n * One row in the DeFi tab list (a protocol on a given chain), with the details\n * needed to render the details page embedded directly inside it.\n */\nexport type DeFiProtocolPositionGroup = {\n protocolId: string;\n /**\n * Product name from the first position seen for this protocol. Prefer\n * `protocolId` for the list-row title; use section `productName`s for\n * per-product detail headings.\n */\n productName: string;\n protocolIconUrl: string;\n chainId: CaipChainId;\n /**\n * Aggregated fiat market value across all positions in the group.\n * `lending` positions are subtracted; all other types are added.\n */\n marketValue: number;\n /** Icon-group entries for the list row. */\n iconGroup: DeFiPositionIconGroupItem[];\n /**\n * Detail sections consumed by the details page, one per distinct API\n * `productName` under this `protocolId`.\n */\n sections: DeFiPositionDetailsSection[];\n};\n\n/**\n * DeFi positions for every queried account, keyed by the internal MetaMask\n * account ID (`InternalAccount.id` UUID), the same key AssetsController uses.\n * Each account maps to a flat list of protocol groups; filter by each group's\n * `chainId` rather than digging through a nested chain map.\n */\nexport type DeFiPositionsByAccount = {\n [accountId: string]: DeFiProtocolPositionGroup[];\n};\n\n// Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple\n// underlyings. Display-only.\nconst SYMBOL_PRIORITY = ['ETH', 'WETH'];\n\ntype DefiBalanceWithMetadata = V6BalanceItem & { metadata: V6BalanceMetadata };\n\n/**\n * Builds a static token icon URL for a CAIP asset ID.\n *\n * @param assetId - The CAIP-19 asset ID.\n * @returns The token icon URL, or `undefined` when it cannot be built.\n */\nfunction getDefiTokenImageUrl(assetId: CaipAssetType): string | undefined {\n try {\n const { chainId } = parseCaipAssetType(assetId);\n const { namespace } = parseCaipChainId(chainId);\n const isEvm = namespace === KnownCaipNamespace.Eip155;\n const normalizedAssetId = (isEvm ? assetId.toLowerCase() : assetId).replace(\n /:/gu,\n '/',\n );\n\n return `${STATIC_METAMASK_BASE_URL}/api/v2/tokenIcons/assets/${normalizedAssetId}.png`;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns whether a balance row is a DeFi position carrying protocol metadata.\n *\n * @param balance - A balance row from the v6 API.\n * @returns True when the row is a `category: defi` row with protocol metadata.\n */\nfunction isDefiBalanceWithMetadata(\n balance: V6BalanceItem,\n): balance is DefiBalanceWithMetadata {\n return (\n balance.category === 'defi' &&\n balance.metadata !== undefined &&\n (balance.metadata as Partial<V6BalanceMetadata>).protocolId !== undefined\n );\n}\n\n/**\n * Returns the fiat market value for a v6 DeFi balance row.\n *\n * @param balance - A balance row from the v6 API.\n * @returns The fiat value, or `undefined` when price is missing or the\n * balance/price is invalid.\n */\nfunction getMarketValue(balance: V6BalanceItem): number | undefined {\n if (balance.price === undefined) {\n return undefined;\n }\n\n const normalizedBalance = Number.parseFloat(balance.balance);\n const price = Number.parseFloat(balance.price);\n\n if (!Number.isFinite(normalizedBalance) || !Number.isFinite(price)) {\n return undefined;\n }\n\n return normalizedBalance * price;\n}\n\n/**\n * Returns the sign used when rolling a position's market value into a protocol\n * group total. Liability types (currently `lending`) subtract; all others add.\n *\n * @param positionType - The position's protocol module type.\n * @returns `-1` for liabilities, `1` otherwise.\n */\nfunction getMarketValueSign(positionType: DeFiPositionType): 1 | -1 {\n return DEFI_POSITION_LIABILITY_TYPES.has(positionType) ? -1 : 1;\n}\n\n/**\n * Moves a priority symbol (ETH/WETH) to the front of the icon group, in place.\n *\n * @param iconGroup - The icon-group entries to reorder.\n */\nfunction orderIconGroup(iconGroup: DeFiPositionIconGroupItem[]): void {\n const priorityIndex = iconGroup.findIndex((item) =>\n SYMBOL_PRIORITY.includes(item.symbol),\n );\n\n if (priorityIndex > 0) {\n const [priorityIcon] = iconGroup.splice(priorityIndex, 1);\n iconGroup.unshift(priorityIcon);\n }\n}\n\n/**\n * Maps a DeFi balance row to a details-page underlying position.\n *\n * @param balance - A DeFi balance row with protocol metadata.\n * @returns The underlying position for the details page.\n */\nfunction toUnderlyingPosition(\n balance: DefiBalanceWithMetadata,\n): DeFiUnderlyingPosition {\n const assetId = balance.assetId as CaipAssetType;\n const { chainId } = parseCaipAssetType(assetId);\n const { positionType, poolAddress, groupId } = balance.metadata;\n\n return {\n assetId,\n chainId,\n symbol: balance.symbol,\n name: balance.name,\n balance: balance.balance,\n decimals: balance.decimals,\n marketValue: getMarketValue(balance),\n positionType,\n poolAddress,\n groupId,\n tokenImage: getDefiTokenImageUrl(assetId),\n };\n}\n\n/**\n * Builds a chain-reference-agnostic key (`namespace:address`) for matching the\n * CAIP-10 account IDs we request against the ones the v6 API echoes back.\n *\n * We request EVM balances with the all-chains reference (`eip155:0:<address>`),\n * but the response echoes a separate per-chain ID for every chain\n * (`eip155:1:<address>`, `eip155:137:<address>`, ...). Matching on the full\n * CAIP-10 string therefore fails, so we drop the reference and match on\n * namespace + address instead. EVM addresses are lowercased; other namespaces\n * keep their case.\n *\n * @param caipAccountId - A CAIP-10 account ID.\n * @returns The match key, or a case-normalized fallback if parsing fails.\n */\nfunction toAccountMatchKey(caipAccountId: string): string {\n try {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(caipAccountId as CaipAccountId);\n const normalizedAddress =\n namespace === KnownCaipNamespace.Eip155 ? address.toLowerCase() : address;\n return `${namespace}:${normalizedAddress}`;\n } catch {\n return caipAccountId.startsWith(`${KnownCaipNamespace.Eip155}:`)\n ? caipAccountId.toLowerCase()\n : caipAccountId;\n }\n}\n\n/**\n * Transforms a v6 multiaccount balances response into the stored DeFi state:\n * positions keyed by internal account ID, each mapping to a flat list of\n * protocol groups. Every group carries its own `chainId` (so the client can\n * filter without a nested chain map) plus both the DeFi-tab summary and the\n * details-page sections. Accounts present in the response but with no DeFi\n * positions are included with an empty list so stale data is cleared.\n *\n * When `internalAccountIdByCaip` is provided, response account IDs are matched\n * to internal MetaMask account IDs via namespace + address (ignoring chain\n * reference and EVM case). Unmatched accounts are skipped. When omitted, the\n * response account ID is used as-is (handy for unit tests).\n *\n * @param response - The v6 multiaccount balances response.\n * @param internalAccountIdByCaip - Optional map of request CAIP-10 account IDs\n * to internal MetaMask account IDs.\n * @returns DeFi positions keyed by internal account ID.\n */\nexport function groupDeFiPositionsV6(\n response: V6BalancesResponse,\n internalAccountIdByCaip?: Map<string, string>,\n): DeFiPositionsByAccount {\n const internalAccountIdByMatchKey = internalAccountIdByCaip\n ? new Map(\n [...internalAccountIdByCaip].map(([caipAccountId, internalId]) => [\n toAccountMatchKey(caipAccountId),\n internalId,\n ]),\n )\n : undefined;\n\n // Accumulate groups per resolved internal account ID. The v6 response returns\n // a separate entry per chain (e.g. `eip155:1:<addr>`, `eip155:137:<addr>`),\n // and several of them can resolve to the same internal account ID, so we must\n // merge across all of them rather than overwrite per response account.\n const groupsByAccountKey = new Map<\n string,\n Map<string, DeFiProtocolPositionGroup>\n >();\n\n for (const account of response.accounts) {\n const accountId = internalAccountIdByMatchKey\n ? internalAccountIdByMatchKey.get(toAccountMatchKey(account.accountId))\n : account.accountId;\n if (accountId === undefined) {\n continue;\n }\n\n // Seed every queried account so accounts that no longer hold positions\n // overwrite (clear) any previously stored data.\n let groupsByKey = groupsByAccountKey.get(accountId);\n if (!groupsByKey) {\n groupsByKey = new Map<string, DeFiProtocolPositionGroup>();\n groupsByAccountKey.set(accountId, groupsByKey);\n }\n\n for (const balance of account.balances) {\n if (!isDefiBalanceWithMetadata(balance)) {\n continue;\n }\n\n const position = toUnderlyingPosition(balance);\n const { protocolId, productName, protocolIconUrl } = balance.metadata;\n const groupKey = `${position.chainId}#${protocolId}`;\n\n let group = groupsByKey.get(groupKey);\n if (!group) {\n group = {\n protocolId,\n productName,\n protocolIconUrl,\n chainId: position.chainId,\n marketValue: 0,\n iconGroup: [],\n sections: [],\n };\n groupsByKey.set(groupKey, group);\n }\n\n if (position.marketValue !== undefined) {\n group.marketValue +=\n position.marketValue * getMarketValueSign(position.positionType);\n }\n\n if (!group.iconGroup.some((item) => item.symbol === position.symbol)) {\n group.iconGroup.push({\n symbol: position.symbol,\n avatarValue: position.tokenImage,\n });\n }\n\n // Sections are keyed by productName; distinct groupIds under the same\n // product remain available on each underlying position.\n let section = group.sections.find(\n (item) => item.productName === productName,\n );\n if (!section) {\n section = { productName, positions: [] };\n group.sections.push(section);\n }\n section.positions.push(position);\n }\n }\n\n const result: DeFiPositionsByAccount = {};\n for (const [accountId, groupsByKey] of groupsByAccountKey) {\n const groups = [...groupsByKey.values()];\n for (const group of groups) {\n orderIconGroup(group.iconGroup);\n }\n result[accountId] = groups;\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"group-defi-positions-v6.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":";;;AAAA,yDAAgE;AAYhE,2CAKyB;AAEzB,+EAA+E;AAC/E,MAAM,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AAC;QACD,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAhGD,oDAgGC","sourcesContent":["import { V6_DEFI_POSITION_TYPES } from '@metamask/core-backend';\nimport type {\n V6BalanceItem,\n V6BalanceMetadata,\n V6BalancesResponse,\n V6DeFiPositionType,\n} from '@metamask/core-backend';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\nimport {\n KnownCaipNamespace,\n parseCaipAccountId,\n parseCaipAssetType,\n parseCaipChainId,\n} from '@metamask/utils';\n\n/** Static.cx host used to build CAIP-19 token icon URLs for DeFi positions. */\nconst STATIC_METAMASK_BASE_URL = 'https://static.cx.metamask.io';\n\n/**\n * Possible `positionType` values from Accounts API v6 DeFi metadata.\n * Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.\n */\nexport const DEFI_POSITION_TYPES = V6_DEFI_POSITION_TYPES;\n\n/**\n * The specific module or functionality within a DeFi protocol where a position\n * is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.\n */\nexport type DeFiPositionType = V6DeFiPositionType;\n\n/**\n * Position types whose fiat value is a liability and is subtracted from the\n * protocol group's aggregated `marketValue`.\n */\nexport const DEFI_POSITION_LIABILITY_TYPES: ReadonlySet<DeFiPositionType> =\n new Set<DeFiPositionType>(['loan']);\n\n/**\n * An icon-group entry shown next to a protocol in the DeFi tab list.\n */\nexport type DeFiPositionIconGroupItem = {\n /** Token icon URL, when one can be built for the asset. */\n avatarValue?: string;\n symbol: string;\n};\n\n/**\n * A single underlying position row shown on the DeFi details page.\n */\nexport type DeFiUnderlyingPosition = {\n assetId: CaipAssetType;\n chainId: CaipChainId;\n symbol: string;\n name: string;\n decimals: number;\n /** Raw balance string as returned by the API. */\n balance: string;\n /** Fiat market value in the requested currency, when a price is available. */\n marketValue?: number;\n /** Position type from protocol metadata. */\n positionType: DeFiPositionType;\n /** Address of the pool this position belongs to. */\n poolAddress: string;\n /**\n * Upstream grouping id from the API. Rows that share a `productName` can\n * still carry distinct `groupId`s (e.g. multiple Pendle YT markets).\n */\n groupId: string;\n /** Token icon URL, when one can be built for the asset. */\n tokenImage?: string;\n};\n\n/**\n * A section of the details page, grouping positions that share the same\n * API `productName`. A single `protocolId` can have multiple products\n * (different pools/markets under one protocol), so a group may contain\n * several sections.\n */\nexport type DeFiPositionDetailsSection = {\n /** Section label from the API (`metadata.productName`). */\n productName: string;\n positions: DeFiUnderlyingPosition[];\n};\n\n/**\n * One row in the DeFi tab list (a protocol on a given chain), with the details\n * needed to render the details page embedded directly inside it.\n */\nexport type DeFiProtocolPositionGroup = {\n protocolId: string;\n /**\n * Product name from the first position seen for this protocol. Prefer\n * `protocolId` for the list-row title; use section `productName`s for\n * per-product detail headings.\n */\n productName: string;\n protocolIconUrl: string;\n chainId: CaipChainId;\n /**\n * Aggregated fiat market value across all positions in the group.\n * `lending` positions are subtracted; all other types are added.\n */\n marketValue: number;\n /** Icon-group entries for the list row. */\n iconGroup: DeFiPositionIconGroupItem[];\n /**\n * Detail sections consumed by the details page, one per distinct API\n * `productName` under this `protocolId`.\n */\n sections: DeFiPositionDetailsSection[];\n};\n\n/**\n * DeFi positions for every queried account, keyed by the internal MetaMask\n * account ID (`InternalAccount.id` UUID), the same key AssetsController uses.\n * Each account maps to a flat list of protocol groups; filter by each group's\n * `chainId` rather than digging through a nested chain map.\n */\nexport type DeFiPositionsByAccount = {\n [accountId: string]: DeFiProtocolPositionGroup[];\n};\n\n// Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple\n// underlyings. Display-only.\nconst SYMBOL_PRIORITY = ['ETH', 'WETH'];\n\ntype DefiBalanceWithMetadata = V6BalanceItem & { metadata: V6BalanceMetadata };\n\n/**\n * Builds a static token icon URL for a CAIP asset ID.\n *\n * @param assetId - The CAIP-19 asset ID.\n * @returns The token icon URL, or `undefined` when it cannot be built.\n */\nfunction getDefiTokenImageUrl(assetId: CaipAssetType): string | undefined {\n try {\n const { chainId } = parseCaipAssetType(assetId);\n const { namespace } = parseCaipChainId(chainId);\n const isEvm = namespace === KnownCaipNamespace.Eip155;\n const normalizedAssetId = (isEvm ? assetId.toLowerCase() : assetId).replace(\n /:/gu,\n '/',\n );\n\n return `${STATIC_METAMASK_BASE_URL}/api/v2/tokenIcons/assets/${normalizedAssetId}.png`;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns whether a balance row is a DeFi position carrying protocol metadata.\n *\n * @param balance - A balance row from the v6 API.\n * @returns True when the row is a `category: defi` row with protocol metadata.\n */\nfunction isDefiBalanceWithMetadata(\n balance: V6BalanceItem,\n): balance is DefiBalanceWithMetadata {\n return (\n balance.category === 'defi' &&\n balance.metadata !== undefined &&\n (balance.metadata as Partial<V6BalanceMetadata>).protocolId !== undefined\n );\n}\n\n/**\n * Returns the fiat market value for a v6 DeFi balance row.\n *\n * @param balance - A balance row from the v6 API.\n * @returns The fiat value, or `undefined` when price is missing or the\n * balance/price is invalid.\n */\nfunction getMarketValue(balance: V6BalanceItem): number | undefined {\n if (balance.price === undefined) {\n return undefined;\n }\n\n const normalizedBalance = Number.parseFloat(balance.balance);\n const price = Number.parseFloat(balance.price);\n\n if (!Number.isFinite(normalizedBalance) || !Number.isFinite(price)) {\n return undefined;\n }\n\n return normalizedBalance * price;\n}\n\n/**\n * Returns the sign used when rolling a position's market value into a protocol\n * group total. Liability types (currently `lending`) subtract; all others add.\n *\n * @param positionType - The position's protocol module type.\n * @returns `-1` for liabilities, `1` otherwise.\n */\nfunction getMarketValueSign(positionType: DeFiPositionType): 1 | -1 {\n return DEFI_POSITION_LIABILITY_TYPES.has(positionType) ? -1 : 1;\n}\n\n/**\n * Moves a priority symbol (ETH/WETH) to the front of the icon group, in place.\n *\n * @param iconGroup - The icon-group entries to reorder.\n */\nfunction orderIconGroup(iconGroup: DeFiPositionIconGroupItem[]): void {\n const priorityIndex = iconGroup.findIndex((item) =>\n SYMBOL_PRIORITY.includes(item.symbol),\n );\n\n if (priorityIndex > 0) {\n const [priorityIcon] = iconGroup.splice(priorityIndex, 1);\n iconGroup.unshift(priorityIcon);\n }\n}\n\n/**\n * Maps a DeFi balance row to a details-page underlying position.\n *\n * @param balance - A DeFi balance row with protocol metadata.\n * @returns The underlying position for the details page.\n */\nfunction toUnderlyingPosition(\n balance: DefiBalanceWithMetadata,\n): DeFiUnderlyingPosition {\n const assetId = balance.assetId as CaipAssetType;\n const { chainId } = parseCaipAssetType(assetId);\n const { positionType, poolAddress, groupId } = balance.metadata;\n\n return {\n assetId,\n chainId,\n symbol: balance.symbol,\n name: balance.name,\n balance: balance.balance,\n decimals: balance.decimals,\n marketValue: getMarketValue(balance),\n positionType,\n poolAddress,\n groupId,\n tokenImage: getDefiTokenImageUrl(assetId),\n };\n}\n\n/**\n * Builds a chain-reference-agnostic key (`namespace:address`) for matching the\n * CAIP-10 account IDs we request against the ones the v6 API echoes back.\n *\n * We request EVM balances with the all-chains reference (`eip155:0:<address>`),\n * but the response echoes a separate per-chain ID for every chain\n * (`eip155:1:<address>`, `eip155:137:<address>`, ...). Matching on the full\n * CAIP-10 string therefore fails, so we drop the reference and match on\n * namespace + address instead. EVM addresses are lowercased; other namespaces\n * keep their case.\n *\n * @param caipAccountId - A CAIP-10 account ID.\n * @returns The match key, or a case-normalized fallback if parsing fails.\n */\nfunction toAccountMatchKey(caipAccountId: string): string {\n try {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(caipAccountId as CaipAccountId);\n const normalizedAddress =\n namespace === KnownCaipNamespace.Eip155 ? address.toLowerCase() : address;\n return `${namespace}:${normalizedAddress}`;\n } catch {\n return caipAccountId.startsWith(`${KnownCaipNamespace.Eip155}:`)\n ? caipAccountId.toLowerCase()\n : caipAccountId;\n }\n}\n\n/**\n * Transforms a v6 multiaccount balances response into the stored DeFi state:\n * positions keyed by internal account ID, each mapping to a flat list of\n * protocol groups. Every group carries its own `chainId` (so the client can\n * filter without a nested chain map) plus both the DeFi-tab summary and the\n * details-page sections. Accounts present in the response but with no DeFi\n * positions are included with an empty list so stale data is cleared.\n *\n * When `internalAccountIdByCaip` is provided, response account IDs are matched\n * to internal MetaMask account IDs via namespace + address (ignoring chain\n * reference and EVM case). Unmatched accounts are skipped. When omitted, the\n * response account ID is used as-is (handy for unit tests).\n *\n * @param response - The v6 multiaccount balances response.\n * @param internalAccountIdByCaip - Optional map of request CAIP-10 account IDs\n * to internal MetaMask account IDs.\n * @returns DeFi positions keyed by internal account ID.\n */\nexport function groupDeFiPositionsV6(\n response: V6BalancesResponse,\n internalAccountIdByCaip?: Map<string, string>,\n): DeFiPositionsByAccount {\n const internalAccountIdByMatchKey = internalAccountIdByCaip\n ? new Map(\n [...internalAccountIdByCaip].map(([caipAccountId, internalId]) => [\n toAccountMatchKey(caipAccountId),\n internalId,\n ]),\n )\n : undefined;\n\n // Accumulate groups per resolved internal account ID. The v6 response returns\n // a separate entry per chain (e.g. `eip155:1:<addr>`, `eip155:137:<addr>`),\n // and several of them can resolve to the same internal account ID, so we must\n // merge across all of them rather than overwrite per response account.\n const groupsByAccountKey = new Map<\n string,\n Map<string, DeFiProtocolPositionGroup>\n >();\n\n for (const account of response.accounts) {\n const accountId = internalAccountIdByMatchKey\n ? internalAccountIdByMatchKey.get(toAccountMatchKey(account.accountId))\n : account.accountId;\n if (accountId === undefined) {\n continue;\n }\n\n // Seed every queried account so accounts that no longer hold positions\n // overwrite (clear) any previously stored data.\n let groupsByKey = groupsByAccountKey.get(accountId);\n if (!groupsByKey) {\n groupsByKey = new Map<string, DeFiProtocolPositionGroup>();\n groupsByAccountKey.set(accountId, groupsByKey);\n }\n\n for (const balance of account.balances) {\n if (!isDefiBalanceWithMetadata(balance)) {\n continue;\n }\n\n const position = toUnderlyingPosition(balance);\n const { protocolId, productName, protocolIconUrl } = balance.metadata;\n const groupKey = `${position.chainId}#${protocolId}`;\n\n let group = groupsByKey.get(groupKey);\n if (!group) {\n group = {\n protocolId,\n productName,\n protocolIconUrl,\n chainId: position.chainId,\n marketValue: 0,\n iconGroup: [],\n sections: [],\n };\n groupsByKey.set(groupKey, group);\n }\n\n if (position.marketValue !== undefined) {\n group.marketValue +=\n position.marketValue * getMarketValueSign(position.positionType);\n }\n\n if (!group.iconGroup.some((item) => item.symbol === position.symbol)) {\n group.iconGroup.push({\n symbol: position.symbol,\n avatarValue: position.tokenImage,\n });\n }\n\n // Sections are keyed by productName; distinct groupIds under the same\n // product remain available on each underlying position.\n let section = group.sections.find(\n (item) => item.productName === productName,\n );\n if (!section) {\n section = { productName, positions: [] };\n group.sections.push(section);\n }\n section.positions.push(position);\n }\n }\n\n const result: DeFiPositionsByAccount = {};\n for (const [accountId, groupsByKey] of groupsByAccountKey) {\n const groups = [...groupsByKey.values()];\n for (const group of groups) {\n orderIconGroup(group.iconGroup);\n }\n result[accountId] = groups;\n }\n\n return result;\n}\n"]}
@@ -4,7 +4,7 @@ import type { CaipAssetType, CaipChainId } from "@metamask/utils";
4
4
  * Possible `positionType` values from Accounts API v6 DeFi metadata.
5
5
  * Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.
6
6
  */
7
- export declare const DEFI_POSITION_TYPES: readonly ["deposit", "lending", "yield", "liquidity_pool", "staked", "leveraged_farming", "nft_staked", "farming", "locked", "vesting", "rewards", "investment"];
7
+ export declare const DEFI_POSITION_TYPES: readonly ["deposit", "loan", "locked", "staked", "reward", "wallet", "investment"];
8
8
  /**
9
9
  * The specific module or functionality within a DeFi protocol where a position
10
10
  * is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.
@@ -1 +1 @@
1
- {"version":3,"file":"group-defi-positions-v6.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,kBAAkB,EAClB,kBAAkB,EACnB,+BAA+B;AAChC,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EACZ,wBAAwB;AAWzB;;;GAGG;AACH,eAAO,MAA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IACH,QAAQ,EAAE,0BAA0B,EAAE,CAAC;CACxC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,CAAC,SAAS,EAAE,MAAM,GAAG,yBAAyB,EAAE,CAAC;CAClD,CAAC;AAyJF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,kBAAkB,EAC5B,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5C,sBAAsB,CA6FxB"}
1
+ {"version":3,"file":"group-defi-positions-v6.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,kBAAkB,EAClB,kBAAkB,EACnB,+BAA+B;AAChC,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EACZ,wBAAwB;AAWzB;;;GAGG;AACH,eAAO,MAAM,mBAAmB,oFAAyB,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,6BAA6B,EAAE,WAAW,CAAC,gBAAgB,CACnC,CAAC;AAEtC;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,YAAY,EAAE,gBAAgB,CAAC;IAC/B,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,sBAAsB,EAAE,CAAC;CACrC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,SAAS,EAAE,yBAAyB,EAAE,CAAC;IACvC;;;OAGG;IACH,QAAQ,EAAE,0BAA0B,EAAE,CAAC;CACxC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,CAAC,SAAS,EAAE,MAAM,GAAG,yBAAyB,EAAE,CAAC;CAClD,CAAC;AAyJF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,kBAAkB,EAC5B,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5C,sBAAsB,CA6FxB"}
@@ -4,7 +4,7 @@ import type { CaipAssetType, CaipChainId } from "@metamask/utils";
4
4
  * Possible `positionType` values from Accounts API v6 DeFi metadata.
5
5
  * Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.
6
6
  */
7
- export declare const DEFI_POSITION_TYPES: readonly ["deposit", "lending", "yield", "liquidity_pool", "staked", "leveraged_farming", "nft_staked", "farming", "locked", "vesting", "rewards", "investment"];
7
+ export declare const DEFI_POSITION_TYPES: readonly ["deposit", "loan", "locked", "staked", "reward", "wallet", "investment"];
8
8
  /**
9
9
  * The specific module or functionality within a DeFi protocol where a position
10
10
  * is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.
@@ -1 +1 @@
1
- {"version":3,"file":"group-defi-positions-v6.d.mts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,kBAAkB,EAClB,kBAAkB,EACnB,+BAA+B;AAChC,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EACZ,wBAAwB;AAWzB;;;GAGG;AACH,eAAO,MAAM,mBAAmB,kKAAyB,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,6BAA6B,EAAE,WAAW,CAAC,gBAAgB,CAChC,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,YAAY,EAAE,gBAAgB,CAAC;IAC/B,oDAAoD;IACpD,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,sBAAsB,EAAE,CAAC;CACrC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,WAAW,CAAC;IACrB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,SAAS,EAAE,yBAAyB,EAAE,CAAC;IACvC;;;OAGG;IACH,QAAQ,EAAE,0BAA0B,EAAE,CAAC;CACxC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,CAAC,SAAS,EAAE,MAAM,GAAG,yBAAyB,EAAE,CAAC;CAClD,CAAC;AAyJF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,kBAAkB,EAC5B,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5C,sBAAsB,CA6FxB"}
1
+ {"version":3,"file":"group-defi-positions-v6.d.mts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,kBAAkB,EAClB,kBAAkB,EACnB,+BAA+B;AAChC,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EACZ,wBAAwB;AAWzB;;;GAGG;AACH,eAAO,MAAM,mBAAmB,oFAAyB,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,6BAA6B,EAAE,WAAW,CAAC,gBAAgB,CACnC,CAAC;AAEtC;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;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uB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5C,sBAAsB,CA6FxB"}
@@ -11,7 +11,7 @@ export const DEFI_POSITION_TYPES = V6_DEFI_POSITION_TYPES;
11
11
  * Position types whose fiat value is a liability and is subtracted from the
12
12
  * protocol group's aggregated `marketValue`.
13
13
  */
14
- export const DEFI_POSITION_LIABILITY_TYPES = new Set(['lending']);
14
+ export const DEFI_POSITION_LIABILITY_TYPES = new Set(['loan']);
15
15
  // Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple
16
16
  // underlyings. Display-only.
17
17
  const SYMBOL_PRIORITY = ['ETH', 'WETH'];
@@ -1 +1 @@
1
- {"version":3,"file":"group-defi-positions-v6.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions-v6.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,+BAA+B;AAYhE,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EACjB,wBAAwB;AAEzB,+EAA+E;AAC/E,MAAM,wBAAwB,GAAG,+BAA+B,CAAC;AAEjE;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AAQ1D;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GACxC,IAAI,GAAG,CAAmB,CAAC,SAAS,CAAC,CAAC,CAAC;AAuFzC,gFAAgF;AAChF,6BAA6B;AAC7B,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAIxC;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,OAAsB;IAClD,IAAI,CAAC;QACH,MAAM,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,KAAK,GAAG,SAAS,KAAK,kBAAkB,CAAC,MAAM,CAAC;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AI,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAC/B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,KAAK,WAAW,CAC3C,CAAC;YACF,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;gBACzC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC/B,CAAC;YACD,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,IAAI,kBAAkB,EAAE,CAAC;QAC1D,MAAM,MAAM,GAAG,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;QACzC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,cAAc,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAClC,CAAC;QACD,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { V6_DEFI_POSITION_TYPES } from '@metamask/core-backend';\nimport type {\n V6BalanceItem,\n V6BalanceMetadata,\n V6BalancesResponse,\n V6DeFiPositionType,\n} from '@metamask/core-backend';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\nimport {\n KnownCaipNamespace,\n parseCaipAccountId,\n parseCaipAssetType,\n parseCaipChainId,\n} from '@metamask/utils';\n\n/** Static.cx host used to build CAIP-19 token icon URLs for DeFi positions. */\nconst STATIC_METAMASK_BASE_URL = 'https://static.cx.metamask.io';\n\n/**\n * Possible `positionType` values from Accounts API v6 DeFi metadata.\n * Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.\n */\nexport const DEFI_POSITION_TYPES = V6_DEFI_POSITION_TYPES;\n\n/**\n * The specific module or functionality within a DeFi protocol where a position\n * is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.\n */\nexport type DeFiPositionType = V6DeFiPositionType;\n\n/**\n * Position types whose fiat value is a liability and is subtracted from the\n * protocol group's aggregated `marketValue`.\n */\nexport const DEFI_POSITION_LIABILITY_TYPES: ReadonlySet<DeFiPositionType> =\n new Set<DeFiPositionType>(['lending']);\n\n/**\n * An icon-group entry shown next to a protocol in the DeFi tab list.\n */\nexport type DeFiPositionIconGroupItem = {\n /** Token icon URL, when one can be built for the asset. */\n avatarValue?: string;\n symbol: string;\n};\n\n/**\n * A single underlying position row shown on the DeFi details page.\n */\nexport type DeFiUnderlyingPosition = {\n assetId: CaipAssetType;\n chainId: CaipChainId;\n symbol: string;\n name: string;\n decimals: number;\n /** Raw balance string as returned by the API. */\n balance: string;\n /** Fiat market value in the requested currency, when a price is available. */\n marketValue?: number;\n /** Position type from protocol metadata. */\n positionType: DeFiPositionType;\n /** Address of the pool this position belongs to. */\n poolAddress: string;\n /**\n * Upstream grouping id from the API. Rows that share a `productName` can\n * still carry distinct `groupId`s (e.g. multiple Pendle YT markets).\n */\n groupId: string;\n /** Token icon URL, when one can be built for the asset. */\n tokenImage?: string;\n};\n\n/**\n * A section of the details page, grouping positions that share the same\n * API `productName`. A single `protocolId` can have multiple products\n * (different pools/markets under one protocol), so a group may contain\n * several sections.\n */\nexport type DeFiPositionDetailsSection = {\n /** Section label from the API (`metadata.productName`). */\n productName: string;\n positions: DeFiUnderlyingPosition[];\n};\n\n/**\n * One row in the DeFi tab list (a protocol on a given chain), with the details\n * needed to render the details page embedded directly inside it.\n */\nexport type DeFiProtocolPositionGroup = {\n protocolId: string;\n /**\n * Product name from the first position seen for this protocol. Prefer\n * `protocolId` for the list-row title; use section `productName`s for\n * per-product detail headings.\n */\n productName: string;\n protocolIconUrl: string;\n chainId: CaipChainId;\n /**\n * Aggregated fiat market value across all positions in the group.\n * `lending` positions are subtracted; all other types are added.\n */\n marketValue: number;\n /** Icon-group entries for the list row. */\n iconGroup: DeFiPositionIconGroupItem[];\n /**\n * Detail sections consumed by the details page, one per distinct API\n * `productName` under this `protocolId`.\n */\n sections: DeFiPositionDetailsSection[];\n};\n\n/**\n * DeFi positions for every queried account, keyed by the internal MetaMask\n * account ID (`InternalAccount.id` UUID), the same key AssetsController uses.\n * Each account maps to a flat list of protocol groups; filter by each group's\n * `chainId` rather than digging through a nested chain map.\n */\nexport type DeFiPositionsByAccount = {\n [accountId: string]: DeFiProtocolPositionGroup[];\n};\n\n// Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple\n// underlyings. Display-only.\nconst SYMBOL_PRIORITY = ['ETH', 'WETH'];\n\ntype DefiBalanceWithMetadata = V6BalanceItem & { metadata: V6BalanceMetadata };\n\n/**\n * Builds a static token icon URL for a CAIP asset ID.\n *\n * @param assetId - The CAIP-19 asset ID.\n * @returns The token icon URL, or `undefined` when it cannot be built.\n */\nfunction getDefiTokenImageUrl(assetId: CaipAssetType): string | undefined {\n try {\n const { chainId } = parseCaipAssetType(assetId);\n const { namespace } = parseCaipChainId(chainId);\n const isEvm = namespace === KnownCaipNamespace.Eip155;\n const normalizedAssetId = (isEvm ? assetId.toLowerCase() : assetId).replace(\n /:/gu,\n '/',\n );\n\n return `${STATIC_METAMASK_BASE_URL}/api/v2/tokenIcons/assets/${normalizedAssetId}.png`;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns whether a balance row is a DeFi position carrying protocol metadata.\n *\n * @param balance - A balance row from the v6 API.\n * @returns True when the row is a `category: defi` row with protocol metadata.\n */\nfunction isDefiBalanceWithMetadata(\n balance: V6BalanceItem,\n): balance is DefiBalanceWithMetadata {\n return (\n balance.category === 'defi' &&\n balance.metadata !== undefined &&\n (balance.metadata as Partial<V6BalanceMetadata>).protocolId !== undefined\n );\n}\n\n/**\n * Returns the fiat market value for a v6 DeFi balance row.\n *\n * @param balance - A balance row from the v6 API.\n * @returns The fiat value, or `undefined` when price is missing or the\n * balance/price is invalid.\n */\nfunction getMarketValue(balance: V6BalanceItem): number | undefined {\n if (balance.price === undefined) {\n return undefined;\n }\n\n const normalizedBalance = Number.parseFloat(balance.balance);\n const price = Number.parseFloat(balance.price);\n\n if (!Number.isFinite(normalizedBalance) || !Number.isFinite(price)) {\n return undefined;\n }\n\n return normalizedBalance * price;\n}\n\n/**\n * Returns the sign used when rolling a position's market value into a protocol\n * group total. Liability types (currently `lending`) subtract; all others add.\n *\n * @param positionType - The position's protocol module type.\n * @returns `-1` for liabilities, `1` otherwise.\n */\nfunction getMarketValueSign(positionType: DeFiPositionType): 1 | -1 {\n return DEFI_POSITION_LIABILITY_TYPES.has(positionType) ? -1 : 1;\n}\n\n/**\n * Moves a priority symbol (ETH/WETH) to the front of the icon group, in place.\n *\n * @param iconGroup - The icon-group entries to reorder.\n */\nfunction orderIconGroup(iconGroup: DeFiPositionIconGroupItem[]): void {\n const priorityIndex = iconGroup.findIndex((item) =>\n SYMBOL_PRIORITY.includes(item.symbol),\n );\n\n if (priorityIndex > 0) {\n const [priorityIcon] = iconGroup.splice(priorityIndex, 1);\n iconGroup.unshift(priorityIcon);\n }\n}\n\n/**\n * Maps a DeFi balance row to a details-page underlying position.\n *\n * @param balance - A DeFi balance row with protocol metadata.\n * @returns The underlying position for the details page.\n */\nfunction toUnderlyingPosition(\n balance: DefiBalanceWithMetadata,\n): DeFiUnderlyingPosition {\n const assetId = balance.assetId as CaipAssetType;\n const { chainId } = parseCaipAssetType(assetId);\n const { positionType, poolAddress, groupId } = balance.metadata;\n\n return {\n assetId,\n chainId,\n symbol: balance.symbol,\n name: balance.name,\n balance: balance.balance,\n decimals: balance.decimals,\n marketValue: getMarketValue(balance),\n positionType,\n poolAddress,\n groupId,\n tokenImage: getDefiTokenImageUrl(assetId),\n };\n}\n\n/**\n * Builds a chain-reference-agnostic key (`namespace:address`) for matching the\n * CAIP-10 account IDs we request against the ones the v6 API echoes back.\n *\n * We request EVM balances with the all-chains reference (`eip155:0:<address>`),\n * but the response echoes a separate per-chain ID for every chain\n * (`eip155:1:<address>`, `eip155:137:<address>`, ...). Matching on the full\n * CAIP-10 string therefore fails, so we drop the reference and match on\n * namespace + address instead. EVM addresses are lowercased; other namespaces\n * keep their case.\n *\n * @param caipAccountId - A CAIP-10 account ID.\n * @returns The match key, or a case-normalized fallback if parsing fails.\n */\nfunction toAccountMatchKey(caipAccountId: string): string {\n try {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(caipAccountId as CaipAccountId);\n const normalizedAddress =\n namespace === KnownCaipNamespace.Eip155 ? address.toLowerCase() : address;\n return `${namespace}:${normalizedAddress}`;\n } catch {\n return caipAccountId.startsWith(`${KnownCaipNamespace.Eip155}:`)\n ? caipAccountId.toLowerCase()\n : caipAccountId;\n }\n}\n\n/**\n * Transforms a v6 multiaccount balances response into the stored DeFi state:\n * positions keyed by internal account ID, each mapping to a flat list of\n * protocol groups. Every group carries its own `chainId` (so the client can\n * filter without a nested chain map) plus both the DeFi-tab summary and the\n * details-page sections. Accounts present in the response but with no DeFi\n * positions are included with an empty list so stale data is cleared.\n *\n * When `internalAccountIdByCaip` is provided, response account IDs are matched\n * to internal MetaMask account IDs via namespace + address (ignoring chain\n * reference and EVM case). Unmatched accounts are skipped. When omitted, the\n * response account ID is used as-is (handy for unit tests).\n *\n * @param response - The v6 multiaccount balances response.\n * @param internalAccountIdByCaip - Optional map of request CAIP-10 account IDs\n * to internal MetaMask account IDs.\n * @returns DeFi positions keyed by internal account ID.\n */\nexport function groupDeFiPositionsV6(\n response: V6BalancesResponse,\n internalAccountIdByCaip?: Map<string, string>,\n): DeFiPositionsByAccount {\n const internalAccountIdByMatchKey = internalAccountIdByCaip\n ? new Map(\n [...internalAccountIdByCaip].map(([caipAccountId, internalId]) => [\n toAccountMatchKey(caipAccountId),\n internalId,\n ]),\n )\n : undefined;\n\n // Accumulate groups per resolved internal account ID. The v6 response returns\n // a separate entry per chain (e.g. `eip155:1:<addr>`, `eip155:137:<addr>`),\n // and several of them can resolve to the same internal account ID, so we must\n // merge across all of them rather than overwrite per response account.\n const groupsByAccountKey = new Map<\n string,\n Map<string, DeFiProtocolPositionGroup>\n >();\n\n for (const account of response.accounts) {\n const accountId = internalAccountIdByMatchKey\n ? internalAccountIdByMatchKey.get(toAccountMatchKey(account.accountId))\n : account.accountId;\n if (accountId === undefined) {\n continue;\n }\n\n // Seed every queried account so accounts that no longer hold positions\n // overwrite (clear) any previously stored data.\n let groupsByKey = groupsByAccountKey.get(accountId);\n if (!groupsByKey) {\n groupsByKey = new Map<string, DeFiProtocolPositionGroup>();\n groupsByAccountKey.set(accountId, groupsByKey);\n }\n\n for (const balance of account.balances) {\n if (!isDefiBalanceWithMetadata(balance)) {\n continue;\n }\n\n const position = toUnderlyingPosition(balance);\n const { protocolId, productName, protocolIconUrl } = balance.metadata;\n const groupKey = `${position.chainId}#${protocolId}`;\n\n let group = groupsByKey.get(groupKey);\n if (!group) {\n group = {\n protocolId,\n productName,\n protocolIconUrl,\n chainId: position.chainId,\n marketValue: 0,\n iconGroup: [],\n sections: [],\n };\n groupsByKey.set(groupKey, group);\n }\n\n if (position.marketValue !== undefined) {\n group.marketValue +=\n position.marketValue * getMarketValueSign(position.positionType);\n }\n\n if (!group.iconGroup.some((item) => item.symbol === position.symbol)) {\n group.iconGroup.push({\n symbol: position.symbol,\n avatarValue: position.tokenImage,\n });\n }\n\n // Sections are keyed by productName; distinct groupIds under the same\n // product remain available on each underlying position.\n let section = group.sections.find(\n (item) => item.productName === productName,\n );\n if (!section) {\n section = { productName, positions: [] };\n group.sections.push(section);\n }\n section.positions.push(position);\n }\n }\n\n const result: DeFiPositionsByAccount = {};\n for (const [accountId, groupsByKey] of groupsByAccountKey) {\n const groups = [...groupsByKey.values()];\n for (const group of groups) {\n orderIconGroup(group.iconGroup);\n }\n result[accountId] = groups;\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"group-defi-positions-v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,SAAS,EAAE,WAAW,CAAC,IAAI,kBAAkB,EAAE,CAAC;QAC1D,MAAM,MAAM,GAAG,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;QACzC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,cAAc,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAClC,CAAC;QACD,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { V6_DEFI_POSITION_TYPES } from '@metamask/core-backend';\nimport type {\n V6BalanceItem,\n V6BalanceMetadata,\n V6BalancesResponse,\n V6DeFiPositionType,\n} from '@metamask/core-backend';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n} from '@metamask/utils';\nimport {\n KnownCaipNamespace,\n parseCaipAccountId,\n parseCaipAssetType,\n parseCaipChainId,\n} from '@metamask/utils';\n\n/** Static.cx host used to build CAIP-19 token icon URLs for DeFi positions. */\nconst STATIC_METAMASK_BASE_URL = 'https://static.cx.metamask.io';\n\n/**\n * Possible `positionType` values from Accounts API v6 DeFi metadata.\n * Re-export of {@link V6_DEFI_POSITION_TYPES} from `@metamask/core-backend`.\n */\nexport const DEFI_POSITION_TYPES = V6_DEFI_POSITION_TYPES;\n\n/**\n * The specific module or functionality within a DeFi protocol where a position\n * is held. Alias of {@link V6DeFiPositionType} from `@metamask/core-backend`.\n */\nexport type DeFiPositionType = V6DeFiPositionType;\n\n/**\n * Position types whose fiat value is a liability and is subtracted from the\n * protocol group's aggregated `marketValue`.\n */\nexport const DEFI_POSITION_LIABILITY_TYPES: ReadonlySet<DeFiPositionType> =\n new Set<DeFiPositionType>(['loan']);\n\n/**\n * An icon-group entry shown next to a protocol in the DeFi tab list.\n */\nexport type DeFiPositionIconGroupItem = {\n /** Token icon URL, when one can be built for the asset. */\n avatarValue?: string;\n symbol: string;\n};\n\n/**\n * A single underlying position row shown on the DeFi details page.\n */\nexport type DeFiUnderlyingPosition = {\n assetId: CaipAssetType;\n chainId: CaipChainId;\n symbol: string;\n name: string;\n decimals: number;\n /** Raw balance string as returned by the API. */\n balance: string;\n /** Fiat market value in the requested currency, when a price is available. */\n marketValue?: number;\n /** Position type from protocol metadata. */\n positionType: DeFiPositionType;\n /** Address of the pool this position belongs to. */\n poolAddress: string;\n /**\n * Upstream grouping id from the API. Rows that share a `productName` can\n * still carry distinct `groupId`s (e.g. multiple Pendle YT markets).\n */\n groupId: string;\n /** Token icon URL, when one can be built for the asset. */\n tokenImage?: string;\n};\n\n/**\n * A section of the details page, grouping positions that share the same\n * API `productName`. A single `protocolId` can have multiple products\n * (different pools/markets under one protocol), so a group may contain\n * several sections.\n */\nexport type DeFiPositionDetailsSection = {\n /** Section label from the API (`metadata.productName`). */\n productName: string;\n positions: DeFiUnderlyingPosition[];\n};\n\n/**\n * One row in the DeFi tab list (a protocol on a given chain), with the details\n * needed to render the details page embedded directly inside it.\n */\nexport type DeFiProtocolPositionGroup = {\n protocolId: string;\n /**\n * Product name from the first position seen for this protocol. Prefer\n * `protocolId` for the list-row title; use section `productName`s for\n * per-product detail headings.\n */\n productName: string;\n protocolIconUrl: string;\n chainId: CaipChainId;\n /**\n * Aggregated fiat market value across all positions in the group.\n * `lending` positions are subtracted; all other types are added.\n */\n marketValue: number;\n /** Icon-group entries for the list row. */\n iconGroup: DeFiPositionIconGroupItem[];\n /**\n * Detail sections consumed by the details page, one per distinct API\n * `productName` under this `protocolId`.\n */\n sections: DeFiPositionDetailsSection[];\n};\n\n/**\n * DeFi positions for every queried account, keyed by the internal MetaMask\n * account ID (`InternalAccount.id` UUID), the same key AssetsController uses.\n * Each account maps to a flat list of protocol groups; filter by each group's\n * `chainId` rather than digging through a nested chain map.\n */\nexport type DeFiPositionsByAccount = {\n [accountId: string]: DeFiProtocolPositionGroup[];\n};\n\n// Prefer ETH/WETH first in the list-row icon stack when a protocol has multiple\n// underlyings. Display-only.\nconst SYMBOL_PRIORITY = ['ETH', 'WETH'];\n\ntype DefiBalanceWithMetadata = V6BalanceItem & { metadata: V6BalanceMetadata };\n\n/**\n * Builds a static token icon URL for a CAIP asset ID.\n *\n * @param assetId - The CAIP-19 asset ID.\n * @returns The token icon URL, or `undefined` when it cannot be built.\n */\nfunction getDefiTokenImageUrl(assetId: CaipAssetType): string | undefined {\n try {\n const { chainId } = parseCaipAssetType(assetId);\n const { namespace } = parseCaipChainId(chainId);\n const isEvm = namespace === KnownCaipNamespace.Eip155;\n const normalizedAssetId = (isEvm ? assetId.toLowerCase() : assetId).replace(\n /:/gu,\n '/',\n );\n\n return `${STATIC_METAMASK_BASE_URL}/api/v2/tokenIcons/assets/${normalizedAssetId}.png`;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Returns whether a balance row is a DeFi position carrying protocol metadata.\n *\n * @param balance - A balance row from the v6 API.\n * @returns True when the row is a `category: defi` row with protocol metadata.\n */\nfunction isDefiBalanceWithMetadata(\n balance: V6BalanceItem,\n): balance is DefiBalanceWithMetadata {\n return (\n balance.category === 'defi' &&\n balance.metadata !== undefined &&\n (balance.metadata as Partial<V6BalanceMetadata>).protocolId !== undefined\n );\n}\n\n/**\n * Returns the fiat market value for a v6 DeFi balance row.\n *\n * @param balance - A balance row from the v6 API.\n * @returns The fiat value, or `undefined` when price is missing or the\n * balance/price is invalid.\n */\nfunction getMarketValue(balance: V6BalanceItem): number | undefined {\n if (balance.price === undefined) {\n return undefined;\n }\n\n const normalizedBalance = Number.parseFloat(balance.balance);\n const price = Number.parseFloat(balance.price);\n\n if (!Number.isFinite(normalizedBalance) || !Number.isFinite(price)) {\n return undefined;\n }\n\n return normalizedBalance * price;\n}\n\n/**\n * Returns the sign used when rolling a position's market value into a protocol\n * group total. Liability types (currently `lending`) subtract; all others add.\n *\n * @param positionType - The position's protocol module type.\n * @returns `-1` for liabilities, `1` otherwise.\n */\nfunction getMarketValueSign(positionType: DeFiPositionType): 1 | -1 {\n return DEFI_POSITION_LIABILITY_TYPES.has(positionType) ? -1 : 1;\n}\n\n/**\n * Moves a priority symbol (ETH/WETH) to the front of the icon group, in place.\n *\n * @param iconGroup - The icon-group entries to reorder.\n */\nfunction orderIconGroup(iconGroup: DeFiPositionIconGroupItem[]): void {\n const priorityIndex = iconGroup.findIndex((item) =>\n SYMBOL_PRIORITY.includes(item.symbol),\n );\n\n if (priorityIndex > 0) {\n const [priorityIcon] = iconGroup.splice(priorityIndex, 1);\n iconGroup.unshift(priorityIcon);\n }\n}\n\n/**\n * Maps a DeFi balance row to a details-page underlying position.\n *\n * @param balance - A DeFi balance row with protocol metadata.\n * @returns The underlying position for the details page.\n */\nfunction toUnderlyingPosition(\n balance: DefiBalanceWithMetadata,\n): DeFiUnderlyingPosition {\n const assetId = balance.assetId as CaipAssetType;\n const { chainId } = parseCaipAssetType(assetId);\n const { positionType, poolAddress, groupId } = balance.metadata;\n\n return {\n assetId,\n chainId,\n symbol: balance.symbol,\n name: balance.name,\n balance: balance.balance,\n decimals: balance.decimals,\n marketValue: getMarketValue(balance),\n positionType,\n poolAddress,\n groupId,\n tokenImage: getDefiTokenImageUrl(assetId),\n };\n}\n\n/**\n * Builds a chain-reference-agnostic key (`namespace:address`) for matching the\n * CAIP-10 account IDs we request against the ones the v6 API echoes back.\n *\n * We request EVM balances with the all-chains reference (`eip155:0:<address>`),\n * but the response echoes a separate per-chain ID for every chain\n * (`eip155:1:<address>`, `eip155:137:<address>`, ...). Matching on the full\n * CAIP-10 string therefore fails, so we drop the reference and match on\n * namespace + address instead. EVM addresses are lowercased; other namespaces\n * keep their case.\n *\n * @param caipAccountId - A CAIP-10 account ID.\n * @returns The match key, or a case-normalized fallback if parsing fails.\n */\nfunction toAccountMatchKey(caipAccountId: string): string {\n try {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(caipAccountId as CaipAccountId);\n const normalizedAddress =\n namespace === KnownCaipNamespace.Eip155 ? address.toLowerCase() : address;\n return `${namespace}:${normalizedAddress}`;\n } catch {\n return caipAccountId.startsWith(`${KnownCaipNamespace.Eip155}:`)\n ? caipAccountId.toLowerCase()\n : caipAccountId;\n }\n}\n\n/**\n * Transforms a v6 multiaccount balances response into the stored DeFi state:\n * positions keyed by internal account ID, each mapping to a flat list of\n * protocol groups. Every group carries its own `chainId` (so the client can\n * filter without a nested chain map) plus both the DeFi-tab summary and the\n * details-page sections. Accounts present in the response but with no DeFi\n * positions are included with an empty list so stale data is cleared.\n *\n * When `internalAccountIdByCaip` is provided, response account IDs are matched\n * to internal MetaMask account IDs via namespace + address (ignoring chain\n * reference and EVM case). Unmatched accounts are skipped. When omitted, the\n * response account ID is used as-is (handy for unit tests).\n *\n * @param response - The v6 multiaccount balances response.\n * @param internalAccountIdByCaip - Optional map of request CAIP-10 account IDs\n * to internal MetaMask account IDs.\n * @returns DeFi positions keyed by internal account ID.\n */\nexport function groupDeFiPositionsV6(\n response: V6BalancesResponse,\n internalAccountIdByCaip?: Map<string, string>,\n): DeFiPositionsByAccount {\n const internalAccountIdByMatchKey = internalAccountIdByCaip\n ? new Map(\n [...internalAccountIdByCaip].map(([caipAccountId, internalId]) => [\n toAccountMatchKey(caipAccountId),\n internalId,\n ]),\n )\n : undefined;\n\n // Accumulate groups per resolved internal account ID. The v6 response returns\n // a separate entry per chain (e.g. `eip155:1:<addr>`, `eip155:137:<addr>`),\n // and several of them can resolve to the same internal account ID, so we must\n // merge across all of them rather than overwrite per response account.\n const groupsByAccountKey = new Map<\n string,\n Map<string, DeFiProtocolPositionGroup>\n >();\n\n for (const account of response.accounts) {\n const accountId = internalAccountIdByMatchKey\n ? internalAccountIdByMatchKey.get(toAccountMatchKey(account.accountId))\n : account.accountId;\n if (accountId === undefined) {\n continue;\n }\n\n // Seed every queried account so accounts that no longer hold positions\n // overwrite (clear) any previously stored data.\n let groupsByKey = groupsByAccountKey.get(accountId);\n if (!groupsByKey) {\n groupsByKey = new Map<string, DeFiProtocolPositionGroup>();\n groupsByAccountKey.set(accountId, groupsByKey);\n }\n\n for (const balance of account.balances) {\n if (!isDefiBalanceWithMetadata(balance)) {\n continue;\n }\n\n const position = toUnderlyingPosition(balance);\n const { protocolId, productName, protocolIconUrl } = balance.metadata;\n const groupKey = `${position.chainId}#${protocolId}`;\n\n let group = groupsByKey.get(groupKey);\n if (!group) {\n group = {\n protocolId,\n productName,\n protocolIconUrl,\n chainId: position.chainId,\n marketValue: 0,\n iconGroup: [],\n sections: [],\n };\n groupsByKey.set(groupKey, group);\n }\n\n if (position.marketValue !== undefined) {\n group.marketValue +=\n position.marketValue * getMarketValueSign(position.positionType);\n }\n\n if (!group.iconGroup.some((item) => item.symbol === position.symbol)) {\n group.iconGroup.push({\n symbol: position.symbol,\n avatarValue: position.tokenImage,\n });\n }\n\n // Sections are keyed by productName; distinct groupIds under the same\n // product remain available on each underlying position.\n let section = group.sections.find(\n (item) => item.productName === productName,\n );\n if (!section) {\n section = { productName, positions: [] };\n group.sections.push(section);\n }\n section.positions.push(position);\n }\n }\n\n const result: DeFiPositionsByAccount = {};\n for (const [accountId, groupsByKey] of groupsByAccountKey) {\n const groups = [...groupsByKey.values()];\n for (const group of groups) {\n orderIconGroup(group.iconGroup);\n }\n result[accountId] = groups;\n }\n\n return result;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"group-defi-positions.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions.ts"],"names":[],"mappings":";;;AAAA,iEAAmD;AAuCnD;;;;GAIG;AACH,SAAgB,kBAAkB,CAChC,qBAA6C;IAI7C,MAAM,oBAAoB,GAAyC,EAAE,CAAC;IAEtE,KAAK,MAAM,QAAQ,IAAI,qBAAqB,EAAE,CAAC;QAC7C,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YACtB,SAAS;QACX,CAAC;QAED,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,GACvE,QAAQ,CAAC;QAEX,MAAM,KAAK,GAAG,IAAA,wBAA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AC,CAAC,WAAW,KAAK,SAAS;QAC9C,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,WAAW,EACzB,CAAC,CACF,CAAC;IAEF,OAAO;QACL,GAAG,YAAY;QACf,WAAW;QACX,MAAM,EAAE,eAAe;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type {\n DefiPositionResponse,\n PositionType,\n ProtocolToken,\n Underlying,\n Balance,\n} from './fetch-positions';\n\nexport type GroupedDeFiPositions = {\n aggregatedMarketValue: number;\n protocols: {\n [protocolId: string]: {\n protocolDetails: {\n name: string;\n iconUrl: string;\n };\n aggregatedMarketValue: number;\n positionTypes: {\n [key in PositionType]?: {\n aggregatedMarketValue: number;\n positions: ProtocolTokenWithMarketValue[][];\n };\n };\n };\n };\n};\n\nexport type ProtocolTokenWithMarketValue = Omit<ProtocolToken, 'tokens'> & {\n marketValue?: number;\n tokens: UnderlyingWithMarketValue[];\n};\n\nexport type UnderlyingWithMarketValue = Omit<Underlying, 'tokens'> & {\n marketValue?: number;\n};\n\n/**\n *\n * @param defiPositionsResponse - The response from the defi positions API\n * @returns The grouped positions that get assigned to the state\n */\nexport function groupDeFiPositions(\n defiPositionsResponse: DefiPositionResponse[],\n): {\n [key: Hex]: GroupedDeFiPositions;\n} {\n const groupedDeFiPositions: { [key: Hex]: GroupedDeFiPositions } = {};\n\n for (const position of defiPositionsResponse) {\n if (!position.success) {\n continue;\n }\n\n const { chainId, protocolId, iconUrl, positionType, protocolDisplayName } =\n position;\n\n const chain = toHex(chainId);\n\n if (!groupedDeFiPositions[chain]) {\n groupedDeFiPositions[chain] = {\n aggregatedMarketValue: 0,\n protocols: {},\n };\n }\n\n const chainData = groupedDeFiPositions[chain];\n\n if (!chainData.protocols[protocolId]) {\n chainData.protocols[protocolId] = {\n protocolDetails: {\n name: protocolDisplayName,\n iconUrl,\n },\n aggregatedMarketValue: 0,\n positionTypes: {},\n };\n }\n\n const protocolData = chainData.protocols[protocolId];\n\n let positionTypeData = protocolData.positionTypes[positionType];\n if (!positionTypeData) {\n positionTypeData = {\n aggregatedMarketValue: 0,\n positions: [],\n };\n protocolData.positionTypes[positionType] = positionTypeData;\n }\n\n for (const protocolToken of position.tokens) {\n const token = processToken(protocolToken) as ProtocolTokenWithMarketValue;\n\n // If groupPositions is true, we group all positions of the same type\n if (position.metadata?.groupPositions) {\n if (positionTypeData.positions.length === 0) {\n positionTypeData.positions.push([token]);\n } else {\n positionTypeData.positions[0].push(token);\n }\n } else {\n positionTypeData.positions.push([token]);\n }\n\n if (token.marketValue) {\n const multiplier = position.positionType === 'borrow' ? -1 : 1;\n\n positionTypeData.aggregatedMarketValue += token.marketValue;\n protocolData.aggregatedMarketValue += token.marketValue * multiplier;\n chainData.aggregatedMarketValue += token.marketValue * multiplier;\n }\n }\n }\n\n return groupedDeFiPositions;\n}\n\n/**\n *\n * @param tokenBalance - The token balance that is going to be processed\n * @returns The processed token balance\n */\nfunction processToken<T extends Balance>(\n tokenBalance: T,\n): T & {\n marketValue?: number;\n tokens?: UnderlyingWithMarketValue[];\n} {\n if (!tokenBalance.tokens) {\n return {\n ...tokenBalance,\n marketValue: tokenBalance.price\n ? tokenBalance.balance * tokenBalance.price\n : undefined,\n };\n }\n\n const processedTokens = tokenBalance.tokens.map((t) => {\n const { tokens, ...tokenWithoutUnderlyings } = processToken(t);\n\n return tokenWithoutUnderlyings;\n });\n\n const marketValue = processedTokens.reduce<number | undefined>(\n (acc, t) =>\n acc === undefined || t.marketValue === undefined\n ? undefined\n : acc + t.marketValue,\n 0,\n );\n\n return {\n ...tokenBalance,\n marketValue,\n tokens: processedTokens,\n };\n}\n"]}
1
+ {"version":3,"file":"group-defi-positions.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions.ts"],"names":[],"mappings":";;;AAAA,iEAAmD;AAuCnD;;;;GAIG;AACH,SAAgB,kBAAkB,CAChC,qB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AAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACpD,MAAM,EAAE,MAAM,EAAE,GAAG,uBAAuB,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;QAE/D,OAAO,uBAAuB,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,eAAe,CAAC,MAAM,CACxC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CACT,GAAG,KAAK,SAAS,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS;QAC9C,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,WAAW,EACzB,CAAC,CACF,CAAC;IAEF,OAAO;QACL,GAAG,YAAY;QACf,WAAW;QACX,MAAM,EAAE,eAAe;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type {\n DefiPositionResponse,\n PositionType,\n ProtocolToken,\n Underlying,\n Balance,\n} from './fetch-positions.js';\n\nexport type GroupedDeFiPositions = {\n aggregatedMarketValue: number;\n protocols: {\n [protocolId: string]: {\n protocolDetails: {\n name: string;\n iconUrl: string;\n };\n aggregatedMarketValue: number;\n positionTypes: {\n [key in PositionType]?: {\n aggregatedMarketValue: number;\n positions: ProtocolTokenWithMarketValue[][];\n };\n };\n };\n };\n};\n\nexport type ProtocolTokenWithMarketValue = Omit<ProtocolToken, 'tokens'> & {\n marketValue?: number;\n tokens: UnderlyingWithMarketValue[];\n};\n\nexport type UnderlyingWithMarketValue = Omit<Underlying, 'tokens'> & {\n marketValue?: number;\n};\n\n/**\n *\n * @param defiPositionsResponse - The response from the defi positions API\n * @returns The grouped positions that get assigned to the state\n */\nexport function groupDeFiPositions(\n defiPositionsResponse: DefiPositionResponse[],\n): {\n [key: Hex]: GroupedDeFiPositions;\n} {\n const groupedDeFiPositions: { [key: Hex]: GroupedDeFiPositions } = {};\n\n for (const position of defiPositionsResponse) {\n if (!position.success) {\n continue;\n }\n\n const { chainId, protocolId, iconUrl, positionType, protocolDisplayName } =\n position;\n\n const chain = toHex(chainId);\n\n if (!groupedDeFiPositions[chain]) {\n groupedDeFiPositions[chain] = {\n aggregatedMarketValue: 0,\n protocols: {},\n };\n }\n\n const chainData = groupedDeFiPositions[chain];\n\n if (!chainData.protocols[protocolId]) {\n chainData.protocols[protocolId] = {\n protocolDetails: {\n name: protocolDisplayName,\n iconUrl,\n },\n aggregatedMarketValue: 0,\n positionTypes: {},\n };\n }\n\n const protocolData = chainData.protocols[protocolId];\n\n let positionTypeData = protocolData.positionTypes[positionType];\n if (!positionTypeData) {\n positionTypeData = {\n aggregatedMarketValue: 0,\n positions: [],\n };\n protocolData.positionTypes[positionType] = positionTypeData;\n }\n\n for (const protocolToken of position.tokens) {\n const token = processToken(protocolToken) as ProtocolTokenWithMarketValue;\n\n // If groupPositions is true, we group all positions of the same type\n if (position.metadata?.groupPositions) {\n if (positionTypeData.positions.length === 0) {\n positionTypeData.positions.push([token]);\n } else {\n positionTypeData.positions[0].push(token);\n }\n } else {\n positionTypeData.positions.push([token]);\n }\n\n if (token.marketValue) {\n const multiplier = position.positionType === 'borrow' ? -1 : 1;\n\n positionTypeData.aggregatedMarketValue += token.marketValue;\n protocolData.aggregatedMarketValue += token.marketValue * multiplier;\n chainData.aggregatedMarketValue += token.marketValue * multiplier;\n }\n }\n }\n\n return groupedDeFiPositions;\n}\n\n/**\n *\n * @param tokenBalance - The token balance that is going to be processed\n * @returns The processed token balance\n */\nfunction processToken<T extends Balance>(\n tokenBalance: T,\n): T & {\n marketValue?: number;\n tokens?: UnderlyingWithMarketValue[];\n} {\n if (!tokenBalance.tokens) {\n return {\n ...tokenBalance,\n marketValue: tokenBalance.price\n ? tokenBalance.balance * tokenBalance.price\n : undefined,\n };\n }\n\n const processedTokens = tokenBalance.tokens.map((t) => {\n const { tokens, ...tokenWithoutUnderlyings } = processToken(t);\n\n return tokenWithoutUnderlyings;\n });\n\n const marketValue = processedTokens.reduce<number | undefined>(\n (acc, t) =>\n acc === undefined || t.marketValue === undefined\n ? undefined\n : acc + t.marketValue,\n 0,\n );\n\n return {\n ...tokenBalance,\n marketValue,\n tokens: processedTokens,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"group-defi-positions.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,UAAU,EAEX,8BAA0B;AAE3B,MAAM,MAAM,oBAAoB,GAAG;IACjC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE;QACT,CAAC,UAAU,EAAE,MAAM,GAAG;YACpB,eAAe,EAAE;gBACf,IAAI,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,CAAC;aACjB,CAAC;YACF,qBAAqB,EAAE,MAAM,CAAC;YAC9B,aAAa,EAAE;iBACZ,GAAG,IAAI,YAAY,CAAC,CAAC,EAAE;oBACtB,qBAAqB,EAAE,MAAM,CAAC;oBAC9B,SAAS,EAAE,4BAA4B,EAAE,EAAE,CAAC;iBAC7C;aACF,CAAC;SACH,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,yBAAyB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,qBAAqB,EAAE,oBAAoB,EAAE,GAC5C;IACD,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB,CAAC;CAClC,CAqEA"}
1
+ {"version":3,"file":"group-defi-positions.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,UAAU,EAEX,8BAA6B;AAE9B,MAAM,MAAM,oBAAoB,GAAG;IACjC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE;QACT,CAAC,UAAU,EAAE,MAAM,GAAG;YACpB,eAAe,EAAE;gBACf,IAAI,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,CAAC;aACjB,CAAC;YACF,qBAAqB,EAAE,MAAM,CAAC;YAC9B,aAAa,EAAE;iBACZ,GAAG,IAAI,YAAY,CAAC,CAAC,EAAE;oBACtB,qBAAqB,EAAE,MAAM,CAAC;oBAC9B,SAAS,EAAE,4BAA4B,EAAE,EAAE,CAAC;iBAC7C;aACF,CAAC;SACH,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,yBAAyB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,qBAAqB,EAAE,oBAAoB,EAAE,GAC5C;IACD,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB,CAAC;CAClC,CAqEA"}
@@ -1 +1 @@
1
- {"version":3,"file":"group-defi-positions.d.mts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,UAAU,EAEX,8BAA0B;AAE3B,MAAM,MAAM,oBAAoB,GAAG;IACjC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE;QACT,CAAC,UAAU,EAAE,MAAM,GAAG;YACpB,eAAe,EAAE;gBACf,IAAI,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,CAAC;aACjB,CAAC;YACF,qBAAqB,EAAE,MAAM,CAAC;YAC9B,aAAa,EAAE;iBACZ,GAAG,IAAI,YAAY,CAAC,CAAC,EAAE;oBACtB,qBAAqB,EAAE,MAAM,CAAC;oBAC9B,SAAS,EAAE,4BAA4B,EAAE,EAAE,CAAC;iBAC7C;aACF,CAAC;SACH,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,yBAAyB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,qBAAqB,EAAE,oBAAoB,EAAE,GAC5C;IACD,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB,CAAC;CAClC,CAqEA"}
1
+ {"version":3,"file":"group-defi-positions.d.mts","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,UAAU,EAEX,8BAA6B;AAE9B,MAAM,MAAM,oBAAoB,GAAG;IACjC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE;QACT,CAAC,UAAU,EAAE,MAAM,GAAG;YACpB,eAAe,EAAE;gBACf,IAAI,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,CAAC;aACjB,CAAC;YACF,qBAAqB,EAAE,MAAM,CAAC;YAC9B,aAAa,EAAE;iBACZ,GAAG,IAAI,YAAY,CAAC,CAAC,EAAE;oBACtB,qBAAqB,EAAE,MAAM,CAAC;oBAC9B,SAAS,EAAE,4BAA4B,EAAE,EAAE,CAAC;iBAC7C;aACF,CAAC;SACH,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,yBAAyB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,qBAAqB,EAAE,oBAAoB,EAAE,GAC5C;IACD,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB,CAAC;CAClC,CAqEA"}
@@ -1 +1 @@
1
- {"version":3,"file":"group-defi-positions.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAuCnD;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,qBAA6C;IAI7C,MAAM,oBAAoB,GAAyC,EAAE,CAAC;IAEtE,KAAK,MAAM,QAAQ,IAAI,qBAAqB,EAAE,CAAC;QAC7C,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YACtB,SAAS;QACX,CAAC;QAED,MAAM,EAAE,OAAO,EAAE,UAAU,EAA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CACxC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CACT,GAAG,KAAK,SAAS,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS;QAC9C,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,WAAW,EACzB,CAAC,CACF,CAAC;IAEF,OAAO;QACL,GAAG,YAAY;QACf,WAAW;QACX,MAAM,EAAE,eAAe;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type {\n DefiPositionResponse,\n PositionType,\n ProtocolToken,\n Underlying,\n Balance,\n} from './fetch-positions';\n\nexport type GroupedDeFiPositions = {\n aggregatedMarketValue: number;\n protocols: {\n [protocolId: string]: {\n protocolDetails: {\n name: string;\n iconUrl: string;\n };\n aggregatedMarketValue: number;\n positionTypes: {\n [key in PositionType]?: {\n aggregatedMarketValue: number;\n positions: ProtocolTokenWithMarketValue[][];\n };\n };\n };\n };\n};\n\nexport type ProtocolTokenWithMarketValue = Omit<ProtocolToken, 'tokens'> & {\n marketValue?: number;\n tokens: UnderlyingWithMarketValue[];\n};\n\nexport type UnderlyingWithMarketValue = Omit<Underlying, 'tokens'> & {\n marketValue?: number;\n};\n\n/**\n *\n * @param defiPositionsResponse - The response from the defi positions API\n * @returns The grouped positions that get assigned to the state\n */\nexport function groupDeFiPositions(\n defiPositionsResponse: DefiPositionResponse[],\n): {\n [key: Hex]: GroupedDeFiPositions;\n} {\n const groupedDeFiPositions: { [key: Hex]: GroupedDeFiPositions } = {};\n\n for (const position of defiPositionsResponse) {\n if (!position.success) {\n continue;\n }\n\n const { chainId, protocolId, iconUrl, positionType, protocolDisplayName } =\n position;\n\n const chain = toHex(chainId);\n\n if (!groupedDeFiPositions[chain]) {\n groupedDeFiPositions[chain] = {\n aggregatedMarketValue: 0,\n protocols: {},\n };\n }\n\n const chainData = groupedDeFiPositions[chain];\n\n if (!chainData.protocols[protocolId]) {\n chainData.protocols[protocolId] = {\n protocolDetails: {\n name: protocolDisplayName,\n iconUrl,\n },\n aggregatedMarketValue: 0,\n positionTypes: {},\n };\n }\n\n const protocolData = chainData.protocols[protocolId];\n\n let positionTypeData = protocolData.positionTypes[positionType];\n if (!positionTypeData) {\n positionTypeData = {\n aggregatedMarketValue: 0,\n positions: [],\n };\n protocolData.positionTypes[positionType] = positionTypeData;\n }\n\n for (const protocolToken of position.tokens) {\n const token = processToken(protocolToken) as ProtocolTokenWithMarketValue;\n\n // If groupPositions is true, we group all positions of the same type\n if (position.metadata?.groupPositions) {\n if (positionTypeData.positions.length === 0) {\n positionTypeData.positions.push([token]);\n } else {\n positionTypeData.positions[0].push(token);\n }\n } else {\n positionTypeData.positions.push([token]);\n }\n\n if (token.marketValue) {\n const multiplier = position.positionType === 'borrow' ? -1 : 1;\n\n positionTypeData.aggregatedMarketValue += token.marketValue;\n protocolData.aggregatedMarketValue += token.marketValue * multiplier;\n chainData.aggregatedMarketValue += token.marketValue * multiplier;\n }\n }\n }\n\n return groupedDeFiPositions;\n}\n\n/**\n *\n * @param tokenBalance - The token balance that is going to be processed\n * @returns The processed token balance\n */\nfunction processToken<T extends Balance>(\n tokenBalance: T,\n): T & {\n marketValue?: number;\n tokens?: UnderlyingWithMarketValue[];\n} {\n if (!tokenBalance.tokens) {\n return {\n ...tokenBalance,\n marketValue: tokenBalance.price\n ? tokenBalance.balance * tokenBalance.price\n : undefined,\n };\n }\n\n const processedTokens = tokenBalance.tokens.map((t) => {\n const { tokens, ...tokenWithoutUnderlyings } = processToken(t);\n\n return tokenWithoutUnderlyings;\n });\n\n const marketValue = processedTokens.reduce<number | undefined>(\n (acc, t) =>\n acc === undefined || t.marketValue === undefined\n ? undefined\n : acc + t.marketValue,\n 0,\n );\n\n return {\n ...tokenBalance,\n marketValue,\n tokens: processedTokens,\n };\n}\n"]}
1
+ {"version":3,"file":"group-defi-positions.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/group-defi-positions.ts"],"names":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BAC3C,CAAC,CAAC,SAAS;SACd,CAAC;IACJ,CAAC;IAED,MAAM,eAAe,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACpD,MAAM,EAAE,MAAM,EAAE,GAAG,uBAAuB,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;QAE/D,OAAO,uBAAuB,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,eAAe,CAAC,MAAM,CACxC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CACT,GAAG,KAAK,SAAS,IAAI,CAAC,CAAC,WAAW,KAAK,SAAS;QAC9C,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,WAAW,EACzB,CAAC,CACF,CAAC;IAEF,OAAO;QACL,GAAG,YAAY;QACf,WAAW;QACX,MAAM,EAAE,eAAe;KACxB,CAAC;AACJ,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type {\n DefiPositionResponse,\n PositionType,\n ProtocolToken,\n Underlying,\n Balance,\n} from './fetch-positions.js';\n\nexport type GroupedDeFiPositions = {\n aggregatedMarketValue: number;\n protocols: {\n [protocolId: string]: {\n protocolDetails: {\n name: string;\n iconUrl: string;\n };\n aggregatedMarketValue: number;\n positionTypes: {\n [key in PositionType]?: {\n aggregatedMarketValue: number;\n positions: ProtocolTokenWithMarketValue[][];\n };\n };\n };\n };\n};\n\nexport type ProtocolTokenWithMarketValue = Omit<ProtocolToken, 'tokens'> & {\n marketValue?: number;\n tokens: UnderlyingWithMarketValue[];\n};\n\nexport type UnderlyingWithMarketValue = Omit<Underlying, 'tokens'> & {\n marketValue?: number;\n};\n\n/**\n *\n * @param defiPositionsResponse - The response from the defi positions API\n * @returns The grouped positions that get assigned to the state\n */\nexport function groupDeFiPositions(\n defiPositionsResponse: DefiPositionResponse[],\n): {\n [key: Hex]: GroupedDeFiPositions;\n} {\n const groupedDeFiPositions: { [key: Hex]: GroupedDeFiPositions } = {};\n\n for (const position of defiPositionsResponse) {\n if (!position.success) {\n continue;\n }\n\n const { chainId, protocolId, iconUrl, positionType, protocolDisplayName } =\n position;\n\n const chain = toHex(chainId);\n\n if (!groupedDeFiPositions[chain]) {\n groupedDeFiPositions[chain] = {\n aggregatedMarketValue: 0,\n protocols: {},\n };\n }\n\n const chainData = groupedDeFiPositions[chain];\n\n if (!chainData.protocols[protocolId]) {\n chainData.protocols[protocolId] = {\n protocolDetails: {\n name: protocolDisplayName,\n iconUrl,\n },\n aggregatedMarketValue: 0,\n positionTypes: {},\n };\n }\n\n const protocolData = chainData.protocols[protocolId];\n\n let positionTypeData = protocolData.positionTypes[positionType];\n if (!positionTypeData) {\n positionTypeData = {\n aggregatedMarketValue: 0,\n positions: [],\n };\n protocolData.positionTypes[positionType] = positionTypeData;\n }\n\n for (const protocolToken of position.tokens) {\n const token = processToken(protocolToken) as ProtocolTokenWithMarketValue;\n\n // If groupPositions is true, we group all positions of the same type\n if (position.metadata?.groupPositions) {\n if (positionTypeData.positions.length === 0) {\n positionTypeData.positions.push([token]);\n } else {\n positionTypeData.positions[0].push(token);\n }\n } else {\n positionTypeData.positions.push([token]);\n }\n\n if (token.marketValue) {\n const multiplier = position.positionType === 'borrow' ? -1 : 1;\n\n positionTypeData.aggregatedMarketValue += token.marketValue;\n protocolData.aggregatedMarketValue += token.marketValue * multiplier;\n chainData.aggregatedMarketValue += token.marketValue * multiplier;\n }\n }\n }\n\n return groupedDeFiPositions;\n}\n\n/**\n *\n * @param tokenBalance - The token balance that is going to be processed\n * @returns The processed token balance\n */\nfunction processToken<T extends Balance>(\n tokenBalance: T,\n): T & {\n marketValue?: number;\n tokens?: UnderlyingWithMarketValue[];\n} {\n if (!tokenBalance.tokens) {\n return {\n ...tokenBalance,\n marketValue: tokenBalance.price\n ? tokenBalance.balance * tokenBalance.price\n : undefined,\n };\n }\n\n const processedTokens = tokenBalance.tokens.map((t) => {\n const { tokens, ...tokenWithoutUnderlyings } = processToken(t);\n\n return tokenWithoutUnderlyings;\n });\n\n const marketValue = processedTokens.reduce<number | undefined>(\n (acc, t) =>\n acc === undefined || t.marketValue === undefined\n ? undefined\n : acc + t.marketValue,\n 0,\n );\n\n return {\n ...tokenBalance,\n marketValue,\n tokens: processedTokens,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"merge-positions-for-accounts.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/merge-positions-for-accounts.ts"],"names":[],"mappings":";;;AAMA;;;;;;;;GAQG;AACH,SAAS,aAAa,CACpB,gBAA8C,EAC9C,gBAA8C;IAE9C,MAAM,aAAa,GAAG,IAAI,GAAG,CAC3B,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAChC,OAAO,CAAC,WAAW;QACnB,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,EAAE;KAClD,CAAC,CACH,CAAC;IAEF,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;QACvC,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAExD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE;gBACrC,GAAG,OAAO;gBACV,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;aAClC,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QAED,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,yBAAyB,CACvC,kBAA0C,EAC1C,UAAoB;IAEpB,MAAM,KA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\n} from './group-defi-positions-v6';\n\n/**\n * Merges details-page sections that share the same `productName`, appending\n * positions rather than keeping them as separate adjacent sections.\n *\n * @param existingSections - Sections already collected for this protocol group.\n * @param incomingSections - Sections from another account holding the same\n * protocol, to be merged in.\n * @returns The merged sections, one per distinct `productName`.\n */\nfunction mergeSections(\n existingSections: DeFiPositionDetailsSection[],\n incomingSections: DeFiPositionDetailsSection[],\n): DeFiPositionDetailsSection[] {\n const byProductName = new Map<string, DeFiPositionDetailsSection>(\n existingSections.map((section) => [\n section.productName,\n { ...section, positions: [...section.positions] },\n ]),\n );\n\n for (const section of incomingSections) {\n const existing = byProductName.get(section.productName);\n\n if (!existing) {\n byProductName.set(section.productName, {\n ...section,\n positions: [...section.positions],\n });\n continue;\n }\n\n existing.positions.push(...section.positions);\n }\n\n return [...byProductName.values()];\n}\n\n/**\n * Merges the protocol groups of every account in the selected group into a\n * single flat list, combining groups that share the same chain and protocol.\n *\n * The controller stores DeFi positions keyed per internal account, but every\n * client surface consumes the selected account group as a single merged list.\n * This helper is exported so both clients share one implementation rather than\n * each maintaining a copy.\n *\n * @param positionsByAccount - DeFi positions keyed by internal account ID.\n * @param accountIds - Internal account IDs in the selected account group.\n * @returns The merged protocol groups.\n */\nexport function mergePositionsForAccounts(\n positionsByAccount: DeFiPositionsByAccount,\n accountIds: string[],\n): DeFiProtocolPositionGroup[] {\n const byKey = new Map<string, DeFiProtocolPositionGroup>();\n\n for (const accountId of accountIds) {\n for (const group of positionsByAccount[accountId] ?? []) {\n const key = `${group.chainId}#${group.protocolId}`;\n const existing = byKey.get(key);\n\n if (!existing) {\n // Clone so we never mutate the object held in client state.\n byKey.set(key, {\n ...group,\n iconGroup: [...group.iconGroup],\n sections: mergeSections([], group.sections),\n });\n continue;\n }\n\n existing.marketValue += group.marketValue;\n for (const icon of group.iconGroup) {\n if (!existing.iconGroup.some((item) => item.symbol === icon.symbol)) {\n existing.iconGroup.push(icon);\n }\n }\n existing.sections = mergeSections(existing.sections, group.sections);\n }\n }\n\n return [...byKey.values()];\n}\n"]}
1
+ {"version":3,"file":"merge-positions-for-accounts.cjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/merge-positions-for-accounts.ts"],"names":[],"mappings":";;;AAMA;;;;;;;;GAQG;AACH,SAAS,aAAa,CACpB,gBAA8C,EAC9C,gBAA8C;IAE9C,MAAM,aAAa,GAAG,IAAI,GAAG,CAC3B,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAChC,OAAO,CAAC,WAAW;QACnB,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,EAAE;KAClD,CAAC,CACH,CAAC;IAEF,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;QACvC,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAExD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE;gBACrC,GAAG,OAAO;gBACV,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;aAClC,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QAED,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,yBAAyB,CACvC,kBAA0C,EAC1C,UAAoB;IAEpB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAqC,CAAC;IAE3D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,KAAK,MAAM,KAAK,IAAI,kBAAkB,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;YACxD,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;YACnD,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAEhC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,4DAA4D;gBAC5D,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;oBACb,GAAG,KAAK;oBACR,SAAS,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;oBAC/B,QAAQ,EAAE,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC,QAAQ,CAAC;iBAC5C,CAAC,CAAC;gBACH,SAAS;YACX,CAAC;YAED,QAAQ,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,CAAC;YAC1C,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;gBACnC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;oBACpE,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAChC,CAAC;YACH,CAAC;YACD,QAAQ,CAAC,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;AAC7B,CAAC;AAhCD,8DAgCC","sourcesContent":["import type {\n DeFiPositionDetailsSection,\n DeFiPositionsByAccount,\n DeFiProtocolPositionGroup,\n} from './group-defi-positions-v6.js';\n\n/**\n * Merges details-page sections that share the same `productName`, appending\n * positions rather than keeping them as separate adjacent sections.\n *\n * @param existingSections - Sections already collected for this protocol group.\n * @param incomingSections - Sections from another account holding the same\n * protocol, to be merged in.\n * @returns The merged sections, one per distinct `productName`.\n */\nfunction mergeSections(\n existingSections: DeFiPositionDetailsSection[],\n incomingSections: DeFiPositionDetailsSection[],\n): DeFiPositionDetailsSection[] {\n const byProductName = new Map<string, DeFiPositionDetailsSection>(\n existingSections.map((section) => [\n section.productName,\n { ...section, positions: [...section.positions] },\n ]),\n );\n\n for (const section of incomingSections) {\n const existing = byProductName.get(section.productName);\n\n if (!existing) {\n byProductName.set(section.productName, {\n ...section,\n positions: [...section.positions],\n });\n continue;\n }\n\n existing.positions.push(...section.positions);\n }\n\n return [...byProductName.values()];\n}\n\n/**\n * Merges the protocol groups of every account in the selected group into a\n * single flat list, combining groups that share the same chain and protocol.\n *\n * The controller stores DeFi positions keyed per internal account, but every\n * client surface consumes the selected account group as a single merged list.\n * This helper is exported so both clients share one implementation rather than\n * each maintaining a copy.\n *\n * @param positionsByAccount - DeFi positions keyed by internal account ID.\n * @param accountIds - Internal account IDs in the selected account group.\n * @returns The merged protocol groups.\n */\nexport function mergePositionsForAccounts(\n positionsByAccount: DeFiPositionsByAccount,\n accountIds: string[],\n): DeFiProtocolPositionGroup[] {\n const byKey = new Map<string, DeFiProtocolPositionGroup>();\n\n for (const accountId of accountIds) {\n for (const group of positionsByAccount[accountId] ?? []) {\n const key = `${group.chainId}#${group.protocolId}`;\n const existing = byKey.get(key);\n\n if (!existing) {\n // Clone so we never mutate the object held in client state.\n byKey.set(key, {\n ...group,\n iconGroup: [...group.iconGroup],\n sections: mergeSections([], group.sections),\n });\n continue;\n }\n\n existing.marketValue += group.marketValue;\n for (const icon of group.iconGroup) {\n if (!existing.iconGroup.some((item) => item.symbol === icon.symbol)) {\n existing.iconGroup.push(icon);\n }\n }\n existing.sections = mergeSections(existing.sections, group.sections);\n }\n }\n\n return [...byKey.values()];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"merge-positions-for-accounts.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/merge-positions-for-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,sBAAsB,EACtB,yBAAyB,EAC1B,sCAAkC;AAuCnC;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,kBAAkB,EAAE,sBAAsB,EAC1C,UAAU,EAAE,MAAM,EAAE,GACnB,yBAAyB,EAAE,CA6B7B"}
1
+ {"version":3,"file":"merge-positions-for-accounts.d.cts","sourceRoot":"","sources":["../../src/DeFiPositionsController/merge-positions-for-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,sBAAsB,EACtB,yBAAyB,EAC1B,sCAAqC;AAuCtC;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,kBAAkB,EAAE,sBAAsB,EAC1C,UAAU,EAAE,MAAM,EAAE,GACnB,yBAAyB,EAAE,CA6B7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"merge-positions-for-accounts.d.mts","sourceRoot":"","sources":["../../src/DeFiPositionsController/merge-positions-for-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,sBAAsB,EACtB,yBAAyB,EAC1B,sCAAkC;AAuCnC;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,kBAAkB,EAAE,sBAAsB,EAC1C,UAAU,EAAE,MAAM,EAAE,GACnB,yBAAyB,EAAE,CA6B7B"}
1
+ {"version":3,"file":"merge-positions-for-accounts.d.mts","sourceRoot":"","sources":["../../src/DeFiPositionsController/merge-positions-for-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,sBAAsB,EACtB,yBAAyB,EAC1B,sCAAqC;AAuCtC;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,kBAAkB,EAAE,sBAAsB,EAC1C,UAAU,EAAE,MAAM,EAAE,GACnB,yBAAyB,EAAE,CA6B7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"merge-positions-for-accounts.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/merge-positions-for-accounts.ts"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AACH,SAAS,aAAa,CACpB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AC,GAAG,CAAC,GAAG,EAAE;oBACb,GAAG,KAAK;oBACR,SAAS,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;oBAC/B,QAAQ,EAAE,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC,QAAQ,CAAC;iBAC5C,CAAC,CAAC;gBACH,SAAS;YACX,CAAC;YAED,QAAQ,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,CAAC;YAC1C,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;gBACnC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;oBACpE,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAChC,CAAC;YACH,CAAC;YACD,QAAQ,CAAC,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import type {\n DeFiPositionDetailsSection,\n DeFiPositionsByAccount,\n DeFiProtocolPositionGroup,\n} from './group-defi-positions-v6';\n\n/**\n * Merges details-page sections that share the same `productName`, appending\n * positions rather than keeping them as separate adjacent sections.\n *\n * @param existingSections - Sections already collected for this protocol group.\n * @param incomingSections - Sections from another account holding the same\n * protocol, to be merged in.\n * @returns The merged sections, one per distinct `productName`.\n */\nfunction mergeSections(\n existingSections: DeFiPositionDetailsSection[],\n incomingSections: DeFiPositionDetailsSection[],\n): DeFiPositionDetailsSection[] {\n const byProductName = new Map<string, DeFiPositionDetailsSection>(\n existingSections.map((section) => [\n section.productName,\n { ...section, positions: [...section.positions] },\n ]),\n );\n\n for (const section of incomingSections) {\n const existing = byProductName.get(section.productName);\n\n if (!existing) {\n byProductName.set(section.productName, {\n ...section,\n positions: [...section.positions],\n });\n continue;\n }\n\n existing.positions.push(...section.positions);\n }\n\n return [...byProductName.values()];\n}\n\n/**\n * Merges the protocol groups of every account in the selected group into a\n * single flat list, combining groups that share the same chain and protocol.\n *\n * The controller stores DeFi positions keyed per internal account, but every\n * client surface consumes the selected account group as a single merged list.\n * This helper is exported so both clients share one implementation rather than\n * each maintaining a copy.\n *\n * @param positionsByAccount - DeFi positions keyed by internal account ID.\n * @param accountIds - Internal account IDs in the selected account group.\n * @returns The merged protocol groups.\n */\nexport function mergePositionsForAccounts(\n positionsByAccount: DeFiPositionsByAccount,\n accountIds: string[],\n): DeFiProtocolPositionGroup[] {\n const byKey = new Map<string, DeFiProtocolPositionGroup>();\n\n for (const accountId of accountIds) {\n for (const group of positionsByAccount[accountId] ?? []) {\n const key = `${group.chainId}#${group.protocolId}`;\n const existing = byKey.get(key);\n\n if (!existing) {\n // Clone so we never mutate the object held in client state.\n byKey.set(key, {\n ...group,\n iconGroup: [...group.iconGroup],\n sections: mergeSections([], group.sections),\n });\n continue;\n }\n\n existing.marketValue += group.marketValue;\n for (const icon of group.iconGroup) {\n if (!existing.iconGroup.some((item) => item.symbol === icon.symbol)) {\n existing.iconGroup.push(icon);\n }\n }\n existing.sections = mergeSections(existing.sections, group.sections);\n }\n }\n\n return [...byKey.values()];\n}\n"]}
1
+ {"version":3,"file":"merge-positions-for-accounts.mjs","sourceRoot":"","sources":["../../src/DeFiPositionsController/merge-positions-for-accounts.ts"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AACH,SAAS,aAAa,CACpB,gBAA8C,EAC9C,gBAA8C;IAE9C,MAAM,aAAa,GAAG,IAAI,GAAG,CAC3B,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAChC,OAAO,CAAC,WAAW;QACnB,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,C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,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,CAAC;YAC1C,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;gBACnC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;oBACpE,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAChC,CAAC;YACH,CAAC;YACD,QAAQ,CAAC,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import type {\n DeFiPositionDetailsSection,\n DeFiPositionsByAccount,\n DeFiProtocolPositionGroup,\n} from './group-defi-positions-v6.js';\n\n/**\n * Merges details-page sections that share the same `productName`, appending\n * positions rather than keeping them as separate adjacent sections.\n *\n * @param existingSections - Sections already collected for this protocol group.\n * @param incomingSections - Sections from another account holding the same\n * protocol, to be merged in.\n * @returns The merged sections, one per distinct `productName`.\n */\nfunction mergeSections(\n existingSections: DeFiPositionDetailsSection[],\n incomingSections: DeFiPositionDetailsSection[],\n): DeFiPositionDetailsSection[] {\n const byProductName = new Map<string, DeFiPositionDetailsSection>(\n existingSections.map((section) => [\n section.productName,\n { ...section, positions: [...section.positions] },\n ]),\n );\n\n for (const section of incomingSections) {\n const existing = byProductName.get(section.productName);\n\n if (!existing) {\n byProductName.set(section.productName, {\n ...section,\n positions: [...section.positions],\n });\n continue;\n }\n\n existing.positions.push(...section.positions);\n }\n\n return [...byProductName.values()];\n}\n\n/**\n * Merges the protocol groups of every account in the selected group into a\n * single flat list, combining groups that share the same chain and protocol.\n *\n * The controller stores DeFi positions keyed per internal account, but every\n * client surface consumes the selected account group as a single merged list.\n * This helper is exported so both clients share one implementation rather than\n * each maintaining a copy.\n *\n * @param positionsByAccount - DeFi positions keyed by internal account ID.\n * @param accountIds - Internal account IDs in the selected account group.\n * @returns The merged protocol groups.\n */\nexport function mergePositionsForAccounts(\n positionsByAccount: DeFiPositionsByAccount,\n accountIds: string[],\n): DeFiProtocolPositionGroup[] {\n const byKey = new Map<string, DeFiProtocolPositionGroup>();\n\n for (const accountId of accountIds) {\n for (const group of positionsByAccount[accountId] ?? []) {\n const key = `${group.chainId}#${group.protocolId}`;\n const existing = byKey.get(key);\n\n if (!existing) {\n // Clone so we never mutate the object held in client state.\n byKey.set(key, {\n ...group,\n iconGroup: [...group.iconGroup],\n sections: mergeSections([], group.sections),\n });\n continue;\n }\n\n existing.marketValue += group.marketValue;\n for (const icon of group.iconGroup) {\n if (!existing.iconGroup.some((item) => item.symbol === icon.symbol)) {\n existing.iconGroup.push(icon);\n }\n }\n existing.sections = mergeSections(existing.sections, group.sections);\n }\n }\n\n return [...byKey.values()];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MultichainAssetsController-method-action-types.cjs","sourceRoot":"","sources":["../../src/MultichainAssetsController/MultichainAssetsController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { MultichainAssetsController } from './MultichainAssetsController';\n\n/**\n * Returns the metadata for the given asset\n *\n * @param asset - The asset to get metadata for\n * @returns The metadata for the asset or undefined if not found.\n */\nexport type MultichainAssetsControllerGetAssetMetadataAction = {\n type: `MultichainAssetsController:getAssetMetadata`;\n handler: MultichainAssetsController['getAssetMetadata'];\n};\n\n/**\n * Ignores a batch of assets for a specific account.\n *\n * @param assetsToIgnore - Array of asset IDs to ignore.\n * @param accountId - The account ID to ignore assets for.\n */\nexport type MultichainAssetsControllerIgnoreAssetsAction = {\n type: `MultichainAssetsController:ignoreAssets`;\n handler: MultichainAssetsController['ignoreAssets'];\n};\n\n/**\n * Adds multiple assets to the stored asset list for a specific account.\n * All assets must belong to the same chain.\n *\n * @param assetIds - Array of CAIP asset IDs to add (must be from same chain).\n * @param accountId - The account ID to add the assets to.\n * @returns The updated asset list for the account.\n * @throws Error if assets are from different chains.\n */\nexport type MultichainAssetsControllerAddAssetsAction = {\n type: `MultichainAssetsController:addAssets`;\n handler: MultichainAssetsController['addAssets'];\n};\n\n/**\n * Union of all MultichainAssetsController action types.\n */\nexport type MultichainAssetsControllerMethodActions =\n | MultichainAssetsControllerGetAssetMetadataAction\n | MultichainAssetsControllerIgnoreAssetsAction\n | MultichainAssetsControllerAddAssetsAction;\n"]}
1
+ {"version":3,"file":"MultichainAssetsController-method-action-types.cjs","sourceRoot":"","sources":["../../src/MultichainAssetsController/MultichainAssetsController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { MultichainAssetsController } from './MultichainAssetsController.js';\n\n/**\n * Returns the metadata for the given asset\n *\n * @param asset - The asset to get metadata for\n * @returns The metadata for the asset or undefined if not found.\n */\nexport type MultichainAssetsControllerGetAssetMetadataAction = {\n type: `MultichainAssetsController:getAssetMetadata`;\n handler: MultichainAssetsController['getAssetMetadata'];\n};\n\n/**\n * Ignores a batch of assets for a specific account.\n *\n * @param assetsToIgnore - Array of asset IDs to ignore.\n * @param accountId - The account ID to ignore assets for.\n */\nexport type MultichainAssetsControllerIgnoreAssetsAction = {\n type: `MultichainAssetsController:ignoreAssets`;\n handler: MultichainAssetsController['ignoreAssets'];\n};\n\n/**\n * Adds multiple assets to the stored asset list for a specific account.\n * All assets must belong to the same chain.\n *\n * @param assetIds - Array of CAIP asset IDs to add (must be from same chain).\n * @param accountId - The account ID to add the assets to.\n * @returns The updated asset list for the account.\n * @throws Error if assets are from different chains.\n */\nexport type MultichainAssetsControllerAddAssetsAction = {\n type: `MultichainAssetsController:addAssets`;\n handler: MultichainAssetsController['addAssets'];\n};\n\n/**\n * Union of all MultichainAssetsController action types.\n */\nexport type MultichainAssetsControllerMethodActions =\n | MultichainAssetsControllerGetAssetMetadataAction\n | MultichainAssetsControllerIgnoreAssetsAction\n | MultichainAssetsControllerAddAssetsAction;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MultichainAssetsController-method-action-types.d.cts","sourceRoot":"","sources":["../../src/MultichainAssetsController/MultichainAssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,yCAAqC;AAE/E;;;;;GAKG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;CACzD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,0BAA0B,CAAC,cAAc,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,0BAA0B,CAAC,WAAW,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uCAAuC,GAC/C,gDAAgD,GAChD,4CAA4C,GAC5C,yCAAyC,CAAC"}
1
+ {"version":3,"file":"MultichainAssetsController-method-action-types.d.cts","sourceRoot":"","sources":["../../src/MultichainAssetsController/MultichainAssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,yCAAwC;AAElF;;;;;GAKG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;CACzD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,0BAA0B,CAAC,cAAc,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,0BAA0B,CAAC,WAAW,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uCAAuC,GAC/C,gDAAgD,GAChD,4CAA4C,GAC5C,yCAAyC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MultichainAssetsController-method-action-types.d.mts","sourceRoot":"","sources":["../../src/MultichainAssetsController/MultichainAssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,yCAAqC;AAE/E;;;;;GAKG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;CACzD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,0BAA0B,CAAC,cAAc,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,0BAA0B,CAAC,WAAW,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uCAAuC,GAC/C,gDAAgD,GAChD,4CAA4C,GAC5C,yCAAyC,CAAC"}
1
+ {"version":3,"file":"MultichainAssetsController-method-action-types.d.mts","sourceRoot":"","sources":["../../src/MultichainAssetsController/MultichainAssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,yCAAwC;AAElF;;;;;GAKG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;CACzD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,0BAA0B,CAAC,cAAc,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,yCAAyC,GAAG;IACtD,IAAI,EAAE,sCAAsC,CAAC;IAC7C,OAAO,EAAE,0BAA0B,CAAC,WAAW,CAAC,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uCAAuC,GAC/C,gDAAgD,GAChD,4CAA4C,GAC5C,yCAAyC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MultichainAssetsController-method-action-types.mjs","sourceRoot":"","sources":["../../src/MultichainAssetsController/MultichainAssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { MultichainAssetsController } from './MultichainAssetsController';\n\n/**\n * Returns the metadata for the given asset\n *\n * @param asset - The asset to get metadata for\n * @returns The metadata for the asset or undefined if not found.\n */\nexport type MultichainAssetsControllerGetAssetMetadataAction = {\n type: `MultichainAssetsController:getAssetMetadata`;\n handler: MultichainAssetsController['getAssetMetadata'];\n};\n\n/**\n * Ignores a batch of assets for a specific account.\n *\n * @param assetsToIgnore - Array of asset IDs to ignore.\n * @param accountId - The account ID to ignore assets for.\n */\nexport type MultichainAssetsControllerIgnoreAssetsAction = {\n type: `MultichainAssetsController:ignoreAssets`;\n handler: MultichainAssetsController['ignoreAssets'];\n};\n\n/**\n * Adds multiple assets to the stored asset list for a specific account.\n * All assets must belong to the same chain.\n *\n * @param assetIds - Array of CAIP asset IDs to add (must be from same chain).\n * @param accountId - The account ID to add the assets to.\n * @returns The updated asset list for the account.\n * @throws Error if assets are from different chains.\n */\nexport type MultichainAssetsControllerAddAssetsAction = {\n type: `MultichainAssetsController:addAssets`;\n handler: MultichainAssetsController['addAssets'];\n};\n\n/**\n * Union of all MultichainAssetsController action types.\n */\nexport type MultichainAssetsControllerMethodActions =\n | MultichainAssetsControllerGetAssetMetadataAction\n | MultichainAssetsControllerIgnoreAssetsAction\n | MultichainAssetsControllerAddAssetsAction;\n"]}
1
+ {"version":3,"file":"MultichainAssetsController-method-action-types.mjs","sourceRoot":"","sources":["../../src/MultichainAssetsController/MultichainAssetsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { MultichainAssetsController } from './MultichainAssetsController.js';\n\n/**\n * Returns the metadata for the given asset\n *\n * @param asset - The asset to get metadata for\n * @returns The metadata for the asset or undefined if not found.\n */\nexport type MultichainAssetsControllerGetAssetMetadataAction = {\n type: `MultichainAssetsController:getAssetMetadata`;\n handler: MultichainAssetsController['getAssetMetadata'];\n};\n\n/**\n * Ignores a batch of assets for a specific account.\n *\n * @param assetsToIgnore - Array of asset IDs to ignore.\n * @param accountId - The account ID to ignore assets for.\n */\nexport type MultichainAssetsControllerIgnoreAssetsAction = {\n type: `MultichainAssetsController:ignoreAssets`;\n handler: MultichainAssetsController['ignoreAssets'];\n};\n\n/**\n * Adds multiple assets to the stored asset list for a specific account.\n * All assets must belong to the same chain.\n *\n * @param assetIds - Array of CAIP asset IDs to add (must be from same chain).\n * @param accountId - The account ID to add the assets to.\n * @returns The updated asset list for the account.\n * @throws Error if assets are from different chains.\n */\nexport type MultichainAssetsControllerAddAssetsAction = {\n type: `MultichainAssetsController:addAssets`;\n handler: MultichainAssetsController['addAssets'];\n};\n\n/**\n * Union of all MultichainAssetsController action types.\n */\nexport type MultichainAssetsControllerMethodActions =\n | MultichainAssetsControllerGetAssetMetadataAction\n | MultichainAssetsControllerIgnoreAssetsAction\n | MultichainAssetsControllerAddAssetsAction;\n"]}
@@ -20,7 +20,7 @@ const polling_controller_1 = require("@metamask/polling-controller");
20
20
  const snaps_utils_1 = require("@metamask/snaps-utils");
21
21
  const utils_1 = require("@metamask/utils");
22
22
  const async_mutex_1 = require("async-mutex");
23
- const utils_2 = require("./utils.cjs");
23
+ const utils_js_1 = require("./utils.cjs");
24
24
  const controllerName = 'MultichainAssetsController';
25
25
  /**
26
26
  * Constructs the default {@link MultichainAssetsController} state. This allows
@@ -449,7 +449,7 @@ async function _MultichainAssetsController_updateAssetsMetadata(assets) {
449
449
  for (const [index, permission] of allPermissions.entries()) {
450
450
  let scopes;
451
451
  for (const singlePermissionConstraint of Object.values(permission)) {
452
- scopes = (0, utils_2.getChainIdsCaveat)(singlePermissionConstraint);
452
+ scopes = (0, utils_js_1.getChainIdsCaveat)(singlePermissionConstraint);
453
453
  if (!scopes) {
454
454
  continue;
455
455
  }