Skip to content

kyoshoku/kyo-dex-integrate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kyo DEX Integration

A comprehensive Rust library for integrating with multiple Solana DEX protocols, including Humidify, TesseraV, Solfi, and ZeroFi.

Features

  • 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

Supported DEXes

DEX Version Status
Humidify Latest ✅ Supported
TesseraV Latest ✅ Supported
Solfi v1 ✅ Supported
Solfi v2 ✅ Supported
ZeroFi Latest ✅ Supported

Installation

Add this to your Cargo.toml:

[dependencies]
kyo-dex-integrate = "0.1.0"

Quick Start

Basic Single-Hop Swap

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(())
}

Multi-Hop Swap

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?;

CLI Usage

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 EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v

Examples

See the examples/ directory for complete usage examples:

  • basic_swap.rs - Simple single-hop swap
  • multi_hop_swap.rs - Complex multi-hop routing

Architecture

The library is organized into several modules:

  • client: Main SwapClient for executing swaps
  • adapters: DEX-specific implementations
  • types: Common types and data structures
  • error: Comprehensive error handling

DEX Adapters

Each DEX has its own adapter module:

  • humidifi.rs - Humidify DEX integration
  • tessera.rs - TesseraV DEX integration
  • solfi.rs - Solfi v1 and v2 integration
  • zerofi.rs - ZeroFi DEX integration

Configuration

Program IDs

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
}

RPC Configuration

let client = SwapClient::new_with_commitment(
    "https://api.mainnet-beta.solana.com",
    CommitmentConfig::confirmed(),
);

Error Handling

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),
}

Development

Building

cargo build

Testing

cargo test

Running Examples

cargo run --example basic_swap
cargo run --example multi_hop_swap

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Disclaimer

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages