@metamask/assets-controllers 45.1.2 → 46.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 (102) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/dist/MultichainBalancesController/BalancesTracker.cjs +122 -0
  3. package/dist/MultichainBalancesController/BalancesTracker.cjs.map +1 -0
  4. package/dist/MultichainBalancesController/BalancesTracker.d.cts +54 -0
  5. package/dist/MultichainBalancesController/BalancesTracker.d.cts.map +1 -0
  6. package/dist/MultichainBalancesController/BalancesTracker.d.mts +54 -0
  7. package/dist/MultichainBalancesController/BalancesTracker.d.mts.map +1 -0
  8. package/dist/MultichainBalancesController/BalancesTracker.mjs +118 -0
  9. package/dist/MultichainBalancesController/BalancesTracker.mjs.map +1 -0
  10. package/dist/MultichainBalancesController/MultichainBalancesController.cjs +194 -0
  11. package/dist/MultichainBalancesController/MultichainBalancesController.cjs.map +1 -0
  12. package/dist/MultichainBalancesController/MultichainBalancesController.d.cts +94 -0
  13. package/dist/MultichainBalancesController/MultichainBalancesController.d.cts.map +1 -0
  14. package/dist/MultichainBalancesController/MultichainBalancesController.d.mts +94 -0
  15. package/dist/MultichainBalancesController/MultichainBalancesController.d.mts.map +1 -0
  16. package/dist/MultichainBalancesController/MultichainBalancesController.mjs +189 -0
  17. package/dist/MultichainBalancesController/MultichainBalancesController.mjs.map +1 -0
  18. package/dist/MultichainBalancesController/Poller.cjs +45 -0
  19. package/dist/MultichainBalancesController/Poller.cjs.map +1 -0
  20. package/dist/MultichainBalancesController/Poller.d.cts +7 -0
  21. package/dist/MultichainBalancesController/Poller.d.cts.map +1 -0
  22. package/dist/MultichainBalancesController/Poller.d.mts +7 -0
  23. package/dist/MultichainBalancesController/Poller.d.mts.map +1 -0
  24. package/dist/MultichainBalancesController/Poller.mjs +41 -0
  25. package/dist/MultichainBalancesController/Poller.mjs.map +1 -0
  26. package/dist/MultichainBalancesController/constants.cjs +45 -0
  27. package/dist/MultichainBalancesController/constants.cjs.map +1 -0
  28. package/dist/MultichainBalancesController/constants.d.cts +29 -0
  29. package/dist/MultichainBalancesController/constants.d.cts.map +1 -0
  30. package/dist/MultichainBalancesController/constants.d.mts +29 -0
  31. package/dist/MultichainBalancesController/constants.d.mts.map +1 -0
  32. package/dist/MultichainBalancesController/constants.mjs +42 -0
  33. package/dist/MultichainBalancesController/constants.mjs.map +1 -0
  34. package/dist/MultichainBalancesController/error.cjs +18 -0
  35. package/dist/MultichainBalancesController/error.cjs.map +1 -0
  36. package/dist/MultichainBalancesController/error.d.cts +7 -0
  37. package/dist/MultichainBalancesController/error.d.cts.map +1 -0
  38. package/dist/MultichainBalancesController/error.d.mts +7 -0
  39. package/dist/MultichainBalancesController/error.d.mts.map +1 -0
  40. package/dist/MultichainBalancesController/error.mjs +13 -0
  41. package/dist/MultichainBalancesController/error.mjs.map +1 -0
  42. package/dist/MultichainBalancesController/index.cjs +13 -0
  43. package/dist/MultichainBalancesController/index.cjs.map +1 -0
  44. package/dist/MultichainBalancesController/index.d.cts +5 -0
  45. package/dist/MultichainBalancesController/index.d.cts.map +1 -0
  46. package/dist/MultichainBalancesController/index.d.mts +5 -0
  47. package/dist/MultichainBalancesController/index.d.mts.map +1 -0
  48. package/dist/MultichainBalancesController/index.mjs +4 -0
  49. package/dist/MultichainBalancesController/index.mjs.map +1 -0
  50. package/dist/MultichainBalancesController/utils.cjs +73 -0
  51. package/dist/MultichainBalancesController/utils.cjs.map +1 -0
  52. package/dist/MultichainBalancesController/utils.d.cts +36 -0
  53. package/dist/MultichainBalancesController/utils.d.cts.map +1 -0
  54. package/dist/MultichainBalancesController/utils.d.mts +36 -0
  55. package/dist/MultichainBalancesController/utils.d.mts.map +1 -0
  56. package/dist/MultichainBalancesController/utils.mjs +66 -0
  57. package/dist/MultichainBalancesController/utils.mjs.map +1 -0
  58. package/dist/NftController.cjs +14 -7
  59. package/dist/NftController.cjs.map +1 -1
  60. package/dist/NftController.d.cts.map +1 -1
  61. package/dist/NftController.d.mts.map +1 -1
  62. package/dist/NftController.mjs +14 -7
  63. package/dist/NftController.mjs.map +1 -1
  64. package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs +1 -1
  65. package/dist/Standards/NftStandards/ERC721/ERC721Standard.cjs.map +1 -1
  66. package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs +1 -1
  67. package/dist/Standards/NftStandards/ERC721/ERC721Standard.mjs.map +1 -1
  68. package/dist/TokensController.cjs +6 -4
  69. package/dist/TokensController.cjs.map +1 -1
  70. package/dist/TokensController.d.cts.map +1 -1
  71. package/dist/TokensController.d.mts.map +1 -1
  72. package/dist/TokensController.mjs +6 -4
  73. package/dist/TokensController.mjs.map +1 -1
  74. package/dist/assetsUtil.cjs +16 -1
  75. package/dist/assetsUtil.cjs.map +1 -1
  76. package/dist/assetsUtil.d.cts +7 -0
  77. package/dist/assetsUtil.d.cts.map +1 -1
  78. package/dist/assetsUtil.d.mts +7 -0
  79. package/dist/assetsUtil.d.mts.map +1 -1
  80. package/dist/assetsUtil.mjs +14 -0
  81. package/dist/assetsUtil.mjs.map +1 -1
  82. package/dist/crypto-compare-service/crypto-compare.cjs +5 -2
  83. package/dist/crypto-compare-service/crypto-compare.cjs.map +1 -1
  84. package/dist/crypto-compare-service/crypto-compare.d.cts.map +1 -1
  85. package/dist/crypto-compare-service/crypto-compare.d.mts.map +1 -1
  86. package/dist/crypto-compare-service/crypto-compare.mjs +5 -2
  87. package/dist/crypto-compare-service/crypto-compare.mjs.map +1 -1
  88. package/dist/index.cjs +10 -1
  89. package/dist/index.cjs.map +1 -1
  90. package/dist/index.d.cts +3 -1
  91. package/dist/index.d.cts.map +1 -1
  92. package/dist/index.d.mts +3 -1
  93. package/dist/index.d.mts.map +1 -1
  94. package/dist/index.mjs +4 -1
  95. package/dist/index.mjs.map +1 -1
  96. package/dist/multicall.cjs +16 -3
  97. package/dist/multicall.cjs.map +1 -1
  98. package/dist/multicall.d.cts.map +1 -1
  99. package/dist/multicall.d.mts.map +1 -1
  100. package/dist/multicall.mjs +16 -3
  101. package/dist/multicall.mjs.map +1 -1
  102. package/package.json +16 -10
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/constants.ts"],"names":[],"mappings":";;;AAAA,uDAAuE;AAEvE;;;;GAIG;AACH,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,yEAAmD,CAAA;IACnD,gFAA0D,CAAA;IAC1D,wEAAkD,CAAA;IAClD,8EAAwD,CAAA;IACxD,+EAAyD,CAAA;AAC3D,CAAC,EANW,kBAAkB,kCAAlB,kBAAkB,QAM7B;AAED,IAAY,sBAMX;AAND,WAAY,sBAAsB;IAChC,sFAAkD,CAAA;IAClD,6FAAgE,CAAA;IAChE,uFAAkD,CAAA;IAClD,6FAA8D,CAAA;IAC9D,8FAAgE,CAAA;AAClE,CAAC,EANW,sBAAsB,sCAAtB,sBAAsB,QAMjC;AAED,MAAM,sBAAsB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,6BAA6B;AAC5E,MAAM,qBAAqB,GAAG,GAAG,CAAC,CAAC,mBAAmB;AAEzC,QAAA,wBAAwB,GAAG;IACtC,sEAAsE;IACtE,+EAA+E;IAC/E,CAAC,4BAAc,CAAC,MAAM,CAAC,EAAE,sBAAsB,GAAG,CAAC;IACnD,CAAC,4BAAc,CAAC,WAAW,CAAC,EAAE,qBAAqB;CACpD,CAAC;AAEF;;;GAGG;AACU,QAAA,kBAAkB,GAA6C;IAC1E,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,sBAAsB,CAAC,MAAM,CAAC;IAC5D,CAAC,kBAAkB,CAAC,aAAa,CAAC,EAAE,CAAC,sBAAsB,CAAC,aAAa,CAAC;IAC1E,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC,sBAAsB,CAAC,YAAY,CAAC;IACxE,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,sBAAsB,CAAC,OAAO,CAAC;IAC9D,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,CAAC,sBAAsB,CAAC,cAAc,CAAC;CAC7E,CAAC","sourcesContent":["import { BtcAccountType, SolAccountType } from '@metamask/keyring-api';\n\n/**\n * The network identifiers for supported networks in CAIP-2 format.\n * Note: This is a temporary workaround until we have a more robust\n * solution for network identifiers.\n */\nexport enum MultichainNetworks {\n Bitcoin = 'bip122:000000000019d6689c085ae165831e93',\n BitcoinTestnet = 'bip122:000000000933ea01ad0ee984209779ba',\n Solana = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',\n SolanaDevnet = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',\n SolanaTestnet = 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',\n}\n\nexport enum MultichainNativeAssets {\n Bitcoin = `${MultichainNetworks.Bitcoin}/slip44:0`,\n BitcoinTestnet = `${MultichainNetworks.BitcoinTestnet}/slip44:0`,\n Solana = `${MultichainNetworks.Solana}/slip44:501`,\n SolanaDevnet = `${MultichainNetworks.SolanaDevnet}/slip44:501`,\n SolanaTestnet = `${MultichainNetworks.SolanaTestnet}/slip44:501`,\n}\n\nconst BITCOIN_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds\nconst SOLANA_AVG_BLOCK_TIME = 400; // 400 milliseconds\n\nexport const BALANCE_UPDATE_INTERVALS = {\n // NOTE: We set an interval of half the average block time for bitcoin\n // to mitigate when our interval is de-synchronized with the actual block time.\n [BtcAccountType.P2wpkh]: BITCOIN_AVG_BLOCK_TIME / 2,\n [SolAccountType.DataAccount]: SOLANA_AVG_BLOCK_TIME,\n};\n\n/**\n * Maps network identifiers to their corresponding native asset types.\n * Each network is mapped to an array containing its native asset for consistency.\n */\nexport const NETWORK_ASSETS_MAP: Record<string, MultichainNativeAssets[]> = {\n [MultichainNetworks.Solana]: [MultichainNativeAssets.Solana],\n [MultichainNetworks.SolanaTestnet]: [MultichainNativeAssets.SolanaTestnet],\n [MultichainNetworks.SolanaDevnet]: [MultichainNativeAssets.SolanaDevnet],\n [MultichainNetworks.Bitcoin]: [MultichainNativeAssets.Bitcoin],\n [MultichainNetworks.BitcoinTestnet]: [MultichainNativeAssets.BitcoinTestnet],\n};\n"]}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The network identifiers for supported networks in CAIP-2 format.
3
+ * Note: This is a temporary workaround until we have a more robust
4
+ * solution for network identifiers.
5
+ */
6
+ export declare enum MultichainNetworks {
7
+ Bitcoin = "bip122:000000000019d6689c085ae165831e93",
8
+ BitcoinTestnet = "bip122:000000000933ea01ad0ee984209779ba",
9
+ Solana = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
10
+ SolanaDevnet = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
11
+ SolanaTestnet = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"
12
+ }
13
+ export declare enum MultichainNativeAssets {
14
+ Bitcoin = "bip122:000000000019d6689c085ae165831e93/slip44:0",
15
+ BitcoinTestnet = "bip122:000000000933ea01ad0ee984209779ba/slip44:0",
16
+ Solana = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501",
17
+ SolanaDevnet = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501",
18
+ SolanaTestnet = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501"
19
+ }
20
+ export declare const BALANCE_UPDATE_INTERVALS: {
21
+ "bip122:p2wpkh": number;
22
+ "solana:data-account": number;
23
+ };
24
+ /**
25
+ * Maps network identifiers to their corresponding native asset types.
26
+ * Each network is mapped to an array containing its native asset for consistency.
27
+ */
28
+ export declare const NETWORK_ASSETS_MAP: Record<string, MultichainNativeAssets[]>;
29
+ //# sourceMappingURL=constants.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../src/MultichainBalancesController/constants.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,oBAAY,kBAAkB;IAC5B,OAAO,4CAA4C;IACnD,cAAc,4CAA4C;IAC1D,MAAM,4CAA4C;IAClD,YAAY,4CAA4C;IACxD,aAAa,4CAA4C;CAC1D;AAED,oBAAY,sBAAsB;IAChC,OAAO,qDAA2C;IAClD,cAAc,qDAAkD;IAChE,MAAM,uDAA4C;IAClD,YAAY,uDAAkD;IAC9D,aAAa,uDAAmD;CACjE;AAKD,eAAO,MAAM,wBAAwB;;;CAKpC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,EAAE,CAMvE,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The network identifiers for supported networks in CAIP-2 format.
3
+ * Note: This is a temporary workaround until we have a more robust
4
+ * solution for network identifiers.
5
+ */
6
+ export declare enum MultichainNetworks {
7
+ Bitcoin = "bip122:000000000019d6689c085ae165831e93",
8
+ BitcoinTestnet = "bip122:000000000933ea01ad0ee984209779ba",
9
+ Solana = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
10
+ SolanaDevnet = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
11
+ SolanaTestnet = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z"
12
+ }
13
+ export declare enum MultichainNativeAssets {
14
+ Bitcoin = "bip122:000000000019d6689c085ae165831e93/slip44:0",
15
+ BitcoinTestnet = "bip122:000000000933ea01ad0ee984209779ba/slip44:0",
16
+ Solana = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501",
17
+ SolanaDevnet = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501",
18
+ SolanaTestnet = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501"
19
+ }
20
+ export declare const BALANCE_UPDATE_INTERVALS: {
21
+ "bip122:p2wpkh": number;
22
+ "solana:data-account": number;
23
+ };
24
+ /**
25
+ * Maps network identifiers to their corresponding native asset types.
26
+ * Each network is mapped to an array containing its native asset for consistency.
27
+ */
28
+ export declare const NETWORK_ASSETS_MAP: Record<string, MultichainNativeAssets[]>;
29
+ //# sourceMappingURL=constants.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../src/MultichainBalancesController/constants.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,oBAAY,kBAAkB;IAC5B,OAAO,4CAA4C;IACnD,cAAc,4CAA4C;IAC1D,MAAM,4CAA4C;IAClD,YAAY,4CAA4C;IACxD,aAAa,4CAA4C;CAC1D;AAED,oBAAY,sBAAsB;IAChC,OAAO,qDAA2C;IAClD,cAAc,qDAAkD;IAChE,MAAM,uDAA4C;IAClD,YAAY,uDAAkD;IAC9D,aAAa,uDAAmD;CACjE;AAKD,eAAO,MAAM,wBAAwB;;;CAKpC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,EAAE,CAMvE,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { BtcAccountType, SolAccountType } from "@metamask/keyring-api";
2
+ /**
3
+ * The network identifiers for supported networks in CAIP-2 format.
4
+ * Note: This is a temporary workaround until we have a more robust
5
+ * solution for network identifiers.
6
+ */
7
+ export var MultichainNetworks;
8
+ (function (MultichainNetworks) {
9
+ MultichainNetworks["Bitcoin"] = "bip122:000000000019d6689c085ae165831e93";
10
+ MultichainNetworks["BitcoinTestnet"] = "bip122:000000000933ea01ad0ee984209779ba";
11
+ MultichainNetworks["Solana"] = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
12
+ MultichainNetworks["SolanaDevnet"] = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
13
+ MultichainNetworks["SolanaTestnet"] = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
14
+ })(MultichainNetworks || (MultichainNetworks = {}));
15
+ export var MultichainNativeAssets;
16
+ (function (MultichainNativeAssets) {
17
+ MultichainNativeAssets["Bitcoin"] = "bip122:000000000019d6689c085ae165831e93/slip44:0";
18
+ MultichainNativeAssets["BitcoinTestnet"] = "bip122:000000000933ea01ad0ee984209779ba/slip44:0";
19
+ MultichainNativeAssets["Solana"] = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501";
20
+ MultichainNativeAssets["SolanaDevnet"] = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501";
21
+ MultichainNativeAssets["SolanaTestnet"] = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501";
22
+ })(MultichainNativeAssets || (MultichainNativeAssets = {}));
23
+ const BITCOIN_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds
24
+ const SOLANA_AVG_BLOCK_TIME = 400; // 400 milliseconds
25
+ export const BALANCE_UPDATE_INTERVALS = {
26
+ // NOTE: We set an interval of half the average block time for bitcoin
27
+ // to mitigate when our interval is de-synchronized with the actual block time.
28
+ [BtcAccountType.P2wpkh]: BITCOIN_AVG_BLOCK_TIME / 2,
29
+ [SolAccountType.DataAccount]: SOLANA_AVG_BLOCK_TIME,
30
+ };
31
+ /**
32
+ * Maps network identifiers to their corresponding native asset types.
33
+ * Each network is mapped to an array containing its native asset for consistency.
34
+ */
35
+ export const NETWORK_ASSETS_MAP = {
36
+ [MultichainNetworks.Solana]: [MultichainNativeAssets.Solana],
37
+ [MultichainNetworks.SolanaTestnet]: [MultichainNativeAssets.SolanaTestnet],
38
+ [MultichainNetworks.SolanaDevnet]: [MultichainNativeAssets.SolanaDevnet],
39
+ [MultichainNetworks.Bitcoin]: [MultichainNativeAssets.Bitcoin],
40
+ [MultichainNetworks.BitcoinTestnet]: [MultichainNativeAssets.BitcoinTestnet],
41
+ };
42
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAEvE;;;;GAIG;AACH,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,yEAAmD,CAAA;IACnD,gFAA0D,CAAA;IAC1D,wEAAkD,CAAA;IAClD,8EAAwD,CAAA;IACxD,+EAAyD,CAAA;AAC3D,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B;AAED,MAAM,CAAN,IAAY,sBAMX;AAND,WAAY,sBAAsB;IAChC,sFAAkD,CAAA;IAClD,6FAAgE,CAAA;IAChE,uFAAkD,CAAA;IAClD,6FAA8D,CAAA;IAC9D,8FAAgE,CAAA;AAClE,CAAC,EANW,sBAAsB,KAAtB,sBAAsB,QAMjC;AAED,MAAM,sBAAsB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,6BAA6B;AAC5E,MAAM,qBAAqB,GAAG,GAAG,CAAC,CAAC,mBAAmB;AAEtD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,sEAAsE;IACtE,+EAA+E;IAC/E,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,sBAAsB,GAAG,CAAC;IACnD,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,qBAAqB;CACpD,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA6C;IAC1E,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,sBAAsB,CAAC,MAAM,CAAC;IAC5D,CAAC,kBAAkB,CAAC,aAAa,CAAC,EAAE,CAAC,sBAAsB,CAAC,aAAa,CAAC;IAC1E,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC,sBAAsB,CAAC,YAAY,CAAC;IACxE,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC,sBAAsB,CAAC,OAAO,CAAC;IAC9D,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,CAAC,sBAAsB,CAAC,cAAc,CAAC;CAC7E,CAAC","sourcesContent":["import { BtcAccountType, SolAccountType } from '@metamask/keyring-api';\n\n/**\n * The network identifiers for supported networks in CAIP-2 format.\n * Note: This is a temporary workaround until we have a more robust\n * solution for network identifiers.\n */\nexport enum MultichainNetworks {\n Bitcoin = 'bip122:000000000019d6689c085ae165831e93',\n BitcoinTestnet = 'bip122:000000000933ea01ad0ee984209779ba',\n Solana = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',\n SolanaDevnet = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',\n SolanaTestnet = 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',\n}\n\nexport enum MultichainNativeAssets {\n Bitcoin = `${MultichainNetworks.Bitcoin}/slip44:0`,\n BitcoinTestnet = `${MultichainNetworks.BitcoinTestnet}/slip44:0`,\n Solana = `${MultichainNetworks.Solana}/slip44:501`,\n SolanaDevnet = `${MultichainNetworks.SolanaDevnet}/slip44:501`,\n SolanaTestnet = `${MultichainNetworks.SolanaTestnet}/slip44:501`,\n}\n\nconst BITCOIN_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds\nconst SOLANA_AVG_BLOCK_TIME = 400; // 400 milliseconds\n\nexport const BALANCE_UPDATE_INTERVALS = {\n // NOTE: We set an interval of half the average block time for bitcoin\n // to mitigate when our interval is de-synchronized with the actual block time.\n [BtcAccountType.P2wpkh]: BITCOIN_AVG_BLOCK_TIME / 2,\n [SolAccountType.DataAccount]: SOLANA_AVG_BLOCK_TIME,\n};\n\n/**\n * Maps network identifiers to their corresponding native asset types.\n * Each network is mapped to an array containing its native asset for consistency.\n */\nexport const NETWORK_ASSETS_MAP: Record<string, MultichainNativeAssets[]> = {\n [MultichainNetworks.Solana]: [MultichainNativeAssets.Solana],\n [MultichainNetworks.SolanaTestnet]: [MultichainNativeAssets.SolanaTestnet],\n [MultichainNetworks.SolanaDevnet]: [MultichainNativeAssets.SolanaDevnet],\n [MultichainNetworks.Bitcoin]: [MultichainNativeAssets.Bitcoin],\n [MultichainNetworks.BitcoinTestnet]: [MultichainNativeAssets.BitcoinTestnet],\n};\n"]}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PollerError = exports.BalancesTrackerError = void 0;
4
+ class BalancesTrackerError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'BalancesTrackerError';
8
+ }
9
+ }
10
+ exports.BalancesTrackerError = BalancesTrackerError;
11
+ class PollerError extends Error {
12
+ constructor(message) {
13
+ super(message);
14
+ this.name = 'PollerError';
15
+ }
16
+ }
17
+ exports.PollerError = PollerError;
18
+ //# sourceMappingURL=error.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.cjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/error.ts"],"names":[],"mappings":";;;AAAA,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AALD,oDAKC;AAED,MAAa,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AALD,kCAKC","sourcesContent":["export class BalancesTrackerError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'BalancesTrackerError';\n }\n}\n\nexport class PollerError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'PollerError';\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ export declare class BalancesTrackerError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare class PollerError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ //# sourceMappingURL=error.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.cts","sourceRoot":"","sources":["../../src/MultichainBalancesController/error.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI5B"}
@@ -0,0 +1,7 @@
1
+ export declare class BalancesTrackerError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare class PollerError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ //# sourceMappingURL=error.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.mts","sourceRoot":"","sources":["../../src/MultichainBalancesController/error.ts"],"names":[],"mappings":"AAAA,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI5B"}
@@ -0,0 +1,13 @@
1
+ export class BalancesTrackerError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = 'BalancesTrackerError';
5
+ }
6
+ }
7
+ export class PollerError extends Error {
8
+ constructor(message) {
9
+ super(message);
10
+ this.name = 'PollerError';
11
+ }
12
+ }
13
+ //# sourceMappingURL=error.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAED,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF","sourcesContent":["export class BalancesTrackerError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'BalancesTrackerError';\n }\n}\n\nexport class PollerError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'PollerError';\n }\n}\n"]}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MultichainNativeAssets = exports.MultichainNetworks = exports.NETWORK_ASSETS_MAP = exports.BALANCE_UPDATE_INTERVALS = exports.MultichainBalancesController = exports.BalancesTracker = void 0;
4
+ var BalancesTracker_1 = require("./BalancesTracker.cjs");
5
+ Object.defineProperty(exports, "BalancesTracker", { enumerable: true, get: function () { return BalancesTracker_1.BalancesTracker; } });
6
+ var MultichainBalancesController_1 = require("./MultichainBalancesController.cjs");
7
+ Object.defineProperty(exports, "MultichainBalancesController", { enumerable: true, get: function () { return MultichainBalancesController_1.MultichainBalancesController; } });
8
+ var constants_1 = require("./constants.cjs");
9
+ Object.defineProperty(exports, "BALANCE_UPDATE_INTERVALS", { enumerable: true, get: function () { return constants_1.BALANCE_UPDATE_INTERVALS; } });
10
+ Object.defineProperty(exports, "NETWORK_ASSETS_MAP", { enumerable: true, get: function () { return constants_1.NETWORK_ASSETS_MAP; } });
11
+ Object.defineProperty(exports, "MultichainNetworks", { enumerable: true, get: function () { return constants_1.MultichainNetworks; } });
12
+ Object.defineProperty(exports, "MultichainNativeAssets", { enumerable: true, get: function () { return constants_1.MultichainNativeAssets; } });
13
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/index.ts"],"names":[],"mappings":";;;AAAA,yDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,mFAA8E;AAArE,4IAAA,4BAA4B,OAAA;AACrC,6CAKqB;AAJnB,qHAAA,wBAAwB,OAAA;AACxB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA","sourcesContent":["export { BalancesTracker } from './BalancesTracker';\nexport { MultichainBalancesController } from './MultichainBalancesController';\nexport {\n BALANCE_UPDATE_INTERVALS,\n NETWORK_ASSETS_MAP,\n MultichainNetworks,\n MultichainNativeAssets,\n} from './constants';\nexport type {\n MultichainBalancesControllerState,\n MultichainBalancesControllerGetStateAction,\n MultichainBalancesControllerUpdateBalancesAction,\n MultichainBalancesControllerStateChange,\n MultichainBalancesControllerActions,\n MultichainBalancesControllerEvents,\n MultichainBalancesControllerMessenger,\n} from './MultichainBalancesController';\n"]}
@@ -0,0 +1,5 @@
1
+ export { BalancesTracker } from "./BalancesTracker.cjs";
2
+ export { MultichainBalancesController } from "./MultichainBalancesController.cjs";
3
+ export { BALANCE_UPDATE_INTERVALS, NETWORK_ASSETS_MAP, MultichainNetworks, MultichainNativeAssets, } from "./constants.cjs";
4
+ export type { MultichainBalancesControllerState, MultichainBalancesControllerGetStateAction, MultichainBalancesControllerUpdateBalancesAction, MultichainBalancesControllerStateChange, MultichainBalancesControllerActions, MultichainBalancesControllerEvents, MultichainBalancesControllerMessenger, } from "./MultichainBalancesController.cjs";
5
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/MultichainBalancesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,8BAA0B;AACpD,OAAO,EAAE,4BAA4B,EAAE,2CAAuC;AAC9E,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,GACvB,wBAAoB;AACrB,YAAY,EACV,iCAAiC,EACjC,0CAA0C,EAC1C,gDAAgD,EAChD,uCAAuC,EACvC,mCAAmC,EACnC,kCAAkC,EAClC,qCAAqC,GACtC,2CAAuC"}
@@ -0,0 +1,5 @@
1
+ export { BalancesTracker } from "./BalancesTracker.mjs";
2
+ export { MultichainBalancesController } from "./MultichainBalancesController.mjs";
3
+ export { BALANCE_UPDATE_INTERVALS, NETWORK_ASSETS_MAP, MultichainNetworks, MultichainNativeAssets, } from "./constants.mjs";
4
+ export type { MultichainBalancesControllerState, MultichainBalancesControllerGetStateAction, MultichainBalancesControllerUpdateBalancesAction, MultichainBalancesControllerStateChange, MultichainBalancesControllerActions, MultichainBalancesControllerEvents, MultichainBalancesControllerMessenger, } from "./MultichainBalancesController.mjs";
5
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/MultichainBalancesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,8BAA0B;AACpD,OAAO,EAAE,4BAA4B,EAAE,2CAAuC;AAC9E,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,GACvB,wBAAoB;AACrB,YAAY,EACV,iCAAiC,EACjC,0CAA0C,EAC1C,gDAAgD,EAChD,uCAAuC,EACvC,mCAAmC,EACnC,kCAAkC,EAClC,qCAAqC,GACtC,2CAAuC"}
@@ -0,0 +1,4 @@
1
+ export { BalancesTracker } from "./BalancesTracker.mjs";
2
+ export { MultichainBalancesController } from "./MultichainBalancesController.mjs";
3
+ export { BALANCE_UPDATE_INTERVALS, NETWORK_ASSETS_MAP, MultichainNetworks, MultichainNativeAssets } from "./constants.mjs";
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,8BAA0B;AACpD,OAAO,EAAE,4BAA4B,EAAE,2CAAuC;AAC9E,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACvB,wBAAoB","sourcesContent":["export { BalancesTracker } from './BalancesTracker';\nexport { MultichainBalancesController } from './MultichainBalancesController';\nexport {\n BALANCE_UPDATE_INTERVALS,\n NETWORK_ASSETS_MAP,\n MultichainNetworks,\n MultichainNativeAssets,\n} from './constants';\nexport type {\n MultichainBalancesControllerState,\n MultichainBalancesControllerGetStateAction,\n MultichainBalancesControllerUpdateBalancesAction,\n MultichainBalancesControllerStateChange,\n MultichainBalancesControllerActions,\n MultichainBalancesControllerEvents,\n MultichainBalancesControllerMessenger,\n} from './MultichainBalancesController';\n"]}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBlockTimeForAccount = exports.getScopeForAccount = exports.getScopeForSolAddress = exports.getScopeForBtcAddress = void 0;
4
+ const keyring_api_1 = require("@metamask/keyring-api");
5
+ const bitcoin_address_validation_1 = require("bitcoin-address-validation");
6
+ const constants_1 = require("./constants.cjs");
7
+ /**
8
+ * Gets the scope for a specific and supported Bitcoin account.
9
+ * Note: This is a temporary method and will be replaced by a more robust solution
10
+ * once the new `account.scopes` is available in the `@metamask/keyring-api` module.
11
+ *
12
+ * @param account - Bitcoin account
13
+ * @returns The scope for the given account.
14
+ */
15
+ const getScopeForBtcAddress = (account) => {
16
+ if ((0, bitcoin_address_validation_1.validate)(account.address, bitcoin_address_validation_1.Network.mainnet)) {
17
+ return constants_1.MultichainNetworks.Bitcoin;
18
+ }
19
+ if ((0, bitcoin_address_validation_1.validate)(account.address, bitcoin_address_validation_1.Network.testnet)) {
20
+ return constants_1.MultichainNetworks.BitcoinTestnet;
21
+ }
22
+ throw new Error(`Invalid Bitcoin address: ${account.address}`);
23
+ };
24
+ exports.getScopeForBtcAddress = getScopeForBtcAddress;
25
+ /**
26
+ * Gets the scope for a specific and supported Solana account.
27
+ * Note: This is a temporary method and will be replaced by a more robust solution
28
+ * once the new `account.scopes` is available in the `keyring-api`.
29
+ *
30
+ * @param account - Solana account
31
+ * @returns The scope for the given account.
32
+ */
33
+ const getScopeForSolAddress = (account) => {
34
+ // For Solana accounts, we know we have a `scope` on the account's `options` bag.
35
+ if (!account.options.scope) {
36
+ throw new Error('Solana account scope is undefined');
37
+ }
38
+ return account.options.scope;
39
+ };
40
+ exports.getScopeForSolAddress = getScopeForSolAddress;
41
+ /**
42
+ * Get the scope for a given address.
43
+ * Note: This is a temporary method and will be replaced by a more robust solution
44
+ * once the new `account.scopes` is available in the `keyring-api`.
45
+ *
46
+ * @param account - The account to get the scope for.
47
+ * @returns The scope for the given account.
48
+ */
49
+ const getScopeForAccount = (account) => {
50
+ switch (account.type) {
51
+ case keyring_api_1.BtcAccountType.P2wpkh:
52
+ return (0, exports.getScopeForBtcAddress)(account);
53
+ case keyring_api_1.SolAccountType.DataAccount:
54
+ return (0, exports.getScopeForSolAddress)(account);
55
+ default:
56
+ throw new Error(`Unsupported non-EVM account type: ${account.type}`);
57
+ }
58
+ };
59
+ exports.getScopeForAccount = getScopeForAccount;
60
+ /**
61
+ * Gets the block time for a given account.
62
+ *
63
+ * @param accountType - The account type to get the block time for.
64
+ * @returns The block time for the account.
65
+ */
66
+ const getBlockTimeForAccount = (accountType) => {
67
+ if (accountType in constants_1.BALANCE_UPDATE_INTERVALS) {
68
+ return constants_1.BALANCE_UPDATE_INTERVALS[accountType];
69
+ }
70
+ throw new Error(`Unsupported account type for balance tracking: ${accountType}`);
71
+ };
72
+ exports.getBlockTimeForAccount = getBlockTimeForAccount;
73
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/utils.ts"],"names":[],"mappings":";;;AAAA,uDAAuE;AAEvE,2EAA+D;AAE/D,+CAA2E;AAE3E;;;;;;;GAOG;AACI,MAAM,qBAAqB,GAAG,CAAC,OAAwB,EAAU,EAAE;IACxE,IAAI,IAAA,qCAAQ,EAAC,OAAO,CAAC,OAAO,EAAE,oCAAO,CAAC,OAAO,CAAC,EAAE;QAC9C,OAAO,8BAAkB,CAAC,OAAO,CAAC;KACnC;IAED,IAAI,IAAA,qCAAQ,EAAC,OAAO,CAAC,OAAO,EAAE,oCAAO,CAAC,OAAO,CAAC,EAAE;QAC9C,OAAO,8BAAkB,CAAC,cAAc,CAAC;KAC1C;IAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;AACjE,CAAC,CAAC;AAVW,QAAA,qBAAqB,yBAUhC;AAEF;;;;;;;GAOG;AACI,MAAM,qBAAqB,GAAG,CAAC,OAAwB,EAAU,EAAE;IACxE,iFAAiF;IACjF,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAe,CAAC;AACzC,CAAC,CAAC;AANW,QAAA,qBAAqB,yBAMhC;AAEF;;;;;;;GAOG;AACI,MAAM,kBAAkB,GAAG,CAAC,OAAwB,EAAU,EAAE;IACrE,QAAQ,OAAO,CAAC,IAAI,EAAE;QACpB,KAAK,4BAAc,CAAC,MAAM;YACxB,OAAO,IAAA,6BAAqB,EAAC,OAAO,CAAC,CAAC;QACxC,KAAK,4BAAc,CAAC,WAAW;YAC7B,OAAO,IAAA,6BAAqB,EAAC,OAAO,CAAC,CAAC;QACxC;YACE,MAAM,IAAI,KAAK,CAAC,qCAAqC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACxE;AACH,CAAC,CAAC;AATW,QAAA,kBAAkB,sBAS7B;AAEF;;;;;GAKG;AACI,MAAM,sBAAsB,GAAG,CAAC,WAAmB,EAAU,EAAE;IACpE,IAAI,WAAW,IAAI,oCAAwB,EAAE;QAC3C,OAAO,oCAAwB,CAC7B,WAAoD,CACrD,CAAC;KACH;IACD,MAAM,IAAI,KAAK,CACb,kDAAkD,WAAW,EAAE,CAChE,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,sBAAsB,0BASjC","sourcesContent":["import { BtcAccountType, SolAccountType } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { validate, Network } from 'bitcoin-address-validation';\n\nimport { MultichainNetworks, BALANCE_UPDATE_INTERVALS } from './constants';\n\n/**\n * Gets the scope for a specific and supported Bitcoin account.\n * Note: This is a temporary method and will be replaced by a more robust solution\n * once the new `account.scopes` is available in the `@metamask/keyring-api` module.\n *\n * @param account - Bitcoin account\n * @returns The scope for the given account.\n */\nexport const getScopeForBtcAddress = (account: InternalAccount): string => {\n if (validate(account.address, Network.mainnet)) {\n return MultichainNetworks.Bitcoin;\n }\n\n if (validate(account.address, Network.testnet)) {\n return MultichainNetworks.BitcoinTestnet;\n }\n\n throw new Error(`Invalid Bitcoin address: ${account.address}`);\n};\n\n/**\n * Gets the scope for a specific and supported Solana account.\n * Note: This is a temporary method and will be replaced by a more robust solution\n * once the new `account.scopes` is available in the `keyring-api`.\n *\n * @param account - Solana account\n * @returns The scope for the given account.\n */\nexport const getScopeForSolAddress = (account: InternalAccount): string => {\n // For Solana accounts, we know we have a `scope` on the account's `options` bag.\n if (!account.options.scope) {\n throw new Error('Solana account scope is undefined');\n }\n return account.options.scope as string;\n};\n\n/**\n * Get the scope for a given address.\n * Note: This is a temporary method and will be replaced by a more robust solution\n * once the new `account.scopes` is available in the `keyring-api`.\n *\n * @param account - The account to get the scope for.\n * @returns The scope for the given account.\n */\nexport const getScopeForAccount = (account: InternalAccount): string => {\n switch (account.type) {\n case BtcAccountType.P2wpkh:\n return getScopeForBtcAddress(account);\n case SolAccountType.DataAccount:\n return getScopeForSolAddress(account);\n default:\n throw new Error(`Unsupported non-EVM account type: ${account.type}`);\n }\n};\n\n/**\n * Gets the block time for a given account.\n *\n * @param accountType - The account type to get the block time for.\n * @returns The block time for the account.\n */\nexport const getBlockTimeForAccount = (accountType: string): number => {\n if (accountType in BALANCE_UPDATE_INTERVALS) {\n return BALANCE_UPDATE_INTERVALS[\n accountType as keyof typeof BALANCE_UPDATE_INTERVALS\n ];\n }\n throw new Error(\n `Unsupported account type for balance tracking: ${accountType}`,\n );\n};\n"]}
@@ -0,0 +1,36 @@
1
+ import type { InternalAccount } from "@metamask/keyring-internal-api";
2
+ /**
3
+ * Gets the scope for a specific and supported Bitcoin account.
4
+ * Note: This is a temporary method and will be replaced by a more robust solution
5
+ * once the new `account.scopes` is available in the `@metamask/keyring-api` module.
6
+ *
7
+ * @param account - Bitcoin account
8
+ * @returns The scope for the given account.
9
+ */
10
+ export declare const getScopeForBtcAddress: (account: InternalAccount) => string;
11
+ /**
12
+ * Gets the scope for a specific and supported Solana account.
13
+ * Note: This is a temporary method and will be replaced by a more robust solution
14
+ * once the new `account.scopes` is available in the `keyring-api`.
15
+ *
16
+ * @param account - Solana account
17
+ * @returns The scope for the given account.
18
+ */
19
+ export declare const getScopeForSolAddress: (account: InternalAccount) => string;
20
+ /**
21
+ * Get the scope for a given address.
22
+ * Note: This is a temporary method and will be replaced by a more robust solution
23
+ * once the new `account.scopes` is available in the `keyring-api`.
24
+ *
25
+ * @param account - The account to get the scope for.
26
+ * @returns The scope for the given account.
27
+ */
28
+ export declare const getScopeForAccount: (account: InternalAccount) => string;
29
+ /**
30
+ * Gets the block time for a given account.
31
+ *
32
+ * @param accountType - The account type to get the block time for.
33
+ * @returns The block time for the account.
34
+ */
35
+ export declare const getBlockTimeForAccount: (accountType: string) => number;
36
+ //# sourceMappingURL=utils.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/MultichainBalancesController/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAKtE;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YAAa,eAAe,KAAG,MAUhE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YAAa,eAAe,KAAG,MAMhE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,YAAa,eAAe,KAAG,MAS7D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,gBAAiB,MAAM,KAAG,MAS5D,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { InternalAccount } from "@metamask/keyring-internal-api";
2
+ /**
3
+ * Gets the scope for a specific and supported Bitcoin account.
4
+ * Note: This is a temporary method and will be replaced by a more robust solution
5
+ * once the new `account.scopes` is available in the `@metamask/keyring-api` module.
6
+ *
7
+ * @param account - Bitcoin account
8
+ * @returns The scope for the given account.
9
+ */
10
+ export declare const getScopeForBtcAddress: (account: InternalAccount) => string;
11
+ /**
12
+ * Gets the scope for a specific and supported Solana account.
13
+ * Note: This is a temporary method and will be replaced by a more robust solution
14
+ * once the new `account.scopes` is available in the `keyring-api`.
15
+ *
16
+ * @param account - Solana account
17
+ * @returns The scope for the given account.
18
+ */
19
+ export declare const getScopeForSolAddress: (account: InternalAccount) => string;
20
+ /**
21
+ * Get the scope for a given address.
22
+ * Note: This is a temporary method and will be replaced by a more robust solution
23
+ * once the new `account.scopes` is available in the `keyring-api`.
24
+ *
25
+ * @param account - The account to get the scope for.
26
+ * @returns The scope for the given account.
27
+ */
28
+ export declare const getScopeForAccount: (account: InternalAccount) => string;
29
+ /**
30
+ * Gets the block time for a given account.
31
+ *
32
+ * @param accountType - The account type to get the block time for.
33
+ * @returns The block time for the account.
34
+ */
35
+ export declare const getBlockTimeForAccount: (accountType: string) => number;
36
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/MultichainBalancesController/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAKtE;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YAAa,eAAe,KAAG,MAUhE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YAAa,eAAe,KAAG,MAMhE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,YAAa,eAAe,KAAG,MAS7D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,gBAAiB,MAAM,KAAG,MAS5D,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { BtcAccountType, SolAccountType } from "@metamask/keyring-api";
2
+ import { validate, Network } from "bitcoin-address-validation";
3
+ import { MultichainNetworks, BALANCE_UPDATE_INTERVALS } from "./constants.mjs";
4
+ /**
5
+ * Gets the scope for a specific and supported Bitcoin account.
6
+ * Note: This is a temporary method and will be replaced by a more robust solution
7
+ * once the new `account.scopes` is available in the `@metamask/keyring-api` module.
8
+ *
9
+ * @param account - Bitcoin account
10
+ * @returns The scope for the given account.
11
+ */
12
+ export const getScopeForBtcAddress = (account) => {
13
+ if (validate(account.address, Network.mainnet)) {
14
+ return MultichainNetworks.Bitcoin;
15
+ }
16
+ if (validate(account.address, Network.testnet)) {
17
+ return MultichainNetworks.BitcoinTestnet;
18
+ }
19
+ throw new Error(`Invalid Bitcoin address: ${account.address}`);
20
+ };
21
+ /**
22
+ * Gets the scope for a specific and supported Solana account.
23
+ * Note: This is a temporary method and will be replaced by a more robust solution
24
+ * once the new `account.scopes` is available in the `keyring-api`.
25
+ *
26
+ * @param account - Solana account
27
+ * @returns The scope for the given account.
28
+ */
29
+ export const getScopeForSolAddress = (account) => {
30
+ // For Solana accounts, we know we have a `scope` on the account's `options` bag.
31
+ if (!account.options.scope) {
32
+ throw new Error('Solana account scope is undefined');
33
+ }
34
+ return account.options.scope;
35
+ };
36
+ /**
37
+ * Get the scope for a given address.
38
+ * Note: This is a temporary method and will be replaced by a more robust solution
39
+ * once the new `account.scopes` is available in the `keyring-api`.
40
+ *
41
+ * @param account - The account to get the scope for.
42
+ * @returns The scope for the given account.
43
+ */
44
+ export const getScopeForAccount = (account) => {
45
+ switch (account.type) {
46
+ case BtcAccountType.P2wpkh:
47
+ return getScopeForBtcAddress(account);
48
+ case SolAccountType.DataAccount:
49
+ return getScopeForSolAddress(account);
50
+ default:
51
+ throw new Error(`Unsupported non-EVM account type: ${account.type}`);
52
+ }
53
+ };
54
+ /**
55
+ * Gets the block time for a given account.
56
+ *
57
+ * @param accountType - The account type to get the block time for.
58
+ * @returns The block time for the account.
59
+ */
60
+ export const getBlockTimeForAccount = (accountType) => {
61
+ if (accountType in BALANCE_UPDATE_INTERVALS) {
62
+ return BALANCE_UPDATE_INTERVALS[accountType];
63
+ }
64
+ throw new Error(`Unsupported account type for balance tracking: ${accountType}`);
65
+ };
66
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/MultichainBalancesController/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAEvE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,mCAAmC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,wBAAoB;AAE3E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAwB,EAAU,EAAE;IACxE,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9C,OAAO,kBAAkB,CAAC,OAAO,CAAC;KACnC;IAED,IAAI,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9C,OAAO,kBAAkB,CAAC,cAAc,CAAC;KAC1C;IAED,MAAM,IAAI,KAAK,CAAC,4BAA4B,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;AACjE,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAwB,EAAU,EAAE;IACxE,iFAAiF;IACjF,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAe,CAAC;AACzC,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAwB,EAAU,EAAE;IACrE,QAAQ,OAAO,CAAC,IAAI,EAAE;QACpB,KAAK,cAAc,CAAC,MAAM;YACxB,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC;QACxC,KAAK,cAAc,CAAC,WAAW;YAC7B,OAAO,qBAAqB,CAAC,OAAO,CAAC,CAAC;QACxC;YACE,MAAM,IAAI,KAAK,CAAC,qCAAqC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACxE;AACH,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,WAAmB,EAAU,EAAE;IACpE,IAAI,WAAW,IAAI,wBAAwB,EAAE;QAC3C,OAAO,wBAAwB,CAC7B,WAAoD,CACrD,CAAC;KACH;IACD,MAAM,IAAI,KAAK,CACb,kDAAkD,WAAW,EAAE,CAChE,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { BtcAccountType, SolAccountType } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { validate, Network } from 'bitcoin-address-validation';\n\nimport { MultichainNetworks, BALANCE_UPDATE_INTERVALS } from './constants';\n\n/**\n * Gets the scope for a specific and supported Bitcoin account.\n * Note: This is a temporary method and will be replaced by a more robust solution\n * once the new `account.scopes` is available in the `@metamask/keyring-api` module.\n *\n * @param account - Bitcoin account\n * @returns The scope for the given account.\n */\nexport const getScopeForBtcAddress = (account: InternalAccount): string => {\n if (validate(account.address, Network.mainnet)) {\n return MultichainNetworks.Bitcoin;\n }\n\n if (validate(account.address, Network.testnet)) {\n return MultichainNetworks.BitcoinTestnet;\n }\n\n throw new Error(`Invalid Bitcoin address: ${account.address}`);\n};\n\n/**\n * Gets the scope for a specific and supported Solana account.\n * Note: This is a temporary method and will be replaced by a more robust solution\n * once the new `account.scopes` is available in the `keyring-api`.\n *\n * @param account - Solana account\n * @returns The scope for the given account.\n */\nexport const getScopeForSolAddress = (account: InternalAccount): string => {\n // For Solana accounts, we know we have a `scope` on the account's `options` bag.\n if (!account.options.scope) {\n throw new Error('Solana account scope is undefined');\n }\n return account.options.scope as string;\n};\n\n/**\n * Get the scope for a given address.\n * Note: This is a temporary method and will be replaced by a more robust solution\n * once the new `account.scopes` is available in the `keyring-api`.\n *\n * @param account - The account to get the scope for.\n * @returns The scope for the given account.\n */\nexport const getScopeForAccount = (account: InternalAccount): string => {\n switch (account.type) {\n case BtcAccountType.P2wpkh:\n return getScopeForBtcAddress(account);\n case SolAccountType.DataAccount:\n return getScopeForSolAddress(account);\n default:\n throw new Error(`Unsupported non-EVM account type: ${account.type}`);\n }\n};\n\n/**\n * Gets the block time for a given account.\n *\n * @param accountType - The account type to get the block time for.\n * @returns The block time for the account.\n */\nexport const getBlockTimeForAccount = (accountType: string): number => {\n if (accountType in BALANCE_UPDATE_INTERVALS) {\n return BALANCE_UPDATE_INTERVALS[\n accountType as keyof typeof BALANCE_UPDATE_INTERVALS\n ];\n }\n throw new Error(\n `Unsupported account type for balance tracking: ${accountType}`,\n );\n};\n"]}
@@ -43,6 +43,7 @@ const getDefaultNftControllerState = () => ({
43
43
  ignoredNfts: [],
44
44
  });
45
45
  exports.getDefaultNftControllerState = getDefaultNftControllerState;
46
+ const NFT_UPDATE_THRESHOLD = 500;
46
47
  /**
47
48
  * Controller that stores assets and exposes convenience methods
48
49
  */
@@ -603,12 +604,17 @@ _NftController_mutex = new WeakMap(), _NftController_selectedAccountId = new Wea
603
604
  async function _NftController_onPreferencesControllerStateChange({ ipfsGateway, openSeaEnabled, isIpfsGatewayEnabled, }) {
604
605
  const selectedAccount = this.messagingSystem.call('AccountsController:getSelectedAccount');
605
606
  __classPrivateFieldSet(this, _NftController_selectedAccountId, selectedAccount.id, "f");
606
- __classPrivateFieldSet(this, _NftController_ipfsGateway, ipfsGateway, "f");
607
- __classPrivateFieldSet(this, _NftController_openSeaEnabled, openSeaEnabled, "f");
608
- __classPrivateFieldSet(this, _NftController_isIpfsGatewayEnabled, isIpfsGatewayEnabled, "f");
609
- const needsUpdateNftMetadata = (isIpfsGatewayEnabled && ipfsGateway !== '') || openSeaEnabled;
610
- if (needsUpdateNftMetadata && selectedAccount) {
611
- await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNftUpdateForAccount).call(this, selectedAccount);
607
+ // Get current state values
608
+ if (__classPrivateFieldGet(this, _NftController_ipfsGateway, "f") !== ipfsGateway ||
609
+ __classPrivateFieldGet(this, _NftController_openSeaEnabled, "f") !== openSeaEnabled ||
610
+ __classPrivateFieldGet(this, _NftController_isIpfsGatewayEnabled, "f") !== isIpfsGatewayEnabled) {
611
+ __classPrivateFieldSet(this, _NftController_ipfsGateway, ipfsGateway, "f");
612
+ __classPrivateFieldSet(this, _NftController_openSeaEnabled, openSeaEnabled, "f");
613
+ __classPrivateFieldSet(this, _NftController_isIpfsGatewayEnabled, isIpfsGatewayEnabled, "f");
614
+ const needsUpdateNftMetadata = (isIpfsGatewayEnabled && ipfsGateway !== '') || openSeaEnabled;
615
+ if (needsUpdateNftMetadata && selectedAccount) {
616
+ await __classPrivateFieldGet(this, _NftController_instances, "m", _NftController_updateNftUpdateForAccount).call(this, selectedAccount);
617
+ }
612
618
  }
613
619
  }, _NftController_onSelectedAccountChange =
614
620
  /**
@@ -1156,7 +1162,8 @@ async function _NftController_addNftContract({ tokenAddress, userAddress, networ
1156
1162
  const nfts = this.state.allNfts[account.address]?.[__classPrivateFieldGet(this, _NftController_chainId, "f")] ?? [];
1157
1163
  // Filter only nfts
1158
1164
  const nftsToUpdate = nfts.filter((singleNft) => !singleNft.name && !singleNft.description && !singleNft.image);
1159
- if (nftsToUpdate.length !== 0) {
1165
+ if (nftsToUpdate.length !== 0 &&
1166
+ nftsToUpdate.length < NFT_UPDATE_THRESHOLD) {
1160
1167
  await this.updateNftMetadata({
1161
1168
  nfts: nftsToUpdate,
1162
1169
  userAddress: account.address,