Skip to content

Commit 98ebd34

Browse files
authored
feat: add CAIP-19 asset identifiers for each chain into the state (#7609)
## Explanation ### Current State The `NetworkEnablementController` tracks which networks are enabled/disabled but lacks information about the native asset identifier for each chain. This information is needed to properly identify native assets across different blockchain networks using a standardized format. Extension UI PR: MetaMask/metamask-extension#39234 ### Solution This PR adds a new state property `nativeAssetIdentifiers` to the `NetworkEnablementController` that maps CAIP-2 chain IDs to CAIP-19-like native asset identifiers. For example: - `eip155:1` → `eip155:1/slip44:60` (Ethereum uses ETH, SLIP-44 coin type 60) - `eip155:56` → `eip155:56/slip44:714` (BSC uses BNB, SLIP-44 coin type 714) - `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` → `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501` ### Implementation Details 1. **New `Slip44Service`**: A service that wraps the `@metamask/slip44` package to look up SLIP-44 coin types by symbol (e.g., `ETH` → `60`, `BTC` → `0`). 2. **State Updates**: The `nativeAssetIdentifiers` state is automatically updated when: - A network is added (`NetworkController:networkAdded`) - A network is removed (`NetworkController:networkRemoved`) - A network's native currency symbol is changed (`NetworkController:stateChange`) 3. **Default State**: Popular networks are pre-populated with their correct native asset identifiers based on their native currency symbols. 4. **Graceful Handling**: If a symbol has no SLIP-44 mapping, the entry is removed from the state rather than storing an invalid identifier. ### Dependency Addition Added `@metamask/slip44` package to dynamically look up SLIP-44 coin types instead of hardcoding them, ensuring accuracy and maintainability. ## References - [SLIP-44 Standard](https://github.com/satoshilabs/slips/blob/master/slip-0044.md) - [CAIP-2 Chain ID Specification](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md) - [CAIP-19 Asset Identifier Specification](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md) - [@metamask/slip44 npm package](https://www.npmjs.com/package/@metamask/slip44) ## 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 - [ ] 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] > Introduces native asset tracking and supporting utilities. > > - Adds `nativeAssetIdentifiers` mapping (CAIP-2 -> `.../slip44:<coinType>`) to `NetworkEnablementController` state and metadata > - New `Slip44Service` (uses `@metamask/slip44` and chainid.network) to resolve coin types by symbol/chainId; exports helpers > - Makes `init()` async and populates EVM identifiers; new `initNativeAssetIdentifiers(networks)` API for bulk initialization > - Updates network lifecycle: on add (async) computes and stores identifier; on remove deletes identifier > - Extends public exports (types, service) and adds `@metamask/slip44` dependency > - Updates/extends tests for controller, selectors, utils, and new service > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit f8cdcfc. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent ec75c14 commit 98ebd34

File tree

12 files changed

+1290
-264
lines changed

12 files changed

+1290
-264
lines changed

eslint-suppressions.json

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,17 +1468,6 @@
14681468
"count": 1
14691469
}
14701470
},
1471-
"packages/network-enablement-controller/src/NetworkEnablementController.ts": {
1472-
"@typescript-eslint/explicit-function-return-type": {
1473-
"count": 1
1474-
},
1475-
"@typescript-eslint/prefer-nullish-coalescing": {
1476-
"count": 2
1477-
},
1478-
"id-length": {
1479-
"count": 7
1480-
}
1481-
},
14821471
"packages/network-enablement-controller/src/selectors.ts": {
14831472
"@typescript-eslint/explicit-function-return-type": {
14841473
"count": 3

packages/network-enablement-controller/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `nativeAssetIdentifiers` state property that maps CAIP-2 chain IDs to CAIP-19-like native asset identifiers (e.g., `eip155:1/slip44:60`) ([#7609](https://github.com/MetaMask/core/pull/7609))
13+
- Add `Slip44Service` to look up SLIP-44 coin types by native currency symbol ([#7609](https://github.com/MetaMask/core/pull/7609))
14+
- Add `@metamask/slip44` dependency for SLIP-44 coin type lookups ([#7609](https://github.com/MetaMask/core/pull/7609))
15+
- Subscribe to `NetworkController:stateChange` to update `nativeAssetIdentifiers` when a network's native currency changes ([#7609](https://github.com/MetaMask/core/pull/7609))
16+
1017
### Changed
1118

1219
- Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511))

packages/network-enablement-controller/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@metamask/messenger": "^0.3.0",
5555
"@metamask/multichain-network-controller": "^3.0.1",
5656
"@metamask/network-controller": "^28.0.0",
57+
"@metamask/slip44": "^4.3.0",
5758
"@metamask/transaction-controller": "^62.9.1",
5859
"@metamask/utils": "^11.9.0",
5960
"reselect": "^5.1.1"

0 commit comments

Comments
 (0)