Pump Swap SDK

Docs: https://sdk.pumpk.it/ · Getting started · Examples
TypeScript SDK for the Pump Swap AMM program (pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA).
PumpAmmSdk (singleton PUMP_AMM_SDK) builds instructions and decodes accounts fully
offline from a "Solana state" object.
OnlinePumpAmmSdk fetches those state objects over RPC (swapSolanaState,
liquiditySolanaState, createPoolSolanaState, collectCoinCreatorFeeSolanaState) and
reads balances.
PumpAmmAdminSdk builds the admin-gated instructions.
- Pure pricing functions (
buyBaseInput, buyQuoteInput, sellBaseInput, sellQuoteInput)
and fee helpers (computeFeesBps, feesForQuoteMint, poolMarketCap, ...) are exported
from the package root for callers that keep their own state.
This repository mirrors the published
@pump-fun/pump-swap-sdk package:
src/ and dist/ are the 2.1.0 release byte for byte, matching the October 2026 PumpSwap
program (v2 trades, multi-hop routes, fee sweeps, signed virtual_quote_reserves). The
repository adds a TypeScript and Jest setup to run the upstream specs, plus its own specs for
the v2 builders and negative virtual reserves. See Development.
Installation
npm install @pump-fun/pump-swap-sdk
Usage
import { Connection } from "@solana/web3.js";
import { OnlinePumpAmmSdk, PUMP_AMM_SDK } from "@pump-fun/pump-swap-sdk";
const connection = new Connection(rpcUrl);
const onlineSdk = new OnlinePumpAmmSdk(connection);
All amounts are BNs in the raw base units of the mint they refer to (lamports for wSOL,
micro-units for USDC, ...). slippage is a percentage: 1 means 1%.
Create pool
const createPoolSolanaState = await onlineSdk.createPoolSolanaState(
index,
creator,
baseMint,
quoteMint,
);
const createPoolInstructions = await PUMP_AMM_SDK.createPoolInstructions(
createPoolSolanaState,
baseIn,
quoteIn,
);
// Initial pool price for the UI
const initialPoolPrice = await PUMP_AMM_SDK.createAutocompleteInitialPoolPrice(
initialBase,
initialQuote,
);
Deposit
const liquiditySolanaState = await onlineSdk.liquiditySolanaState(
poolKey,
user,
);
// When the base input changes
const { quote, lpToken } =
PUMP_AMM_SDK.depositAutocompleteQuoteAndLpTokenFromBase(
liquiditySolanaState,
base,
slippage,
);
// When the quote input changes
const { base, lpToken } =
PUMP_AMM_SDK.depositAutocompleteBaseAndLpTokenFromQuote(
liquiditySolanaState,
quote,
slippage,
);
const depositInstructions = await PUMP_AMM_SDK.depositInstructions(
liquiditySolanaState,
lpToken,
slippage,
);
Swap
swapSolanaState fetches the pool, its reserves, the global and fee configs, the two token
programs (read from the mint owners, so Token-2022 quotes work) and the user's token accounts.
The four PUMP_AMM_SDK swap builders price the trade with the pool's quote mint and mayhem
flag, apply slippage, wrap and unwrap wSOL when the quote is legacy WSOL, and create the user's
missing base ATA (buy) or quote ATA (sell); a buy on a non-wSOL quote expects the user's quote
token account to exist.
const swapSolanaState = await onlineSdk.swapSolanaState(poolKey, user);
// Buy `base` tokens, paying at most quote + slippage
const buyInstructions = await PUMP_AMM_SDK.buyBaseInput(
swapSolanaState,
base,
slippage,
);
// Spend `quote` tokens, receiving base - slippage
const buyInstructions2 = await PUMP_AMM_SDK.buyQuoteInput(
swapSolanaState,
quote,
slippage,
);
// Sell `base` tokens, receiving at least quote - slippage
const sellInstructions = await PUMP_AMM_SDK.sellBaseInput(
swapSolanaState,
base,
slippage,
);
// Receive `quote` tokens, selling at most base + slippage
const sellInstructions2 = await PUMP_AMM_SDK.sellQuoteInput(
swapSolanaState,
quote,
slippage,
);
To show a quote before building, or to build with explicit limits, use the pure functions and
buyInstructions / sellInstructions: