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
*_thresholdarguments that the trade builders need. - Transaction building (
AsyncPumpClient, behind theclientfeature): fetches on-chain state, prepends compute-budget, signs, simulates, and sends.
Canonical sources:
- Bonding-curve builders:
src/sdk/pump_v2.rs - AMM builders:
src/sdk/pump_amm_ix.rs - Auto-routed trade + quote:
src/sdk/trade_tx.rs - Quote helpers:
src/sdk/mod.rs - RPC wrapper:
src/async_client.rs - Runnable end-to-end code:
examples/
Quickstart — buy
Adapted from examples/buy_v2.rs:
use ComputeBudgetInstruction;
use LAMPORTS_PER_SOL;
use ;
use ;
let sdk = new;
let client = new; // requires the `client` feature
let global = client.fetch_global.await?;
let bonding_curve = client.fetch_bonding_curve.await?;
// `buy_v2_instructions` returns idempotent ATA creates + the trade ix.
let mut ixs = vec!;
ixs.extend;
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 PumpSdk;
let sdk = new;
let global = client.fetch_global.await?;
let fee_config = client.fetch_fee_config.await?;
let bonding_curve = client.fetch_bonding_curve.await?;
let quote = sdk.buy_quote_bonding_curve_sol_in?;
// 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 ;
let quote = sdk.quote_trade; // 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 |
quote_trade |
src/sdk/trade_tx.rs |
Auto-routed via bonding_curve.complete |
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:
| Builder | Example |
|---|---|
buy_v2_instruction / buy_v2_instructions |
examples/buy_v2.rs |
sell_v2_instruction / sell_v2_instructions |
examples/sell_v2.rs |
buy_exact_quote_in_v2_instruction[s] |
— |
create_v2_instruction |
examples/create_v2.rs |
create_v2_and_buy_instruction |
examples/create_v2_and_buy.rs |
create_coin_instructions |
— |
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 |
Auto-routed trade — src/sdk/trade_tx.rs:
| Builder | Notes |
|---|---|
trade_tx_instructions |
Routes on bonding_curve.complete; wraps/unwraps wSOL for native-quote AMM trades |
trade_tx_instructions_with_venue |
Same, but the caller pins the TradeVenue |
The auto-routed builders take TradeTxParams / TradeTxWithVenueParams
(both re-exported at the crate root, see src/lib.rs) and
handle ATA creation and wSOL wrap/unwrap themselves — the caller only
assembles compute-budget plus signers.
The bonding-curve *_instructions plural builders take a fetched
Global and BondingCurve so the SDK can
pick the correct fee recipients and quote layout.
create_v2_and_buy_instruction synthesises a bonding-curve preview
internally from the supplied quote_mint (Pubkey::default() → wSOL),
so a fetch is not required before the curve exists.
Building, signing, and sending — AsyncPumpClient
With the client feature, AsyncPumpClient wraps
solana_client::nonblocking::rpc_client::RpcClient and handles the full
buy lifecycle:
use Arc;
use RpcClient;
use ;
use ;
let rpc = new;
let client = new;
let user = new;
// 1. Fetch live state.
let global = client.fetch_global.await?;
let bonding_curve = client.fetch_bonding_curve.await?;
// 2. Build instructions via the inner SDK.
let ixs = client.sdk.buy_v2_instructions.expect;
// 3. Sign — compute-budget instructions are prepended automatically.
let tx = client.build_transaction.await?;
// 4. Simulate, then send.
let _sim = client.simulate_transaction.await?;
let sig = client.send_and_confirm_transaction.await?;
| Helper | Purpose |
|---|---|
fetch_global / fetch_fee_config / fetch_bonding_curve |
Load the on-chain state needed by builders and quoters |
fetch_buy_state / fetch_sell_state |
One round-trip fetch of bonding curve + user ATA |
fetch_global_volume_accumulator / fetch_user_volume_accumulator |
Volume accumulators (cashback) |
get_creator_vault_balance |
Spendable lamports above rent |
latest_blockhash |
Recent blockhash at the client's commitment |
build_transaction / build_transaction_with_blockhash |
Sign with optional ComputeBudget prepended |
simulate_transaction |
Preflight against the RPC |
send_transaction / send_and_confirm_transaction |
Submit to the cluster |
sdk() / rpc() |
Borrow the underlying PumpSdk / RpcClient |
Account initialization
The trade instructions pull in 25+ accounts. You do not need to pre-create
most of them — the SDK derives every PDA and ATA inside
V2TradeAccounts::derive (see src/sdk/pump_v2.rs). The only ATAs the
caller is responsible for are the user's own base/quote ATAs, and those are
auto-prepended by the *_instructions variants.
The exact rules for which user ATAs are created when are encoded in
fn user_trade_atas in src/sdk/pump_v2.rs.
Summary:
- Base ATA: created on buy, skipped on sell (the user already holds the base balance to spend).
- Quote ATA: created only when the curve's
quote_mintis non-default (i.e. non-wSOL curves). Legacy SOL-only curves skip the quote ATA.
trade_tx_instructions additionally handles wSOL wrap/unwrap for
native-quote AMM trades, so callers using the auto-routed path do not need
a separate setup transaction.
If you need different behavior (e.g. you manage user ATAs upstream), call
the singular *_instruction builders directly.
Examples
| Example | Demonstrates |
|---|---|
examples/create_v2.rs |
Creating a coin with create_v2_instruction (mint signer required) |
examples/buy_v2.rs |
Bonding-curve buy with buy_v2_instructions |
examples/sell_v2.rs |
Buy → sell cycle with buy_v2_instructions + sell_v2_instructions |
examples/create_v2_and_buy.rs |
Atomic create + buy via create_v2_and_buy_instruction |
examples/buy_amm.rs |
AMM buy on a graduated coin via buy_amm_instructions |
examples/sell_amm.rs |
AMM buy → sell via buy_amm_instructions + sell_amm_instructions |
Features
client— enablesAsyncPumpClientand thesolana-sdk/solana-clientdependencies. Required to callfetch_global/fetch_bonding_curveand the transaction-building helpers.
Without client, the SDK still exposes every *_instruction /
*_instructions builder and every quoter — only the RPC wrapper is gated.
The base crate (no features) only needs anchor-lang and solana-program,
so it stays buildable inside on-chain programs that depend on the SDK for
PDA / account-meta derivation.
CPI from another program
If you want to CPI into pump's buy_v2 / sell_v2 from your own Anchor
program and reuse this SDK to derive the account metas, see
CPI_README.md.