Skip to content

Simple solver example that fires a datarequest and pushes the result to an array of chains

Notifications You must be signed in to change notification settings

sedaprotocol/seda-push-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

52 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SEDA Push Solver

git add A robust TypeScript-based SEDA Oracle Push Solver for enterprise-grade Oracle integrations. This system posts DataRequests to the SEDA oracle network, orchestrates EVM integrations across multiple chains, and provides comprehensive batch processing with advanced reliability features.

🌟 Features

  • πŸ”— Multi-Chain Oracle Integration - Seamlessly integrate SEDA oracle data with multiple EVM chains
  • πŸ—οΈ Enterprise Architecture - Service-oriented design with dependency injection and clean separation of concerns
  • πŸ”„ Robust Batch Processing - Advanced batch handling with signature validation and merkle proof generation
  • ⚑ Type-Safe Operations - Full TypeScript support with comprehensive type definitions
  • πŸ›‘οΈ Production-Ready Reliability - Comprehensive error handling, retry logic, and graceful degradation
  • πŸ“Š Advanced Scheduling - Cosmos sequence coordination, task management, and intelligent retry mechanisms
  • 🌐 Multi-Network Support - Testnet, mainnet, and local development environments
  • πŸ”§ Consolidated Configuration - Centralized, environment-based configuration management
  • πŸ“ Structured Logging - Comprehensive execution tracking with configurable log levels
  • πŸ§ͺ Comprehensive Testing - Full test coverage with mock services and integration tests

πŸš€ Quick Start

# Install dependencies
npm install

# Set up environment (copy and edit)
cp env.example .env

# Run the push solver
npm start

# Or run in development mode
npm run dev

πŸ“ Project Architecture

seda-push-solver/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts                      # Main exports
β”‚   β”œβ”€β”€ runner.ts                     # Application runner
β”‚   β”œβ”€β”€ scheduler.ts                  # Main scheduler entry point
β”‚   β”‚
β”‚   β”œβ”€β”€ config/                       # πŸ”§ Consolidated Configuration
β”‚   β”‚   β”œβ”€β”€ index.ts                  # Configuration exports
β”‚   β”‚   β”œβ”€β”€ seda.ts                   # SEDA network configurations
β”‚   β”‚   β”œβ”€β”€ evm.ts                    # EVM network configurations
β”‚   β”‚   β”œβ”€β”€ environment.ts            # Environment utilities
β”‚   β”‚   └── validators.ts             # Configuration validation
β”‚   β”‚
β”‚   β”œβ”€β”€ types/                        # πŸ“‹ Type Definitions
β”‚   β”‚   β”œβ”€β”€ index.ts                  # Type exports
β”‚   β”‚   β”œβ”€β”€ core.ts                   # Core system types
β”‚   β”‚   β”œβ”€β”€ seda.ts                   # SEDA-specific types
β”‚   β”‚   β”œβ”€β”€ evm.ts                    # EVM-specific types
β”‚   β”‚   └── batch-types.ts            # Batch processing types
β”‚   β”‚
β”‚   β”œβ”€β”€ core/                         # πŸ—οΈ Core Business Logic
β”‚   β”‚   β”œβ”€β”€ data-request/             # DataRequest operations
β”‚   β”‚   β”‚   β”œβ”€β”€ data-request-builder.ts  # DataRequest construction
β”‚   β”‚   β”‚   β”œβ”€β”€ executor.ts           # DataRequest execution
β”‚   β”‚   β”‚   β”œβ”€β”€ input-builder.ts      # Input parameter building
β”‚   β”‚   β”‚   β”œβ”€β”€ signer.ts             # SEDA signer management
β”‚   β”‚   β”‚   β”œβ”€β”€ config-loader.ts      # Configuration loading
β”‚   β”‚   β”‚   └── index.ts              # Module exports
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ scheduler/                # Advanced scheduling system
β”‚   β”‚   β”‚   β”œβ”€β”€ scheduler-core.ts     # Core scheduling logic
β”‚   β”‚   β”‚   β”œβ”€β”€ task-manager.ts       # Task lifecycle management
β”‚   β”‚   β”‚   β”œβ”€β”€ task-executor.ts      # Task execution engine
β”‚   β”‚   β”‚   β”œβ”€β”€ cosmos-sequence-coordinator.ts # Cosmos sequence handling
β”‚   β”‚   β”‚   β”œβ”€β”€ retry-handler.ts      # Intelligent retry logic
β”‚   β”‚   β”‚   β”œβ”€β”€ statistics.ts         # Performance metrics
β”‚   β”‚   β”‚   └── types.ts              # Scheduler types
β”‚   β”‚   β”‚
β”‚   β”‚   └── network/                  # Network abstractions (legacy compatibility)
β”‚   β”‚       └── index.ts              # Re-exports from config module
β”‚   β”‚
β”‚   β”œβ”€β”€ evm/                          # πŸ”— EVM Integration
β”‚   β”‚   β”œβ”€β”€ orchestrator.ts           # Multi-chain orchestration
β”‚   β”‚   β”œβ”€β”€ batch-poster.ts           # Batch posting to EVM chains
β”‚   β”‚   β”œβ”€β”€ result-poster.ts          # Result posting logic
β”‚   β”‚   β”œβ”€β”€ prover-discovery.ts       # Prover contract discovery
β”‚   β”‚   └── abi/                      # Contract ABIs
β”‚   β”‚
β”‚   β”œβ”€β”€ crypto/                       # πŸ” Cryptographic Operations
β”‚   β”‚   β”œβ”€β”€ signature-processor.ts    # Signature validation and processing
β”‚   β”‚   β”œβ”€β”€ merkle-proof-generator.ts # Merkle proof generation
β”‚   β”‚   └── constants.ts              # Crypto constants
β”‚   β”‚
β”‚   β”œβ”€β”€ seda/                         # 🌐 SEDA Network Integration
β”‚   β”‚   β”œβ”€β”€ batch-client.ts           # Batch data client
β”‚   β”‚   β”œβ”€β”€ batch-service.ts          # Batch processing service
β”‚   β”‚   └── data-request-client.ts    # DataRequest client
β”‚   β”‚
β”‚   β”œβ”€β”€ services/                     # 🎯 Service Layer
β”‚   β”‚   β”œβ”€β”€ service-container.ts      # Dependency injection container
β”‚   β”‚   β”œβ”€β”€ seda-service.ts           # SEDA operations service
β”‚   β”‚   β”œβ”€β”€ config-service.ts         # Configuration management service
β”‚   β”‚   β”œβ”€β”€ logging-service.ts        # Structured logging service
β”‚   β”‚   └── index.ts                  # Service exports
β”‚   β”‚
β”‚   β”œβ”€β”€ infrastructure/               # πŸ—οΈ Infrastructure Services
β”‚   β”‚   β”œβ”€β”€ infrastructure-container.ts # Infrastructure DI container
β”‚   β”‚   β”œβ”€β”€ timer-service.ts          # Timer abstractions
β”‚   β”‚   β”œβ”€β”€ process-service.ts        # Process lifecycle management
β”‚   β”‚   β”œβ”€β”€ health-service.ts         # Health monitoring
β”‚   β”‚   └── index.ts                  # Infrastructure exports
β”‚   β”‚
β”‚   β”œβ”€β”€ helpers/                      # πŸ”§ Utility Functions
β”‚   β”‚   β”œβ”€β”€ error-utils.ts            # Error handling utilities
β”‚   β”‚   β”œβ”€β”€ timeout-utils.ts          # Timeout management
β”‚   β”‚   └── index.ts                  # Helper exports
β”‚   β”‚
β”‚   └── utils/                        # πŸ› οΈ General Utilities
β”‚       └── hex.ts                    # Hex conversion utilities
β”‚
β”œβ”€β”€ tests/                            # πŸ§ͺ Test Suite
β”‚   β”œβ”€β”€ unit/                         # Unit tests
β”‚   β”‚   β”œβ”€β”€ types.test.ts             # Type definition tests
β”‚   β”‚   β”œβ”€β”€ config.test.ts            # Configuration tests
β”‚   β”‚   β”œβ”€β”€ services.test.ts          # Service layer tests
β”‚   β”‚   β”œβ”€β”€ infrastructure.test.ts    # Infrastructure tests
β”‚   β”‚   └── index-exports.test.ts     # Export validation tests
β”‚   β”‚
β”‚   β”œβ”€β”€ mocks/                        # Mock implementations
β”‚   β”‚   β”œβ”€β”€ config-service.mock.ts    # Mock configuration service
β”‚   β”‚   β”œβ”€β”€ seda-service.mock.ts      # Mock SEDA service
β”‚   β”‚   β”œβ”€β”€ logging-service.mock.ts   # Mock logging service
β”‚   β”‚   └── infrastructure.mock.ts    # Mock infrastructure services
β”‚   β”‚
β”‚   └── integration/                  # Integration tests
β”‚
β”œβ”€β”€ config.ts                         # Global configuration
β”œβ”€β”€ package.json                      # Dependencies and scripts
β”œβ”€β”€ tsconfig.json                     # TypeScript configuration
└── .env                              # Environment variables (create from template)

