This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Language: Always write code in English (including comments, variables, logs, and error messages), even when we communicate in other languages.
Environment Variables: You may read .env.example for reference, but you must NOT read .env as it contains sensitive credentials.
npm run build- Build the library using tsup (ESM + CJS + types)npm run lint- Run ESLint on TypeScript filesnpm run format- Format code with Prettiernpm run clean- Remove dist folder
npm test- Run unit tests (excludes integration tests)npm run test:integration- Run integration tests onlynpm run test -- -t 'isUri'- Run specific unit testnpm run test:integration -- -t 'evmFetcher'- Run specific integration test
npm version patch && git push origin main --tags- Version bump and publish
This is a token registry library for multi-chain token metadata management with Redis caching and pluggable fetchers.
TokenRegistry (src/TokenRegistry.ts): Main class that manages token metadata with dual-layer caching (LRU in-memory + Redis) and validation. Handles batched token fetching and pagination.
Fetcher (src/Fetcher.ts): Abstract base class for blockchain-specific token fetchers. Each fetcher implements _fetch() and uniformTokenAddress() methods.
Fetchers (src/fetchers/): Blockchain-specific implementations:
solana.ts- Jupiter API integrationevm.ts- Web3/Viem for Ethereum-compatible chainsaptos.ts- Aptos Labs SDKsui.ts- Mysten Labs SDKbitcoin.ts- Basic Bitcoin fetcher
Jobs (src/jobs/): Background data population tasks:
jupiterJob.ts- Fetches all Jupiter tokens for SolanacoingeckoJob.ts- Fetches CoinGecko token data
- Token validation using AJV schema (
src/tokenSchema.ts) - Uniform token addressing across chains via
@sonarwatch/portfolio-core - Transform pipeline with
defaultTransformTokenhelper - Batch processing with configurable concurrency
- TTL randomization (±10%) to prevent cache stampedes
TokenRegistry requires:
- Redis connection options
- Network-specific fetchers map
- Optional custom token transform function
- Configurable TTL for memory and Redis caches
- Unit tests for core logic and utilities
- Integration tests for fetchers and jobs (require network access)
- Separate test commands allow running tests independently