@metamask-previews/multichain-transactions-controller 0.1.0-preview-99939da3 → 0.2.0-preview-224dff25

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 (42) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/MultichainTransactionsController.cjs +51 -76
  3. package/dist/MultichainTransactionsController.cjs.map +1 -1
  4. package/dist/MultichainTransactionsController.d.cts +5 -24
  5. package/dist/MultichainTransactionsController.d.cts.map +1 -1
  6. package/dist/MultichainTransactionsController.d.mts +5 -24
  7. package/dist/MultichainTransactionsController.d.mts.map +1 -1
  8. package/dist/MultichainTransactionsController.mjs +52 -77
  9. package/dist/MultichainTransactionsController.mjs.map +1 -1
  10. package/dist/constants.cjs +1 -11
  11. package/dist/constants.cjs.map +1 -1
  12. package/dist/constants.d.cts +0 -4
  13. package/dist/constants.d.cts.map +1 -1
  14. package/dist/constants.d.mts +0 -4
  15. package/dist/constants.d.mts.map +1 -1
  16. package/dist/constants.mjs +0 -10
  17. package/dist/constants.mjs.map +1 -1
  18. package/dist/index.cjs +1 -2
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +1 -1
  21. package/dist/index.d.cts.map +1 -1
  22. package/dist/index.d.mts +1 -1
  23. package/dist/index.d.mts.map +1 -1
  24. package/dist/index.mjs +1 -1
  25. package/dist/index.mjs.map +1 -1
  26. package/package.json +9 -9
  27. package/dist/MultichainTransactionsTracker.cjs +0 -124
  28. package/dist/MultichainTransactionsTracker.cjs.map +0 -1
  29. package/dist/MultichainTransactionsTracker.d.cts +0 -62
  30. package/dist/MultichainTransactionsTracker.d.cts.map +0 -1
  31. package/dist/MultichainTransactionsTracker.d.mts +0 -62
  32. package/dist/MultichainTransactionsTracker.d.mts.map +0 -1
  33. package/dist/MultichainTransactionsTracker.mjs +0 -120
  34. package/dist/MultichainTransactionsTracker.mjs.map +0 -1
  35. package/dist/Poller.cjs +0 -40
  36. package/dist/Poller.cjs.map +0 -1
  37. package/dist/Poller.d.cts +0 -7
  38. package/dist/Poller.d.cts.map +0 -1
  39. package/dist/Poller.d.mts +0 -7
  40. package/dist/Poller.d.mts.map +0 -1
  41. package/dist/Poller.mjs +0 -36
  42. package/dist/Poller.mjs.map +0 -1
@@ -3,19 +3,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
- var _MultichainTransactionsController_instances, _MultichainTransactionsController_tracker, _MultichainTransactionsController_listMultichainAccounts, _MultichainTransactionsController_listAccounts, _MultichainTransactionsController_updateTransactions, _MultichainTransactionsController_getTransactions, _MultichainTransactionsController_getBlockTimeFor, _MultichainTransactionsController_isNonEvmAccount, _MultichainTransactionsController_handleOnAccountAdded, _MultichainTransactionsController_handleOnAccountRemoved, _MultichainTransactionsController_getClient;
6
+ var _MultichainTransactionsController_instances, _MultichainTransactionsController_listMultichainAccounts, _MultichainTransactionsController_listAccounts, _MultichainTransactionsController_getTransactions, _MultichainTransactionsController_isNonEvmAccount, _MultichainTransactionsController_handleOnAccountAdded, _MultichainTransactionsController_handleOnAccountRemoved, _MultichainTransactionsController_handleOnAccountTransactionsUpdated, _MultichainTransactionsController_getClient;
13
7
  import { BaseController } from "@metamask/base-controller";
14
8
  import { isEvmAccountType } from "@metamask/keyring-api";
15
9
  import { KeyringClient } from "@metamask/keyring-snap-client";
16
10
  import { HandlerType } from "@metamask/snaps-utils";
17
- import { MultichainNetwork, TRANSACTIONS_CHECK_INTERVALS } from "./constants.mjs";
18
- import { MultichainTransactionsTracker } from "./MultichainTransactionsTracker.mjs";
11
+ import { KnownCaipNamespace, parseCaipChainId } from "@metamask/utils";
12
+ import { MultichainNetwork } from "./constants.mjs";
19
13
  const controllerName = 'MultichainTransactionsController';
20
14
  /**
21
15
  * Constructs the default {@link MultichainTransactionsController} state.
@@ -56,81 +50,61 @@ export class MultichainTransactionsController extends BaseController {
56
50
  },
57
51
  });
58
52
  _MultichainTransactionsController_instances.add(this);
59
- _MultichainTransactionsController_tracker.set(this, void 0);
60
- __classPrivateFieldSet(this, _MultichainTransactionsController_tracker, new MultichainTransactionsTracker(async (accountId, pagination) => await __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_updateTransactions).call(this, accountId, pagination)), "f");
61
- // Register all non-EVM accounts into the tracker
53
+ // Fetch initial transactions for all non-EVM accounts
62
54
  for (const account of __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_listAccounts).call(this)) {
63
- if (__classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_isNonEvmAccount).call(this, account)) {
64
- __classPrivateFieldGet(this, _MultichainTransactionsController_tracker, "f").track(account.id, __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_getBlockTimeFor).call(this, account));
65
- }
55
+ this.updateTransactionsForAccount(account.id).catch((error) => {
56
+ console.error(`Failed to fetch initial transactions for account ${account.id}:`, error);
57
+ });
66
58
  }
67
59
  this.messagingSystem.subscribe('AccountsController:accountAdded', (account) => __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_handleOnAccountAdded).call(this, account));
68
60
  this.messagingSystem.subscribe('AccountsController:accountRemoved', (accountId) => __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_handleOnAccountRemoved).call(this, accountId));
61
+ this.messagingSystem.subscribe('AccountsController:accountTransactionsUpdated', (transactionsUpdate) => __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_handleOnAccountTransactionsUpdated).call(this, transactionsUpdate));
69
62
  }
70
63
  /**
71
- * Updates transactions for a specific account
64
+ * Updates transactions for a specific account. This is used for the initial fetch
65
+ * when an account is first added.
72
66
  *
73
67
  * @param accountId - The ID of the account to get transactions for.
74
68
  */
75
69
  async updateTransactionsForAccount(accountId) {
76
- await __classPrivateFieldGet(this, _MultichainTransactionsController_tracker, "f").updateTransactionsForAccount(accountId);
77
- }
78
- /**
79
- * Updates the transactions of all supported accounts. This method doesn't return
80
- * anything, but it updates the state of the controller.
81
- */
82
- async updateTransactions() {
83
- await __classPrivateFieldGet(this, _MultichainTransactionsController_tracker, "f").updateTransactions();
84
- }
85
- /**
86
- * Starts the polling process.
87
- */
88
- start() {
89
- __classPrivateFieldGet(this, _MultichainTransactionsController_tracker, "f").start();
90
- }
91
- /**
92
- * Stops the polling process.
93
- */
94
- stop() {
95
- __classPrivateFieldGet(this, _MultichainTransactionsController_tracker, "f").stop();
70
+ try {
71
+ const account = __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_listAccounts).call(this).find((accountItem) => accountItem.id === accountId);
72
+ if (account?.metadata.snap) {
73
+ const response = await __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_getTransactions).call(this, account.id, account.metadata.snap.id, { limit: 10 });
74
+ // Filter only Solana transactions to ensure they're on mainnet.
75
+ // All other chain transactions are included as-is.
76
+ // TODO: Maybe we should not do any filtering here? Or maybe have it
77
+ // being configurable somehow?
78
+ const transactions = response.data.filter((tx) => {
79
+ const chain = tx.chain;
80
+ const { namespace } = parseCaipChainId(chain);
81
+ // Enum comparison is safe here as we control both enum values
82
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
83
+ if (namespace === KnownCaipNamespace.Solana) {
84
+ return chain === MultichainNetwork.Solana;
85
+ }
86
+ return true;
87
+ });
88
+ this.update((state) => {
89
+ const entry = {
90
+ transactions,
91
+ next: response.next,
92
+ lastUpdated: Date.now(),
93
+ };
94
+ Object.assign(state.nonEvmTransactions, { [account.id]: entry });
95
+ });
96
+ }
97
+ }
98
+ catch (error) {
99
+ console.error(`Failed to fetch transactions for account ${accountId}:`, error);
100
+ }
96
101
  }
97
102
  }
98
- _MultichainTransactionsController_tracker = new WeakMap(), _MultichainTransactionsController_instances = new WeakSet(), _MultichainTransactionsController_listMultichainAccounts = function _MultichainTransactionsController_listMultichainAccounts() {
103
+ _MultichainTransactionsController_instances = new WeakSet(), _MultichainTransactionsController_listMultichainAccounts = function _MultichainTransactionsController_listMultichainAccounts() {
99
104
  return this.messagingSystem.call('AccountsController:listMultichainAccounts');
100
105
  }, _MultichainTransactionsController_listAccounts = function _MultichainTransactionsController_listAccounts() {
101
106
  const accounts = __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_listMultichainAccounts).call(this);
102
107
  return accounts.filter((account) => __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_isNonEvmAccount).call(this, account));
103
- }, _MultichainTransactionsController_updateTransactions =
104
- /**
105
- * Updates the transactions for one account.
106
- *
107
- * @param accountId - The ID of the account to update transactions for.
108
- * @param pagination - Options for paginating transaction results.
109
- */
110
- async function _MultichainTransactionsController_updateTransactions(accountId, pagination) {
111
- const account = __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_listAccounts).call(this).find((accountItem) => accountItem.id === accountId);
112
- if (account?.metadata.snap) {
113
- const response = await __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_getTransactions).call(this, account.id, account.metadata.snap.id, pagination);
114
- /**
115
- * Filter only Solana transactions to ensure they're mainnet
116
- * All other chain transactions are included as-is
117
- */
118
- const transactions = response.data.filter((tx) => {
119
- const chain = tx.chain;
120
- if (chain.startsWith(MultichainNetwork.Solana)) {
121
- return chain === MultichainNetwork.Solana;
122
- }
123
- return true;
124
- });
125
- this.update((state) => {
126
- const entry = {
127
- transactions,
128
- next: response.next,
129
- lastUpdated: Date.now(),
130
- };
131
- Object.assign(state.nonEvmTransactions, { [account.id]: entry });
132
- });
133
- }
134
108
  }, _MultichainTransactionsController_getTransactions =
135
109
  /**
136
110
  * Gets transactions for an account.
@@ -142,11 +116,6 @@ async function _MultichainTransactionsController_updateTransactions(accountId, p
142
116
  */
143
117
  async function _MultichainTransactionsController_getTransactions(accountId, snapId, pagination) {
144
118
  return await __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_getClient).call(this, snapId).listAccountTransactions(accountId, pagination);
