Skip to content

Comments

feat: add staked balance data source#7936

Merged
salimtb merged 26 commits intomainfrom
feat/add-staked-balance-data-source
Feb 17, 2026
Merged

feat: add staked balance data source#7936
salimtb merged 26 commits intomainfrom
feat/add-staked-balance-data-source

Conversation

@salimtb
Copy link
Contributor

@salimtb salimtb commented Feb 15, 2026

Explanation

Current state: AssetsController already had accountsApiDataSourceConfig and priceDataSourceConfig for per-data-source options (e.g. pollInterval, tokenDetectionEnabled). Two gaps: (1) priceDataSourceConfig.pollInterval was not applied when subscribing to price updates—the controller always passed its defaultUpdateInterval into the subscription request, so the price data source’s configured interval was never used and spot-price requests did not follow the configured interval. (2) The staked balance data source had no dedicated config object on the controller, so consumers could not configure it (e.g. enabled, pollInterval) in the same way as the other data sources.

Solution: (1) The controller now stores priceDataSourceConfig?.pollInterval in a #pricePollInterval field and uses it when calling subscribeAssetsPrice (as the default updateInterval). So e.g. priceDataSourceConfig: { pollInterval: 5000 } results in spot-price requests every 5s. (2) StakedBalanceDataSourceConfig and stakedBalanceDataSourceConfig are added to the controller options and passed through to StakedBalanceDataSource, supporting enabled and pollInterval so the staked balance data source is configurable alongside accounts API and price.

Non-obvious: Price polling uses the subscription request’s updateInterval when present; the data source’s internal #pollInterval is only a fallback. So the fix had to be in the controller: pass the configured price interval when building the subscription request rather than relying on the data source default.

No other packages or dependencies were changed in this PR.

UI extension: MetaMask/metamask-extension#40137

References

  • None.

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

Medium Risk
Introduces new polling/chain-selection logic and transaction-driven refresh behavior that can affect balance accuracy and update frequency across networks. While scoped to the assets pipeline, it touches subscription lifecycle and network/transaction event handling.

Overview
Adds a new StakedBalanceDataSource and StakedBalanceFetcher that poll known staking contracts on enabled EVM chains and merge staked balances (and built-in metadata) into assetsBalance; the controller now subscribes/unsubscribes this source separately and exposes stakedBalanceDataSourceConfig (enabled, pollInterval).

Fixes price subscriptions to default to priceDataSourceConfig.pollInterval when no updateInterval is provided, hardens CAIP parsing (skip malformed asset IDs; rely on @metamask/utils helpers), and updates RpcDataSource to refresh balances on TransactionController confirmed/incoming transaction events. Tests and dependencies/TS references are updated accordingly (adds @metamask/transaction-controller and @metamask/assets-controllers).

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

@salimtb salimtb changed the title Feat/add staked balance data source feat: add staked balance data source Feb 16, 2026
@salimtb salimtb marked this pull request as ready for review February 16, 2026 09:07
@salimtb salimtb requested review from a team as code owners February 16, 2026 09:07
@salimtb
Copy link
Contributor Author

