Skip to content

bleu/chainlink-price-feed-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Chainlink Registry

A comprehensive dual-process indexing system for Chainlink data feeds and price aggregators across multiple chains.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Flags Indexer      β”‚    β”‚  Aggregators Indexer    β”‚
β”‚  (Port 42069)       β”‚    β”‚  (Port 42070)           β”‚
β”‚                     β”‚    β”‚                         β”‚
β”‚ - Index flags only  β”‚    β”‚ - Index flags + aggs    β”‚
β”‚ - Discover aggs     β”‚    β”‚ - Complete dataset      β”‚
β”‚ - Lightweight       β”‚    β”‚ - Updated dynamically   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                           β–²
         β”‚ Discovers new aggregators β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚    Supervisor       β”‚
         β”‚                     β”‚
         β”‚ - Polls flags DB    β”‚
         β”‚ - Updates agg configβ”‚
         β”‚ - Manages processes β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

This monorepo contains three main applications:

🏁 Flags Indexer (apps/chainlink-flags-indexer/)

Lightweight indexer that processes only Chainlink flag events to discover aggregators.

Key Features:

  • Flags-only indexing - Processes FlagRaised/FlagLowered events
  • Aggregator discovery - Finds aggregator addresses from flag events
  • Lightweight & fast - Minimal resource usage for quick discovery
  • Always running - Provides continuous discovery of new aggregators

πŸ“Š Aggregators Indexer (apps/chainlink-aggregators-indexer/)

Full-featured indexer that processes both flag events and aggregator price events.

Key Features:

  • Complete dataset - Indexes both flags and aggregator events
  • Price tracking - Tracks AnswerUpdated and NewRound events
  • Dynamic config - Aggregator addresses added dynamically by supervisor
  • Price quote API - REST endpoints with BFS pathfinding for cross-token pricing

πŸŽ›οΈ Supervisor (apps/chainlink-supervisor/)

Orchestrates both indexers and manages the discovery process.

Key Features:

  • Process management - Starts, stops, and monitors both indexers
  • Discovery polling - Polls flags database for new aggregators
  • Config updates - Updates aggregator indexer config dynamically
  • Health monitoring - Automatic restart and fault tolerance

πŸ› οΈ SDK (pkg/sdk/)

A TypeScript SDK that provides a clean, type-safe interface for consuming the price API.

Key Features:

  • Type-safe - Full TypeScript support with comprehensive types
  • Modern API - Promise-based with async/await support
  • Batch operations - Fetch multiple quotes in parallel
  • Error handling - Specific error classes for different failure scenarios

πŸš€ Quick Start

Option 1: Supervisor Mode (Recommended)

# Install dependencies
pnpm install

# Set up environment files
cp apps/chainlink-flags-indexer/.envrc.template apps/chainlink-flags-indexer/.envrc
cp apps/chainlink-aggregators-indexer/.envrc.template apps/chainlink-aggregators-indexer/.envrc  
cp apps/chainlink-supervisor/.envrc.template apps/chainlink-supervisor/.envrc

# Edit .envrc files with your database URL and DRPC API key

# Start the supervisor (manages everything)
cd apps/chainlink-supervisor
pnpm start

Option 2: Manual Mode

# Terminal 1: Flags indexer
cd apps/chainlink-flags-indexer && pnpm dev

# Terminal 2: Aggregators indexer
cd apps/chainlink-aggregators-indexer && pnpm dev

# Terminal 3: Supervisor  
cd apps/chainlink-supervisor && pnpm dev

APIs will be available at:

  • Flags Indexer: http://localhost:42069
  • Aggregators Indexer: http://localhost:42070

Using the SDK

cd pkg/sdk
pnpm install
pnpm build
import { ChainlinkRegistryClient } from '@chainlink-registry/sdk';

const client = new ChainlinkRegistryClient({
  baseUrl: 'http://localhost:42070'  // Use aggregators indexer for price data
});

// Get a price quote
const quote = await client.getPriceQuote(8453, 'ETH', 'USD');
console.log(`1 ETH = ${quote.formattedPrice} USD`);

// Get available tokens
const tokens = await client.getAvailableTokens(8453);
console.log(`Available tokens: ${tokens.tokens.join(', ')}`);

🌐 Supported Networks

Chain ID Network Status
1 Ethereum βœ… Active
10 Optimism βœ… Active
100 Gnosis βœ… Active
130 Unichain βœ… Active
137 Polygon βœ… Active
146 Sonic βœ… Active
324 zkSync Era βœ… Active
1868 Soneium βœ… Active
5000 Mantle βœ… Active
8453 Base βœ… Active
42161 Arbitrum One βœ… Active
42220 Celo βœ… Active
43114 Avalanche βœ… Active
57073 Ink βœ… Active
59144 Linea βœ… Active
60808 BOB βœ… Active
534352 Scroll βœ… Active

πŸ“– Examples

Basic Price Query

curl "http://localhost:42070/price/quote/8453/ETH/USD"

Multi-hop Pricing

curl "http://localhost:42070/price/quote/1/BTC/EUR"

🚧 Development

Prerequisites

  • Node.js 18+
  • pnpm
  • PostgreSQL (handled by Ponder)
  • DRPC API key

Project Structure

chainlink-registry/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ chainlink-flags-indexer/      # Lightweight flags-only indexer
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ index.ts              # Flag event processing
β”‚   β”‚   β”‚   β”œβ”€β”€ api/                  # GraphQL/SQL API
β”‚   β”‚   β”‚   └── utils/                # Data feed utilities
β”‚   β”‚   β”œβ”€β”€ abis/                     # Contract ABIs
β”‚   β”‚   β”œβ”€β”€ ponder.config.ts          # Multi-chain configuration
β”‚   β”‚   └── ponder.schema.ts          # Database schema
β”‚   β”œβ”€β”€ chainlink-aggregators-indexer/ # Full aggregator indexer
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ index.ts              # Flag + aggregator processing
β”‚   β”‚   β”‚   β”œβ”€β”€ api/                  # Price quote API
β”‚   β”‚   β”‚   └── utils/                # Pricing utilities
β”‚   β”‚   β”œβ”€β”€ abis/                     # Contract ABIs
β”‚   β”‚   β”œβ”€β”€ ponder.config.ts          # Dynamic configuration
β”‚   β”‚   └── ponder.schema.ts          # Extended database schema
β”‚   └── chainlink-supervisor/         # Process orchestrator
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ index.ts              # Main supervisor logic
β”‚       β”‚   β”œβ”€β”€ process-manager.ts    # Process lifecycle management
β”‚       β”‚   β”œβ”€β”€ aggregator-discovery.ts # Discovery logic
β”‚       β”‚   └── config-generator.ts   # Dynamic config updates
β”‚       └── types.ts                  # TypeScript definitions
β”œβ”€β”€ pkg/
β”‚   └── sdk/                          # TypeScript SDK
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ client.ts             # Main client class
β”‚       β”‚   β”œβ”€β”€ types.ts              # TypeScript definitions
β”‚       β”‚   └── utils.ts              # Helper functions
β”‚       └── examples/                 # Usage examples
└── package.json                      # Workspace configuration

πŸ“„ License

MIT

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ”— Links

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors