DEX Connector
A Rust library for connecting to multiple decentralized exchanges (DEX) with conditional feature support.
Supported DEX Protocols
- Hyperliquid: Native Rust implementation (always available)
- Lighter: Go SDK integration (conditional feature)
- Others: Extensible architecture for additional protocols
Feature Flags
lighter-sdk (default: disabled for safety)
Enables Lighter Go SDK integration with external shared library dependency.
When enabled:
- Full Lighter DEX functionality
- Requires
libsigner.soshared library - Go FFI bindings available
- Architecture-specific: Must match target platform
When disabled:
- Lighter functions return runtime errors
- No shared library dependencies
- Reduced binary size
- Safe for all architectures
Build Options
Default Build (Safe for All Architectures)
Builds without native dependencies. Hyperliquid and other connectors work normally.
With Lighter SDK Support
Cross-Platform Development
Development Environment (x86_64):
# Install x86_64 Go libraries
# Build with Lighter support
Production Environment (ARM64):
# Build ARM64 Go libraries
# Set environment and build
Important: Always ensure libsigner.so matches your target architecture. Using x86_64 libraries on ARM64 (or vice versa) will cause segmentation faults.
Usage Examples
Creating Connectors
use *;
// Hyperliquid (always available)
let hyperliquid = create_hyperliquid_connector?;
// Lighter (requires lighter-sdk feature)
let lighter = create_lighter_connector?;
Feature-Conditional Code
The lighter-sdk feature enables integration with the Lighter Go shared library for cryptographic operations. When this feature is not available, the connector will return appropriate error messages.
Dependencies
Always Required
- Standard Rust crypto libraries
- HTTP/WebSocket clients
- Serde for JSON handling
Conditional (lighter-sdk feature)
libcfor FFI- External Go shared library (
libsigner.so)
Architecture
dex-connector/
├── src/
│ ├── lib.rs # Public API and traits
│ ├── dex_connector.rs # Core connector trait
│ ├── hyperliquid_connector.rs # Hyperliquid implementation
│ └── lighter_connector.rs # Lighter implementation (conditional)
├── Cargo.toml # Feature flag configuration
└── README.md # This file
Integration Notes
For Library Users
- Default: Safe build without native dependencies
- Enable lighter-sdk: Only when you have matching architecture libraries
- Handle errors: Gracefully handle disabled feature runtime errors
- Cross-platform: Always rebuild
libsigner.sofor target architecture
For Contributors
- Mark Lighter-specific code with
#[cfg(feature = "lighter-sdk")] - Provide meaningful error messages for disabled features
- Keep core functionality independent of optional features
Error Handling
When lighter-sdk feature is disabled, Lighter-related functions return:
Err
This allows applications to handle missing functionality gracefully.