Skip to content
Open
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: 4 additions & 0 deletions packages/solana-wallet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add a read-only `CoreAssetsAdapter` and `mapControllerAsset` for AssetsController integration (wired unused until routing lands), including Core messenger plumbing (`coreMessenger`, `RemoteFeatureFlagsProvider`, `AssetsProvider`). Solana has no snap-owned assets, so the adapter does not fetch, persist, or publish balances. When mapping SPL tokens, the adapter derives associated token account (ATA) pubkeys from the mint's token program (including Token-2022) so Transaction History can still call `getSignaturesForAddress`. ([#122](https://github.com/MetaMask/internal-snaps/pull/122))

### Changed

- Extract Snap-owned assets domain logic into `SnapAssetsAdapter`; `AssetsService` is a thin facade that delegates metadata, market data, fetch, persist, and account asset reads through the adapter (no Core routing yet). ([#121](https://github.com/MetaMask/internal-snaps/pull/121))
Expand Down
3 changes: 3 additions & 0 deletions packages/solana-wallet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@metamask/assets-controller": "^13.0.0",
"@metamask/auto-changelog": "^6.1.1",
"@metamask/key-tree": "^10.1.1",
"@metamask/keyring-api": "^23.7.0",
"@metamask/keyring-snap-sdk": "^9.2.1",
"@metamask/messenger": "^2.0.0",
"@metamask/remote-feature-flag-controller": "^5.0.0",
"@metamask/snap-networks-utils": "^1.0.0",
"@metamask/snaps-cli": "^8.4.1",
"@metamask/snaps-jest": "^10.2.0",
Expand Down
12 changes: 10 additions & 2 deletions packages/solana-wallet-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/internal-snaps.git"
},
"source": {
"shasum": "/PhLDvRV3M/0N7rlAqg7pypEkZAHTfFNP9/TNxi8G80=",
"shasum": "YAhMrNcEE5rIa14naIJWiLwWLZSFaR87z/4HqjxR+8A=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down Expand Up @@ -88,7 +88,15 @@
"snap_manageAccounts": {},
"snap_manageState": {},
"snap_dialog": {},
"snap_getPreferences": {}
"snap_getPreferences": {},
"endowment:messenger": {
"actions": [
"RemoteFeatureFlagController:getState",
"AssetsController:getAccountAssetByID",
"AssetsController:getAccountAssetsByIDs",
"AssetsController:getAccountAssetsByScope"
]
}
},
"platformVersion": "11.2.0",
"manifestVersion": "0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type { AccountsService } from '../accounts/AccountsService';
import type { ConfigProvider } from '../config';
import type { SolanaConnection } from '../connection';
import type { TokenPricesService } from '../token-prices/TokenPrices';
import { CoreAssetsAdapter } from './adapters/CoreAssetsAdapter';
import { SnapAssetsAdapter } from './adapters/SnapAssetsAdapter';
import type { AssetsRepository } from './AssetsRepository';
import { AssetsService } from './AssetsService';
Expand Down Expand Up @@ -101,8 +102,20 @@ describe('AssetsService', () => {
nftApiClient: mockNftApiClient,
});

const coreAdapter = new CoreAssetsAdapter({
logger: mockLogger,
getAccountAssetByID: jest.fn().mockResolvedValue(null),
getAccountAssetsByIDs: jest.fn().mockResolvedValue({}),
getAccountAssetsByScope: jest.fn().mockResolvedValue({}),
findAccountById: mockAccountsService.findById.bind(mockAccountsService),
getActiveNetworks:
mockConfigProvider.getActiveNetworks.bind(mockConfigProvider),
fetchMint: mockConnection.fetchMint.bind(mockConnection),
});

assetsService = new AssetsService({
snapAdapter: snapAssetsAdapter,
coreAdapter,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@ import type { FungibleAssetMarketData } from '@metamask/snaps-sdk';
import type { CaipAssetType, CaipChainId } from '@metamask/utils';

import type { AssetEntity, SolanaKeyringAccount } from '../../../entities';
import type { CoreAssetsAdapter } from './adapters/CoreAssetsAdapter';
import { SnapAssetsAdapter } from './adapters/SnapAssetsAdapter';
import type { AssetMetadata } from './types';

/**
* Assets domain facade. Currently delegates all behavior to SnapAssetsAdapter
* (legacy snap-owned reads/writes).
* (legacy snap-owned reads/writes). Core adapter is initialized for upcoming
* routing without changing callers.
*/
export class AssetsService {
readonly #snapAdapter: SnapAssetsAdapter;

// Initialized for upcoming Core routing; not read until the migration PR lands.
// eslint-disable-next-line no-unused-private-class-members -- reserved adapter slot
readonly #coreAdapter: CoreAssetsAdapter;

readonly cacheTtlsMilliseconds: typeof SnapAssetsAdapter.cacheTtlsMilliseconds;

constructor({ snapAdapter }: { snapAdapter: SnapAssetsAdapter }) {
constructor({
snapAdapter,
coreAdapter,
}: {
snapAdapter: SnapAssetsAdapter;
coreAdapter: CoreAssetsAdapter;
}) {
this.#snapAdapter = snapAdapter;
this.#coreAdapter = coreAdapter;
this.cacheTtlsMilliseconds = SnapAssetsAdapter.cacheTtlsMilliseconds;
}

Expand Down
Loading