pump-rust-client
Rust SDK for the pump and pump_amm Solana programs. Three things in one
crate:
- Instruction builders for buy / sell / create on both the bonding
curve (
pump) and the AMM (pump_amm), with auto-routing across the
two.
- Quoting for both venues, with slippage applied — drives UI prices
and the
*_threshold arguments that the trade builders need.
- Transaction building (
AsyncPumpClient,
behind the client feature): fetches on-chain state, prepends
compute-budget, signs, simulates, and sends.
Canonical sources:
Quickstart — buy
Adapted from examples/buy_v2.rs:
use solana_sdk::compute_budget::ComputeBudgetInstruction;
use solana_sdk::native_token::LAMPORTS_PER_SOL;
use solana_sdk::signature::{Keypair, Signer};
use pump_rust_client::{constants, AsyncPumpClient, PumpSdk};
let sdk = PumpSdk::new();
let client = AsyncPumpClient::new(rpc.clone()); // requires the `client` feature
let global = client.fetch_global().await?;
let bonding_curve = client.fetch_bonding_curve(&mint).await?;
// `buy_v2_instructions` returns idempotent ATA creates + the trade ix.
let mut ixs = vec![ComputeBudgetInstruction::set_compute_unit_limit(400_000)];
ixs.extend(
sdk.buy_v2_instructions(
&global,
&bonding_curve,
mint,
constants::SPL_TOKEN_PROGRAM_ID, // quote token program
user.pubkey(),
300_000_000, // base tokens to buy
LAMPORTS_PER_SOL, // max quote spent
)
.expect("buy_v2_instructions"),
);
The other examples follow the same shape:
examples/sell_v2.rs,
examples/create_v2_and_buy.rs,
examples/buy_amm.rs, and
examples/sell_amm.rs.
Quoting
Every trade builder takes a *_threshold (max quote spent on a buy, min
quote out on a sell). The quote helpers compute that threshold from a
slippage in basis points:
use pump_rust_client::PumpSdk;
let sdk = PumpSdk::new();
let global = client.fetch_global().await?;
let fee_config = client.fetch_fee_config().await?;
let bonding_curve = client.fetch_bonding_curve(&mint).await?;
let quote = sdk.buy_quote_bonding_curve_sol_in(
&global,
&fee_config,
&bonding_curve,
mint_supply, // base mint supply
LAMPORTS_PER_SOL, // sol_amount in
100, // 1% slippage
)?;
// quote.amount — tokens out at the current curve
// quote.min_out — slippage-protected floor; pass to sell builders
// quote.max_input — slippage-protected ceiling; pass to buy builders
For code that doesn't know yet whether the curve has graduated, use the
auto-routed quote_trade — it dispatches to bonding-curve or AMM math
based on bonding_curve.complete, mirroring trade_tx_instructions:
use pump_rust_client::{PumpSdk, TradeQuoteParams};
let quote = sdk.quote_trade(TradeQuoteParams {
is_buy: true,
base_amount: 300_000_000,
slippage_bps: 100,
base_mint_supply: mint_supply,
pump_global: &global,
pump_fee_config: &fee_config,
bonding_curve: &bonding_curve,
pump_pool: None, // Some(PumpPoolQuoteCtx { … }) required when curve.complete
}); // returns None if the curve is complete and pump_pool was not supplied
| Quote builder |
Source |
Notes |
buy_quote_bonding_curve_sol_in |
src/sdk/mod.rs |
SOL in → tokens out |
buy_quote_bonding_curve_token_out |
src/sdk/mod.rs |
Tokens out → SOL needed |
sell_quote_bonding_curve |
src/sdk/mod.rs |
Tokens in → SOL out |
buy_quote_amm_sol_in / buy_quote_amm_token_out |
src/sdk/mod.rs |
AMM equivalents |
sell_quote_amm |
src/sdk/mod.rs |
AMM sell |
buy_quote_bonding_curve_v3_sol_in / buy_quote_bonding_curve_v3_token_out |
src/sdk/mod.rs |
v3 buys, post-completion leg included (take the curve's base ATA balance) |
quote_multi_hop_swap |
src/sdk/mod.rs |
multi_hop_swap route output from per-hop RouteHop state |
quote_trade |
src/sdk/trade_tx.rs |
Auto-routed via bonding_curve.complete |
Quotes follow the on-chain fee resolution and take the pump-fees FeeConfig
(fetch_fee_config for curves, fetch_amm_fee_config for pools; the two are
different PDAs): the schedule is picked by quote mint, and a coin's own
creator_fee_bps (set at create_v2) replaces the schedule's creator rate
while Global.creator_fee_configurable is on. Global's own bps fields play
no part in pricing. A v2 buy that would take more than a curve's remaining
tokens fills only the remainder and completes the curve (partial_fill), and
the v2 *_bonding_curve_* quotes clamp to match. A v3 buy on a non-mayhem
curve instead completes it and buys the rest from the pool the migration will
create, in the same trade; quote v3 buys with the *_v3_* quoters (v2 quotes
under-price them past the remaining supply). Pool quotes price against the vault plus
Pool.virtual_quote_reserves and pay sells out of the vault less the un-swept
fee buckets, as pump-amm does after v2 trades. A pump-amm disable flag
surfaces as TradingDisabled. To quote the first buy of a coin that does not exist yet, build the
curve with PumpSdk::initial_bonding_curve using the reserves from
PumpSdk::initial_virtual_quote_reserves (Global whitelist, then the
quote-control PDA via fetch_quote_control), or
PumpSdk::pump_quote_initial_virtual_quote_reserves for a coin quoted in
another pump coin.
Instruction reference
All builders live on PumpSdk. Prefer the *_instructions (plural)
variants — they prepend the idempotent ATA creates the user needs. The
singular *_instruction returns only the trade ix, for callers that manage
ATAs themselves.
Bonding curve (pump_v2) — src/sdk/pump_v2.rs:
Bonding curve v3 (pump_v3) — src/sdk/pump_v3.rs.
One 17-account set, no fee recipients: the protocol fee (less its buyback
slice) and the creator fee accrue in the curve's protocol_fees /
creator_fee buckets until a permissionless sweep pays them out;
the buyback slice is paid in the trade to buyback_fee_recipient. Pricing
equals v2 up to the remaining supply; past it a buy takes the post-completion
leg, so use the v3 quoters. Cashback coins stay on v2.
| Builder |
Example |
buy_v3_instruction / buy_v3_instructions |
examples/buy_v3.rs |
buy_exact_quote_in_v3_instruction[s] |
— |
sell_v3_instruction / sell_v3_instructions |
— |
sweep_creator_fee_instruction |
examples/sweep_creator_fee.rs |
AsyncPumpClient::build_buy_v3 / build_buy_exact_quote_in_v3 / build_sell_v3 |
One call: fetch, quote with slippage, instructions |
The v3 builders work from keys alone: (base_mint, quote_mint, base_token_program, quote_token_program, user, buyback_fee_recipient, amount, limit). Pass Pubkey::default() or wSOL as the quote of a SOL curve,
Token-2022 as the base program of a create_v2 coin and SPL Token for a
legacy create coin (the mint account's owner). buyback_fee_recipient is a
listed Global.buyback_fee_recipients wallet
(PumpSdk::buyback_fee_recipient_from_pump_global draws one); the builder
passes the wallet itself on a SOL curve and its quote ATA on a token quote.
The program never creates that ATA: the plural *_v3_instructions prepend an
idempotent create (the user pays), the singular builders need it to exist. fetch_curve_quote_state returns all of that plus
the state the quoters need; the build_*_v3 helpers use it.
Prepend sweep_creator_fee_instruction in the same transaction as any
distribute_creator_fees*, update_fee_shares* or admin_cto on a coin
that has seen a v3 trade; those fail with CreatorFeesNotSwept otherwise.
distribute_creator_fees_v2_instructions does this for you.
AMM (pump_amm, post-graduation) — src/sdk/pump_amm_ix.rs:
| Builder |
Example |
buy_amm_instruction / buy_amm_instructions |
examples/buy_amm.rs |
sell_amm_instruction / sell_amm_instructions |
examples/sell_amm.rs |
buy_amm_v2_instruction[s] / buy_exact_quote_in_amm_v2_instruction / sell_amm_v2_instruction[s] |
17-account pool trades from a fetched Pool (the address is derived from its seeds) and a listed GlobalConfig.buyback_fee_recipients wallet, whose quote ATA (which must exist) takes the buyback slice in the trade; the rest of the protocol fee and the creator fee accrue in Pool.protocol_fees / creator_fees. Any pool but a cashback coin's (a mayhem pool takes no buyback slice, a non-pump pool pays the flat fees) |