-
-
Notifications
You must be signed in to change notification settings - Fork 268
feat: use dynamic supported networks from Price API #7716
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
base: main
Are you sure you want to change the base?
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. |
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.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
| ) { | ||
| lastFetchedSupportedNetworks = response as SupportedNetworksResponse; | ||
| return lastFetchedSupportedNetworks; | ||
| } |
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.
Incomplete API response validation causes runtime crash
Medium Severity
The validation in fetchSupportedNetworks only checks for fullSupport and partialSupport top-level properties but doesn't verify the nested structure. If the API returns { fullSupport: [], partialSupport: {} } (missing spotPricesV3), the validation passes, the malformed response gets cached, and getSupportedChainIdsV3AsHex will crash when spreading undefined from partialSupport.spotPricesV3.
Explanation
Current State
The
CodefiTokenPricesServiceV2inassets-controllersuses a hardcoded list (SPOT_PRICES_SUPPORT_INFO) to determine which blockchain networks are supported by the Price API's/v3/spot-pricesendpoint. This approach has several drawbacks:Additionally, the native asset CAIP-19 identifiers (e.g.,
eip155:1/slip44:60for ETH) were also hardcoded, duplicating data that already exists inNetworkEnablementController.state.nativeAssetIdentifiers.Solution
This PR introduces dynamic fetching of supported networks from the Price API's
/v2/supportedNetworksendpoint:fetchSupportedNetworks()function that fetches from/v2/supportedNetworksand caches the responsefetchTokenPrices()callsetNativeAssetIdentifiers()method to receive native asset mappings fromNetworkEnablementController, eliminating duplicationnativeAssetIdentifiersfromNetworkEnablementControllerto the token prices serviceChanges Summary
codefi-v2.ts: Added dynamic network fetching, caching, and native asset identifier supportabstract-token-prices-service.ts: AddedNativeAssetIdentifiersMaptype and optionalsetNativeAssetIdentifiers()method to interfaceTokenRatesController.ts: Integrated withNetworkEnablementControllerto pass native asset identifiers@metamask/network-enablement-controlleras a dependencyReferences
https://price.api.cx.metamask.io/v2/supportedNetworksNetworkEnablementController.state.nativeAssetIdentifiersfor CAIP-19 native token mappingsChecklist
Note
Introduces dynamic network support and native asset ID integration for token pricing.
/v2/supportedNetworksintegration intoken-prices-servicewith caching, background refresh, and fallback; exportfetchSupportedNetworks,getSupportedNetworks,resetSupportedNetworksCacheCodefiTokenPricesServiceV2to: acceptsetNativeAssetIdentifiers(), build CAIP-19 for natives via provided map, validate chains via dynamic lists, and exposeupdateSupportedNetworks()TokenRatesControllernow callsNetworkEnablementController:getStateto passnativeAssetIdentifiersinto the token price service on initNativeAssetIdentifiersMapand optionalsetNativeAssetIdentifiers(); update exports and tests accordingly@metamask/network-enablement-controllerdependency and TypeScript project referencesWritten by Cursor Bugbot for commit 863782e. This will update automatically on new commits. Configure here.