| Crates.io | jup-perps-client |
| lib.rs | jup-perps-client |
| version | 1.0.0 |
| created_at | 2025-07-19 14:37:53.310643+00 |
| updated_at | 2025-07-19 14:37:53.310643+00 |
| description | Rust client for Jupiter Perpetuals Protocol |
| homepage | |
| repository | https://github.com/monakki/jup-perps-client |
| max_upload_size | |
| id | 1760293 |
| size | 1,446,991 |
A Rust client for Jupiter Perpetuals Protocol, auto-generated from IDL using Codama.
Add to your Cargo.toml:
[dependencies]
jup-perps-client = "1.0"
solana-client = "1.18" # For RPC functionality
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
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
use jup_perps_rust_client::{accounts::*, types::*};
// Use the generated types in your on-chain program
let pool_account = Pool::default();
fetch_perpetuals(rpc, address) - Get main protocol datafetch_pool(rpc, address) - Get liquidity pool datafetch_position(rpc, address) - Get position datafetch_custody(rpc, address) - Get token custody datafetch_token_ledger(rpc, address) - Get token ledger datafetch_position_request(rpc, address) - Get position request datafetch_all_perpetuals(rpc, addresses) - Fetch multiple protocol accountsfetch_all_pool(rpc, addresses) - Fetch multiple poolsfetch_all_position(rpc, addresses) - Fetch multiple positionsfetch_maybe_perpetuals(rpc, address) - Safe protocol data fetchfetch_maybe_pool(rpc, address) - Safe pool data fetchfetch_maybe_position(rpc, address) - Safe position data fetchAll data types are available:
use jup_perps_client::{
Perpetuals,
Pool,
Position,
Custody,
PositionRequest,
TokenLedger,
// ... and many more
};
use jup_perps_client::PERPETUALS_PROGRAM_ADDRESS;
println!("Program Address: {}", PERPETUALS_PROGRAM_ADDRESS);
serde feature)fetch (default) - Enables RPC client functions like fetch_pool(). Includes solana-client and solana-account dependenciesserde - Enables JSON serialization/deserialization supportanchor - Additional Anchor-specific functionalityanchor-idl-build - IDL build supportFor minimal on-chain usage without RPC dependencies:
[dependencies]
jup-perps-client = { version = "1.0", default-features = false }
This client is auto-generated from Jupiter Perpetuals IDL using Codama.
MIT
This client is auto-generated from Jupiter Perpetuals IDL files using Codama. For issues or feature requests, please visit the main repository.
instructions moduleIf 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!