Getting Started

Learn how to install Predicta and integrate it into your Solana trading bots, wallets, or DeFi backends.

1. Installation

Predicta is published on crates.io. It is a fully bundled suite, so you just need to run:

cargo add predicta

This will download the entire suite (simulator, data ingestion, tx-model, and network context).

2. CLI Usage (Testing)

If you want to quickly test the engine without writing Rust code, you can use the built-in CLI tool to simulate a JSON transaction against live Mainnet data.

Step 1: Generate a sample

cargo run -p predicta-cli -- sample > my_tx.json

Step 2: Run the prediction

cargo run -p predicta-cli -- predict --tx-file my_tx.json

3. Rust Integration Example

This is how a Trading Bot or Wallet Backend uses the library to predict landing probability and assess fees before broadcasting.

use predicta::data::RpcIngestor;
use predicta::simulator::{Simulator, FeeAdequacy, RetryAdvice, RiskReason};
use predicta::tx_model::{AccountMeta, Instruction, Transaction};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 1. Build your transaction domain model
    let my_tx = Transaction {
        instructions: vec![Instruction {
            program_id: "JUP6LkbZbjS1jKKwapdH67yIeI2tWcbkXJ5A2e8YpXF".to_string(), // Jupiter
            accounts: vec!["payer".to_string(), "pool_address".to_string()],
        }],
        accounts: vec![
            AccountMeta { pubkey: "payer".to_string(), is_signer: true, is_writable: true },
            AccountMeta { pubkey: "pool_address".to_string(), is_signer: false, is_writable: true },
        ],
        compute_unit_limit: 300_000,
        priority_fee_microlamports: 5_000,
        tx_size_bytes: 450,
        recent_blockhash_age_slots: 2, 
    };

    // 2. Profile the Tx
    let tx_profile = my_tx.profile().unwrap();

    // 3. Fetch Live Network Conditions from Mainnet
    let ingestor = RpcIngestor::new("https://api.mainnet-beta.solana.com");
    let network_snapshot = ingestor.fetch_snapshot().await.unwrap();
    let network_profile = network_snapshot.profile().unwrap();

    // 4. Run the Simulator
    let result = Simulator::simulate(&tx_profile, &network_profile);

    println!("Landing Probability: {:.1}%", result.landing_probability * 100.0);
    println!("Estimated Delay: {} slots", result.estimated_delay_slots);
    
    match result.retry_advice {
        RetryAdvice::WaitAndSee => println!("Action: Send it, wait a few slots."),
        RetryAdvice::RetryImmediately => println!("Action: Send and spam retries."),
        _ => {}
    }

    Ok(())
}