-
-
Notifications
You must be signed in to change notification settings - Fork 267
feat: add CAIP-19 asset identifiers for each chain into the state #7609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
589e726 to
f075c1f
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
packages/network-enablement-controller/src/NetworkEnablementController.ts
Outdated
Show resolved
Hide resolved
packages/network-enablement-controller/src/NetworkEnablementController.ts
Show resolved
Hide resolved
packages/network-enablement-controller/src/NetworkEnablementController.ts
Outdated
Show resolved
Hide resolved
packages/network-enablement-controller/src/NetworkEnablementController.ts
Show resolved
Hide resolved
packages/network-enablement-controller/src/NetworkEnablementController.ts
Outdated
Show resolved
Hide resolved
packages/network-enablement-controller/src/NetworkEnablementController.ts
Outdated
Show resolved
Hide resolved
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
packages/network-enablement-controller/src/NetworkEnablementController.ts
Show resolved
Hide resolved
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
| * @param index - The SLIP-44 coin type index (e.g., 60 for ETH, 0 for BTC) | ||
| * @returns The SLIP-44 entry with metadata, or undefined if not found | ||
| */ | ||
| static getSlip44Entry(index: number): Slip44Entry | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a use case for this method at the client? I cannot see it being currently used and the parameter name (index) is a bit confusing.
If there are no plans to use it I'd use remove it until it's needed, but otherwise we can rename index to chainId like in getSlip44ByChainId.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't need this method anymore , the one we need is the getSlip44ByChainId, i'll remove it in a separated PR now
| // Fall back to symbol lookup if provided | ||
| if (symbol) { | ||
| return this.getSlip44BySymbol(symbol); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are quite a few entries with repeated symbols in the imported json. This does not look very safe.
LBTC
LKY
LTO
LUM
MONK
MTR
NXT
ONE
PAC
RYO
SAFE
SAMA
SBC
SCR
SUM
TAO
UC
VAL
VARA
XCH
XEC
XRD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm actually using this only for non evm ( BTC, SOL, Tron ) , they are unique , for evm the provider https://chainid.network/chains.json is used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so the case of duplicated symbols is handled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe i should remove the fallback here , is this your point ?
Explanation
Current State
The
NetworkEnablementControllertracks 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
nativeAssetIdentifiersto theNetworkEnablementControllerthat 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:501Implementation Details
New
Slip44Service: A service that wraps the@metamask/slip44package to look up SLIP-44 coin types by symbol (e.g.,ETH→60,BTC→0).State Updates: The
nativeAssetIdentifiersstate is automatically updated when:NetworkController:networkAdded)NetworkController:networkRemoved)NetworkController:stateChange)Default State: Popular networks are pre-populated with their correct native asset identifiers based on their native currency symbols.
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/slip44package to dynamically look up SLIP-44 coin types instead of hardcoding them, ensuring accuracy and maintainability.References
Checklist
Note
Introduces native asset tracking and supporting utilities.
nativeAssetIdentifiersmapping (CAIP-2 ->.../slip44:<coinType>) toNetworkEnablementControllerstate and metadataSlip44Service(uses@metamask/slip44and chainid.network) to resolve coin types by symbol/chainId; exports helpersinit()async and populates EVM identifiers; newinitNativeAssetIdentifiers(networks)API for bulk initialization@metamask/slip44dependencyWritten by Cursor Bugbot for commit f8cdcfc. This will update automatically on new commits. Configure here.