Skip to content

chore: create new assets controller package#7587

Merged
salimtb merged 13 commits into
mainfrom
chore/create-new-assets-controller-package
Jan 12, 2026
Merged

chore: create new assets controller package#7587
salimtb merged 13 commits into
mainfrom
chore/create-new-assets-controller-package

Conversation

@salimtb

@salimtb salimtb commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Explanation

This PR introduces a new @metamask/assets-controller package as a placeholder for future consolidation of asset tracking functionality.

Current state:
Asset tracking functionality (account balances, token balances, asset detection) is currently spread across multiple controllers in the @metamask/assets-controllers package.

Solution:
This PR creates an empty @metamask/assets-controller package as a foundation for future work to consolidate asset tracking into a single, unified controller. The package currently exports nothing and serves as a placeholder with TODOs indicating the intended scope:

  • Account balance tracking
  • Token balance tracking
  • Asset detection

No functional changes are included in this PR.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Introduces a scaffolded @metamask/assets-controller package (empty controller, exports, tests, build/test/docs configs, changelog, license) as a foundation for future asset tracking consolidation.

  • Adds packages/assets-controller with AssetsController stub, unit tests, TypeScript/Jest/Typedoc configs, and package metadata
  • Updates monorepo wiring: README package list and dependency graph, tsconfig.json/tsconfig.build.json references, yarn.lock, .github/CODEOWNERS, and teams.json

Written by Cursor Bugbot for commit 65d631f. This will update automatically on new commits. Configure here.

@salimtb salimtb marked this pull request as ready for review January 8, 2026 16:05
@salimtb salimtb requested a review from a team as a code owner January 8, 2026 16:05
Comment thread packages/assets-controller/package.json Outdated
Comment thread tsconfig.build.json
Comment thread tsconfig.json
Comment thread packages/assets-controller/src/AssetsController.test.ts Outdated
Comment thread packages/assets-controller/src/AssetsController.ts Outdated
Comment thread packages/assets-controller/src/index.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two questions:

  1. What do you think about copying and pasting one of the controllers in the sample-controllers package? This way we can keep the general look and feel for a controller consistent across all packages.

  2. I see that we are creating a new package called assets-controller, when we already have a package called assets-controllers (with an "s"). I'm a bit worried this will be a constant source of confusion, and so perhaps we shouldn't make a new package yet? Or — are there any near-term plans to split apart assets-controllers?

@salimtb salimtb Jan 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcmire yes, there are near-term plans to split apart assets-controllers. The goal is to deprecate the existing assets-controllers (plural) package and break it into several focused, single-responsibility packages:

  • @metamask/assets-controller - consolidated asset tracking (balances, detection)
  • Other controllers from the package will be split into their own dedicated packages as well

The naming is intentional:

  • assets-controllers = legacy "kitchen sink" package (to be deprecated)
  • assets-controller = new single unified controller

This follows the pattern we've used elsewhere in the monorepo where packages contain a single controller (e.g., @metamask/network-controller, @metamask/keyring-controller).

Once the migration is complete and assets-controllers is deprecated and deleted, the confusion will be resolved. In the meantime, we can add a note to the assets-controllers README indicating it's being deprecated and pointing to the new packages.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@salimtb Okay, that sounds like a great plan. Thanks for clarifying!

@salimtb salimtb requested a review from mcmire January 12, 2026 09:52
mcmire
mcmire previously approved these changes Jan 12, 2026

@mcmire mcmire left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left another comment, but it's non-blocking. LGTM!

Comment thread packages/assets-controller/src/AssetsController.test.ts Outdated

@cryptodev-2s cryptodev-2s left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@salimtb salimtb added this pull request to the merge queue Jan 12, 2026
Merged via the queue into main with commit b250eeb Jan 12, 2026
290 checks passed
@salimtb salimtb deleted the chore/create-new-assets-controller-package branch January 12, 2026 15:17
@salimtb salimtb mentioned this pull request Jan 23, 2026
4 tasks
github-merge-queue Bot pushed a commit that referenced this pull request Jan 23, 2026
## Explanation

This PR adds comprehensive unit tests for the new
`@metamask/assets-controller` package to ensure code quality and
maintainability.

**Current state:** The assets-controller package was recently introduced
with a middleware-based architecture for unified asset management across
all blockchain networks. However, test coverage was limited, leaving
critical code paths untested.

**Changes in this PR:**
- Added unit tests for all data sources:
- `AccountsApiDataSource` (18 tests, includes timer cleanup fix using
`.unref()` to prevent Jest worker process hanging)
  - `BackendWebsocketDataSource` (19 tests)
  - `PriceDataSource` (29 tests)
  - `TokenDataSource` (20 tests)
  - `SnapDataSource` (47 tests)
- Added unit tests for `DetectionMiddleware` (13 tests, 100% coverage)
- Expanded unit tests for `AssetsController` (42 tests, coverage
increased from 33% to 81%)

**Test architecture patterns used:**
- `setupController` / `withController` helper functions for consistent
test setup
- Proper messenger mocking with `MOCK_ANY_NAMESPACE`
- Test cleanup to prevent resource leaks
- `it.each` for parameterized tests where applicable
- Flat test structure avoiding deeply nested describe blocks

## References

- Related to #7685 (AssetsController middleware architecture)
- Related to #7587 (Initial assets-controller release)

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Significantly increases test coverage and validates core behaviors
across the new middleware-based assets stack.
> 
> - Add extensive unit tests for `AssetsController`,
`DetectionMiddleware`, and data sources: `AbstractDataSource`,
`AccountsApiDataSource`, `BackendWebsocketDataSource`,
`PriceDataSource`, `RpcDataSource`, and `SnapDataSource`
> - Cover subscriptions, middleware chaining, lifecycle/events
(app/keyring/network), WebSocket handling, pricing polls, and snap-based
balances
> - Update `RpcDataSource` to import `BalanceFetcher`,
`MulticallClient`, and `TokenDetector` from `evm-rpc-services` (was
`rpc-datasource`)
> - Update `CHANGELOG.md` to note test additions
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
9b08b0a. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants