Skip to content

Add token transfers, contract explainer, transaction decoder and wallet charts - #6

Merged
lijnati merged 2 commits into
mainfrom
tokens-contracts-decoder
Oct 24, 2026
Merged

lijnati merged 2 commits into
mainfrom
tokens-contracts-decoder

Conversation

@lijnati

@lijnati lijnati commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Adds four features, in two commits:

  • ERC-20 token transfers (prepareTokenTransfer): "Send 5 USDC to alice.eth". Validates the token, recipient (address or ENS) and amount against the token's decimals, checks the token balance and ETH for gas, and returns the usual preview card with transfer(to, amount) calldata. Refuses transfers to the zero address or to the token's own contract.
  • Contract explainer (explainContract): verified ABI from the explorer (following EIP-1967 proxies) plus onchain probes for owner, paused and ERC-20/721/1155. Lists functions and flags privileged ones (mint, pause, upgrade, ownership, roles, fees, blocklists, withdrawals).
  • Transaction decoder (decodeTransaction): decodes the call with the target's verified ABI or standard ABIs, and summarizes events in plain English (token transfers, mints, burns, approvals, ApprovalForAll, NFT moves, WETH wraps), flagging unlimited approvals and reverts.
  • Charts in wallet analysis: a new Charts tab with a running net-ETH-flow line (received − sent − gas) and a bar chart of gas spent by activity.

Type of change

  • Bug fix
  • New feature (e.g. a new agent tool or UI)
  • Refactor / cleanup
  • Docs
  • Other:

How was it tested?

  • pnpm lint, pnpm typecheck, pnpm test (127 tests, 28 new) and pnpm build pass locally
  • Tried it in the browser (pnpm dev) on Ethereum Sepolia — not done against the live network: the Sepolia RPC and explorers aren't reachable from the environment this was built in. The charts were rendered with sample data and checked in light mode, dark mode and at 390px wide.
  • Added or updated tests for new logic in src/lib/ (token-transfer.test.ts, contracts.test.ts, decode.test.ts, activity.test.ts)

Screenshots

The Charts tab was checked visually in both themes with sample data; no live screenshots, since live Sepolia data wasn't reachable.

Safety checklist (if this touches transactions or tools)

This touches tools.ts, signing-guard.ts and tx-records.ts:

  • No new tool can sign or broadcast transactions (the tool allowlist test was updated deliberately: two read tools and one prepare tool)
  • The sender still comes from the connected wallet, not from LLM input
  • No API keys or RPC URLs are exposed to the browser or in error messages

Notes:

  • For token transfers, the browser signing guard decodes the calldata itself and only allows transfer(recipient, amount) matching the card, sent to the token contract with zero ETH. Tests cover a swapped recipient, a changed amount, an approve in disguise and garbage calldata.
  • explainContract never passes raw source code to the model, and contract, function and event names are filtered to plain identifiers, so text planted in a contract can't easily steer the agent. The agent instructions also say to treat these names as data.
  • Saved previews keep working: ETH preview keys in tx-records are unchanged.

- prepareTokenTransfer: validates the token, recipient (address or ENS)
  and amount with the token's decimals, checks the token balance and ETH
  for gas, and builds transfer(to, amount) calldata. Refuses transfers to
  the zero address or the token's own contract.
- The signing guard now handles token previews: it decodes the calldata
  itself and only allows transfer(recipient, amount) matching the card,
  sent to the token contract with zero ETH.
- explainContract: verified ABI from the explorer (following EIP-1967
  proxies) plus onchain probes for owner, paused, ERC-20/721/1155. Lists
  functions and flags privileged ones (mint, pause, upgrade, ownership,
  fees, blocklists). Raw source is never passed to the model and ABI
  names are filtered to identifiers.
- decodeTransaction: decodes the call with the target's verified ABI or
  standard ABIs, and summarizes events (ERC-20/721 transfers, mints,
  burns, approvals, ApprovalForAll, WETH wraps), flagging unlimited
  approvals and reverts.
- New result cards, tool labels, agent instructions, landing examples
  and README docs. Tests for all three features.
- analyzeWalletActivity now returns flowSeries (per-day received − sent
  − gas, plus a running total) and gasBreakdown (gas per activity, top
  five plus Other, with shares).
- New Charts tab on the wallet activity card: a running net-flow line
  with a zero line, crosshair and keyboard-navigable readout, a data
  table, and a note that it is not a balance; and a labeled bar chart of
  where the gas went.
- New --chart-1 color token with its own dark step, validated for
  lightness, chroma and contrast against both themes.
@vercel

vercel Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
chainly Ready Ready Preview Oct 24, 2026 6:01am UTC

Request Review

@lijnati
lijnati merged commit 0085bb9 into main Oct 24, 2026
3 checks passed
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.

1 participant