kybr 0.2.2

Unofficial Rust client for the KyberSwap API (kybr)
Documentation

Features

  • Route API - Get optimal swap routes across DEXs
  • Build API - Get transaction calldata for execution
  • Swap API - Route and calldata in one call (partner-restricted)
  • Multi-chain - Supports the 19 EVM chains KyberSwap lists as active

Installation

[dependencies]
kybr = "0.2"
tokio = { version = "1", features = ["full"] }

Quick Start

use kybr::{Client, Chain, RouteRequest};

#[tokio::main]
async fn main() -> Result<(), kybr::Error> {
    let client = Client::new()?;

    // Get swap routes
    let request = RouteRequest::new(
        "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
        "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
        "1000000000000000000", // 1 WETH
    ); // slippage is set when building (BuildRouteRequest)

    let route = client.get_routes(Chain::Ethereum, &request).await?;
    println!("Output: {} USDC", route.amount_out);

    Ok(())
}

Getting Transaction Data

use kybr::{Client, Chain, RouteRequest, BuildRouteRequest};

// First get route data (routeSummary is kept as raw JSON)
let route_data = client.get_route_data(Chain::Ethereum, &request).await?;

// Then build for execution - the summary must be sent back unmodified
let build_request = BuildRouteRequest {
    route_summary: route_data.route_summary,
    sender: "0xYourAddress".to_string(),
    recipient: "0xYourAddress".to_string(),
    slippage_tolerance_bps: Some(50),
    deadline: None,
    enable_permit: None,
};

let tx_data = client.build_route(Chain::Ethereum, &build_request).await?;
println!("Router: {}", tx_data.router_address);
println!("Calldata: {}", tx_data.data);

Supported Chains

Ethereum, BSC, Polygon, Arbitrum, Optimism, Avalanche, Base, Linea, Sonic, Berachain, Unichain, Ronin, HyperEVM, Plasma, Monad, Etherlink, MegaETH, Robinhood Chain, Arc

Chain::all() returns this list. KyberSwap has deactivated Fantom, Scroll, zkSync, Blast and Mantle, and Polygon zkEVM is no longer listed, so those variants were removed.

Terms of Service

This is an unofficial client. By using this library, you agree to comply with KyberSwap Terms of Use.

Disclaimer

This crate is not affiliated with or endorsed by Kyber Network.

License

MIT