Skip to content

poc: Token list - #263

Open
chrstph-dvx wants to merge 5 commits into
masterfrom
token-poc
Open

poc: Token list#263
chrstph-dvx wants to merge 5 commits into
masterfrom
token-poc

Conversation

@chrstph-dvx

@chrstph-dvx chrstph-dvx commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Steps to test

Copilot AI review requested due to automatic review settings April 13, 2026 19:06
@vercel

vercel Bot commented Apr 13, 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 May 12, 2026 4:56pm

Request Review

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 introduces a proof-of-concept “token graph” module and UI for graph-backed token discovery, route resolution, and balance-based source token loading across a small set of chains.

Changes:

  • Add a token graph library that merges token sources (native/manual/Uniswap list/LiFi registry) and protocol/LiFi mapping edges.
  • Add API routes to search source tokens, resolve destination tokens (with optional LiFi swap fallback), and fetch wallet balances via multicall.
  • Add a standalone /token-graph-poc page + client UI and a Vitest test suite for destination routing behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/app/src/lib/token-graph-poc/types.ts Adds shared type definitions for token variants, edges, and API responses.
packages/app/src/lib/token-graph-poc/graph.ts Core token graph build/cache logic plus public functions for search, destination resolution, and balances.
packages/app/src/lib/token-graph-poc/graph.test.ts Adds tests covering destination token routing and swap fallback behavior.
packages/app/src/app/api/token-graph-poc/tokens/route.ts API endpoint to search/filter source tokens (optionally by destination).
packages/app/src/app/api/token-graph-poc/destination/route.ts API endpoint to resolve destination tokens/routes for a selected source token.
packages/app/src/app/api/token-graph-poc/balances/route.ts API endpoint to load wallet balances (optionally filtered by destination reachability).
packages/app/src/app/(with-sidebar)/token-graph-poc/page.tsx Registers the PoC page route and metadata.
packages/app/src/app/(with-sidebar)/token-graph-poc/TokenGraphPocClient.tsx Client UI to explore source tokens (balances/search) and destination routes (direct + on-demand swap fallback).

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

Comment on lines +669 to +671
const [nativeBalance, tokenBalances] = await Promise.all([
nativeToken ? client.getBalance({ address: walletAddress }) : null,
client.multicall({

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

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

walletAddress is validated with isAddress, but it remains typed as string while viem expects an Address for getBalance. In strict TS this won’t typecheck, and it also misses an opportunity to normalize the address once (e.g. checksummed) before use.

Copilot uses AI. Check for mistakes.
Comment on lines +641 to +645

const rpcUrl = rpcURLs[chainId];
if (!rpcUrl) {
throw new Error(`No RPC URL configured for chain ${chainId}`);
}

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

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

supportedChainIds/chains include ChainId.ApeChain, but rpcURLs (from @/bridge/util/networks) does not include an entry for ApeChain by default. This makes GET /api/token-graph-poc/balances return No RPC URL configured... whenever ApeChain is selected. Either remove ApeChain from the PoC-supported set or source an RPC URL for it (e.g. from orbit chain config) so balances work consistently.

Copilot uses AI. Check for mistakes.
Comment on lines +675 to +679
abi: erc20Abi,
functionName: 'balanceOf' as const,
args: [walletAddress],
})),
}),

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

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

The balanceOf call should receive a validated/normalized Address as its argument. Here walletAddress is still a plain string, which is likely to fail strict viem typing and can lead to inconsistent formatting. Consider normalizing once after validation (e.g. checksummed Address) and reusing it for both native + ERC20 reads.

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +31
describe('token graph destination tokens', () => {
beforeEach(() => {
mockLifiRegistry.tokensByChain = {};
mockLifiRegistry.tokensByChainAndCoinKey = {};

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

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

graph.ts caches cachedTokens/cachedEdges/graphPromise at module scope, but these tests mutate mockLifiRegistry between cases. Once the first test populates the cache, later tests can reuse the cached graph and never observe the updated registry/fetch stubs, making the suite order-dependent (and likely failing). Reset the graph module state between tests (e.g. vi.resetModules() + re-import, or expose a test-only reset function).

Copilot uses AI. Check for mistakes.
Comment on lines +506 to +510
if (!graphPromise) {
graphPromise = Promise.all([fetchUniswapTokens(), getLifiGraphData()]).then(
([uniswapTokens, lifiGraphData]) => {
const tokenById = new Map<string, TokenVariant>();

Copilot AI Apr 13, 2026

Copy link

Choose a reason for hiding this comment

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

If fetchUniswapTokens() / getLifiGraphData() rejects, the assigned graphPromise will stay rejected and never be cleared, so subsequent calls to getGraphData() will keep failing until the process restarts. Add error handling (e.g. a .catch) that resets graphPromise/caches on failure to allow retries after transient errors.

Copilot uses AI. Check for mistakes.
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