Skip to main content

pumpswap-python

Direct Pump AMM (pAMMBay…) + legacy PumpSwap swaps. From Python. No Jupiter.

Python 3.10+ License: PolyForm NC Typed

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 buy vs sell ≠ user buy/sell. The instructions are relative to the pool's base/quote. build_buy/build_sell translate intent for you.
  • Reversed pools. Some Pump AMM pools are base_mint = SOL, quote_mint = TOKEN. PoolState.base_is_sol flags it; a user "buy" then maps to a program sell, and vice-versa.
  • buy has 23 accounts, sell has 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 pool creator, 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


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.

Metadata

Release files for pumpswap-python 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pumpswap-python 0.1.0
File Size Uploaded
pumpswap_python-0.1.0.tar.gz 21.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pumpswap-python 0.1.0
File Interpreter ABI Platform
pumpswap_python-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.8 kB

Release files / pumpswap_python-0.1.0.tar.gz

Download URL pumpswap_python-0.1.0.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
507d21409a5ca9a4ffc81a643f4de822a0ab55a93eff476861c99a790f1e6525
BLAKE2b-256 checksum
How to use checksums
3b3dd5baf6bafa7216cf74972b883fbea193e1eab05265f143b97ad8639e9f0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / pumpswap_python-0.1.0-py3-none-any.whl

Download URL pumpswap_python-0.1.0-py3-none-any.whl
Size 22.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e20eb03235ae0b74ae448a135cf15e0b90b98c939c192139f111af1e3e2a5fa1
BLAKE2b-256 checksum
How to use checksums
09de896867b4635ea221fe2f23a349c7e5b64ec877e5d013707ff16ebdf2ac16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page