fix: the bundled token list names tokens on Ethereum Mainnet only (closes #632)
bundledToken(address, chainId) in tokenList.js answers only for Ethereum Mainnet's chain id. Every reader of TOKEN_BY_ADDRESS now goes through it, with the chain id of the transaction, balance or history entry it draws. The token sources the screens build carry that chain id. The Uniswap decoder sets the transaction's chain id on them. fetchTokenBalances() takes the chain id of the network it asks about. isSpoofedSymbol() takes the chain id of the token's network. It checks the bundled list's symbols only on Ethereum Mainnet. The native asset's labels stay reserved on every network. Twenty existing tests and four shared test helpers read the bundled list without naming a network. Each now names Ethereum Mainnet. Model: opus-5-5
This commit was merged in pull request #703.
This commit is contained in:
+20
-11
@@ -452,8 +452,8 @@ const ADDRESS_THIS = "0x0000000000000000000000000000000000000002";
|
||||
// `decimals` is null when nothing knows this token's scale. It is not
|
||||
// defaulted to 18: the swap lines land on the same approval screen as the
|
||||
// ERC-20 line, and a scale guessed there is what showed a 1,000 USDT swap as
|
||||
// 0.000000000001. `sources` is { trackedTokens, wallets }, shaped as they are
|
||||
// on `state`; resolveTokenDecimals() reads the bundled list, then those.
|
||||
// 0.000000000001. `sources` is as for resolveTokenDecimals(), which reads the
|
||||
// bundled list on Ethereum Mainnet, then the tracked tokens and the wallets.
|
||||
//
|
||||
// A null `address` means UNDETERMINED — the calldata named no currency for
|
||||
// that side — and is refused rather than named. It is not native ETH: Uniswap
|
||||
@@ -1246,6 +1246,9 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
const release = routerRelease(toAddress, chainId);
|
||||
if (release === null) return null;
|
||||
const { commandTypeMask, commands, allowRevert } = release;
|
||||
// The swap's tokens are contracts on the network with `chainId`, so they
|
||||
// are named and scaled for that network.
|
||||
const tokenSources = { ...sources, chainId };
|
||||
try {
|
||||
const parsed = ROUTER_IFACE.parseTransaction({ data });
|
||||
if (!parsed) return null;
|
||||
@@ -2338,11 +2341,11 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
// Any other output keeps its own token and figure: a swap that pays
|
||||
// its WETH to the user and then unwraps receives WETH, and one that
|
||||
// buys USDC and then unwraps the WETH it did not spend receives USDC.
|
||||
const inInfo = tokenInfo(inputToken, sources);
|
||||
const inInfo = tokenInfo(inputToken, tokenSources);
|
||||
const outInfo =
|
||||
outputUnwrapped || (hasUnwrapWeth && !outputEstablished)
|
||||
? { symbol: "ETH", decimals: 18, address: null }
|
||||
: tokenInfo(outputToken, sources);
|
||||
: tokenInfo(outputToken, tokenSources);
|
||||
|
||||
const inSymbol = inInfo.symbol;
|
||||
const outSymbol = outInfo.symbol;
|
||||
@@ -2469,13 +2472,19 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
details.push({
|
||||
label: "Moved from the sender",
|
||||
value: present(s.amount)
|
||||
? spentText(s.amount, tokenInfo(s.token, sources), s.atMost)
|
||||
.display
|
||||
? spentText(
|
||||
s.amount,
|
||||
tokenInfo(s.token, tokenSources),
|
||||
s.atMost,
|
||||
).display
|
||||
: UNDECODED_CURRENCY,
|
||||
});
|
||||
if (present(s.token)) {
|
||||
details.push(
|
||||
tokenMovedLine("Token moved", tokenInfo(s.token, sources)),
|
||||
tokenMovedLine(
|
||||
"Token moved",
|
||||
tokenInfo(s.token, tokenSources),
|
||||
),
|
||||
);
|
||||
if (!present(s.recipient)) {
|
||||
details.push({
|
||||
@@ -2497,7 +2506,7 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
// What each PERMIT2_TRANSFER_FROM moves: its amount, its token and
|
||||
// where it goes, an address on a line of its own.
|
||||
for (const m of movedFromSender) {
|
||||
const info = permit2TokenInfo(m.token, sources);
|
||||
const info = permit2TokenInfo(m.token, tokenSources);
|
||||
details.push({
|
||||
label: "Moved from the sender",
|
||||
value: amountText(m.amount, info).display,
|
||||
@@ -2532,7 +2541,7 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const info = permit2TokenInfo(p.token, sources);
|
||||
const info = permit2TokenInfo(p.token, tokenSources);
|
||||
details.push({
|
||||
label: "Permit2 allowance",
|
||||
value:
|
||||
@@ -2598,7 +2607,7 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
paidTo.push({ label: "Paid to", value: PAID_TO_BRIDGE });
|
||||
}
|
||||
for (const m of movedIntoRouter) {
|
||||
const info = permit2TokenInfo(m.token, sources);
|
||||
const info = permit2TokenInfo(m.token, tokenSources);
|
||||
paidTo.push({
|
||||
label: "Paid to",
|
||||
value:
|
||||
@@ -2623,7 +2632,7 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
paidTo.push(
|
||||
tokenMovedLine(
|
||||
"Token moved into the router",
|
||||
tokenInfo(getAddress(token), sources),
|
||||
tokenInfo(getAddress(token), tokenSources),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user