Skip to main content

pump_swap_sdk/
lib.rs

1//! Rust SDK for the PumpSwap (pump-amm) AMM on Solana.
2//!
3//! Build buy / sell / create-pool / withdraw / creator-fee-distribution
4//! instructions, derive pool and fee PDAs, simulate or submit swaps via an
5//! [`RpcClient`](solana_client::nonblocking::rpc_client::RpcClient), and
6//! bundle through Jito.
7//!
8//! The instruction layouts target the current pump-amm IDL: Buy uses 23
9//! accounts (with `coin_creator_vault_*`, volume accumulators, fee config,
10//! fee program), Sell uses 21. All non-input accounts are derived internally
11//! from `PoolInfo` + `user`.
12//!
13//! # Quickstart
14//! ```no_run
15//! use std::sync::Arc;
16//! use solana_client::nonblocking::rpc_client::RpcClient;
17//! use solana_sdk::commitment_config::CommitmentConfig;
18//! use solana_sdk::pubkey::Pubkey;
19//! use std::str::FromStr;
20//! use pump_swap_sdk::{load_pool, PumpSwapClient};
21//!
22//! # async fn run(rpc_url: &str, pool: &str) -> anyhow::Result<()> {
23//! let rpc = Arc::new(RpcClient::new_with_commitment(
24//!     rpc_url.to_string(),
25//!     CommitmentConfig::confirmed(),
26//! ));
27//! let pool_info = load_pool(&Pubkey::from_str(pool)?, &rpc).await?;
28//! let client = PumpSwapClient::new(rpc);
29//! let (base, quote) = client.fetch_pool_reserves(&pool_info).await?;
30//! println!("reserves: base={}, quote={}", base, quote);
31//! # Ok(()) }
32//! ```
33
34pub mod client;
35pub mod constants;
36pub mod instruction;
37pub mod math;
38pub mod state;
39pub mod util;
40
41pub use client::{PumpSwapClient, get_token_balance};
42pub use constants::{
43    BUYBACK_FEE_RECIPIENTS, EVENT_AUTHORITY, FEE_PROGRAM, GLOBAL_CONFIG, GLOBAL_VOLUME_ACCUMULATOR,
44    PROTOCOL_FEE_RECIPIENTS, PUMP_CREATOR_VAULT, PUMP_SWAP_PROGRAM_ID, PUMPFUN_EVENT_AUTHORITY,
45    PUMPFUN_PROGRAM, WRAPPED_SOL_MINT,
46};
47pub use instruction::{
48    BuyExactQuoteInInstruction, BuyInstruction, ClaimCashbackInstruction, CreatePoolInstruction,
49    DepositInstruction, SellInstruction, WithdrawInstruction, create_pool_instruction,
50    distribute_creator_fees_instruction, make_buy_exact_quote_in_instruction, make_buy_instruction,
51    make_claim_cashback_instruction, make_deposit_instruction, make_sell_instruction,
52    transfer_creator_fees_to_pump_instruction, withdraw_instruction,
53};
54pub use math::{buy_amount_out, calc_amount_out, sell_amount_out};
55pub use state::{Pool, PoolInfo};
56pub use util::{
57    JitoPool, calc_lp_mint_pda, calc_pool_pda, calc_user_pool_token_account, clone_keypairs,
58    create_ata_token_or_not, create_ata_token_or_not_with_program, fee_config_pda,
59    find_coin_creator_vault_ata, find_coin_creator_vault_authority, find_user_vol_accumulator,
60    gen_pubkey_with_seed, load_pool, load_pool_with_token_program, pick_buyback_fee_recipient,
61    pick_protocol_fee_recipient, pool_v2_pda, send_bundle_with_retry, send_jito_bundle,
62    user_volume_accumulator_quote_ata,
63};