fix: weth incorrectly resolves to eth info #1866
Closed
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.
Fix WETH/ETH Symbol Resolution
Linear: ACX-4369
📝 Summary
This pull request addresses a bug where the
swap/approval
endpoint was incorrectly resolving the symbol for wrapped native tokens (like WETH) as the native token symbol (e.g., ETH). This was happening on chains like Base and Linea where the wrapped native token address is also present in theTOKEN_SYMBOLS_MAP
under theETH
symbol.🔧 Changes
getTokenByAddress
function inapi/_utils.ts
to correctly resolve the token symbol in cases of ambiguity betweenETH
andWETH
.getTokenByAddress
to ensure the correct symbol is returned for all supported chains.💭 Rationale
The root cause of this issue lies in the
@across-protocol/constants
package, where some wrapped native token addresses are associated with bothETH
andWETH
symbols. ThegetTokenByAddress
function was not deterministically picking the correct symbol, sometimes defaulting toETH
when it should have beenWETH
.This pull request implements a solution that prioritizes
WETH
when a token address is associated with both symbols. This is a robust solution because it correctly handles the ambiguity in the constants file and ensures that the correct token symbol is used throughout the application.The alternative of fixing the constants file is not feasible as it is an external dependency. This solution provides a local fix that is both effective and maintainable.