Conversation
packages/assets-controller/src/data-sources/StakedBalanceDataSource.ts
Outdated
Show resolved
Hide resolved
packages/assets-controller/src/data-sources/evm-rpc-services/utils/staking-contracts.ts
Outdated
Show resolved
Hide resolved
packages/assets-controller/src/data-sources/evm-rpc-services/services/StakedBalanceFetcher.ts
Outdated
Show resolved
Hide resolved
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
packages/assets-controller/src/data-sources/StakedBalanceDataSource.ts
Outdated
Show resolved
Hide resolved
packages/assets-controller/src/data-sources/evm-rpc-services/utils/parsing.ts
Outdated
Show resolved
Hide resolved
packages/assets-controller/src/data-sources/evm-rpc-services/utils/staking-contracts.ts
Outdated
Show resolved
Hide resolved
packages/assets-controller/src/data-sources/AccountsApiDataSource.ts
Outdated
Show resolved
Hide resolved
packages/assets-controller/src/data-sources/AccountsApiDataSource.ts
Outdated
Show resolved
Hide resolved
packages/assets-controller/src/data-sources/BackendWebsocketDataSource.ts
Outdated
Show resolved
Hide resolved
packages/assets-controller/src/data-sources/StakedBalanceDataSource.ts
Outdated
Show resolved
Hide resolved
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
|
@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. |
Prithpal-Sooriya
left a comment
There was a problem hiding this comment.
As discussed, we can fully tackle the messenger types in a followup PR.
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
Prithpal-Sooriya
left a comment
There was a problem hiding this comment.
As discussed we will have a follow up to use valid messenger setup, and remove all the type assertions.
## 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 -->
Explanation
Current state: AssetsController already had
accountsApiDataSourceConfigandpriceDataSourceConfigfor per-data-source options (e.g.pollInterval,tokenDetectionEnabled). Two gaps: (1)priceDataSourceConfig.pollIntervalwas not applied when subscribing to price updates—the controller always passed itsdefaultUpdateIntervalinto 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?.pollIntervalin a#pricePollIntervalfield and uses it when callingsubscribeAssetsPrice(as the defaultupdateInterval). So e.g.priceDataSourceConfig: { pollInterval: 5000 }results in spot-price requests every 5s. (2)StakedBalanceDataSourceConfigandstakedBalanceDataSourceConfigare added to the controller options and passed through toStakedBalanceDataSource, supportingenabledandpollIntervalso the staked balance data source is configurable alongside accounts API and price.Non-obvious: Price polling uses the subscription request’s
updateIntervalwhen present; the data source’s internal#pollIntervalis 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
Checklist
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
StakedBalanceDataSourceandStakedBalanceFetcherthat poll known staking contracts on enabled EVM chains and merge staked balances (and built-in metadata) intoassetsBalance; the controller now subscribes/unsubscribes this source separately and exposesstakedBalanceDataSourceConfig(enabled,pollInterval).Fixes price subscriptions to default to
priceDataSourceConfig.pollIntervalwhen noupdateIntervalis provided, hardens CAIP parsing (skip malformed asset IDs; rely on@metamask/utilshelpers), and updatesRpcDataSourceto refresh balances onTransactionControllerconfirmed/incoming transaction events. Tests and dependencies/TS references are updated accordingly (adds@metamask/transaction-controllerand@metamask/assets-controllers).Written by Cursor Bugbot for commit 0cc7da3. This will update automatically on new commits. Configure here.