Commit 98ebd34
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- packages/network-enablement-controller
- src
- services
12 files changed
+1290
-264
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1468 | 1468 | | |
1469 | 1469 | | |
1470 | 1470 | | |
1471 | | - | |
1472 | | - | |
1473 | | - | |
1474 | | - | |
1475 | | - | |
1476 | | - | |
1477 | | - | |
1478 | | - | |
1479 | | - | |
1480 | | - | |
1481 | | - | |
1482 | 1471 | | |
1483 | 1472 | | |
1484 | 1473 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
10 | 17 | | |
11 | 18 | | |
12 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
0 commit comments