salimtb commented Feb 16, 2026

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-tree-controller": "4.1.1-preview-1ad6631",
  "@metamask-previews/accounts-controller": "36.0.0-preview-1ad6631",
  "@metamask-previews/address-book-controller": "7.0.1-preview-1ad6631",
  "@metamask-previews/ai-controllers": "0.0.0-preview-1ad6631",
  "@metamask-previews/analytics-controller": "1.0.0-preview-1ad6631",
  "@metamask-previews/analytics-data-regulation-controller": "0.0.0-preview-1ad6631",
  "@metamask-previews/announcement-controller": "8.0.0-preview-1ad6631",
  "@metamask-previews/app-metadata-controller": "2.0.0-preview-1ad6631",
  "@metamask-previews/approval-controller": "8.0.0-preview-1ad6631",
  "@metamask-previews/assets-controller": "1.0.0-preview-1ad6631",
  "@metamask-previews/assets-controllers": "99.3.2-preview-1ad6631",
  "@metamask-previews/base-controller": "9.0.0-preview-1ad6631",
  "@metamask-previews/bridge-controller": "66.1.1-preview-1ad6631",
  "@metamask-previews/bridge-status-controller": "66.0.2-preview-1ad6631",
  "@metamask-previews/build-utils": "3.0.4-preview-1ad6631",
  "@metamask-previews/chain-agnostic-permission": "1.4.0-preview-1ad6631",
  "@metamask-previews/claims-controller": "0.4.2-preview-1ad6631",
  "@metamask-previews/composable-controller": "12.0.0-preview-1ad6631",
  "@metamask-previews/connectivity-controller": "0.1.0-preview-1ad6631",
  "@metamask-previews/controller-utils": "11.18.0-preview-1ad6631",
  "@metamask-previews/core-backend": "5.1.1-preview-1ad6631",
  "@metamask-previews/delegation-controller": "2.0.1-preview-1ad6631",
  "@metamask-previews/earn-controller": "11.1.0-preview-1ad6631",
  "@metamask-previews/eip-5792-middleware": "2.1.0-preview-1ad6631",
  "@metamask-previews/eip-7702-internal-rpc-middleware": "0.1.0-preview-1ad6631",
  "@metamask-previews/eip1193-permission-middleware": "1.0.3-preview-1ad6631",
  "@metamask-previews/ens-controller": "19.0.2-preview-1ad6631",
  "@metamask-previews/error-reporting-service": "3.0.1-preview-1ad6631",
  "@metamask-previews/eth-block-tracker": "15.0.1-preview-1ad6631",
  "@metamask-previews/eth-json-rpc-middleware": "23.1.0-preview-1ad6631",
  "@metamask-previews/eth-json-rpc-provider": "6.0.0-preview-1ad6631",
  "@metamask-previews/foundryup": "1.0.1-preview-1ad6631",
  "@metamask-previews/gas-fee-controller": "26.0.2-preview-1ad6631",
  "@metamask-previews/gator-permissions-controller": "1.1.2-preview-1ad6631",
  "@metamask-previews/json-rpc-engine": "10.2.2-preview-1ad6631",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.8-preview-1ad6631",
  "@metamask-previews/keyring-controller": "25.1.0-preview-1ad6631",
  "@metamask-previews/logging-controller": "7.0.1-preview-1ad6631",
  "@metamask-previews/message-manager": "14.1.0-preview-1ad6631",
  "@metamask-previews/messenger": "0.3.0-preview-1ad6631",
  "@metamask-previews/multichain-account-service": "7.0.0-preview-1ad6631",
  "@metamask-previews/multichain-api-middleware": "1.2.6-preview-1ad6631",
  "@metamask-previews/multichain-network-controller": "3.0.3-preview-1ad6631",
  "@metamask-previews/multichain-transactions-controller": "7.0.1-preview-1ad6631",
  "@metamask-previews/name-controller": "9.0.0-preview-1ad6631",
  "@metamask-previews/network-controller": "29.0.0-preview-1ad6631",
  "@metamask-previews/network-enablement-controller": "4.1.0-preview-1ad6631",
  "@metamask-previews/notification-services-controller": "22.0.0-preview-1ad6631",
  "@metamask-previews/permission-controller": "12.2.0-preview-1ad6631",
  "@metamask-previews/permission-log-controller": "5.0.0-preview-1ad6631",
  "@metamask-previews/perps-controller": "0.0.0-preview-1ad6631",
  "@metamask-previews/phishing-controller": "16.2.0-preview-1ad6631",
  "@metamask-previews/polling-controller": "16.0.2-preview-1ad6631",
  "@metamask-previews/preferences-controller": "22.1.0-preview-1ad6631",
  "@metamask-previews/profile-metrics-controller": "3.0.1-preview-1ad6631",
  "@metamask-previews/profile-sync-controller": "27.1.0-preview-1ad6631",
  "@metamask-previews/ramps-controller": "8.0.0-preview-1ad6631",
  "@metamask-previews/rate-limit-controller": "7.0.0-preview-1ad6631",
  "@metamask-previews/remote-feature-flag-controller": "4.0.0-preview-1ad6631",
  "@metamask-previews/sample-controllers": "4.0.2-preview-1ad6631",
  "@metamask-previews/seedless-onboarding-controller": "8.0.0-preview-1ad6631",
  "@metamask-previews/selected-network-controller": "26.0.2-preview-1ad6631",
  "@metamask-previews/shield-controller": "5.0.1-preview-1ad6631",
  "@metamask-previews/signature-controller": "39.0.2-preview-1ad6631",
  "@metamask-previews/storage-service": "1.0.0-preview-1ad6631",
  "@metamask-previews/subscription-controller": "6.0.0-preview-1ad6631",
  "@metamask-previews/transaction-controller": "62.17.0-preview-1ad6631",
  "@metamask-previews/transaction-pay-controller": "15.0.0-preview-1ad6631",
  "@metamask-previews/user-operation-controller": "41.0.2-preview-1ad6631"
}

@salimtb salimtb requested a review from Kriys94 February 16, 2026 11:08
@salimtb salimtb requested a review from Kriys94 February 16, 2026 14:13
@socket-security
Copy link

socket-security bot commented Feb 16, 2026

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

@salimtb
Copy link
Contributor Author

salimtb commented Feb 16, 2026

@SocketSecurity ignore npm/@metamask/assets-controllers@99.4.0

Internal package; network access is required for token lists, metadata, and price APIs. Reviewed and accepted.

Copy link
Contributor

@Prithpal-Sooriya Prithpal-Sooriya left a comment

Choose a reason for hiding this comment

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

As discussed, we can fully tackle the messenger types in a followup PR.

@salimtb
Copy link
Contributor Author

salimtb commented Feb 16, 2026

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-tree-controller": "4.1.1-preview-0cc7da31a",
  "@metamask-previews/accounts-controller": "36.0.0-preview-0cc7da31a",
  "@metamask-previews/address-book-controller": "7.0.1-preview-0cc7da31a",
  "@metamask-previews/ai-controllers": "0.0.0-preview-0cc7da31a",
  "@metamask-previews/analytics-controller": "1.0.0-preview-0cc7da31a",
  "@metamask-previews/analytics-data-regulation-controller": "0.0.0-preview-0cc7da31a",
  "@metamask-previews/announcement-controller": "8.0.0-preview-0cc7da31a",
  "@metamask-previews/app-metadata-controller": "2.0.0-preview-0cc7da31a",
  "@metamask-previews/approval-controller": "8.0.0-preview-0cc7da31a",
  "@metamask-previews/assets-controller": "1.0.0-preview-0cc7da31a",
  "@metamask-previews/assets-controllers": "99.4.0-preview-0cc7da31a",
  "@metamask-previews/base-controller": "9.0.0-preview-0cc7da31a",
  "@metamask-previews/bridge-controller": "66.1.1-preview-0cc7da31a",
  "@metamask-previews/bridge-status-controller": "66.0.2-preview-0cc7da31a",
  "@metamask-previews/build-utils": "3.0.4-preview-0cc7da31a",
  "@metamask-previews/chain-agnostic-permission": "1.4.0-preview-0cc7da31a",
  "@metamask-previews/claims-controller": "0.4.2-preview-0cc7da31a",
  "@metamask-previews/composable-controller": "12.0.0-preview-0cc7da31a",
  "@metamask-previews/connectivity-controller": "0.1.0-preview-0cc7da31a",
  "@metamask-previews/controller-utils": "11.18.0-preview-0cc7da31a",
  "@metamask-previews/core-backend": "5.1.1-preview-0cc7da31a",
  "@metamask-previews/delegation-controller": "2.0.1-preview-0cc7da31a",
  "@metamask-previews/earn-controller": "11.1.0-preview-0cc7da31a",
  "@metamask-previews/eip-5792-middleware": "2.1.0-preview-0cc7da31a",
  "@metamask-previews/eip-7702-internal-rpc-middleware": "0.1.0-preview-0cc7da31a",
  "@metamask-previews/eip1193-permission-middleware": "1.0.3-preview-0cc7da31a",
  "@metamask-previews/ens-controller": "19.0.2-preview-0cc7da31a",
  "@metamask-previews/error-reporting-service": "3.0.1-preview-0cc7da31a",
  "@metamask-previews/eth-block-tracker": "15.0.1-preview-0cc7da31a",
  "@metamask-previews/eth-json-rpc-middleware": "23.1.0-preview-0cc7da31a",
  "@metamask-previews/eth-json-rpc-provider": "6.0.0-preview-0cc7da31a",
  "@metamask-previews/foundryup": "1.0.1-preview-0cc7da31a",
  "@metamask-previews/gas-fee-controller": "26.0.2-preview-0cc7da31a",
  "@metamask-previews/gator-permissions-controller": "1.1.2-preview-0cc7da31a",
  "@metamask-previews/json-rpc-engine": "10.2.2-preview-0cc7da31a",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.8-preview-0cc7da31a",
  "@metamask-previews/keyring-controller": "25.1.0-preview-0cc7da31a",
  "@metamask-previews/logging-controller": "7.0.1-preview-0cc7da31a",
  "@metamask-previews/message-manager": "14.1.0-preview-0cc7da31a",
  "@metamask-previews/messenger": "0.3.0-preview-0cc7da31a",
  "@metamask-previews/multichain-account-service": "7.0.0-preview-0cc7da31a",
  "@metamask-previews/multichain-api-middleware": "1.2.6-preview-0cc7da31a",
  "@metamask-previews/multichain-network-controller": "3.0.3-preview-0cc7da31a",
  "@metamask-previews/multichain-transactions-controller": "7.0.1-preview-0cc7da31a",
  "@metamask-previews/name-controller": "9.0.0-preview-0cc7da31a",
  "@metamask-previews/network-controller": "29.0.0-preview-0cc7da31a",
  "@metamask-previews/network-enablement-controller": "4.1.0-preview-0cc7da31a",
  "@metamask-previews/notification-services-controller": "22.0.0-preview-0cc7da31a",
  "@metamask-previews/permission-controller": "12.2.0-preview-0cc7da31a",
  "@metamask-previews/permission-log-controller": "5.0.0-preview-0cc7da31a",
  "@metamask-previews/perps-controller": "0.0.0-preview-0cc7da31a",
  "@metamask-previews/phishing-controller": "16.2.0-preview-0cc7da31a",
  "@metamask-previews/polling-controller": "16.0.2-preview-0cc7da31a",
  "@metamask-previews/preferences-controller": "22.1.0-preview-0cc7da31a",
  "@metamask-previews/profile-metrics-controller": "3.0.1-preview-0cc7da31a",
  "@metamask-previews/profile-sync-controller": "27.1.0-preview-0cc7da31a",
  "@metamask-previews/ramps-controller": "8.0.0-preview-0cc7da31a",
  "@metamask-previews/rate-limit-controller": "7.0.0-preview-0cc7da31a",
  "@metamask-previews/remote-feature-flag-controller": "4.0.0-preview-0cc7da31a",
  "@metamask-previews/sample-controllers": "4.0.2-preview-0cc7da31a",
  "@metamask-previews/seedless-onboarding-controller": "8.0.0-preview-0cc7da31a",
  "@metamask-previews/selected-network-controller": "26.0.2-preview-0cc7da31a",
  "@metamask-previews/shield-controller": "5.0.1-preview-0cc7da31a",
  "@metamask-previews/signature-controller": "39.0.2-preview-0cc7da31a",
  "@metamask-previews/storage-service": "1.0.0-preview-0cc7da31a",
  "@metamask-previews/subscription-controller": "6.0.0-preview-0cc7da31a",
  "@metamask-previews/transaction-controller": "62.17.0-preview-0cc7da31a",
  "@metamask-previews/transaction-pay-controller": "15.0.1-preview-0cc7da31a",
  "@metamask-previews/user-operation-controller": "41.0.2-preview-0cc7da31a"
}

