A comprehensive Rust library for integrating with multiple Solana DEX protocols, including Humidify, TesseraV, Solfi, and ZeroFi.
- Multi-DEX Support: Unified interface for Humidify, TesseraV, Solfi (v1 & v2), and ZeroFi
- Multi-hop Swaps: Execute complex routing across multiple DEXes
- Slippage Protection: Built-in slippage tolerance and minimum output validation
- Type Safety: Strongly typed interfaces with comprehensive error handling
- Async Support: Full async/await support for high-performance applications
| DEX | Version | Status |
|---|---|---|
| Humidify | Latest | ✅ Supported |
| TesseraV | Latest | ✅ Supported |
| Solfi | v1 | ✅ Supported |
| Solfi | v2 | ✅ Supported |
| ZeroFi | Latest | ✅ Supported |
Add this to your Cargo.toml:
[dependencies]
kyo-dex-integrate = "0.1.0"use kyo_dex_integrate::{SwapClient, SwapParams, DexType, PoolConfig};
use solana_sdk::pubkey::Pubkey;
use std::str::FromStr;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize client
let client = SwapClient::new("https://api.mainnet-beta.solana.com");
// Create swap parameters
let swap_params = SwapParams {
amount_in: 1_000_000, // 1 USDC
min_amount_out: 0,
slippage_tolerance_bps: 50, // 0.5%
is_multi_hop: false,
max_hops: 3,
};
// Execute swap (placeholder - requires actual implementation)
let result = client.execute_swap(
&payer_keypair,
swap_params,
DexType::Humidify,
source_token_account,
destination_token_account,
pool_config,
).await?;
println!("Swap completed! Amount out: {}", result.amount_out);
Ok(())
}use kyo_dex_integrate::{SwapClient, SwapRoute, DexType};
// Create a multi-hop route
let route = SwapRoute::new(
vec![token_a, token_b, token_c],
vec![DexType::Humidify, DexType::TesseraV],
);
// Execute multi-hop swap
let result = client.execute_multi_hop_swap(
&payer_keypair,
swap_params,
route,
).await?;The library includes a command-line interface for testing and development:
# Execute a single-hop swap
cargo run --bin kyo-dex-cli swap \
--input-mint EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v \
--output-mint So11111111111111111111111111111111111111112 \
--amount 1000000 \
--dex humidify
# Find the best route
cargo run --bin kyo-dex-cli route \
--input-mint TOKEN_A \
--output-mint TOKEN_B \
--amount 1000000
# Get token information
cargo run --bin kyo-dex-cli token-info \
--mint EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1vSee the examples/ directory for complete usage examples:
basic_swap.rs- Simple single-hop swapmulti_hop_swap.rs- Complex multi-hop routing
The library is organized into several modules:
client: MainSwapClientfor executing swapsadapters: DEX-specific implementationstypes: Common types and data structureserror: Comprehensive error handling
Each DEX has its own adapter module:
humidifi.rs- Humidify DEX integrationtessera.rs- TesseraV DEX integrationsolfi.rs- Solfi v1 and v2 integrationzerofi.rs- ZeroFi DEX integration
Update the program IDs in src/lib.rs:
pub mod program_ids {
pub const HUMIDIFI_PROGRAM_ID: &str = "YOUR_HUMIDIFY_PROGRAM_ID";
pub const TESSERA_PROGRAM_ID: &str = "YOUR_TESSERA_PROGRAM_ID";
// ... other program IDs
}let client = SwapClient::new_with_commitment(
"https://api.mainnet-beta.solana.com",
CommitmentConfig::confirmed(),
);The library provides comprehensive error handling:
use kyo_dex_integrate::error::DexError;
match result {
Ok(swap_result) => println!("Swap successful: {}", swap_result.amount_out),
Err(DexError::InsufficientLiquidity) => println!("Not enough liquidity"),
Err(DexError::SlippageToleranceExceeded) => println!("Slippage too high"),
Err(e) => println!("Other error: {}", e),
}cargo buildcargo testcargo run --example basic_swap
cargo run --example multi_hop_swap- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
MIT License - see LICENSE file for details.
This software is provided for educational and development purposes. Always test thoroughly before using in production. The authors are not responsible for any financial losses.