solana-pipkit 1.3.0

Pragmatic Rust utilities for Solana development - PDA helpers, transaction batching, rent recovery, account graphs, high-performance trading, and more
Documentation

What is solana-pipkit?

solana-pipkit is a Rust utility crate designed to streamline common tasks in Solana program and client development. It focuses on ergonomics, safety, and reusable patterns for production-grade Solana workflows.


Installation

cargo add solana-pipkit

Or add to your Cargo.toml:

[dependencies]
solana-pipkit = "1.3.0"

# Enable high-performance trading features
solana-pipkit = { version = "1.3.0", features = ["speed"] }

High-level features

  • Rent Recovery Efficiently reclaim lamports from dormant or empty accounts

  • SPL Token Helpers Simplified helpers for burning, transferring, and closing token accounts

  • PDA Management Utilities for derivation, seeding, and validation (including Metaplex metadata PDAs)

  • Account Utilities Common validation patterns and deserialization helpers

  • Anchor Reusables Macros and shared structures for cleaner, more maintainable Anchor programs

  • Safety Protocol Client-side validation to prevent costly transaction mistakes

  • Speed Module (v1.3.0 "Lightning") High-performance execution for trading agents with connection pooling, blockhash caching, and optimized swaps


Speed Module

Built for trading bots and agents that need minimal latency. The speed module provides optimized RPC clients, instant transaction building, and fast swap execution.

use solana_pipkit::speed::prelude::*;
use solana_sdk::signature::Keypair;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Multi-endpoint RPC with automatic failover
    let rpc = FastRpcClient::new(vec![
        "https://api.mainnet-beta.solana.com".into(),
        "https://solana-api.projectserum.com".into(),
    ]);

    // Benchmark and use fastest endpoint
    rpc.set_strategy(LoadBalanceStrategy::LeastLatency);
    let health = rpc.benchmark_endpoints().await;
    println!("Fastest: {} ({}ms)", health[0].url, health[0].latency_ms);

    // Fast swap execution
    let payer = Keypair::new();
    let executor = SwapExecutor::new(rpc, payer);

    let result = executor.swap_fast(
        &mints::USDC,
        &mints::SOL,
        1_000_000,  // 1 USDC
        SwapConfig::fast(),  // High priority, direct routes
    ).await?;

    println!("Swapped in {}ms", result.execution_time_ms);
    Ok(())
}

Performance targets:

  • Cached blockhash retrieval: 0ms
  • ATA computation: <50us
  • Quote to execution: <500ms

Safety Features

Crypto losses from typos and decimal errors are preventable. The safety module catches mistakes before they hit the chain.

use solana_pipkit::prelude::*;

let protocol = SafetyProtocol::new()
    .token_price(100.0)  // $100/SOL for USD calculations
    .large_amount_threshold(1000.0);

let report = protocol.validate_offline(
    &sender,
    &recipient,
    amount_lamports,
    9,  // SOL decimals
    balance,
);

if !report.approved {
    println!("Blocked: {:?}", report.blockers);
    return Err("Transaction failed safety check");
}

if report.requires_confirmation {
    println!("Warnings: {:?}", report.warnings);
    // Prompt user to confirm
}

What it prevents:

  • Address typos (invalid base58, wrong length)
  • Sending to yourself accidentally
  • Draining entire balance (>90% warning)
  • Decimal/magnitude errors (1000 vs 1.000)
  • Large transfers without confirmation (>$1000 USD)

Risk levels: Low | Medium | High | Critical

See examples/full_safety_demo.rs for complete usage.


Quick Example

Reclaiming rent from empty accounts:

use solana_pipkit::rent::RentCleaner;
use solana_sdk::{signature::read_keypair_file, signer::Signer};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let keypair = read_keypair_file("~/.config/solana/id.json")?;
    let rpc_url = "https://api.mainnet-beta.solana.com";

    let cleaner = RentCleaner::new(rpc_url, keypair.pubkey(), keypair);

    let reclaimed = cleaner.clean_empty_accounts().await?;
    println!("Reclaimed {} lamports", reclaimed);

    Ok(())
}

More examples are available in the examples/ directory.


Project Status

Early-stage utility crate - APIs may evolve and breaking changes can occur as the toolkit matures.

Fast chains deserve safe, expressive tooling. solana-pipkit exists to remove boilerplate, reduce footguns, and let you focus on protocol logic.


Contributing

Contributions are welcome and appreciated.

  • Open an issue for bugs, ideas, or discussion
  • Submit a PR for improvements or new helpers
  • Keep APIs ergonomic, composable, and Solana-native

Get started


License

This project is licensed under the MIT License.