Skip to content

wip(bridge): keep lifi token registry under 2MB#406

Closed
dewanshparashar wants to merge 4 commits into
masterfrom
fix/lifi-token-registry-cache
Closed

wip(bridge): keep lifi token registry under 2MB#406
dewanshparashar wants to merge 4 commits into
masterfrom
fix/lifi-token-registry-cache

Conversation

@dewanshparashar

Copy link
Copy Markdown
Contributor

The serialized lifi token registry is ~2.6MB, over Next.js' 2MB unstable_cache item limit. Every cache write fails (Failed to set Next.js data cache ... items over 2MB can not be cached), so every request to /api/crosschain-transfers/lifi/tokens refetches the full token universe from li.quest. On CI runners this takes longer than the import E2E test's 30s window, which is why the Import test jobs fail on every PR. It also slows down token search for real users.

This shrinks the cached value from ~2.6MB to ~170KB (6.6%):

  • Cache only tokensByChain and rebuild the tokensByChainAndCoinKey lookup on read — the lookup duplicates almost every token.
  • Strip fields nothing downstream reads (e.g. verification status breakdowns).
  • Drop tokens whose coinKey doesn't exist on any partner chain — they can never match a route. Includes the ApeChain ETH<>WETH special case.

Verified against live li.quest data that the route output is identical for all 25 supported chain pairs before/after.

@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
arbitrum-portal Ready Ready Preview Jul 16, 2026 11:48am

Request Review

@dewanshparashar dewanshparashar changed the title fix(bridge): keep lifi token registry under the cache size limit fix(bridge): keep lifi token registry under 2MB Jul 16, 2026
@dewanshparashar
dewanshparashar marked this pull request as ready for review July 16, 2026 10:53
Copilot AI review requested due to automatic review settings July 16, 2026 10:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces the size of the cached LiFi token registry to stay under Next.js’ 2MB unstable_cache item limit, preventing cache-write failures that currently force every request to refetch the full LiFi token universe.

Changes:

  • Cache only tokensByChain and rebuild tokensByChainAndCoinKey on read to avoid duplicated data.
  • Strip unused token metadata fields to shrink the serialized cache payload.
  • Prune tokens whose coinKey does not exist on any partner chain (with an ApeChain ETH↔WETH routing exception) to remove non-routable tokens.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 263 to 265
if (!response.tokens) {
return {
tokensByChain: {},
tokensByChainAndCoinKey: {},
};
return {};
}
Comment on lines +212 to +218
/**
* Tokens are matched across chains by coinKey (see groupChildTokensAndParentTokens),
* so a token whose coinKey doesn't exist on any partner chain can never appear
* in a route and only bloats the cache. LiFi returns thousands of such tokens
* (e.g. Ethereum-only meme tokens).
*/
function keepRoutableTokens(
@dewanshparashar dewanshparashar changed the title fix(bridge): keep lifi token registry under 2MB wip(bridge): keep lifi token registry under 2MB Jul 16, 2026
@dewanshparashar

Copy link
Copy Markdown
Contributor Author

Superseded by #407, which carries this fix as one of its three commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants