Skip to content

fix: Managed removed property from MultichainAssetsController:accountAssetListUpdated event body#8461

Open
gabrieledm wants to merge 24 commits intomainfrom
fix/NEB-892_usdt-balance-not-updating-after-swap
Open

fix: Managed removed property from MultichainAssetsController:accountAssetListUpdated event body#8461
gabrieledm wants to merge 24 commits intomainfrom
fix/NEB-892_usdt-balance-not-updating-after-swap

Conversation

@gabrieledm
Copy link
Copy Markdown
Contributor

@gabrieledm gabrieledm commented Apr 15, 2026

Explanation

This PR fixes stale multichain asset balances in MultichainBalancesController when MultichainAssetsController:accountAssetListUpdated is emitted.
Before this change, the controller only used the added assets from the event payload and ignored removed.
As a result, balances for assets that were no longer present in the account asset list could remain cached in controller state and continue to appear as stale balances in the client.

Changes in MultichainBalancesController

  • updated the accountAssetListUpdated handler to use both added and removed
  • removed cached balances for assets listed in removed
  • fetched and merge balances for assets listed in added
  • stored { amount: '0', unit: '' } for added assets when the snap does not return a balance for them

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

Medium Risk
Touches multichain balance/rate caching logic and deletion semantics; mistakes could drop valid cached data or cause UI inconsistencies across accounts, though changes are scoped and covered by new tests.

Overview
Ensures multichain cached data is reconciled when MultichainAssetsController:accountAssetListUpdated includes removed assets, preventing stale balances/rates from lingering after assets are no longer tracked.

MultichainBalancesController now treats the event payload as a per-account delta: it deletes balances for removed assets, fetches/merges balances for added assets, and fills missing Snap responses with explicit zero balances; new tests cover stale-balance removal and clearing when an account has no remaining assets.

MultichainAssetsRatesController similarly cleans up cached conversionRates and historicalPrices for removed assets that are no longer tracked by any account (while keeping shared assets), and updates tests to validate both purge and retention behavior. Also fixes a transaction-pay-controller type import to use @metamask/transaction-controller directly and updates related ESLint suppression entries.

Reviewed by Cursor Bugbot for commit 891fa43. Bugbot is set up for automated code reviews on this repo. Configure here.

