Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
"resolutions": {
"elliptic@6.5.4": "^6.5.7",
"fast-xml-parser@^4.3.4": "^4.4.1",
"ws@7.4.6": "^7.5.10"
"ws@7.4.6": "^7.5.10",
"@metamask/keyring-api": "23.1.0",
"@metamask/keyring-internal-api": "11.0.1"
},
"simple-git-hooks": {
"pre-push": "yarn lint"
Expand Down
11 changes: 11 additions & 0 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- `MultichainAssetsController`: track Stellar classic (`asset:`) CAIP-19 tokens added via `addAssets` in `stellarClassicTrustlineInactiveAssetIds` until the keyring lists the same id in `AccountsController:accountAssetListUpdated` `added` (or the asset is removed); one-time backfill for classic ids already in `accountsAssets` when `stellarTrustlineInactiveBackfillComplete` is false (legacy imports before this feature) ([#TODO](https://github.com/MetaMask/core/pull/TODO))
- `selectAllMultichainAssets`: optional `isStellarTrustlineInactive` on multichain `Asset` when the id is in that map ([#TODO](https://github.com/MetaMask/core/pull/TODO))
- `isStellarClassicAssetCaip19` helper; `isStellarTrustlineTrackedAsset` now applies only to classic `asset:` ids, not `sep41:` ([#TODO](https://github.com/MetaMask/core/pull/TODO))

### Fixed

- `MultichainAssetsController`: after `addAssets`, re-fetch the Snap `listAccountAssets` list for Stellar classic (`asset:`) ids and clear `stellarClassicTrustlineInactiveAssetIds` when the keyring already reports the same CAIP-19 id (e.g. hide token then re-add while trustline is still active) ([#TODO](https://github.com/MetaMask/core/pull/TODO))
- `MultichainBalancesController`: when `MultichainAssetsController:accountAssetListUpdated` fires while the vault is locked, balance fetches are skipped and were never retried after unlock, leaving multichain token lists empty despite assets in state; subscribe to `KeyringController:stateChange` and refetch balances for snap-backed accounts that still have no cached balances after unlock. ([#TODO](https://github.com/MetaMask/core/pull/TODO))

### Changed

- Bump `@metamask/account-tree-controller` from `^7.2.0` to `^7.3.0` ([#8722](https://github.com/MetaMask/core/pull/8722))
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/assets-controllers",
"version": "106.0.0",
"version": "106.0.0-dev.2",
"description": "Controllers which manage interactions involving ERC-20, ERC-721, and ERC-1155 tokens (including NFTs)",
"keywords": [
"Ethereum",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type { SubjectPermissions } from '@metamask/permission-controller';
import type { BulkTokenScanResponse } from '@metamask/phishing-controller';
import { TokenScanResultType } from '@metamask/phishing-controller';
import type { Snap } from '@metamask/snaps-utils';
import { HandlerType } from '@metamask/snaps-utils';
import { v4 as uuidv4 } from 'uuid';

import {
Expand Down Expand Up @@ -197,6 +198,17 @@ const mockGetPermissionsReturnValue = [
},
];

const STELLAR_CLASSIC_USDC =
'stellar:pubnet/asset:USDC-GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN' as CaipAssetType;

const STELLAR_CLASSIC_USDC_METADATA = {
name: 'USD Coin',
symbol: 'USDC',
fungible: true,
iconUrl: '',
units: [{ name: 'USD Coin', symbol: 'USDC', decimals: 7 }],
};

const mockGetMetadataReturnValue: AssetMetadataResponse | undefined = {
assets: {
'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/slip44:501': {
Expand Down Expand Up @@ -380,9 +392,51 @@ describe('MultichainAssetsController', () => {
accountsAssets: {},
assetsMetadata: {},
allIgnoredAssets: {},
stellarClassicTrustlineInactiveAssetIds: {},
stellarTrustlineInactiveBackfillComplete: true,
});
});

it('backfills Stellar classic trustline-inactive for assets already in accountsAssets on first load', () => {
const accountId = 'stellar-legacy';
const { controller } = setupController({
state: {
accountsAssets: {
[accountId]: [STELLAR_CLASSIC_USDC],
},
assetsMetadata: {},
allIgnoredAssets: {},
stellarClassicTrustlineInactiveAssetIds: {},
} as MultichainAssetsControllerState,
});

expect(controller.state.stellarTrustlineInactiveBackfillComplete).toBe(
true,
);
expect(
controller.state.stellarClassicTrustlineInactiveAssetIds[accountId],
).toStrictEqual([STELLAR_CLASSIC_USDC]);
});

it('skips Stellar trustline backfill when already completed', () => {
const accountId = 'stellar-legacy';
const { controller } = setupController({
state: {
accountsAssets: {
[accountId]: [STELLAR_CLASSIC_USDC],
},
assetsMetadata: {},
allIgnoredAssets: {},
stellarClassicTrustlineInactiveAssetIds: {},
stellarTrustlineInactiveBackfillComplete: true,
} as MultichainAssetsControllerState,
});

expect(
controller.state.stellarClassicTrustlineInactiveAssetIds[accountId],
).toBeUndefined();
});

it('does not update state when new account added is EVM', async () => {
const { controller, messenger } = setupController();

Expand All @@ -397,6 +451,8 @@ describe('MultichainAssetsController', () => {
accountsAssets: {},
assetsMetadata: {},
allIgnoredAssets: {},
stellarClassicTrustlineInactiveAssetIds: {},
stellarTrustlineInactiveBackfillComplete: true,
});
});

Expand Down Expand Up @@ -430,6 +486,8 @@ describe('MultichainAssetsController', () => {
},
assetsMetadata: mockGetMetadataReturnValue.assets,
allIgnoredAssets: {},
stellarClassicTrustlineInactiveAssetIds: {},
stellarTrustlineInactiveBackfillComplete: true,
});
});

Expand Down Expand Up @@ -499,6 +557,8 @@ describe('MultichainAssetsController', () => {
...mockGetMetadataReturnValue.assets,
},
allIgnoredAssets: {},
stellarClassicTrustlineInactiveAssetIds: {},
stellarTrustlineInactiveBackfillComplete: true,
});
});

Expand Down Expand Up @@ -556,6 +616,8 @@ describe('MultichainAssetsController', () => {
...mockGetMetadataReturnValue.assets,
},
allIgnoredAssets: {},
stellarClassicTrustlineInactiveAssetIds: {},
stellarTrustlineInactiveBackfillComplete: true,
});
});

Expand Down Expand Up @@ -591,6 +653,8 @@ describe('MultichainAssetsController', () => {

assetsMetadata: mockGetMetadataReturnValue.assets,
allIgnoredAssets: {},
stellarClassicTrustlineInactiveAssetIds: {},
stellarTrustlineInactiveBackfillComplete: true,
});
// Remove an EVM account
messenger.publish('AccountsController:accountRemoved', mockEthAccount.id);
Expand All @@ -604,6 +668,8 @@ describe('MultichainAssetsController', () => {

assetsMetadata: mockGetMetadataReturnValue.assets,
allIgnoredAssets: {},
stellarClassicTrustlineInactiveAssetIds: {},
stellarTrustlineInactiveBackfillComplete: true,
});
});

Expand Down Expand Up @@ -639,6 +705,8 @@ describe('MultichainAssetsController', () => {

assetsMetadata: mockGetMetadataReturnValue.assets,
allIgnoredAssets: {},
stellarClassicTrustlineInactiveAssetIds: {},
stellarTrustlineInactiveBackfillComplete: true,
});
// Remove the added solana account
messenger.publish(
Expand All @@ -653,10 +721,46 @@ describe('MultichainAssetsController', () => {

assetsMetadata: mockGetMetadataReturnValue.assets,
allIgnoredAssets: {},
stellarClassicTrustlineInactiveAssetIds: {},
stellarTrustlineInactiveBackfillComplete: true,
});
});

describe('handleAccountAssetListUpdated', () => {
it('clears Stellar trustline-inactive when keyring re-announces an existing classic asset', async () => {
const accountId = 'stellar-test-account';
const { messenger, controller } = setupController({
state: {
accountsAssets: {
[accountId]: [STELLAR_CLASSIC_USDC],
},
assetsMetadata: {
...mockGetMetadataReturnValue.assets,
[STELLAR_CLASSIC_USDC]: STELLAR_CLASSIC_USDC_METADATA,
},
allIgnoredAssets: {},
stellarClassicTrustlineInactiveAssetIds: {
[accountId]: [STELLAR_CLASSIC_USDC],
},
} as MultichainAssetsControllerState,
});

messenger.publish('AccountsController:accountAssetListUpdated', {
assets: {
[accountId]: {
added: [STELLAR_CLASSIC_USDC],
removed: [],
},
},
});

await jestAdvanceTime({ duration: 1 });

expect(
controller.state.stellarClassicTrustlineInactiveAssetIds[accountId],
).toBeUndefined();
});

it('updates the assets list for an account when a new asset is added', async () => {
const mockSolanaAccountId1 = 'account1';
const mockSolanaAccountId2 = 'account2';
Expand Down Expand Up @@ -1067,6 +1171,55 @@ describe('MultichainAssetsController', () => {
).toStrictEqual([assetToAdd]);
});

it('adds Stellar classic assets to trustline-inactive when added via addAssets', async () => {
const { controller } = setupController({
state: {
accountsAssets: {},
assetsMetadata: {
[STELLAR_CLASSIC_USDC]: STELLAR_CLASSIC_USDC_METADATA,
},
allIgnoredAssets: {},
} as MultichainAssetsControllerState,
});

await controller.addAssets([STELLAR_CLASSIC_USDC], mockSolanaAccount.id);

expect(
controller.state.stellarClassicTrustlineInactiveAssetIds[
mockSolanaAccount.id
],
).toStrictEqual([STELLAR_CLASSIC_USDC]);
});

it('clears Stellar classic trustline-inactive when Snap listAccountAssets includes the asset', async () => {
const { controller, mockSnapHandleRequest } = setupController({
state: {
accountsAssets: {},
assetsMetadata: {
[STELLAR_CLASSIC_USDC]: STELLAR_CLASSIC_USDC_METADATA,
},
allIgnoredAssets: {},
} as MultichainAssetsControllerState,
});

mockSnapHandleRequest.mockImplementation(
(params: { handler: string }) => {
if (params.handler === HandlerType.OnKeyringRequest) {
return Promise.resolve([STELLAR_CLASSIC_USDC]);
}
return Promise.resolve(mockHandleRequestOnAssetsLookupReturnValue);
},
);

await controller.addAssets([STELLAR_CLASSIC_USDC], mockSolanaAccount.id);

expect(
controller.state.stellarClassicTrustlineInactiveAssetIds[
mockSolanaAccount.id
],
).toBeUndefined();
});

it('should publish accountAssetListUpdated event when asset is added', async () => {
const { controller, messenger } = setupController({
state: {
Expand Down Expand Up @@ -1709,7 +1862,9 @@ describe('MultichainAssetsController', () => {
const tokens = Array.from(
{ length: 150 },
(_, i) =>
`solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/token:Token${String(i).padStart(3, '0')}`,
`solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/token:Token${String(
i,
).padStart(3, '0')}`,
);

const { controller, messenger, mockBulkScanTokens } = setupController({
Expand Down Expand Up @@ -1778,7 +1933,9 @@ describe('MultichainAssetsController', () => {
const tokens = Array.from(
{ length: 120 },
(_, i) =>
`solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/token:Token${String(i).padStart(3, '0')}`,
`solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1/token:Token${String(
i,
).padStart(3, '0')}`,
);

const { controller, messenger, mockBulkScanTokens } = setupController({
Expand Down Expand Up @@ -2021,6 +2178,8 @@ describe('MultichainAssetsController', () => {
"accountsAssets": {},
"allIgnoredAssets": {},
"assetsMetadata": {},
"stellarClassicTrustlineInactiveAssetIds": {},
"stellarTrustlineInactiveBackfillComplete": true,
}
`);
});
Expand All @@ -2039,6 +2198,7 @@ describe('MultichainAssetsController', () => {
"accountsAssets": {},
"allIgnoredAssets": {},
"assetsMetadata": {},
"stellarClassicTrustlineInactiveAssetIds": {},
}
`);
});
Expand Down
Loading