Skip to content

feat: natural language event search#2

Open
shan8851 wants to merge 1 commit intomainfrom
feat/natural-language-search
Open

feat: natural language event search#2
shan8851 wants to merge 1 commit intomainfrom
feat/natural-language-search

Conversation

@shan8851
Copy link
Copy Markdown
Owner

What

Natural language search bar that translates queries like "USDC transfers over 1M on Ethereum last 24 hours" into structured query params — and runs them.

How

Contract Registry (packages/shared)

  • ~28 curated contracts across Ethereum, Polygon, and Base (USDC, USDT, DAI, WETH, Uniswap factories/routers, Permit2, ENS, etc.)
  • Fuzzy matching by name, aliases, and address
  • Zero-cost local resolution for known contracts

Parse Endpoint (POST /api/parse-query)

  • Registry-first: known contracts resolve instantly without any LLM call
  • OpenRouter fallback: complex queries (address mentions, conditional filters, unusual contracts) go to a cheap model (Gemini Flash by default)
  • Separate rate limiter: 5 parse requests per IP per 15 minutes
  • Graceful degradation: if no OpenRouter key, registry matching still works

Arg Filter Engine (packages/shared/src/lib/argFilter.ts)

  • Post-query filtering on decoded event args
  • Supports: >, <, >=, <=, ==, !=
  • Numeric (BigInt), string, and address-aware comparisons
  • Handles token decimals scaling (e.g. "over 1M USDC" → value > 1000000000000)

Frontend

  • Search bar above the query builder with sparkle icon ✨
  • Auto-resolves auto:24h / auto:7d time references into real block numbers
  • Populates the existing form and runs the query
  • Active filter badges with individual dismiss + clear all
  • Manual query builder remains fully functional

Infra

  • Rate limiter refactored: configurable per-endpoint with custom messages
  • Worker app caching to avoid re-creating Hono app on each request
  • OPENROUTER_API_KEY and OPENROUTER_MODEL added to env schema (both optional)

Testing

  • 40 tests passing (includes new tests for argFilter, contractRegistry, queryParser, createApp)
  • Types clean across all packages

To deploy

# Set OpenRouter key (optional — registry matching works without it)
wrangler secret put OPENROUTER_API_KEY

…r LLM parsing, post-query arg filtering

- Contract registry with ~28 curated contracts across ETH/Polygon/Base (fuzzy match)
- POST /api/parse-query endpoint: registry match first (free), OpenRouter LLM fallback
- Arg filter engine: numeric (BigInt), string, and address comparisons
- Search bar UI with auto block range resolution (auto:24h → real block numbers)
- Active filter badges with individual dismiss and clear all
- Separate rate limiter for parse endpoint (5 req/15min per IP)
- Worker app caching to avoid re-creating on each request
- All tests passing (40 total)
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