Copy link
Contributor

@Prithpal-Sooriya Prithpal-Sooriya left a comment

Choose a reason for hiding this comment

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

As discussed we will have a follow up to use valid messenger setup, and remove all the type assertions.

@salimtb salimtb added this pull request to the merge queue Feb 17, 2026
Merged via the queue into main with commit d92f1bb Feb 17, 2026
302 checks passed
@salimtb salimtb deleted the feat/add-staked-balance-data-source branch February 17, 2026 10:05
khanti42 pushed a commit that referenced this pull request Feb 20, 2026
## Explanation

<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->

**Current state:** AssetsController already had
`accountsApiDataSourceConfig` and `priceDataSourceConfig` for
per-data-source options (e.g. `pollInterval`, `tokenDetectionEnabled`).
Two gaps: (1) `priceDataSourceConfig.pollInterval` was not applied when
subscribing to price updates—the controller always passed its
`defaultUpdateInterval` into the subscription request, so the price data
source’s configured interval was never used and spot-price requests did
not follow the configured interval. (2) The staked balance data source
had no dedicated config object on the controller, so consumers could not
configure it (e.g. `enabled`, `pollInterval`) in the same way as the
other data sources.

**Solution:** (1) The controller now stores
`priceDataSourceConfig?.pollInterval` in a `#pricePollInterval` field
and uses it when calling `subscribeAssetsPrice` (as the default
`updateInterval`). So e.g. `priceDataSourceConfig: { pollInterval: 5000
}` results in spot-price requests every 5s. (2)
`StakedBalanceDataSourceConfig` and `stakedBalanceDataSourceConfig` are
added to the controller options and passed through to
`StakedBalanceDataSource`, supporting `enabled` and `pollInterval` so
the staked balance data source is configurable alongside accounts API
and price.

