jup-perps-client

Crates.iojup-perps-client
lib.rsjup-perps-client
version1.0.0
created_at2025-07-19 14:37:53.310643+00
updated_at2025-07-19 14:37:53.310643+00
descriptionRust client for Jupiter Perpetuals Protocol
homepage
repositoryhttps://github.com/monakki/jup-perps-client
max_upload_size
id1760293
size1,446,991
Monakki (monakki)

documentation

README

Jupiter Perpetuals Rust Client

Crates.io Documentation Rust Solana DeFi License

A Rust client for Jupiter Perpetuals Protocol, auto-generated from IDL using Codama.

šŸš€ Installation

Add to your Cargo.toml:

[dependencies]
jup-perps-client = "1.0"
solana-client = "1.18"  # For RPC functionality

šŸ”§ Usage

Basic Example - Pool Data

use jup_perps_client::{fetch_pool, fetch_custody};
use solana_client::rpc_client::RpcClient;
use solana_program::pubkey::Pubkey;
use std::str::FromStr;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Use SOLANA_RPC_URL environment variable or default to mainnet
    let rpc_url = std::env::var("SOLANA_RPC_URL")
        .unwrap_or_else(|_| "https://api.mainnet-beta.solana.com".to_string());
    let client = RpcClient::new(rpc_url);
    
    // Jupiter Labs Perpetuals Markets
    let pool_address = "5BUwFW4nRbftYTDMbgxykoFWqWHPzahFSNAaaaJtVKsq";
    let pool_pubkey = Pubkey::from_str(pool_address)?;
    let pool = fetch_pool(&client, &pool_pubkey)?;
    
    println!("šŸ“› Pool Name: {}", pool.data.name);
    println!("šŸ¦ Number of Custodies: {}", pool.data.custodies.len());
    println!("šŸ’° AUM USD: ${:.2}", pool.data.aum_usd as f64 / 1_000_000.0);
    
    // Fetch custody details
    for (i, custody_address) in pool.data.custodies.iter().enumerate() {
        let custody = fetch_custody(&client, custody_address)?;
        
        println!("\nšŸŖ™ Custody {}:", i + 1);
        println!("   Token Mint: {}", custody.data.mint);
        println!("   Assets Owned: {}", custody.data.assets.owned);
        println!("   Decimals: {}", custody.data.decimals);
        println!("   Target Ratio: {} bps", custody.data.target_ratio_bps);
    }
    
    Ok(())
}

Example Output:

šŸ“› Pool Name: Pool
šŸ¦ Number of Custodies: 5
šŸ’° AUM USD: $1553760440.14

šŸŖ™ Custody 1:
   Token Mint: So11111111111111111111111111111111111111112
   Assets Owned: 4376906755684259
   Decimals: 9
   Target Ratio: 4700 bps

šŸŖ™ Custody 2:
   Token Mint: 7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs
   Assets Owned: 3764241196893
   Decimals: 8
   Target Ratio: 800 bps

Environment Variables

You can customize the RPC endpoint using environment variables:

# Use a custom RPC endpoint
export SOLANA_RPC_URL="https://your-rpc-endpoint.com"
cargo run --example basic_usage

# Or run with inline environment variable
SOLANA_RPC_URL="https://your-rpc-endpoint.com" cargo run --example basic_usage

On-chain Program Usage

use jup_perps_rust_client::{accounts::*, types::*};

// Use the generated types in your on-chain program
let pool_account = Pool::default();

šŸ“š API Reference

Account Functions

Main Functions

  • fetch_perpetuals(rpc, address) - Get main protocol data
  • fetch_pool(rpc, address) - Get liquidity pool data
  • fetch_position(rpc, address) - Get position data
  • fetch_custody(rpc, address) - Get token custody data
  • fetch_token_ledger(rpc, address) - Get token ledger data
  • fetch_position_request(rpc, address) - Get position request data

Batch Functions

  • fetch_all_perpetuals(rpc, addresses) - Fetch multiple protocol accounts
  • fetch_all_pool(rpc, addresses) - Fetch multiple pools
  • fetch_all_position(rpc, addresses) - Fetch multiple positions

Safe Functions (Maybe variants)

  • fetch_maybe_perpetuals(rpc, address) - Safe protocol data fetch
  • fetch_maybe_pool(rpc, address) - Safe pool data fetch
  • fetch_maybe_position(rpc, address) - Safe position data fetch

Types

All data types are available:

use jup_perps_client::{
    Perpetuals,
    Pool, 
    Position,
    Custody,
    PositionRequest,
    TokenLedger,
    // ... and many more
};

Constants

use jup_perps_client::PERPETUALS_PROGRAM_ADDRESS;

println!("Program Address: {}", PERPETUALS_PROGRAM_ADDRESS);

šŸ› ļø Features

  • šŸ¦€ Native Rust types with comprehensive traits
  • šŸ”— Full Anchor integration
  • šŸ“¦ Borsh serialization support
  • 🌐 RPC client functions (enabled by default)
  • šŸ”„ Optional Serde support (enable serde feature)

Feature Flags

  • fetch (default) - Enables RPC client functions like fetch_pool(). Includes solana-client and solana-account dependencies
  • serde - Enables JSON serialization/deserialization support
  • anchor - Additional Anchor-specific functionality
  • anchor-idl-build - IDL build support

For minimal on-chain usage without RPC dependencies:

[dependencies]
jup-perps-client = { version = "1.0", default-features = false }

šŸ› ļø Generated Client

This client is auto-generated from Jupiter Perpetuals IDL using Codama.

Requirements

  • Rust ≄ 1.75.0
  • Cargo

šŸ“„ License

MIT

šŸ¤ Contributing

This client is auto-generated from Jupiter Perpetuals IDL files using Codama. For issues or feature requests, please visit the main repository.

šŸ”— Links

āš ļø Important Notes

  • This client is designed for reading data from Jupiter Perpetuals
  • For creating transactions, use the appropriate instructions from the instructions module
  • Always verify account addresses are current and valid
  • Use reliable RPC endpoints for production applications
  • The generated code includes comprehensive Rust documentation (rustdoc)

šŸ’° Support

If this client helps you build amazing Solana applications, consider supporting the project:

Solana: uJHFSYDcCRH2c6VLXY1kWBqGFmBb7JbF7FN8bsGAFtx

Your support helps maintain and improve this package for the community!

Commit count: 0

cargo fmt