Skip to content

Commit 8f0baff

Browse files
fix(assets-controllers): revert Snap account-asset enrichment added in 109.3.0 (#9454)
## 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? --> ## 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 --> ## 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](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] > **High Risk** > Marked **BREAKING** in the changelog: removes exported types, changes messenger event payloads, and alters balance merge semantics—consumers relying on 109.3.0 enrichment or `refreshed` must migrate. > > **Overview** > **Breaking revert** of the 109.3.0 Snap `getAccountAssetInfo` flow: multichain balance rows are again `{ amount, unit }` only, with enrichment expected in the unified assets controller on the client. > > `MultichainBalancesController` drops snap enrichment calls, the `account-asset-info` module, and exported types `AccountAssetInfo` / `MultichainAccountBalance`. Asset-list handling no longer treats `refreshed` assets (only `added` / `removed`), and balance merges on updates are simplified (e.g. full replace on `updateBalance`, shallow assign on `accountBalancesUpdated`). > > `MultichainAssetsController:accountAssetListUpdated` no longer emits a `refreshed` list for snap adds that are already tracked; its payload aligns with `AccountsController:accountAssetListUpdated`. Token selectors stop exposing `accountAssetInfo` on `Asset` items. Tests and changelog document the breaking removals; balance tests add coverage for pruning stale balances when assets are removed. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2263d69. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 658c577 commit 8f0baff

10 files changed

Lines changed: 144 additions & 991 deletions

File tree

packages/assets-controllers/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Add `Robinhood` in `SupportedTokenDetectionNetworks`
1414
- Add Robinhood BalanceFetcher address in `SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID`
1515

16+
### Removed
17+
18+
- **BREAKING:** Revert Snap account-asset enrichment added in 109.3.0 ([#9454](https://github.com/MetaMask/core/pull/9454))
19+
- `MultichainBalancesController` no longer fetches or stores `accountAssetInfo` on balance rows; enrichment is handled client-side by the unified assets controller.
20+
- Remove exported types `AccountAssetInfo` and `MultichainAccountBalance`.
21+
- Remove optional `accountAssetInfo` from selector `Asset` items.
22+
- `MultichainAssetsController:accountAssetListUpdated` no longer includes a `refreshed` asset list for already-tracked snap adds;
23+
1624
## [109.4.1]
1725

1826
### Changed

packages/assets-controllers/src/MultichainAssetsController/MultichainAssetsController.test.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -796,50 +796,6 @@ describe('MultichainAssetsController', () => {
796796
});
797797
});
798798

799-
it('publishes refreshed assets when snap reports adds that are already tracked', async () => {
800-
const mockSolanaAccountId1 = 'account1';
801-
const existingToken =
802-
'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/token:Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr' as CaipAssetType;
803-
const { controller, messenger } = setupController({
804-
state: {
805-
accountsAssets: {
806-
[mockSolanaAccountId1]: mockHandleRequestOnAssetsLookupReturnValue,
807-
},
808-
assetsMetadata: mockGetMetadataReturnValue,
809-
allIgnoredAssets: {},
810-
} as MultichainAssetsControllerState,
811-
});
812-
813-
const eventListener = jest.fn();
814-
messenger.subscribe(
815-
'MultichainAssetsController:accountAssetListUpdated',
816-
eventListener,
817-
);
818-
819-
messenger.publish('AccountsController:accountAssetListUpdated', {
820-
assets: {
821-
[mockSolanaAccountId1]: {
822-
added: [existingToken],
823-
removed: [],
824-
},
825-
},
826-
});
827-
await jestAdvanceTime({ duration: 1 });
828-
829-
expect(
830-
controller.state.accountsAssets[mockSolanaAccountId1],
831-
).toStrictEqual(mockHandleRequestOnAssetsLookupReturnValue);
832-
expect(eventListener).toHaveBeenCalledWith({
833-
assets: {
834-
[mockSolanaAccountId1]: {
835-
added: [],
836-
removed: [],
837-
refreshed: [existingToken],
838-
},
839-
},
840-
});
841-
});
842-
843799
it('updates the assets list for an account when a an asset is removed', async () => {
844800
const mockSolanaAccountId1 = 'account1';
845801
const mockSolanaAccountId2 = 'account2';

packages/assets-controllers/src/MultichainAssetsController/MultichainAssetsController.ts

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,9 @@ export type AssetMetadataResponse = {
6161
};
6262
};
6363

64-
/**
65-
* Per-account asset list delta published by {@link MultichainAssetsController}.
66-
*/
67-
export type MultichainAssetsControllerAccountAssetListDelta = {
68-
added: CaipAssetType[];
69-
removed: CaipAssetType[];
70-
/**
71-
* Snap-reported adds that are already tracked in MAC state. Downstream
72-
* controllers should refresh balances and enrichment for these assets.
73-
*/
74-
refreshed?: CaipAssetType[];
75-
};
76-
77-
export type MultichainAssetsControllerAccountAssetListUpdatedPayload = {
78-
assets: Record<string, MultichainAssetsControllerAccountAssetListDelta>;
79-
};
80-
8164
export type MultichainAssetsControllerAccountAssetListUpdatedEvent = {
8265
type: `${typeof controllerName}:accountAssetListUpdated`;
83-
payload: [MultichainAssetsControllerAccountAssetListUpdatedPayload];
66+
payload: AccountsControllerAccountAssetListUpdatedEvent['payload'];
8467
};
8568

8669
/**
@@ -468,9 +451,7 @@ export class MultichainAssetsController extends StaticIntervalPollingController<
468451
this.#assertControllerMutexIsLocked();
469452

470453
const assetsForMetadataRefresh = new Set<CaipAssetType>([]);
471-
const accountsAndAssetsForState: AccountAssetListUpdatedEventPayload['assets'] =
472-
{};
473-
const accountsAndAssetsToPublish: MultichainAssetsControllerAccountAssetListUpdatedPayload['assets'] =
454+
const accountsAndAssetsToUpdate: AccountAssetListUpdatedEventPayload['assets'] =
474455
{};
475456
for (const [accountId, { added, removed }] of Object.entries(
476457
event.assets,
@@ -487,13 +468,6 @@ export class MultichainAssetsController extends StaticIntervalPollingController<
487468
!this.#isAssetIgnored(asset, accountId),
488469
);
489470

490-
const refreshedAssets = added.filter(
491-
(asset): asset is CaipAssetType =>
492-
existing.includes(asset) &&
493-
isCaipAssetType(asset) &&
494-
!this.#isAssetIgnored(asset, accountId),
495-
);
496-
497471
// Filter out tokens that cannot be verified or are flagged malicious
498472
const filteredToBeAddedAssets =
499473
await this.#filterBlockaidSpamTokensOnAdd(preFilteredToBeAddedAssets);
@@ -507,26 +481,12 @@ export class MultichainAssetsController extends StaticIntervalPollingController<
507481
filteredToBeAddedAssets.length > 0 ||
508482
filteredToBeRemovedAssets.length > 0
509483
) {
510-
accountsAndAssetsForState[accountId] = {
484+
accountsAndAssetsToUpdate[accountId] = {
511485
added: filteredToBeAddedAssets,
512486
removed: filteredToBeRemovedAssets,
513487
};
514488
}
515489

516-
if (
517-
filteredToBeAddedAssets.length > 0 ||
518-
filteredToBeRemovedAssets.length > 0 ||
519-
refreshedAssets.length > 0
520-
) {
521-
accountsAndAssetsToPublish[accountId] = {
522-
added: filteredToBeAddedAssets,
523-
removed: filteredToBeRemovedAssets,
524-
...(refreshedAssets.length > 0
525-
? { refreshed: refreshedAssets }
526-
: {}),
527-
};
528-
}
529-
530490
for (const asset of existing) {
531491
assetsForMetadataRefresh.add(asset);
532492
}
@@ -541,7 +501,7 @@ export class MultichainAssetsController extends StaticIntervalPollingController<
541501

542502
this.update((state) => {
543503
for (const [accountId, { added, removed }] of Object.entries(
544-
accountsAndAssetsForState,
504+
accountsAndAssetsToUpdate,
545505
)) {
546506
const assets = new Set([
547507
...(state.accountsAssets[accountId] || []),
@@ -558,11 +518,9 @@ export class MultichainAssetsController extends StaticIntervalPollingController<
558518
// Trigger fetching metadata for new assets
559519
await this.#refreshAssetsMetadata(Array.from(assetsForMetadataRefresh));
560520

561-
if (Object.keys(accountsAndAssetsToPublish).length > 0) {
562-
this.messenger.publish(`${controllerName}:accountAssetListUpdated`, {
563-
assets: accountsAndAssetsToPublish,
564-
});
565-
}
521+
this.messenger.publish(`${controllerName}:accountAssetListUpdated`, {
522+
assets: accountsAndAssetsToUpdate,
523+
});
566524
}
567525

568526
/**

0 commit comments

Comments
 (0)