145
- }, _MultichainTransactionsController_getBlockTimeFor = function _MultichainTransactionsController_getBlockTimeFor(account) {
146
- if (account.type in TRANSACTIONS_CHECK_INTERVALS) {
147
- return TRANSACTIONS_CHECK_INTERVALS[account.type];
148
- }
149
- throw new Error(`Unsupported account type for transactions tracking: ${account.type}`);
150
119
  }, _MultichainTransactionsController_isNonEvmAccount = function _MultichainTransactionsController_isNonEvmAccount(account) {
151
120
  return (!isEvmAccountType(account.type) &&
152
121
  // Non-EVM accounts are backed by a Snap for now
@@ -161,7 +130,7 @@ async function _MultichainTransactionsController_handleOnAccountAdded(account) {
161
130
  if (!__classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_isNonEvmAccount).call(this, account)) {
162
131
  return;
163
132
  }
164
- __classPrivateFieldGet(this, _MultichainTransactionsController_tracker, "f").track(account.id, __classPrivateFieldGet(this, _MultichainTransactionsController_instances, "m", _MultichainTransactionsController_getBlockTimeFor).call(this, account));
133
+ await this.updateTransactionsForAccount(account.id);
165
134
  }, _MultichainTransactionsController_handleOnAccountRemoved =
166
135
  /**
167
136
  * Handles changes when a new account has been removed.
@@ -169,14 +138,20 @@ async function _MultichainTransactionsController_handleOnAccountAdded(account) {
169
138
  * @param accountId - The account ID being removed.
170
139
  */
171
140
  async function _MultichainTransactionsController_handleOnAccountRemoved(accountId) {
172
- if (__classPrivateFieldGet(this, _MultichainTransactionsController_tracker, "f").isTracked(accountId)) {
173
- __classPrivateFieldGet(this, _MultichainTransactionsController_tracker, "f").untrack(accountId);
174
- }
175
141
  if (accountId in this.state.nonEvmTransactions) {
176
142
  this.update((state) => {
177
143
  delete state.nonEvmTransactions[accountId];
178
144
  });
179
145
  }
146
+ }, _MultichainTransactionsController_handleOnAccountTransactionsUpdated = function _MultichainTransactionsController_handleOnAccountTransactionsUpdated(transactionsUpdate) {
147
+ this.update((state) => {
148
+ Object.entries(transactionsUpdate.transactions).forEach(([accountId, transactions]) => {
149
+ if (accountId in state.nonEvmTransactions) {
150
+ state.nonEvmTransactions[accountId].transactions = transactions;
151
+ state.nonEvmTransactions[accountId].lastUpdated = Date.now();
152
+ }
153
+ });
154
+ });
180
155
  }, _MultichainTransactionsController_getClient = function _MultichainTransactionsController_getClient(snapId) {
181
156
  return new KeyringClient({
182
157
  send: async (request) => (await this.messagingSystem.call('SnapController:handleRequest', {
@@ -1 +1 @@
1
- {"version":3,"file":"MultichainTransactionsController.mjs","sourceRoot":"","sources":["../src/MultichainTransactionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EACL,cAAc,EAIf,kCAAkC;AACnC,OAAO,EAAE,gBAAgB,EAAoB,8BAA8B;AAE3E,OAAO,EAAE,aAAa,EAAE,sCAAsC;AAG9D,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAIpD,OAAO,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,wBAAoB;AAC9E,OAAO,EAAE,6BAA6B,EAAE,4CAAwC;AAEhF,MAAM,cAAc,GAAG,kCAAkC,CAAC;AAuB1D;;;;GAIG;AACH,MAAM,UAAU,+CAA+C;IAC7D,OAAO;QACL,kBAAkB,EAAE,EAAE;KACvB,CAAC;AACJ,CAAC;A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IAAI,sGAAiB,MAArB,IAAI,EAAkB,OAAO,CAAC,EAAE;QACnC,OAAO;KACR;IAED,uBAAA,IAAI,iDAAS,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,uBAAA,IAAI,sGAAiB,MAArB,IAAI,EAAkB,OAAO,CAAC,CAAC,CAAC;AAClE,CAAC;AAED;;;;GAIG;AACH,KAAK,mEAAyB,SAAiB;IAC7C,IAAI,uBAAA,IAAI,iDAAS,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;QACtC,uBAAA,IAAI,iDAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;KAClC;IAED,IAAI,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,kBAAkB,EAAE;QAC9C,IAAI,CAAC,MAAM,CAAC,CAAC,KAAmD,EAAE,EAAE;YAClE,OAAO,KAAK,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;KACJ;AACH,CAAC,qGAQU,MAAc;IACvB,OAAO,IAAI,aAAa,CAAC;QACvB,IAAI,EAAE,KAAK,EAAE,OAAuB,EAAE,EAAE,CACtC,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,8BAA8B,EAAE;YAC/D,MAAM,EAAE,MAAgB;YACxB,MAAM,EAAE,UAAU;YAClB,OAAO,EAAE,WAAW,CAAC,gBAAgB;YACrC,OAAO;SACR,CAAC,CAAkB;KACvB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerListMultichainAccountsAction,\n} from '@metamask/accounts-controller';\nimport {\n BaseController,\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type RestrictedMessenger,\n} from '@metamask/base-controller';\nimport { isEvmAccountType, type Transaction } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcRequest } from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport { MultichainNetwork, TRANSACTIONS_CHECK_INTERVALS } from './constants';\nimport { MultichainTransactionsTracker } from './MultichainTransactionsTracker';\n\nconst controllerName = 'MultichainTransactionsController';\n\n/**\n * PaginationOptions\n *\n * Represents options for paginating transaction results\n * limit - The maximum number of transactions to return\n * next - The cursor for the next page of transactions, or null if there is no next page\n */\nexport type PaginationOptions = {\n limit: number;\n next?: string | null;\n};\n\n/**\n * State used by the {@link MultichainTransactionsController} to cache account transactions.\n */\nexport type MultichainTransactionsControllerState = {\n nonEvmTransactions: {\n [accountId: string]: TransactionStateEntry;\n };\n};\n\n/**\n * Constructs the default {@link MultichainTransactionsController} state.\n *\n * @returns The default {@link MultichainTransactionsController} state.\n */\nexport function getDefaultMultichainTransactionsControllerState(): MultichainTransactionsControllerState {\n return {\n nonEvmTransactions: {},\n };\n}\n\n/**\n * Returns the state of the {@link MultichainTransactionsController}.\n */\nexport type MultichainTransactionsControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n MultichainTransactionsControllerState\n >;\n\n/**\n * Updates the transactions of all supported accounts.\n */\nexport type MultichainTransactionsControllerListTransactionsAction = {\n type: `${typeof controllerName}:updateTransactions`;\n handler: MultichainTransactionsController['updateTransactions'];\n};\n\n/**\n * Event emitted when the state of the {@link MultichainTransactionsController} changes.\n */\nexport type MultichainTransactionsControllerStateChange =\n ControllerStateChangeEvent<\n typeof controllerName,\n MultichainTransactionsControllerState\n >;\n\n/**\n * Actions exposed by the {@link MultichainTransactionsController}.\n */\nexport type MultichainTransactionsControllerActions =\n | MultichainTransactionsControllerGetStateAction\n | MultichainTransactionsControllerListTransactionsAction;\n\n/**\n * Events emitted by {@link MultichainTransactionsController}.\n */\nexport type MultichainTransactionsControllerEvents =\n MultichainTransactionsControllerStateChange;\n\n/**\n * Messenger type for the MultichainTransactionsController.\n */\nexport type MultichainTransactionsControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n MultichainTransactionsControllerActions | AllowedActions,\n MultichainTransactionsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Actions that this controller is allowed to call.\n */\nexport type AllowedActions =\n | HandleSnapRequest\n | AccountsControllerListMultichainAccountsAction;\n\n/**\n * Events that this controller is allowed to subscribe.\n */\nexport type AllowedEvents =\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent;\n\n/**\n * {@link MultichainTransactionsController}'s metadata.\n *\n * This allows us to choose if fields of the state should be persisted or not\n * using the `persist` flag; and if they can be sent to Sentry or not, using\n * the `anonymous` flag.\n */\nconst multichainTransactionsControllerMetadata = {\n nonEvmTransactions: {\n persist: true,\n anonymous: false,\n },\n};\n\n/**\n * The state of transactions for a specific account.\n */\nexport type TransactionStateEntry = {\n transactions: Transaction[];\n next: string | null;\n lastUpdated: number;\n};\n\n/**\n * The MultichainTransactionsController is responsible for fetching and caching account\n * transactions for non-EVM accounts.\n */\nexport class MultichainTransactionsController extends BaseController<\n typeof controllerName,\n MultichainTransactionsControllerState,\n MultichainTransactionsControllerMessenger\n> {\n readonly #tracker: MultichainTransactionsTracker;\n\n constructor({\n messenger,\n state,\n }: {\n messenger: MultichainTransactionsControllerMessenger;\n state?: Partial<MultichainTransactionsControllerState>;\n }) {\n super({\n messenger,\n name: controllerName,\n metadata: multichainTransactionsControllerMetadata,\n state: {\n ...getDefaultMultichainTransactionsControllerState(),\n ...state,\n },\n });\n\n this.#tracker = new MultichainTransactionsTracker(\n async (accountId: string, pagination: PaginationOptions) =>\n await this.#updateTransactions(accountId, pagination),\n );\n\n // Register all non-EVM accounts into the tracker\n for (const account of this.#listAccounts()) {\n if (this.#isNonEvmAccount(account)) {\n this.#tracker.track(account.id, this.#getBlockTimeFor(account));\n }\n }\n\n this.messagingSystem.subscribe(\n 'AccountsController:accountAdded',\n (account) => this.#handleOnAccountAdded(account),\n );\n this.messagingSystem.subscribe(\n 'AccountsController:accountRemoved',\n (accountId: string) => this.#handleOnAccountRemoved(accountId),\n );\n }\n\n /**\n * Lists the multichain accounts coming from the `AccountsController`.\n *\n * @returns A list of multichain accounts.\n */\n #listMultichainAccounts(): InternalAccount[] {\n return this.messagingSystem.call(\n 'AccountsController:listMultichainAccounts',\n );\n }\n\n /**\n * Lists the accounts that we should get transactions for.\n *\n * @returns A list of accounts that we should get transactions for.\n */\n #listAccounts(): InternalAccount[] {\n const accounts = this.#listMultichainAccounts();\n return accounts.filter((account) => this.#isNonEvmAccount(account));\n }\n\n /**\n * Updates the transactions for one account.\n *\n * @param accountId - The ID of the account to update transactions for.\n * @param pagination - Options for paginating transaction results.\n */\n async #updateTransactions(accountId: string, pagination: PaginationOptions) {\n const account = this.#listAccounts().find(\n (accountItem) => accountItem.id === accountId,\n );\n\n if (account?.metadata.snap) {\n const response = await this.#getTransactions(\n account.id,\n account.metadata.snap.id,\n pagination,\n );\n\n /**\n * Filter only Solana transactions to ensure they're mainnet\n * All other chain transactions are included as-is\n */\n const transactions = response.data.filter((tx) => {\n const chain = tx.chain as MultichainNetwork;\n if (chain.startsWith(MultichainNetwork.Solana)) {\n return chain === MultichainNetwork.Solana;\n }\n return true;\n });\n\n this.update((state: Draft<MultichainTransactionsControllerState>) => {\n const entry: TransactionStateEntry = {\n transactions,\n next: response.next,\n lastUpdated: Date.now(),\n };\n\n Object.assign(state.nonEvmTransactions, { [account.id]: entry });\n });\n }\n }\n\n /**\n * Gets transactions for an account.\n *\n * @param accountId - The ID of the account to get transactions for.\n * @param snapId - The ID of the snap that manages the account.\n * @param pagination - Options for paginating transaction results.\n * @returns A promise that resolves to the transaction data and pagination info.\n */\n async #getTransactions(\n accountId: string,\n snapId: string,\n pagination: PaginationOptions,\n ): Promise<{\n data: Transaction[];\n next: string | null;\n }> {\n return await this.#getClient(snapId).listAccountTransactions(\n accountId,\n pagination,\n );\n }\n\n /**\n * Updates transactions for a specific account\n *\n * @param accountId - The ID of the account to get transactions for.\n */\n async updateTransactionsForAccount(accountId: string) {\n await this.#tracker.updateTransactionsForAccount(accountId);\n }\n\n /**\n * Updates the transactions of all supported accounts. This method doesn't return\n * anything, but it updates the state of the controller.\n */\n async updateTransactions() {\n await this.#tracker.updateTransactions();\n }\n\n /**\n * Starts the polling process.\n */\n start(): void {\n this.#tracker.start();\n }\n\n /**\n * Stops the polling process.\n */\n stop(): void {\n this.#tracker.stop();\n }\n\n /**\n * Gets the block time for a given account.\n *\n * @param account - The account to get the block time for.\n * @returns The block time for the account.\n */\n #getBlockTimeFor(account: InternalAccount): number {\n if (account.type in TRANSACTIONS_CHECK_INTERVALS) {\n return TRANSACTIONS_CHECK_INTERVALS[\n account.type as keyof typeof TRANSACTIONS_CHECK_INTERVALS\n ];\n }\n throw new Error(\n `Unsupported account type for transactions tracking: ${account.type}`,\n );\n }\n\n /**\n * Checks for non-EVM accounts.\n *\n * @param account - The new account to be checked.\n * @returns True if the account is a non-EVM account, false otherwise.\n */\n #isNonEvmAccount(account: InternalAccount): boolean {\n return (\n !isEvmAccountType(account.type) &&\n // Non-EVM accounts are backed by a Snap for now\n account.metadata.snap !== undefined\n );\n }\n\n /**\n * Handles changes when a new account has been added.\n *\n * @param account - The new account being added.\n */\n async #handleOnAccountAdded(account: InternalAccount) {\n if (!this.#isNonEvmAccount(account)) {\n return;\n }\n\n this.#tracker.track(account.id, this.#getBlockTimeFor(account));\n }\n\n /**\n * Handles changes when a new account has been removed.\n *\n * @param accountId - The account ID being removed.\n */\n async #handleOnAccountRemoved(accountId: string) {\n if (this.#tracker.isTracked(accountId)) {\n this.#tracker.untrack(accountId);\n }\n\n if (accountId in this.state.nonEvmTransactions) {\n this.update((state: Draft<MultichainTransactionsControllerState>) => {\n delete state.nonEvmTransactions[accountId];\n });\n }\n }\n\n /**\n * Gets a `KeyringClient` for a Snap.\n *\n * @param snapId - ID of the Snap to get the client for.\n * @returns A `KeyringClient` for the Snap.\n */\n #getClient(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) =>\n (await this.messagingSystem.call('SnapController:handleRequest', {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n })) as Promise<Json>,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"MultichainTransactionsController.mjs","sourceRoot":"","sources":["../src/MultichainTransactionsController.ts"],"names":[],"mappings":";;;;;;AAMA,OAAO,EACL,cAAc,EAIf,kCAAkC;AACnC,OAAO,EACL,gBAAgB,EAGjB,8BAA8B;AAE/B,OAAO,EAAE,aAAa,EAAE,sCAAsC;AAG9D,OAAO,EAAE,WAAW,EAAE,8BAA8B;AACpD,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAGjB,wBAAwB;AAGzB,OAAO,EAAE,iBAAiB,EAAE,wBAAoB;AAEhD,MAAM,cAAc,GAAG,kCAAkC,CAAC;AAuB1D;;;;GAIG;AACH,MAAM,UAAU,+CAA+C;IAC7D,OAAO;QACL,kBAAkB,EAAE,EAAE;KACvB,CAAC;AACJ,CAAC;AA0DD;;;;;;GAMG;AACH,MAAM,wCAAwC,GAAG;IAC/C,kBAAkB,EAAE;QAClB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AAWF;;;GAGG;AACH,MAAM,OAAO,gCAAiC,SAAQ,cAIrD;IACC,YAAY,EACV,SAAS,EACT,KAAK,GAIN;QACC,KAAK,CAAC;YACJ,SAAS;YACT,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,wCAAwC;YAClD,KAAK,EAAE;gBACL,GAAG,+CAA+C,EAAE;gBACpD,GAAG,KAAK;aACT;SACF,CAAC,CAAC;;QAEH,sDAAsD;QACtD,KAAK,MAAM,OAAO,IAAI,uBAAA,IAAI,mGAAc,MAAlB,IAAI,CAAgB,EAAE;YAC1C,IAAI,CAAC,4BAA4B,CAAC,O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IACvB,OAAO,IAAI,aAAa,CAAC;QACvB,IAAI,EAAE,KAAK,EAAE,OAAuB,EAAE,EAAE,CACtC,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,8BAA8B,EAAE;YAC/D,MAAM,EAAE,MAAgB;YACxB,MAAM,EAAE,UAAU;YAClB,OAAO,EAAE,WAAW,CAAC,gBAAgB;YACrC,OAAO;SACR,CAAC,CAAkB;KACvB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerListMultichainAccountsAction,\n AccountsControllerAccountTransactionsUpdatedEvent,\n} from '@metamask/accounts-controller';\nimport {\n BaseController,\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type RestrictedMessenger,\n} from '@metamask/base-controller';\nimport {\n isEvmAccountType,\n type Transaction,\n type AccountTransactionsUpdatedEventPayload,\n} from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringClient } from '@metamask/keyring-snap-client';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport {\n KnownCaipNamespace,\n parseCaipChainId,\n type Json,\n type JsonRpcRequest,\n} from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport { MultichainNetwork } from './constants';\n\nconst controllerName = 'MultichainTransactionsController';\n\n/**\n * PaginationOptions\n *\n * Represents options for paginating transaction results\n * limit - The maximum number of transactions to return\n * next - The cursor for the next page of transactions, or null if there is no next page\n */\nexport type PaginationOptions = {\n limit: number;\n next?: string | null;\n};\n\n/**\n * State used by the {@link MultichainTransactionsController} to cache account transactions.\n */\nexport type MultichainTransactionsControllerState = {\n nonEvmTransactions: {\n [accountId: string]: TransactionStateEntry;\n };\n};\n\n/**\n * Constructs the default {@link MultichainTransactionsController} state.\n *\n * @returns The default {@link MultichainTransactionsController} state.\n */\nexport function getDefaultMultichainTransactionsControllerState(): MultichainTransactionsControllerState {\n return {\n nonEvmTransactions: {},\n };\n}\n\n/**\n * Returns the state of the {@link MultichainTransactionsController}.\n */\nexport type MultichainTransactionsControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n MultichainTransactionsControllerState\n >;\n\n/**\n * Event emitted when the state of the {@link MultichainTransactionsController} changes.\n */\nexport type MultichainTransactionsControllerStateChange =\n ControllerStateChangeEvent<\n typeof controllerName,\n MultichainTransactionsControllerState\n >;\n\n/**\n * Actions exposed by the {@link MultichainTransactionsController}.\n */\nexport type MultichainTransactionsControllerActions =\n MultichainTransactionsControllerGetStateAction;\n\n/**\n * Events emitted by {@link MultichainTransactionsController}.\n */\nexport type MultichainTransactionsControllerEvents =\n MultichainTransactionsControllerStateChange;\n\n/**\n * Messenger type for the MultichainTransactionsController.\n */\nexport type MultichainTransactionsControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n MultichainTransactionsControllerActions | AllowedActions,\n MultichainTransactionsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Actions that this controller is allowed to call.\n */\nexport type AllowedActions =\n | HandleSnapRequest\n | AccountsControllerListMultichainAccountsAction;\n\n/**\n * Events that this controller is allowed to subscribe.\n */\nexport type AllowedEvents =\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountTransactionsUpdatedEvent;\n\n/**\n * {@link MultichainTransactionsController}'s metadata.\n *\n * This allows us to choose if fields of the state should be persisted or not\n * using the `persist` flag; and if they can be sent to Sentry or not, using\n * the `anonymous` flag.\n */\nconst multichainTransactionsControllerMetadata = {\n nonEvmTransactions: {\n persist: true,\n anonymous: false,\n },\n};\n\n/**\n * The state of transactions for a specific account.\n */\nexport type TransactionStateEntry = {\n transactions: Transaction[];\n next: string | null;\n lastUpdated: number;\n};\n\n/**\n * The MultichainTransactionsController is responsible for fetching and caching account\n * transactions for non-EVM accounts.\n */\nexport class MultichainTransactionsController extends BaseController<\n typeof controllerName,\n MultichainTransactionsControllerState,\n MultichainTransactionsControllerMessenger\n> {\n constructor({\n messenger,\n state,\n }: {\n messenger: MultichainTransactionsControllerMessenger;\n state?: Partial<MultichainTransactionsControllerState>;\n }) {\n super({\n messenger,\n name: controllerName,\n metadata: multichainTransactionsControllerMetadata,\n state: {\n ...getDefaultMultichainTransactionsControllerState(),\n ...state,\n },\n });\n\n // Fetch initial transactions for all non-EVM accounts\n for (const account of this.#listAccounts()) {\n this.updateTransactionsForAccount(account.id).catch((error) => {\n console.error(\n `Failed to fetch initial transactions for account ${account.id}:`,\n error,\n );\n });\n }\n\n this.messagingSystem.subscribe(\n 'AccountsController:accountAdded',\n (account: InternalAccount) => this.#handleOnAccountAdded(account),\n );\n this.messagingSystem.subscribe(\n 'AccountsController:accountRemoved',\n (accountId: string) => this.#handleOnAccountRemoved(accountId),\n );\n this.messagingSystem.subscribe(\n 'AccountsController:accountTransactionsUpdated',\n (transactionsUpdate: AccountTransactionsUpdatedEventPayload) =>\n this.#handleOnAccountTransactionsUpdated(transactionsUpdate),\n );\n }\n\n /**\n * Lists the multichain accounts coming from the `AccountsController`.\n *\n * @returns A list of multichain accounts.\n */\n #listMultichainAccounts(): InternalAccount[] {\n return this.messagingSystem.call(\n 'AccountsController:listMultichainAccounts',\n );\n }\n\n /**\n * Lists the accounts that we should get transactions for.\n *\n * @returns A list of accounts that we should get transactions for.\n */\n #listAccounts(): InternalAccount[] {\n const accounts = this.#listMultichainAccounts();\n return accounts.filter((account) => this.#isNonEvmAccount(account));\n }\n\n /**\n * Gets transactions for an account.\n *\n * @param accountId - The ID of the account to get transactions for.\n * @param snapId - The ID of the snap that manages the account.\n * @param pagination - Options for paginating transaction results.\n * @returns A promise that resolves to the transaction data and pagination info.\n */\n async #getTransactions(\n accountId: string,\n snapId: string,\n pagination: PaginationOptions,\n ): Promise<{\n data: Transaction[];\n next: string | null;\n }> {\n return await this.#getClient(snapId).listAccountTransactions(\n accountId,\n pagination,\n );\n }\n\n /**\n * Updates transactions for a specific account. This is used for the initial fetch\n * when an account is first added.\n *\n * @param accountId - The ID of the account to get transactions for.\n */\n async updateTransactionsForAccount(accountId: string) {\n try {\n const account = this.#listAccounts().find(\n (accountItem) => accountItem.id === accountId,\n );\n\n if (account?.metadata.snap) {\n const response = await this.#getTransactions(\n account.id,\n account.metadata.snap.id,\n { limit: 10 },\n );\n\n // Filter only Solana transactions to ensure they're on mainnet.\n // All other chain transactions are included as-is.\n // TODO: Maybe we should not do any filtering here? Or maybe have it\n // being configurable somehow?\n const transactions = response.data.filter((tx) => {\n const chain = tx.chain as MultichainNetwork;\n const { namespace } = parseCaipChainId(chain);\n // Enum comparison is safe here as we control both enum values\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n if (namespace === KnownCaipNamespace.Solana) {\n return chain === MultichainNetwork.Solana;\n }\n return true;\n });\n\n this.update((state: Draft<MultichainTransactionsControllerState>) => {\n const entry: TransactionStateEntry = {\n transactions,\n next: response.next,\n lastUpdated: Date.now(),\n };\n\n Object.assign(state.nonEvmTransactions, { [account.id]: entry });\n });\n }\n } catch (error) {\n console.error(\n `Failed to fetch transactions for account ${accountId}:`,\n error,\n );\n }\n }\n\n /**\n * Checks for non-EVM accounts.\n *\n * @param account - The new account to be checked.\n * @returns True if the account is a non-EVM account, false otherwise.\n */\n #isNonEvmAccount(account: InternalAccount): boolean {\n return (\n !isEvmAccountType(account.type) &&\n // Non-EVM accounts are backed by a Snap for now\n account.metadata.snap !== undefined\n );\n }\n\n /**\n * Handles changes when a new account has been added.\n *\n * @param account - The new account being added.\n */\n async #handleOnAccountAdded(account: InternalAccount) {\n if (!this.#isNonEvmAccount(account)) {\n return;\n }\n\n await this.updateTransactionsForAccount(account.id);\n }\n\n /**\n * Handles changes when a new account has been removed.\n *\n * @param accountId - The account ID being removed.\n */\n async #handleOnAccountRemoved(accountId: string) {\n if (accountId in this.state.nonEvmTransactions) {\n this.update((state: Draft<MultichainTransactionsControllerState>) => {\n delete state.nonEvmTransactions[accountId];\n });\n }\n }\n\n /**\n * Handles transaction updates received from the AccountsController.\n *\n * @param transactionsUpdate - The transaction update event containing new transactions.\n */\n #handleOnAccountTransactionsUpdated(\n transactionsUpdate: AccountTransactionsUpdatedEventPayload,\n ): void {\n this.update((state: Draft<MultichainTransactionsControllerState>) => {\n Object.entries(transactionsUpdate.transactions).forEach(\n ([accountId, transactions]) => {\n if (accountId in state.nonEvmTransactions) {\n state.nonEvmTransactions[accountId].transactions = transactions;\n state.nonEvmTransactions[accountId].lastUpdated = Date.now();\n }\n },\n );\n });\n }\n\n /**\n * Gets a `KeyringClient` for a Snap.\n *\n * @param snapId - ID of the Snap to get the client for.\n * @returns A `KeyringClient` for the Snap.\n */\n #getClient(snapId: string): KeyringClient {\n return new KeyringClient({\n send: async (request: JsonRpcRequest) =>\n (await this.messagingSystem.call('SnapController:handleRequest', {\n snapId: snapId as SnapId,\n origin: 'metamask',\n handler: HandlerType.OnKeyringRequest,\n request,\n })) as Promise<Json>,\n });\n }\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NETWORK_ASSETS_MAP = exports.TRANSACTIONS_CHECK_INTERVALS = exports.MultichainNativeAsset = exports.MultichainNetwork = void 0;
4
- const keyring_api_1 = require("@metamask/keyring-api");
3
+ exports.NETWORK_ASSETS_MAP = exports.MultichainNativeAsset = exports.MultichainNetwork = void 0;
5
4
  /**
6
5
  * The network identifiers for supported networks in CAIP-2 format.
7
6
  * Note: This is a temporary workaround until we have a more robust
@@ -23,15 +22,6 @@ var MultichainNativeAsset;
23
22
  MultichainNativeAsset["SolanaDevnet"] = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501";
24
23
  MultichainNativeAsset["SolanaTestnet"] = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501";
25
24
  })(MultichainNativeAsset || (exports.MultichainNativeAsset = MultichainNativeAsset = {}));
26
- const BITCOIN_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds
27
- const SOLANA_TRANSACTIONS_UPDATE_TIME = 7000; // 7 seconds
28
- const BTC_TRANSACTIONS_UPDATE_TIME = BITCOIN_AVG_BLOCK_TIME / 2;
29
- exports.TRANSACTIONS_CHECK_INTERVALS = {
30
- // NOTE: We set an interval of half the average block time for bitcoin
31
- // to mitigate when our interval is de-synchronized with the actual block time.
32
- [keyring_api_1.BtcAccountType.P2wpkh]: BTC_TRANSACTIONS_UPDATE_TIME,
33
- [keyring_api_1.SolAccountType.DataAccount]: SOLANA_TRANSACTIONS_UPDATE_TIME,
34
- };
35
25
  /**
36
26
  * Maps network identifiers to their corresponding native asset types.
37
27
  * Each network is mapped to an array containing its native asset for consistency.
@@ -1 +1 @@
1
- {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,uDAAuE;AAEvE;;;;GAIG;AACH,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,wEAAmD,CAAA;IACnD,+EAA0D,CAAA;IAC1D,uEAAkD,CAAA;IAClD,6EAAwD,CAAA;IACxD,8EAAyD,CAAA;AAC3D,CAAC,EANW,iBAAiB,iCAAjB,iBAAiB,QAM5B;AAED,IAAY,qBAMX;AAND,WAAY,qBAAqB;IAC/B,qFAAiD,CAAA;IACjD,4FAA+D,CAAA;IAC/D,sFAAiD,CAAA;IACjD,4FAA6D,CAAA;IAC7D,6FAA+D,CAAA;AACjE,CAAC,EANW,qBAAqB,qCAArB,qBAAqB,QAMhC;AAED,MAAM,sBAAsB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,6BAA6B;AAC5E,MAAM,+BAA+B,GAAG,IAAI,CAAC,CAAC,YAAY;AAC1D,MAAM,4BAA4B,GAAG,sBAAsB,GAAG,CAAC,CAAC;AAEnD,QAAA,4BAA4B,GAAG;IAC1C,sEAAsE;IACtE,+EAA+E;IAC/E,CAAC,4BAAc,CAAC,MAAM,CAAC,EAAE,4BAA4B;IACrD,CAAC,4BAAc,CAAC,WAAW,CAAC,EAAE,+BAA+B;CAC9D,CAAC;AAEF;;;GAGG;AACU,QAAA,kBAAkB,GAA4C;IACzE,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC,qBAAqB,CAAC,MAAM,CAAC;IAC1D,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE,CAAC,qBAAqB,CAAC,aAAa,CAAC;IACxE,CAAC,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC,qBAAqB,CAAC,YAAY,CAAC;IACtE,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC;IAC5D,CAAC,iBAAiB,CAAC,cAAc,CAAC,EAAE,CAAC,qBAAqB,CAAC,cAAc,CAAC;CAC3E,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 MultichainNetwork {\n Bitcoin = 'bip122:000000000019d6689c085ae165831e93',\n BitcoinTestnet = 'bip122:000000000933ea01ad0ee984209779ba',\n Solana = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',\n SolanaDevnet = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',\n SolanaTestnet = 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',\n}\n\nexport enum MultichainNativeAsset {\n Bitcoin = `${MultichainNetwork.Bitcoin}/slip44:0`,\n BitcoinTestnet = `${MultichainNetwork.BitcoinTestnet}/slip44:0`,\n Solana = `${MultichainNetwork.Solana}/slip44:501`,\n SolanaDevnet = `${MultichainNetwork.SolanaDevnet}/slip44:501`,\n SolanaTestnet = `${MultichainNetwork.SolanaTestnet}/slip44:501`,\n}\n\nconst BITCOIN_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds\nconst SOLANA_TRANSACTIONS_UPDATE_TIME = 7000; // 7 seconds\nconst BTC_TRANSACTIONS_UPDATE_TIME = BITCOIN_AVG_BLOCK_TIME / 2;\n\nexport const TRANSACTIONS_CHECK_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]: BTC_TRANSACTIONS_UPDATE_TIME,\n [SolAccountType.DataAccount]: SOLANA_TRANSACTIONS_UPDATE_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, MultichainNativeAsset[]> = {\n [MultichainNetwork.Solana]: [MultichainNativeAsset.Solana],\n [MultichainNetwork.SolanaTestnet]: [MultichainNativeAsset.SolanaTestnet],\n [MultichainNetwork.SolanaDevnet]: [MultichainNativeAsset.SolanaDevnet],\n [MultichainNetwork.Bitcoin]: [MultichainNativeAsset.Bitcoin],\n [MultichainNetwork.BitcoinTestnet]: [MultichainNativeAsset.BitcoinTestnet],\n};\n"]}
1
+ {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,wEAAmD,CAAA;IACnD,+EAA0D,CAAA;IAC1D,uEAAkD,CAAA;IAClD,6EAAwD,CAAA;IACxD,8EAAyD,CAAA;AAC3D,CAAC,EANW,iBAAiB,iCAAjB,iBAAiB,QAM5B;AAED,IAAY,qBAMX;AAND,WAAY,qBAAqB;IAC/B,qFAAiD,CAAA;IACjD,4FAA+D,CAAA;IAC/D,sFAAiD,CAAA;IACjD,4FAA6D,CAAA;IAC7D,6FAA+D,CAAA;AACjE,CAAC,EANW,qBAAqB,qCAArB,qBAAqB,QAMhC;AAED;;;GAGG;AACU,QAAA,kBAAkB,GAA4C;IACzE,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC,qBAAqB,CAAC,MAAM,CAAC;IAC1D,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE,CAAC,qBAAqB,CAAC,aAAa,CAAC;IACxE,CAAC,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC,qBAAqB,CAAC,YAAY,CAAC;IACtE,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC;IAC5D,CAAC,iBAAiB,CAAC,cAAc,CAAC,EAAE,CAAC,qBAAqB,CAAC,cAAc,CAAC;CAC3E,CAAC","sourcesContent":["/**\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 MultichainNetwork {\n Bitcoin = 'bip122:000000000019d6689c085ae165831e93',\n BitcoinTestnet = 'bip122:000000000933ea01ad0ee984209779ba',\n Solana = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',\n SolanaDevnet = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',\n SolanaTestnet = 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',\n}\n\nexport enum MultichainNativeAsset {\n Bitcoin = `${MultichainNetwork.Bitcoin}/slip44:0`,\n BitcoinTestnet = `${MultichainNetwork.BitcoinTestnet}/slip44:0`,\n Solana = `${MultichainNetwork.Solana}/slip44:501`,\n SolanaDevnet = `${MultichainNetwork.SolanaDevnet}/slip44:501`,\n SolanaTestnet = `${MultichainNetwork.SolanaTestnet}/slip44:501`,\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, MultichainNativeAsset[]> = {\n [MultichainNetwork.Solana]: [MultichainNativeAsset.Solana],\n [MultichainNetwork.SolanaTestnet]: [MultichainNativeAsset.SolanaTestnet],\n [MultichainNetwork.SolanaDevnet]: [MultichainNativeAsset.SolanaDevnet],\n [MultichainNetwork.Bitcoin]: [MultichainNativeAsset.Bitcoin],\n [MultichainNetwork.BitcoinTestnet]: [MultichainNativeAsset.BitcoinTestnet],\n};\n"]}
@@ -17,10 +17,6 @@ export declare enum MultichainNativeAsset {
17
17
  SolanaDevnet = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501",
18
18
  SolanaTestnet = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501"
19
19
  }
20
- export declare const TRANSACTIONS_CHECK_INTERVALS: {
21
- "bip122:p2wpkh": number;
22
- "solana:data-account": number;
23
- };
24
20
  /**
25
21
  * Maps network identifiers to their corresponding native asset types.
26
22
  * Each network is mapped to an array containing its native asset for consistency.
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,oBAAY,iBAAiB;IAC3B,OAAO,4CAA4C;IACnD,cAAc,4CAA4C;IAC1D,MAAM,4CAA4C;IAClD,YAAY,4CAA4C;IACxD,aAAa,4CAA4C;CAC1D;AAED,oBAAY,qBAAqB;IAC/B,OAAO,qDAA0C;IACjD,cAAc,qDAAiD;IAC/D,MAAM,uDAA2C;IACjD,YAAY,uDAAiD;IAC7D,aAAa,uDAAkD;CAChE;AAMD,eAAO,MAAM,4BAA4B;;;CAKxC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAMtE,CAAC"}
1
+ {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,oBAAY,iBAAiB;IAC3B,OAAO,4CAA4C;IACnD,cAAc,4CAA4C;IAC1D,MAAM,4CAA4C;IAClD,YAAY,4CAA4C;IACxD,aAAa,4CAA4C;CAC1D;AAED,oBAAY,qBAAqB;IAC/B,OAAO,qDAA0C;IACjD,cAAc,qDAAiD;IAC/D,MAAM,uDAA2C;IACjD,YAAY,uDAAiD;IAC7D,aAAa,uDAAkD;CAChE;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAMtE,CAAC"}
@@ -17,10 +17,6 @@ export declare enum MultichainNativeAsset {
17
17
  SolanaDevnet = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501",
18
18
  SolanaTestnet = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501"
19
19
  }
20
- export declare const TRANSACTIONS_CHECK_INTERVALS: {
21
- "bip122:p2wpkh": number;
22
- "solana:data-account": number;
23
- };
24
20
  /**
25
21
  * Maps network identifiers to their corresponding native asset types.
26
22
  * Each network is mapped to an array containing its native asset for consistency.
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,oBAAY,iBAAiB;IAC3B,OAAO,4CAA4C;IACnD,cAAc,4CAA4C;IAC1D,MAAM,4CAA4C;IAClD,YAAY,4CAA4C;IACxD,aAAa,4CAA4C;CAC1D;AAED,oBAAY,qBAAqB;IAC/B,OAAO,qDAA0C;IACjD,cAAc,qDAAiD;IAC/D,MAAM,uDAA2C;IACjD,YAAY,uDAAiD;IAC7D,aAAa,uDAAkD;CAChE;AAMD,eAAO,MAAM,4BAA4B;;;CAKxC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAMtE,CAAC"}
1
+ {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,oBAAY,iBAAiB;IAC3B,OAAO,4CAA4C;IACnD,cAAc,4CAA4C;IAC1D,MAAM,4CAA4C;IAClD,YAAY,4CAA4C;IACxD,aAAa,4CAA4C;CAC1D;AAED,oBAAY,qBAAqB;IAC/B,OAAO,qDAA0C;IACjD,cAAc,qDAAiD;IAC/D,MAAM,uDAA2C;IACjD,YAAY,uDAAiD;IAC7D,aAAa,uDAAkD;CAChE;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,EAAE,CAMtE,CAAC"}
@@ -1,4 +1,3 @@
1
- import { BtcAccountType, SolAccountType } from "@metamask/keyring-api";
2
1
  /**
3
2
  * The network identifiers for supported networks in CAIP-2 format.
4
3
  * Note: This is a temporary workaround until we have a more robust
@@ -20,15 +19,6 @@ export var MultichainNativeAsset;
20
19
  MultichainNativeAsset["SolanaDevnet"] = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501";
21
20
  MultichainNativeAsset["SolanaTestnet"] = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z/slip44:501";
22
21
  })(MultichainNativeAsset || (MultichainNativeAsset = {}));
23
- const BITCOIN_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds
24
- const SOLANA_TRANSACTIONS_UPDATE_TIME = 7000; // 7 seconds
25
- const BTC_TRANSACTIONS_UPDATE_TIME = BITCOIN_AVG_BLOCK_TIME / 2;
26
- export const TRANSACTIONS_CHECK_INTERVALS = {
27
- // NOTE: We set an interval of half the average block time for bitcoin
28
- // to mitigate when our interval is de-synchronized with the actual block time.
29
- [BtcAccountType.P2wpkh]: BTC_TRANSACTIONS_UPDATE_TIME,
30
- [SolAccountType.DataAccount]: SOLANA_TRANSACTIONS_UPDATE_TIME,
31
- };
32
22
  /**
33
23
  * Maps network identifiers to their corresponding native asset types.
34
24
  * Each network is mapped to an array containing its native asset for consistency.
@@ -1 +1 @@
1
- {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAEvE;;;;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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 MultichainNetwork {\n Bitcoin = 'bip122:000000000019d6689c085ae165831e93',\n BitcoinTestnet = 'bip122:000000000933ea01ad0ee984209779ba',\n Solana = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',\n SolanaDevnet = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',\n SolanaTestnet = 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',\n}\n\nexport enum MultichainNativeAsset {\n Bitcoin = `${MultichainNetwork.Bitcoin}/slip44:0`,\n BitcoinTestnet = `${MultichainNetwork.BitcoinTestnet}/slip44:0`,\n Solana = `${MultichainNetwork.Solana}/slip44:501`,\n SolanaDevnet = `${MultichainNetwork.SolanaDevnet}/slip44:501`,\n SolanaTestnet = `${MultichainNetwork.SolanaTestnet}/slip44:501`,\n}\n\nconst BITCOIN_AVG_BLOCK_TIME = 10 * 60 * 1000; // 10 minutes in milliseconds\nconst SOLANA_TRANSACTIONS_UPDATE_TIME = 7000; // 7 seconds\nconst BTC_TRANSACTIONS_UPDATE_TIME = BITCOIN_AVG_BLOCK_TIME / 2;\n\nexport const TRANSACTIONS_CHECK_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]: BTC_TRANSACTIONS_UPDATE_TIME,\n [SolAccountType.DataAccount]: SOLANA_TRANSACTIONS_UPDATE_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, MultichainNativeAsset[]> = {\n [MultichainNetwork.Solana]: [MultichainNativeAsset.Solana],\n [MultichainNetwork.SolanaTestnet]: [MultichainNativeAsset.SolanaTestnet],\n [MultichainNetwork.SolanaDevnet]: [MultichainNativeAsset.SolanaDevnet],\n [MultichainNetwork.Bitcoin]: [MultichainNativeAsset.Bitcoin],\n [MultichainNetwork.BitcoinTestnet]: [MultichainNativeAsset.BitcoinTestnet],\n};\n"]}
1
+ {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAN,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,wEAAmD,CAAA;IACnD,+EAA0D,CAAA;IAC1D,uEAAkD,CAAA;IAClD,6EAAwD,CAAA;IACxD,8EAAyD,CAAA;AAC3D,CAAC,EANW,iBAAiB,KAAjB,iBAAiB,QAM5B;AAED,MAAM,CAAN,IAAY,qBAMX;AAND,WAAY,qBAAqB;IAC/B,qFAAiD,CAAA;IACjD,4FAA+D,CAAA;IAC/D,sFAAiD,CAAA;IACjD,4FAA6D,CAAA;IAC7D,6FAA+D,CAAA;AACjE,CAAC,EANW,qBAAqB,KAArB,qBAAqB,QAMhC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA4C;IACzE,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC,qBAAqB,CAAC,MAAM,CAAC;IAC1D,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE,CAAC,qBAAqB,CAAC,aAAa,CAAC;IACxE,CAAC,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC,qBAAqB,CAAC,YAAY,CAAC;IACtE,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC;IAC5D,CAAC,iBAAiB,CAAC,cAAc,CAAC,EAAE,CAAC,qBAAqB,CAAC,cAAc,CAAC;CAC3E,CAAC","sourcesContent":["/**\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 MultichainNetwork {\n Bitcoin = 'bip122:000000000019d6689c085ae165831e93',\n BitcoinTestnet = 'bip122:000000000933ea01ad0ee984209779ba',\n Solana = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',\n SolanaDevnet = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1',\n SolanaTestnet = 'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z',\n}\n\nexport enum MultichainNativeAsset {\n Bitcoin = `${MultichainNetwork.Bitcoin}/slip44:0`,\n BitcoinTestnet = `${MultichainNetwork.BitcoinTestnet}/slip44:0`,\n Solana = `${MultichainNetwork.Solana}/slip44:501`,\n SolanaDevnet = `${MultichainNetwork.SolanaDevnet}/slip44:501`,\n SolanaTestnet = `${MultichainNetwork.SolanaTestnet}/slip44:501`,\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, MultichainNativeAsset[]> = {\n [MultichainNetwork.Solana]: [MultichainNativeAsset.Solana],\n [MultichainNetwork.SolanaTestnet]: [MultichainNativeAsset.SolanaTestnet],\n [MultichainNetwork.SolanaDevnet]: [MultichainNativeAsset.SolanaDevnet],\n [MultichainNetwork.Bitcoin]: [MultichainNativeAsset.Bitcoin],\n [MultichainNetwork.BitcoinTestnet]: [MultichainNativeAsset.BitcoinTestnet],\n};\n"]}
package/dist/index.cjs CHANGED
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MultichainNativeAsset = exports.MultichainNetwork = exports.NETWORK_ASSETS_MAP = exports.TRANSACTIONS_CHECK_INTERVALS = exports.MultichainTransactionsController = void 0;
3
+ exports.MultichainNativeAsset = exports.MultichainNetwork = exports.NETWORK_ASSETS_MAP = exports.MultichainTransactionsController = void 0;
4
4
  var MultichainTransactionsController_1 = require("./MultichainTransactionsController.cjs");
5
5
  Object.defineProperty(exports, "MultichainTransactionsController", { enumerable: true, get: function () { return MultichainTransactionsController_1.MultichainTransactionsController; } });
6
6
  var constants_1 = require("./constants.cjs");
7
- Object.defineProperty(exports, "TRANSACTIONS_CHECK_INTERVALS", { enumerable: true, get: function () { return constants_1.TRANSACTIONS_CHECK_INTERVALS; } });
8
7
  Object.defineProperty(exports, "NETWORK_ASSETS_MAP", { enumerable: true, get: function () { return constants_1.NETWORK_ASSETS_MAP; } });
9
8
  Object.defineProperty(exports, "MultichainNetwork", { enumerable: true, get: function () { return constants_1.MultichainNetwork; } });
10
9
  Object.defineProperty(exports, "MultichainNativeAsset", { enumerable: true, get: function () { return constants_1.MultichainNativeAsset; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2FAAsF;AAA7E,oJAAA,gCAAgC,OAAA;AAMzC,6CAKqB;AAJnB,yHAAA,4BAA4B,OAAA;AAC5B,+GAAA,kBAAkB,OAAA;AAClB,8GAAA,iBAAiB,OAAA;AACjB,kHAAA,qBAAqB,OAAA","sourcesContent":["export { MultichainTransactionsController } from './MultichainTransactionsController';\nexport type {\n MultichainTransactionsControllerState,\n PaginationOptions,\n TransactionStateEntry,\n} from './MultichainTransactionsController';\nexport {\n TRANSACTIONS_CHECK_INTERVALS,\n NETWORK_ASSETS_MAP,\n MultichainNetwork,\n MultichainNativeAsset,\n} from './constants';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2FAAsF;AAA7E,oJAAA,gCAAgC,OAAA;AAMzC,6CAIqB;AAHnB,+GAAA,kBAAkB,OAAA;AAClB,8GAAA,iBAAiB,OAAA;AACjB,kHAAA,qBAAqB,OAAA","sourcesContent":["export { MultichainTransactionsController } from './MultichainTransactionsController';\nexport type {\n MultichainTransactionsControllerState,\n PaginationOptions,\n TransactionStateEntry,\n} from './MultichainTransactionsController';\nexport {\n NETWORK_ASSETS_MAP,\n MultichainNetwork,\n MultichainNativeAsset,\n} from './constants';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { MultichainTransactionsController } from "./MultichainTransactionsController.cjs";
2
2
  export type { MultichainTransactionsControllerState, PaginationOptions, TransactionStateEntry, } from "./MultichainTransactionsController.cjs";
3
- export { TRANSACTIONS_CHECK_INTERVALS, NETWORK_ASSETS_MAP, MultichainNetwork, MultichainNativeAsset, } from "./constants.cjs";
3
+ export { NETWORK_ASSETS_MAP, MultichainNetwork, MultichainNativeAsset, } from "./constants.cjs";
4
4
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,+CAA2C;AACtF,YAAY,EACV,qCAAqC,EACrC,iBAAiB,EACjB,qBAAqB,GACtB,+CAA2C;AAC5C,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,GACtB,wBAAoB"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,+CAA2C;AACtF,YAAY,EACV,qCAAqC,EACrC,iBAAiB,EACjB,qBAAqB,GACtB,+CAA2C;AAC5C,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,GACtB,wBAAoB"}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { MultichainTransactionsController } from "./MultichainTransactionsController.mjs";
2
2
  export type { MultichainTransactionsControllerState, PaginationOptions, TransactionStateEntry, } from "./MultichainTransactionsController.mjs";
3
- export { TRANSACTIONS_CHECK_INTERVALS, NETWORK_ASSETS_MAP, MultichainNetwork, MultichainNativeAsset, } from "./constants.mjs";
3
+ export { NETWORK_ASSETS_MAP, MultichainNetwork, MultichainNativeAsset, } from "./constants.mjs";
4
4
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,+CAA2C;AACtF,YAAY,EACV,qCAAqC,EACrC,iBAAiB,EACjB,qBAAqB,GACtB,+CAA2C;AAC5C,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,GACtB,wBAAoB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,+CAA2C;AACtF,YAAY,EACV,qCAAqC,EACrC,iBAAiB,EACjB,qBAAqB,GACtB,+CAA2C;AAC5C,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,GACtB,wBAAoB"}
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  export { MultichainTransactionsController } from "./MultichainTransactionsController.mjs";
2
- export { TRANSACTIONS_CHECK_INTERVALS, NETWORK_ASSETS_MAP, MultichainNetwork, MultichainNativeAsset } from "./constants.mjs";
2
+ export { NETWORK_ASSETS_MAP, MultichainNetwork, MultichainNativeAsset } from "./constants.mjs";
3
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,+CAA2C;AAMtF,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACtB,wBAAoB","sourcesContent":["export { MultichainTransactionsController } from './MultichainTransactionsController';\nexport type {\n MultichainTransactionsControllerState,\n PaginationOptions,\n TransactionStateEntry,\n} from './MultichainTransactionsController';\nexport {\n TRANSACTIONS_CHECK_INTERVALS,\n NETWORK_ASSETS_MAP,\n MultichainNetwork,\n MultichainNativeAsset,\n} from './constants';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,+CAA2C;AAMtF,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACtB,wBAAoB","sourcesContent":["export { MultichainTransactionsController } from './MultichainTransactionsController';\nexport type {\n MultichainTransactionsControllerState,\n PaginationOptions,\n TransactionStateEntry,\n} from './MultichainTransactionsController';\nexport {\n NETWORK_ASSETS_MAP,\n MultichainNetwork,\n MultichainNativeAsset,\n} from './constants';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/multichain-transactions-controller",
3
- "version": "0.1.0-preview-99939da3",
3
+ "version": "0.2.0-preview-224dff25",
4
4
  "description": "This package is responsible for getting transactions from our Bitcoin and Solana snaps",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -48,22 +48,22 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@metamask/base-controller": "^7.1.1",
51
- "@metamask/keyring-api": "^16.1.0",
51
+ "@metamask/keyring-api": "^17.0.0",
52
52
  "@metamask/keyring-internal-api": "^4.0.1",
53
53
  "@metamask/keyring-snap-client": "^3.0.3",
54
54
  "@metamask/polling-controller": "^12.0.2",
55
- "@metamask/snaps-controllers": "^9.10.0",
56
- "@metamask/snaps-sdk": "^6.16.0",
57
- "@metamask/snaps-utils": "^8.9.0",
55
+ "@metamask/snaps-controllers": "^9.19.0",
56
+ "@metamask/snaps-sdk": "^6.17.1",
57
+ "@metamask/snaps-utils": "^8.10.0",
58
58
  "@metamask/utils": "^11.1.0",
59
59
  "@types/uuid": "^8.3.0",
60
60
  "immer": "^9.0.6",
61
61
  "uuid": "^8.3.2"
62
62
  },
63
63
  "devDependencies": {
64
- "@metamask/accounts-controller": "^22.0.0",
64
+ "@metamask/accounts-controller": "^23.0.0",
65
65
  "@metamask/auto-changelog": "^3.4.4",
66
- "@metamask/keyring-controller": "^19.0.5",
66
+ "@metamask/keyring-controller": "^19.0.6",
67
67
  "@types/jest": "^27.4.1",
68
68
  "deepmerge": "^4.2.2",
69
69
  "jest": "^27.5.1",
@@ -73,8 +73,8 @@
73
73
  "typescript": "~5.2.2"
74
74
  },
75
75
  "peerDependencies": {
76
- "@metamask/accounts-controller": "^22.0.0",
77
- "@metamask/snaps-controllers": "^9.10.0"
76
+ "@metamask/accounts-controller": "^23.0.0",
77
+ "@metamask/snaps-controllers": "^9.19.0"
78
78
  },
79
79
  "engines": {
80
80
  "node": "^18.18 || >=20"