…untAssetListUpdated` event body to manage stale balances
@gabrieledm gabrieledm requested review from a team as code owners April 15, 2026 08:48
@gabrieledm
Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.0.0-preview-f45136cd3
@metamask-previews/accounts-controller@37.2.0-preview-f45136cd3
@metamask-previews/address-book-controller@7.1.1-preview-f45136cd3
@metamask-previews/ai-controllers@0.6.3-preview-f45136cd3
@metamask-previews/analytics-controller@1.0.1-preview-f45136cd3
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-f45136cd3
@metamask-previews/announcement-controller@8.1.0-preview-f45136cd3
@metamask-previews/app-metadata-controller@2.0.1-preview-f45136cd3
@metamask-previews/approval-controller@9.0.1-preview-f45136cd3
@metamask-previews/assets-controller@5.0.1-preview-f45136cd3
@metamask-previews/assets-controllers@104.0.0-preview-f45136cd3
@metamask-previews/base-controller@9.1.0-preview-f45136cd3
@metamask-previews/base-data-service@0.1.1-preview-f45136cd3
@metamask-previews/bridge-controller@70.1.0-preview-f45136cd3
@metamask-previews/bridge-status-controller@70.0.5-preview-f45136cd3
@metamask-previews/build-utils@3.0.4-preview-f45136cd3
@metamask-previews/chain-agnostic-permission@1.5.0-preview-f45136cd3
@metamask-previews/claims-controller@0.5.0-preview-f45136cd3
@metamask-previews/client-controller@1.0.1-preview-f45136cd3
@metamask-previews/compliance-controller@2.0.0-preview-f45136cd3
@metamask-previews/composable-controller@12.0.1-preview-f45136cd3
@metamask-previews/config-registry-controller@0.2.0-preview-f45136cd3
@metamask-previews/connectivity-controller@0.2.0-preview-f45136cd3
@metamask-previews/controller-utils@11.20.0-preview-f45136cd3
@metamask-previews/core-backend@6.2.1-preview-f45136cd3
@metamask-previews/delegation-controller@3.0.0-preview-f45136cd3
@metamask-previews/earn-controller@12.0.0-preview-f45136cd3
@metamask-previews/eip-5792-middleware@3.0.3-preview-f45136cd3
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.0-preview-f45136cd3
@metamask-previews/eip1193-permission-middleware@1.0.3-preview-f45136cd3
@metamask-previews/ens-controller@19.1.1-preview-f45136cd3
@metamask-previews/eth-block-tracker@15.0.1-preview-f45136cd3
@metamask-previews/eth-json-rpc-middleware@23.1.1-preview-f45136cd3
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-f45136cd3
@metamask-previews/foundryup@1.0.1-preview-f45136cd3
@metamask-previews/gas-fee-controller@26.1.1-preview-f45136cd3
@metamask-previews/gator-permissions-controller@3.0.1-preview-f45136cd3
@metamask-previews/geolocation-controller@0.1.2-preview-f45136cd3
@metamask-previews/json-rpc-engine@10.2.4-preview-f45136cd3
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-f45136cd3
@metamask-previews/keyring-controller@25.2.0-preview-f45136cd3
@metamask-previews/logging-controller@8.0.1-preview-f45136cd3
@metamask-previews/message-manager@14.1.1-preview-f45136cd3
@metamask-previews/messenger@1.1.1-preview-f45136cd3
@metamask-previews/messenger-cli@0.1.0-preview-f45136cd3
@metamask-previews/money-account-balance-service@0.0.0-preview-f45136cd3
@metamask-previews/money-account-controller@0.1.0-preview-f45136cd3
@metamask-previews/multichain-account-service@8.0.1-preview-f45136cd3
@metamask-previews/multichain-api-middleware@2.0.0-preview-f45136cd3
@metamask-previews/multichain-network-controller@3.0.6-preview-f45136cd3
@metamask-previews/multichain-transactions-controller@7.0.4-preview-f45136cd3
@metamask-previews/name-controller@9.1.1-preview-f45136cd3
@metamask-previews/network-controller@30.0.1-preview-f45136cd3
@metamask-previews/network-enablement-controller@5.0.2-preview-f45136cd3
@metamask-previews/notification-services-controller@23.1.0-preview-f45136cd3
@metamask-previews/permission-controller@12.3.0-preview-f45136cd3
@metamask-previews/permission-log-controller@5.1.0-preview-f45136cd3
@metamask-previews/perps-controller@3.1.0-preview-f45136cd3
@metamask-previews/phishing-controller@17.1.1-preview-f45136cd3
@metamask-previews/polling-controller@16.0.4-preview-f45136cd3
@metamask-previews/preferences-controller@23.1.0-preview-f45136cd3
@metamask-previews/profile-metrics-controller@3.1.3-preview-f45136cd3
@metamask-previews/profile-sync-controller@28.0.2-preview-f45136cd3
@metamask-previews/ramps-controller@13.1.0-preview-f45136cd3
@metamask-previews/rate-limit-controller@7.0.1-preview-f45136cd3
@metamask-previews/react-data-query@0.2.0-preview-f45136cd3
@metamask-previews/remote-feature-flag-controller@4.2.0-preview-f45136cd3
@metamask-previews/sample-controllers@4.0.4-preview-f45136cd3
@metamask-previews/seedless-onboarding-controller@9.1.0-preview-f45136cd3
@metamask-previews/selected-network-controller@26.1.0-preview-f45136cd3
@metamask-previews/shield-controller@5.1.1-preview-f45136cd3
@metamask-previews/signature-controller@39.1.2-preview-f45136cd3
@metamask-previews/social-controllers@0.1.0-preview-f45136cd3
@metamask-previews/storage-service@1.0.1-preview-f45136cd3
@metamask-previews/subscription-controller@6.1.2-preview-f45136cd3
@metamask-previews/transaction-controller@64.2.0-preview-f45136cd3
@metamask-previews/transaction-pay-controller@19.1.2-preview-f45136cd3
@metamask-previews/user-operation-controller@41.2.0-preview-f45136cd3

const newAccountAssets = Object.entries(assets).map(
([accountId, { added }]) => ({
const updatedAccountAssets = Object.entries(assets).map(
([accountId, { added, removed }]) => ({
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.

should we have the same fix on the MultichainAssetsRatesController ?

@gabrieledm gabrieledm requested a review from a team as a code owner April 16, 2026 15:26
Signed-off-by: gabrieledm <gabriele.delmonte-ext@consensys.net>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b2adaa5. Configure here.

Signed-off-by: gabrieledm <gabriele.delmonte-ext@consensys.net>
TransactionPaymentToken,
} from '..';
import { TransactionPayStrategy } from '..';
import type { TransactionMeta } from '../../../transaction-controller/src';
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.

(optional) We can remove this change to minimise CO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants