fix: prevent duplicate native token address in token prices API request #7181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation
What is the current state of things and why does it need to change?
The
CurrencyRateControllerhas a fallback mechanism that uses spot prices from the token prices service when the primary exchange rates API fails. However, this fallback was sending duplicate native token addresses (the 0x0000...0000 address) to the API endpoint, causing requests to fail with the error:"All tokenAddresses's elements must be unique".What is the solution your changes offer and how does it work?
The issue occurred because:
CurrencyRateControllerwas explicitly passing the native token address in thetokenAddressesarray:tokenAddresses: [nativeTokenAddress]fetchTokenPricesmethod inCodefiTokenPricesServiceV2automatically prepends the native token address to any token addresses passed to it (line 496 incodefi-v2.ts)The fix changes
tokenAddresses: [nativeTokenAddress]totokenAddresses: []since the service already handles including the native token address automatically. This ensures each address appears only once in the final API request.Are there any changes whose purpose might not be obvious to those unfamiliar with the domain?
The empty array
[]might seem counterintuitive, but it's the correct approach because thefetchTokenPricesmethod is designed to always include the native token address by default for any chain.References
Fixes the duplicate token address validation error in the spot price fallback mechanism introduced after removing the CryptoCompare fallback in #7167.
Checklist
Note
Stops sending the native token address explicitly to
fetchTokenPrices(passtokenAddresses: []) to avoid duplicates in spot price fallback requests.fetchTokenPrices({ chainId, tokenAddresses: [], currency }), relying on the service to include the native token automatically.CurrencyRateController.test.tsto asserttokenAddresses: []for ETH/BNB/POL scenarios and related calls.Written by Cursor Bugbot for commit 64c9a6b. This will update automatically on new commits. Configure here.