Direct Pump AMM (pAMMBay) + legacy PumpSwap swaps in Python. Build raw Solana instructions, no Jupiter.
Project description
pumpswap-python
Direct Pump AMM (pAMMBay…) + legacy PumpSwap swaps. From Python. No Jupiter.
When a pump.fun token graduates off its bonding curve, it moves to an AMM pool —
today that's Pump AMM, the pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA
program. Jupiter can route through it, but you pay an extra hop of latency and
you're at the mercy of its routing. This library builds the raw on-chain swap
instructions directly, so you control exactly what lands on chain.
There's plenty of bonding-curve tooling out there. A complete, current Pump AMM swap builder in Python — handling the 23/21-account layouts, reversed base/quote pools, coin-creator vaults, volume accumulators, Token-2022, and WSOL wrap/unwrap — was missing. This is that.
Building against the bonding curve (pre-graduation)? See the companion package pumpfun-python.
Install
pip install pumpswap-python
Only two runtime deps: solders and
httpx. No SDK bloat.
Quick start
build_buy / build_sell read the pool, do the math, and hand you an ordered
list of unsigned instructions plus a quote. You sign and send — the library
never touches your keys.
import asyncio
import httpx
from solders.keypair import Keypair
from solders.transaction import VersionedTransaction
from pumpswap import build_buy, build_message, fetch_latest_blockhash
RPC = "https://api.mainnet-beta.solana.com" # use your own (Helius/QuickNode) for real volume
wallet = Keypair() # load your real keypair
MINT = "TokenMintAddress..."
POOL = "PumpAmmPoolAddress..."
async def main():
async with httpx.AsyncClient() as client:
plan = await build_buy(
RPC, wallet.pubkey(), MINT, POOL,
sol_lamports=100_000_000, # 0.1 SOL
slippage_bps=500, # 5%
http_client=client,
)
blockhash = await fetch_latest_blockhash(RPC, http_client=client)
print(f"venue={plan.venue} expected_tokens={plan.expected_tokens:,} max_sol={plan.max_sol_in}")
msg = build_message(wallet.pubkey(), plan.instructions, blockhash)
tx = VersionedTransaction(msg, [wallet]) # ← you sign
# ... send `tx` with your RPC's sendTransaction
asyncio.run(main())
Selling is symmetric:
plan = await build_sell(RPC, wallet.pubkey(), MINT, POOL, token_amount=1_000_000, http_client=client)
print(plan.expected_sol_out, plan.min_sol_out)
Just want the quote / math? No RPC needed.
from pumpswap import calculate_swap_output
amount_out, fee = calculate_swap_output(
amount_in=100_000_000,
reserve_in=5_000_000_000,
reserve_out=1_000_000_000_000,
lp_fee_bps=20,
protocol_fee_bps=5,
)
API
High-level (read pool → unsigned instructions)
| Function | Returns |
|---|---|
build_buy(rpc_url, user, token_mint, pool, sol_lamports, *, slippage_bps=500) |
BuyPlan |
build_sell(rpc_url, user, token_mint, pool, token_amount, *, slippage_bps=500) |
SellPlan |
BuyPlan / SellPlan carry .instructions, .fee, .venue, and the quote
fields (expected_tokens / expected_sol_out, etc.).
State readers
fetch_pool_state · fetch_amm_config · fetch_vault_balances · read_pool_reserves
Pump AMM primitives (pure — no RPC)
calculate_swap_output · build_amm_buy_instruction (23 accounts) ·
build_amm_sell_instruction (21 accounts)
Legacy PumpSwap
build_legacy_swap_instruction (13 accounts)
SPL + tx helpers
build_create_ata_idempotent · build_sol_transfer · build_sync_native ·
build_close_account · build_message · prepend_compute_budget ·
fetch_latest_blockhash
PDAs & constants
get_associated_token_address · get_coin_creator_vault_authority ·
get_user_volume_accumulator; all program IDs and discriminators are exported.
Layout notes (the parts that bite)
- Program
buyvssell≠ user buy/sell. The instructions are relative to the pool's base/quote.build_buy/build_selltranslate intent for you. - Reversed pools. Some Pump AMM pools are
base_mint = SOL,quote_mint = TOKEN.PoolState.base_is_solflags it; a user "buy" then maps to a programsell, and vice-versa. buyhas 23 accounts,sellhas 21. Buy carries the global + user volume accumulators; sell does not.- Coin-creator vault. Derived from
coin_creator, which can legitimately be the zero pubkey — don't substitute the poolcreator, or the on-chain constraint fails. - Token-2022. New mints are usually Token-2022; the token program is auto-detected per mint.
Also by the author
- pumpfun-python — PumpFun bonding-curve buy/sell.
- jupiter-swap-python — Jupiter swap client.
- solana-rpc-resilient — fault-tolerant RPC client.
- dexscreener-python — DexScreener API client.
License
Free for noncommercial use under the PolyForm Noncommercial License 1.0.0 — personal projects, research, education, non-profits.
Commercial use requires a license (trading for profit, products/services, multi-user apps, use inside a company). See COMMERCIAL.md.
Disclaimer
Trading on-chain carries financial risk and these instructions move real funds. This software is provided "as is", without warranty of any kind. You are responsible for what you sign and send. Always test with small amounts first.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pumpswap_python-0.1.0.tar.gz.
File metadata
- Download URL: pumpswap_python-0.1.0.tar.gz
- Upload date:
- Size: 21.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
507d21409a5ca9a4ffc81a643f4de822a0ab55a93eff476861c99a790f1e6525
|
|
| MD5 |
e68a31b155bf1aff4791743754a19356
|
|
| BLAKE2b-256 |
3b3dd5baf6bafa7216cf74972b883fbea193e1eab05265f143b97ad8639e9f0c
|
File details
Details for the file pumpswap_python-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pumpswap_python-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e20eb03235ae0b74ae448a135cf15e0b90b98c939c192139f111af1e3e2a5fa1
|
|
| MD5 |
59be4f9e92213c6f071ba6ed7e1f508d
|
|
| BLAKE2b-256 |
09de896867b4635ea221fe2f23a349c7e5b64ec877e5d013707ff16ebdf2ac16
|