πŸ”§ Configuration

Environment Setup

Create a .env file with your configuration:

# SEDA Network Configuration
SEDA_NETWORK=testnet                           # testnet, mainnet, or local
SEDA_MNEMONIC="your 24-word mnemonic"          # Your SEDA wallet mnemonic
SEDA_RPC_ENDPOINT=                             # Optional: custom RPC endpoint
SEDA_ORACLE_PROGRAM_IDS="program1,program2"    # Your Oracle Program IDs (comma-separated for multiple programs)

# DataRequest Configuration
SEDA_REPLICATION_FACTOR=1                      # Number of oracle replications
SEDA_DR_TIMEOUT_SECONDS=120                    # DataRequest timeout
SEDA_DR_POLLING_INTERVAL_SECONDS=5             # Polling interval
SEDA_DR_MEMO="Custom DataRequest"              # Custom memo text

# Scheduler Configuration
SCHEDULER_INTERVAL_MS=60000                    # Interval between operations (ms)
SCHEDULER_CONTINUOUS=true                      # Run continuously
SCHEDULER_MAX_RETRIES=3                        # Maximum retry attempts
SCHEDULER_MEMO="Scheduled Operation"           # Scheduler memo

# EVM Configuration (if using EVM integration)
EVM_PRIVATE_KEY="your-private-key"             # EVM private key
EVM_NETWORKS=sepolia,polygon                   # Enabled EVM networks

# Advanced Configuration
COSMOS_POSTING_TIMEOUT_MS=20000               # Cosmos posting timeout
COSMOS_MAX_QUEUE_SIZE=100                     # Maximum queue size
LOG_LEVEL=info                                # Logging level (debug, info, warn, error)

Network Configuration

The project now uses consolidated configuration in src/config/seda.ts:

// Network configurations are now centralized and type-safe
export const SEDA_NETWORKS = {
  testnet: {
    name: 'testnet',
    rpcEndpoint: 'https://rpc.testnet.seda.xyz',
    explorerEndpoint: 'https://testnet.explorer.seda.xyz',
    dataRequest: {
      oracleProgramId: getRequiredOracleProgramId(),
      replicationFactor: 1,
      execGasLimit: BigInt(150_000_000_000_000),
      gasPrice: BigInt(10_000),
      consensusOptions: { method: 'none' as const },
      timeoutSeconds: 120,
      pollingIntervalSeconds: 1,
      memo: 'DX Feed Oracle DataRequest'
    }
  }
  // ... other networks
};

🎯 Available Scripts

  • npm start - Start the push solver in production mode
  • npm run dev - Start in development mode with hot reload
  • npm run build - Build and type-check the project
  • npm test - Run the test suite
  • npm run lint - Lint the codebase
  • npm run clean - Clean build artifacts

πŸ’‘ Usage Examples

Programmatic Usage

import { 
  SEDADataRequestBuilder, 
  loadSEDAConfig,
  ServiceContainer 
} from './src';

// Initialize services
const services = ServiceContainer.createProduction();
const config = services.configService.loadSEDAConfig();

// Create and initialize builder
const builder = new SEDADataRequestBuilder(config);
await builder.initialize();

// Post a DataRequest
const result = await builder.postDataRequest({
  memo: 'My custom DataRequest'
});

console.log('DataRequest ID:', result.drId);
console.log('Exit Code:', result.exitCode);

Service Container Usage

import { ServiceContainer, getServices } from './src/services';

// Use production services
const services = ServiceContainer.createProduction();

// Access individual services
const sedaService = services.sedaService;
const logger = services.loggingService;
const config = services.configService;

// Or use global services
const globalServices = getServices();

Advanced Scheduler Usage

import { SEDADataRequestScheduler } from './src';

// Create scheduler with custom configuration
const scheduler = new SEDADataRequestScheduler({
  intervalMs: 30000,  // 30 seconds
  continuous: true,
  maxRetries: 3,
  memo: 'Scheduled DataRequest'
});

// Start the scheduler
await scheduler.initialize();
await scheduler.start();

πŸ—οΈ Architecture Highlights

πŸ”§ Consolidated Configuration Management

  • Centralized: All configuration now lives in src/config/
  • Type-Safe: Full TypeScript support with proper interfaces
  • Environment-Driven: Easy deployment configuration
  • Backward Compatible: Legacy imports still work

🎯 Service-Oriented Architecture

  • Dependency Injection: Clean service container pattern
  • Interface-Based: Easy testing and mocking
  • Separation of Concerns: Clear boundaries between layers
  • Production-Ready: Full error handling and logging

πŸ“‹ Enhanced Type Safety

  • Eliminated any Types: Replaced with proper TypeScript interfaces
  • Comprehensive Type Definitions: Full coverage of all operations
  • Runtime Safety: Type validation and error handling
  • Developer Experience: Better IDE support and autocomplete

πŸ”„ Advanced Batch Processing

  • Signature Validation: Cryptographic signature verification
  • Merkle Proof Generation: Efficient proof generation for validators
  • Multi-Chain Support: Simultaneous EVM chain integration
  • Error Recovery: Robust error handling and retry logic

πŸ§ͺ Testing

The project includes comprehensive testing:

# Run all tests
npm test

# Run specific test suites
npm run test:unit
npm run test:integration
npm run test:types

# Run with coverage
npm run test:coverage

Test Categories:

  • Unit Tests: Individual component testing
  • Integration Tests: End-to-end workflow testing
  • Type Tests: TypeScript compilation and type safety
  • Mock Services: Isolated testing with mock implementations

πŸ”— Requirements

  • Node.js v18 or higher
  • TypeScript v4.5 or higher
  • SEDA Account with testnet/mainnet tokens
  • Oracle Program deployed to SEDA network
  • EVM Private Key (for EVM integration features)

🌐 Resources

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Multi-Program Parallel Execution

The solver now supports executing multiple oracle programs in parallel within each scheduled interval. This allows you to:

  • Post DataRequests for multiple programs simultaneously: All configured programs execute in parallel rather than sequentially
  • Track multiple DataRequests concurrently: Each program's DataRequest is tracked independently
  • Post results to EVM chains in parallel: Results from all programs are processed and posted to EVM networks simultaneously

Configuration

Configure multiple oracle programs using the SEDA_ORACLE_PROGRAM_IDS environment variable:

# Single program (legacy support)
SEDA_ORACLE_PROGRAM_IDS="your-single-program-id"

# Multiple programs (new parallel execution)
SEDA_ORACLE_PROGRAM_IDS="program-id-1,program-id-2,program-id-3"

How It Works

  1. Parallel Posting: When the scheduler triggers, it posts DataRequests for all configured programs simultaneously
  2. Independent Tracking: Each program's DataRequest is tracked independently with its own lifecycle
  3. Parallel Result Processing: Once oracle execution completes, results from all programs are processed and posted to EVM networks in parallel
  4. Comprehensive Logging: The system provides detailed logs for each program's execution status

Benefits

  • Improved Efficiency: Multiple programs execute concurrently instead of waiting for each other
  • Better Resource Utilization: Takes full advantage of parallel processing capabilities
  • Reduced Latency: Overall execution time is determined by the slowest program rather than the sum of all programs
  • Maintained Reliability: Each program operates independently, so failures in one don't affect others

About

Simple solver example that fires a datarequest and pushes the result to an array of chains

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors 2

  •  
  •