**Non-obvious:** Price polling uses the subscription request’s
`updateInterval` when present; the data source’s internal
`#pollInterval` is only a fallback. So the fix had to be in the
controller: pass the configured price interval when building the
subscription request rather than relying on the data source default.

No other packages or dependencies were changed in this PR.


UI extension: MetaMask/metamask-extension#40137

## References

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->
* None.

## 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]
> **Medium Risk**
> Introduces new polling/chain-selection logic and transaction-driven
refresh behavior that can affect balance accuracy and update frequency
across networks. While scoped to the assets pipeline, it touches
subscription lifecycle and network/transaction event handling.
> 
> **Overview**
> Adds a new `StakedBalanceDataSource` and `StakedBalanceFetcher` that
poll known staking contracts on enabled EVM chains and merge staked
balances (and built-in metadata) into `assetsBalance`; the controller
now subscribes/unsubscribes this source separately and exposes
`stakedBalanceDataSourceConfig` (`enabled`, `pollInterval`).
> 
> Fixes price subscriptions to default to
`priceDataSourceConfig.pollInterval` when no `updateInterval` is
provided, hardens CAIP parsing (skip malformed asset IDs; rely on
`@metamask/utils` helpers), and updates `RpcDataSource` to refresh
balances on `TransactionController` confirmed/incoming transaction
events. Tests and dependencies/TS references are updated accordingly
(adds `@metamask/transaction-controller` and
`@metamask/assets-controllers`).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
0cc7da3. 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