Switchboard Protos
Protobuf definitions for Switchboard oracle job schemas.
Overview
This crate provides Protocol Buffer definitions and Rust bindings for Switchboard's oracle job specification system. It enables developers to define, serialize, and deserialize complex oracle jobs that can fetch data from various sources, transform it, and aggregate results.
Features
- Comprehensive Task Library: Support for 70+ oracle tasks including HTTP requests, JSON parsing, mathematical operations, DeFi protocol integrations, and more
- JSON Serialization: Full serde support for JSON serialization/deserialization
- Type Safety: Strongly-typed Rust bindings for all protobuf definitions
- Cross-Platform: Works across Solana, EVM, and other blockchain ecosystems
- Vendored Protoc: No system protoc installation required
Installation
Add this to your Cargo.toml
:
[]
= "0.2.0"
Usage
use ;
// Create a simple HTTP task
let http_task = HttpTask ;
// Wrap it in a Task
let task = Task ;
// Create an OracleJob with the task
let job = OracleJob ;
// Serialize to JSON
let json = to_string.unwrap;
Working with Oracle Feeds
use ;
let feed = OracleFeed ;
Task Types
The library supports numerous task types for building sophisticated oracle jobs:
Data Sources
- HttpTask: Fetch data from HTTP endpoints
- WebsocketTask: Maintain persistent websocket connections
- OracleTask: Read from other oracle protocols (Chainlink, Pyth, Switchboard)
Data Parsing
- JsonParseTask: Extract values from JSON using JSONPath
- RegexExtractTask: Extract data using regular expressions
- BufferLayoutParseTask: Parse binary data formats
Aggregation
- MedianTask: Calculate median of multiple values
- MeanTask: Calculate average of multiple values
- MaxTask/MinTask: Find maximum/minimum values
Mathematical Operations
- MultiplyTask: Multiply values
- DivideTask: Divide values
- AddTask/SubtractTask: Addition and subtraction
- PowTask: Exponential operations
- RoundTask: Round to specific decimal places
DeFi Integrations
- JupiterSwapTask: Fetch swap prices from Jupiter
- LpExchangeRateTask: Fetch exchange rates from AMM pools (Orca, Raydium, etc.)
- UniswapExchangeRateTask: Uniswap pricing
- LpTokenPriceTask: LP token fair pricing
- SanctumLstPriceTask: Sanctum LST pricing
- MeteoraSwapTask: Meteora DEX pricing
- And many more...
Advanced Features
- CacheTask: Store intermediate results
- ConditionalTask: Conditional execution with fallbacks
- ComparisonTask: Compare values and branch logic
- BoundTask: Bound results to upper/lower limits
- SecretsTask: Securely request secrets from Switchboard SecretsServer
- CronParseTask: Parse cron patterns for scheduled updates
Building from Source
# Clone the repository
# Build the crate
# Run tests
# Check for linting issues
# Format code
The build process is fully automated via build.rs
:
- Uses vendored
protoc
(no system installation needed) - Generates Rust types from
job_schemas.proto
usingprost
- Generates Serde implementations using
pbjson
Project Structure
.
├── build.rs # Build script for protobuf generation
├── Cargo.toml # Package manifest
├── job_schemas.proto # Protobuf definitions
├── buf.gen.yaml # Buf configuration
├── README.md # This file
└── src/
└── lib.rs # Library entry point
Dependencies
- prost: Protocol Buffer implementation for Rust
- pbjson: JSON serialization support for prost types
- serde: Serialization framework
- protoc-bin-vendored: Vendored protoc binary (build-time)
Examples
For complete examples and integration patterns, see the Switchboard documentation.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License.
Resources
Support
For questions and support:
- Join our Discord
- Check our documentation
- Open an issue on GitHub