From 203574dc6ce6636c21bc999c6615e44ac121d88b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 5 Aug 2026 18:09:04 +0000 Subject: [PATCH 1/3] feat(tron-wallet-snap): add Core messenger plumbing Instantiate Core messenger via getMessenger and wire RemoteFeatureFlagsProvider / AssetsProvider into context for the upcoming AssetsController migration. Reads still delegate to SnapAssetsAdapter. Co-authored-by: Ulisses Ferreira --- packages/tron-wallet-snap/CHANGELOG.md | 4 +++ packages/tron-wallet-snap/package.json | 4 +++ packages/tron-wallet-snap/snap.manifest.json | 10 +++++- packages/tron-wallet-snap/src/context.ts | 35 ++++++++++++++++++- .../src/services/assets/AssetsService.ts | 6 ++++ .../src/types/core-messenger.ts | 26 ++++++++++++++ yarn.lock | 6 +++- 7 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 packages/tron-wallet-snap/src/types/core-messenger.ts diff --git a/packages/tron-wallet-snap/CHANGELOG.md b/packages/tron-wallet-snap/CHANGELOG.md index bcc74af7..4cc38345 100644 --- a/packages/tron-wallet-snap/CHANGELOG.md +++ b/packages/tron-wallet-snap/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add Core messenger plumbing (`getMessenger`, `RemoteFeatureFlagsProvider`, `AssetsProvider`) for upcoming AssetsController migration ([#95](https://github.com/MetaMask/internal-snaps/pull/95)) + ## [3.0.0] ### Added diff --git a/packages/tron-wallet-snap/package.json b/packages/tron-wallet-snap/package.json index a5b4812d..cd070615 100644 --- a/packages/tron-wallet-snap/package.json +++ b/packages/tron-wallet-snap/package.json @@ -48,10 +48,14 @@ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch" }, "devDependencies": { + "@metamask/assets-controller": "^13.0.0", "@metamask/auto-changelog": "^6.1.1", "@metamask/key-tree": "^10.1.1", "@metamask/keyring-api": "^23.7.0", "@metamask/keyring-snap-sdk": "^9.2.1", + "@metamask/messenger": "^2.0.0", + "@metamask/remote-feature-flag-controller": "^5.0.0", + "@metamask/snap-networks-utils": "^1.0.0", "@metamask/snaps-cli": "^8.4.1", "@metamask/snaps-jest": "^10.2.0", "@metamask/snaps-sdk": "^11.2.0", diff --git a/packages/tron-wallet-snap/snap.manifest.json b/packages/tron-wallet-snap/snap.manifest.json index cd954760..b94dd0f8 100644 --- a/packages/tron-wallet-snap/snap.manifest.json +++ b/packages/tron-wallet-snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/internal-snaps.git" }, "source": { - "shasum": "s5YqLxf2VlRkjAfbTnHJCZXjWGdcaOi3h0JCe+wHeXo=", + "shasum": "cCGFsmmHvqXTN3l54lg4dLDAv3pMqnVc523G4GfZKJA=", "location": { "npm": { "filePath": "dist/bundle.js", @@ -63,6 +63,14 @@ }, "endowment:assets": { "scopes": ["tron:728126428"] + }, + "endowment:messenger": { + "actions": [ + "RemoteFeatureFlagController:getState", + "AssetsController:getAccountAssetByID", + "AssetsController:getAccountAssetsByIDs", + "AssetsController:getAccountAssetsByScope" + ] } }, "platformVersion": "11.2.0", diff --git a/packages/tron-wallet-snap/src/context.ts b/packages/tron-wallet-snap/src/context.ts index db5c9641..278d549b 100644 --- a/packages/tron-wallet-snap/src/context.ts +++ b/packages/tron-wallet-snap/src/context.ts @@ -1,3 +1,13 @@ +import { + AssetsProvider, + RemoteFeatureFlagsProvider, +} from '@metamask/snap-networks-utils'; +import type { + AssetsProviderMessenger, + RemoteFeatureFlagsProviderMessenger, +} from '@metamask/snap-networks-utils'; +import { getMessenger } from '@metamask/snaps-sdk'; + import { InMemoryCache } from './caching/InMemoryCache'; import { StateCache } from './caching/StateCache'; import { PriceApiClient } from './clients/price-api/PriceApiClient'; @@ -29,6 +39,7 @@ import { TransactionScanService } from './services/transaction-scan/TransactionS import { TransactionsRepository } from './services/transactions/TransactionsRepository'; import { TransactionsService } from './services/transactions/TransactionsService'; import { WalletService } from './services/wallet/WalletService'; +import type { CoreMessenger } from './types/core-messenger'; import logger, { noOpLogger } from './utils/logger'; /** @@ -82,13 +93,24 @@ const priceApiClient = new PriceApiClient(configProvider, priceCache); // Token API client const tokenApiClient = new TokenApiClient(configProvider); +/** + * Core controllers plumbing + */ +const coreMessenger = getMessenger(); +const remoteFeatureFlagsProvider = new RemoteFeatureFlagsProvider({ + messenger: coreMessenger as RemoteFeatureFlagsProviderMessenger, +}); +const assetsProvider = new AssetsProvider({ + messenger: coreMessenger as AssetsProviderMessenger, +}); + // Security Alerts API client const securityAlertsApiClient = new SecurityAlertsApiClient( configProvider, logger, ); -// Business Services - depend on Repositories, State and other Services +// Business Services const assetsService = new AssetsService({ logger, state, @@ -98,6 +120,8 @@ const assetsService = new AssetsService({ priceApiClient, tokenApiClient, snapClient, + remoteFeatureFlagsProvider, + assetsProvider, }); const transactionsService = new TransactionsService({ @@ -235,6 +259,12 @@ export type SnapExecutionContext = { confirmationHandler: ConfirmationHandler; transactionScanService: TransactionScanService; transactionExpirationRefresherService: TransactionExpirationRefresherService; + /** + * Core messenger plumbing (routing wired in a follow-up PR). + */ + coreMessenger: CoreMessenger; + remoteFeatureFlagsProvider: RemoteFeatureFlagsProvider; + assetsProvider: AssetsProvider; /** * Handlers */ @@ -267,6 +297,9 @@ const snapContext: SnapExecutionContext = { confirmationHandler, transactionScanService, transactionExpirationRefresherService, + coreMessenger, + remoteFeatureFlagsProvider, + assetsProvider, /** * Handlers */ diff --git a/packages/tron-wallet-snap/src/services/assets/AssetsService.ts b/packages/tron-wallet-snap/src/services/assets/AssetsService.ts index 6ba8e4a3..77f63dc8 100644 --- a/packages/tron-wallet-snap/src/services/assets/AssetsService.ts +++ b/packages/tron-wallet-snap/src/services/assets/AssetsService.ts @@ -1,4 +1,8 @@ import type { KeyringAccount } from '@metamask/keyring-api'; +import { + AssetsProvider, + RemoteFeatureFlagsProvider, +} from '@metamask/snap-networks-utils'; import type { AssetConversion, AssetMetadata, @@ -47,6 +51,8 @@ export class AssetsService { priceApiClient: PriceApiClient; tokenApiClient: TokenApiClient; snapClient: SnapClient; + remoteFeatureFlagsProvider: RemoteFeatureFlagsProvider; + assetsProvider: AssetsProvider; }) { this.#snapAdapter = new SnapAssetsAdapter({ logger, diff --git a/packages/tron-wallet-snap/src/types/core-messenger.ts b/packages/tron-wallet-snap/src/types/core-messenger.ts new file mode 100644 index 00000000..7c826d76 --- /dev/null +++ b/packages/tron-wallet-snap/src/types/core-messenger.ts @@ -0,0 +1,26 @@ +import type { + AssetsControllerGetAccountAssetByIDAction, + AssetsControllerGetAccountAssetsByIDsAction, + AssetsControllerGetAccountAssetsByScopeAction, +} from '@metamask/assets-controller'; +import type { Messenger } from '@metamask/messenger'; +import type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller'; + +/** + * Namespace for this Snap's Core messenger endowment. + */ +export const TRON_WALLET_SNAP_MESSENGER_NAMESPACE = 'TronWalletSnap' as const; + +export type CoreMessengerActions = + | RemoteFeatureFlagControllerGetStateAction + | AssetsControllerGetAccountAssetByIDAction + | AssetsControllerGetAccountAssetsByIDsAction + | AssetsControllerGetAccountAssetsByScopeAction; + +/** + * Messenger type passed to `getMessenger` for Core controller actions. + */ +export type CoreMessenger = Messenger< + typeof TRON_WALLET_SNAP_MESSENGER_NAMESPACE, + CoreMessengerActions +>; diff --git a/yarn.lock b/yarn.lock index 14ac741c..3c395809 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3312,7 +3312,7 @@ __metadata: languageName: node linkType: hard -"@metamask/snap-networks-utils@workspace:packages/snap-networks-utils": +"@metamask/snap-networks-utils@npm:^1.0.0, @metamask/snap-networks-utils@workspace:packages/snap-networks-utils": version: 0.0.0-use.local resolution: "@metamask/snap-networks-utils@workspace:packages/snap-networks-utils" dependencies: @@ -3780,10 +3780,14 @@ __metadata: version: 0.0.0-use.local resolution: "@metamask/tron-wallet-snap@workspace:packages/tron-wallet-snap" dependencies: + "@metamask/assets-controller": "npm:^13.0.0" "@metamask/auto-changelog": "npm:^6.1.1" "@metamask/key-tree": "npm:^10.1.1" "@metamask/keyring-api": "npm:^23.7.0" "@metamask/keyring-snap-sdk": "npm:^9.2.1" + "@metamask/messenger": "npm:^2.0.0" + "@metamask/remote-feature-flag-controller": "npm:^5.0.0" + "@metamask/snap-networks-utils": "npm:^1.0.0" "@metamask/snaps-cli": "npm:^8.4.1" "@metamask/snaps-jest": "npm:^10.2.0" "@metamask/snaps-sdk": "npm:^11.2.0" From 8862c6f8ce172e32b032c5abfa66c0a7d16c94e6 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 5 Aug 2026 18:22:25 +0000 Subject: [PATCH 2/3] fix(tron-wallet-snap): sync CI manifest shasum Co-authored-by: Ulisses Ferreira --- packages/tron-wallet-snap/snap.manifest.json | 24 +++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/tron-wallet-snap/snap.manifest.json b/packages/tron-wallet-snap/snap.manifest.json index b94dd0f8..5d618aeb 100644 --- a/packages/tron-wallet-snap/snap.manifest.json +++ b/packages/tron-wallet-snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/internal-snaps.git" }, "source": { - "shasum": "cCGFsmmHvqXTN3l54lg4dLDAv3pMqnVc523G4GfZKJA=", + "shasum": "B9kqmuUcYgPAD3ojseIm2HymqK77Q4NEzULU876+5Wc=", "location": { "npm": { "filePath": "dist/bundle.js", @@ -16,16 +16,22 @@ "registry": "https://registry.npmjs.org/" } }, - "locales": ["locales/en.json"] + "locales": [ + "locales/en.json" + ] }, "initialConnections": { "https://portfolio.metamask.io": {} }, "initialPermissions": { "endowment:keyring": { - "allowedOrigins": ["https://portfolio.metamask.io"], + "allowedOrigins": [ + "https://portfolio.metamask.io" + ], "capabilities": { - "scopes": ["tron:728126428"], + "scopes": [ + "tron:728126428" + ], "privateKey": { "exportFormats": [ { @@ -42,7 +48,11 @@ }, "snap_getBip32Entropy": [ { - "path": ["m", "44'", "195'"], + "path": [ + "m", + "44'", + "195'" + ], "curve": "secp256k1" } ], @@ -62,7 +72,9 @@ ] }, "endowment:assets": { - "scopes": ["tron:728126428"] + "scopes": [ + "tron:728126428" + ] }, "endowment:messenger": { "actions": [ From 9428a5260a71a3708dcb71fc409dbbfad4b8c336 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 5 Aug 2026 18:29:40 +0000 Subject: [PATCH 3/3] fix(tron-wallet-snap): format manifest and sync CI shasum Co-authored-by: Ulisses Ferreira --- packages/tron-wallet-snap/snap.manifest.json | 22 +++++--------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/packages/tron-wallet-snap/snap.manifest.json b/packages/tron-wallet-snap/snap.manifest.json index 5d618aeb..30ac1291 100644 --- a/packages/tron-wallet-snap/snap.manifest.json +++ b/packages/tron-wallet-snap/snap.manifest.json @@ -16,22 +16,16 @@ "registry": "https://registry.npmjs.org/" } }, - "locales": [ - "locales/en.json" - ] + "locales": ["locales/en.json"] }, "initialConnections": { "https://portfolio.metamask.io": {} }, "initialPermissions": { "endowment:keyring": { - "allowedOrigins": [ - "https://portfolio.metamask.io" - ], + "allowedOrigins": ["https://portfolio.metamask.io"], "capabilities": { - "scopes": [ - "tron:728126428" - ], + "scopes": ["tron:728126428"], "privateKey": { "exportFormats": [ { @@ -48,11 +42,7 @@ }, "snap_getBip32Entropy": [ { - "path": [ - "m", - "44'", - "195'" - ], + "path": ["m", "44'", "195'"], "curve": "secp256k1" } ], @@ -72,9 +62,7 @@ ] }, "endowment:assets": { - "scopes": [ - "tron:728126428" - ] + "scopes": ["tron:728126428"] }, "endowment:messenger": { "actions": [