A TypeScript SDK for router aggregation with comprehensive support for cross-chain bridges and decentralized exchange aggregators.
Router Aggregator Core provides a unified interface for interacting with multiple routing protocols, categorizing them into two distinct types:
- Bridges: Cross-chain protocols that facilitate token transfers between different blockchains
- Exchanges: DEX aggregators that find optimal trading routes within and across chains
- Type-Safe Node Classification: Clear distinction between bridge and exchange nodes with TypeScript support
- Comprehensive Protocol Support: Support for 9+ major protocols including Relay, deBridge, Across, OpenOcean, and more
- Chain Compatibility: Built-in compatibility mappings for different blockchain types
- Utility Functions: Rich set of helper functions for node categorization and filtering
- Modern TypeScript: Built with strict TypeScript and modern tooling
# With npm
npm install @routerprotocol/xplore-core
# With yarn
yarn add @routerprotocol/xplore-core
# With pnpm
pnpm add @routerprotocol/xplore-core
# With bun
bun add @routerprotocol/xplore-core
import { BridgeNodes, ExchangeNodes, isBridgeNode, isExchangeNode } from '@routerprotocol/xplore-core'
// Type-safe node classification
const relay = BridgeNodes.RELAY
const openocean = ExchangeNodes.OPENOCEAN
// Runtime type checking
console.log(isBridgeNode(relay)) // true
console.log(isExchangeNode(relay)) // false
console.log(isExchangeNode(openocean)) // true
- Relay: Multi-chain bridge supporting EVM, Solana, Sui, and Bitcoin
- deBridge: Cross-chain liquidity protocol
- Across: Optimistic cross-chain bridge
- THORChain: Native cross-chain liquidity protocol supporting Bitcoin
- Stargate Taxi: Cross-chain bridge using LayerZero
- Mayan CCTP: Protocol using Circle's Cross-Chain Transfer Protocol
- Mayan Swift: Fast bridging solution from Mayan
- GasZip: Native token bridge for gas fee optimization
- OpenOcean: DEX aggregator with cross-chain capabilities
Complete documentation is available at: https://router-protocol.github.io/xplore-core/
The main class for handling parallel router requests.
new RouterAggregator<T>(configs: RouterConfig[], options?: AggregatorOptions)
configs
: Array of router configurationsoptions
: Optional aggregator settings
Execute requests to all configured routers in parallel.
async execute(endpoint: string, options?: RequestOptions): Promise<AggregatorResult<T>>
Returns an AggregatorResult
with:
successful
: Array of successful responses with timing informationfailed
: Array of failed responses with error detailsmetadata
: Execution metadata and statistics
interface RouterConfig {
url: string; // Base router URL
timeout?: number; // Request timeout in milliseconds
headers?: Record<string, string>; // Custom headers
}
interface AggregatorResult<T> {
successful: RouterResponse<T>[];
failed: RouterResponse<never>[];
metadata: {
totalRequests: number;
successRate: number;
averageResponseTime: number;
};
}
interface RouterResponse<T> {
routerUrl: string;
data: T;
timing: {
start: number;
end: number;
duration: number;
};
status: 'success' | 'error';
error?: string;
}
The SDK includes helper utilities for response analysis:
import {
getFastestResponse,
getSuccessRate,
groupResponsesByStatus
} from '@routerprotocol/xplore-core';
const result = await aggregator.execute('/endpoint');
// Get the fastest successful response
const fastest = getFastestResponse(result.successful);
// Calculate success rate
const successRate = getSuccessRate(result);
// Group responses by status
const grouped = groupResponsesByStatus(result);
const routers = [
{
url: 'https://primary-router.com',
timeout: 5000,
headers: {
'Authorization': 'Bearer token',
'X-API-Key': 'your-key'
}
},
{
url: 'https://fallback-router.com',
timeout: 3000
}
];
const options = {
maxConcurrency: 10, // Maximum concurrent requests
retries: 2, // Number of retries on failure
retryDelay: 1000 // Delay between retries (ms)
};
const aggregator = new RouterAggregator(routers, options);
# Install dependencies
bun install
# Build the package
bun run build
# Run tests
bun run test
# Type checking
bun run typecheck
# Linting
bun run lint
# Documentation development
bun run docs:dev
# Build documentation
bun run docs:build
The project includes comprehensive testing with both Node.js and Bun runtime:
# Run tests with vitest (Node.js)
bun run test
# Run tests with Bun test runner
bun test
This project uses GitHub Actions for continuous integration and deployment:
- CI Pipeline: Multi-version testing (Node 20+, Bun latest/1.1.0)
- Semantic Releases: Automated versioning and publishing
- Beta Releases: PR-based beta deployments to GitHub Packages
- Dual Publishing: NPM + GitHub Packages
- Dependency Updates: Automated via Dependabot
When you create a pull request, a beta version is automatically published:
# Install beta version (from PR comment)
bun add @routerprotocol/[email protected]
ISC
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Make your changes following conventional commits
- Run tests and ensure they pass
- Submit a pull request
This project uses semantic release with conventional commits:
feat:
- New features (minor version bump)fix:
- Bug fixes (patch version bump)docs:
- Documentation changes (patch version bump)chore:
- Maintenance tasks (no version bump)BREAKING CHANGE:
- Breaking changes (major version bump)
Built for high performance with:
- Parallel request execution using
Promise.allSettled()
- Efficient memory usage with streaming responses
- Optimized TypeScript compilation with
tsup
- Bundle size monitoring and analysis
- Native Bun performance optimizations
The CI pipeline includes:
- Bundle size analysis
- Performance benchmarking
- Memory usage tracking
- Multi-runtime compatibility testing
Built with β€οΈ using Bun and TypeScript