Files
pumpfun-bonkfun-bot_github/cookbook
ae937fd477 fix(cookbook,tools): fail on an unreadable value instead of substituting a default (#225)
* fix(cookbook,tools): read GEYSER_AUTH_TYPE and reject an unknown scheme

Four Geyser clients advertised the variable and ignored it, sending Basic for
anything that was not exactly "x-token". Validate against {x-token, basic}.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(cookbook): detect blockSubscribe creations from logs alone

The envelope fallback cannot see a create reached by CPI, so it covered a
subset of the log route. Envelope decoding stays in the decode/ script.
Also skip meta.err: logs emitted before a failure are kept, and that mint
does not exist.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(cookbook): raise when the graduation baseline cannot be read

The watchers fell back to a hardcoded 793,100,000 and still printed it as
"(from Global)". Every progress figure is measured against that baseline.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(cookbook): report an unsent create flag as unknown, not false

Truncated create_v2 args and legacy create were filled in as False, reading
as a coin the program said is not in mayhem mode. Leave them out, print N/A.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(tools): build Geyser credentials before the reconnect loop

The loop catches every exception and sleeps, so an unusable auth type
reconnected forever instead of reporting a misconfiguration.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(cookbook): treat a short Global buffer as an unreadable baseline

The guard only caught a missing account, so a short read raised struct.error
past the documented ValueError.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(tools): surface a listener's exception instead of an idle market

A listener that raised on connect returned nothing, exactly like a quiet
market, in the harness whose job is to certify listeners. Take the listener
list from the factory too, so one added there is not silently skipped.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(tools): simulate the transaction the bot built

The hook rebuilt the transaction itself and dropped the account data size
limit, so the simulation was more permissive than the send. Hook the RPC
client instead, build the client before detection so its blockhash cache is
warm, and report the compute budget read back off the wire.

A listener that raised on connect also read as a quiet market here.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(tools): skip failed migrations on err, not on the word "Error"

The notification carries err beside the logs. Scanning the text dropped a
migration whose logs merely said "Error" and kept ones that truly failed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(cookbook): refuse a letsbonk buy that accepts any output

The only one of the four without the guard. Near graduation the floor
division reaches zero, and the buy submits with no slippage protection.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(cookbook): require the pool's own platform_config

The fallback was a partner-specific address that reverts with
ConstraintAddress (2012). A pool that omits it cannot be traded.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(cookbook): raise when curve data ends before a flag

is_mayhem_mode picks the fee recipient for a buy, and the wrong one reverts
with NotAuthorized (6000), so defaulting it only moves the failure.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* fix(cookbook): trade the coin's own PumpSwap pool, not an arbitrary one

Anyone can open a pool against any mint and getProgramAccounts has no defined
order, so [0] was a stranger's pool. Select on coin_creator, which migration
copies from the bonding curve and nothing else sets, and refuse rather than
guess when there is no single match. --pool trades a specific one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-24 17:49:12 +02:00
..

Cookbook

One script per thing you might want to do on pump.fun, PumpSwap and letsbonk.fun. Each is standalone: run it with uv run <path>, no bot config, no framework. They read .env directly, and most take the mint or curve address as the first argument.

Scripts marked 💸 submit real transactions and spend real funds. Read the module docstring before running one. Everything else only reads.

Reading the names

A filename is <protocol>_<verb>_<noun>[_<variant>].py:

pumpfun_buy_token_v2.py                 buy one coin, using the v2 instructions
pumpfun_snipe_token_geyser.py           wait for a new coin over Geyser, then buy
pumpfun_listen_tokens_logsubscribe.py   watch for new coins over logsSubscribe
letsbonk_sell_token_exact_out.py        sell for a fixed amount received

The variant is either an instruction version (v1, v2, exact_in, exact_out) or the transport (geyser, logsubscribe, blocksubscribe, programsubscribe, pumpportal, gettransaction, getaccountinfo).

Running them

Every script takes its input on the command line:

uv run cookbook/pumpfun/read/pumpfun_read_price.py <CURVE>
uv run cookbook/pumpfun/trade/pumpfun_buy_token_v2.py <MINT> 0.001 --slippage 0.3
uv run cookbook/pumpswap/pumpswap_buy_token.py <MINT>          # amount defaults

--help lists the defaults on any of them. The decode scripts need no arguments at all — they fall back to the fixture beside them.

Two modules are imported by other scripts rather than run: solana/solana_transaction_status.py (did the transaction actually succeed) and pumpfun/trade/pumpfun_instructions_v2.py (the buy_v2 / sell_v2 account layouts).

Solana and Anchor basics

Not specific to any of the launchpads below.

Script What it does
solana/solana_read_balances.py Your SOL and every token you hold, across both token programs
solana/solana_check_transaction.py Whether a signature succeeded, reverted, or is not visible yet
solana/solana_read_token2022_mint.py A Token-2022 mint's extensions, and which scaled-UI multiplier is really in force
solana/anchor_calculate_discriminator.py The 8-byte Anchor discriminator for any instruction or account name

pump.fun

Watch for things happening

Script What it does
pumpfun/listen/pumpfun_listen_tokens_logsubscribe.py New coins over logsSubscribe — works on every provider
pumpfun/listen/pumpfun_listen_tokens_blocksubscribe.py New coins over blockSubscribe — whole blocks, slower, not on every provider
pumpfun/listen/pumpfun_listen_tokens_geyser.py New coins over Geyser gRPC — the fastest of the executed-stream listeners
pumpfun/listen/pumpfun_listen_tokens_deshred.py New coins over Geyser SubscribeDeshred — earlier, but pre-execution: no logs, no CreateEvent, no outcome, and router-created coins are invisible
pumpfun/listen/pumpfun_listen_tokens_pumpportal.py New coins from PumpPortal's feed — third party, misses some coins
pumpfun/listen/pumpfun_listen_wallet_trades.py One wallet's bonding-curve buys and sells — copy trading
pumpfun/listen/pumpfun_capture_transactions_blocksubscribe.py Save live transactions to disk, to build a fixture

tools/compare_listeners.py races the listeners against each other; tools/compare_deshred_latency.py races the deshred stream against the executed one and sizes its blind spot.

Read state

Script What it does
pumpfun/read/pumpfun_read_price.py One coin's price, in whatever asset its curve is paired with
pumpfun/read/pumpfun_read_curve.py A curve's full state, decoded field by field
pumpfun/read/pumpfun_watch_curve_progress.py How close a coin is to graduating, polled over time
pumpfun/read/pumpfun_derive_curve_addresses.py Derive a coin's curve and curve ATA offline, under both token programs
pumpfun/read/pumpfun_read_quote_mints.py Every asset a coin may be priced in, --stocks for the tokenized equities

Trade

Script What it does
💸 pumpfun/trade/pumpfun_buy_token_v2.py Buy a coin you name. --dry-run simulates instead of spending
💸 pumpfun/trade/pumpfun_buy_token_exact_quote_v2.py Spend an exact amount of the quote asset. --dry-run simulates
💸 pumpfun/trade/pumpfun_buy_token_exact_sol_in.py Spend an exact amount of SOL. SOL-paired coins only
💸 pumpfun/trade/pumpfun_sell_token_v2.py Sell your whole position in a coin you name
💸 pumpfun/trade/pumpfun_create_token_v2.py Create a coin with create_v2, buying none of it
💸 pumpfun/trade/pumpfun_create_and_buy_token_v2.py Create a coin and buy it
💸 pumpfun/trade/pumpfun_snipe_token_blocksubscribe.py Wait for the next coin created anywhere, then buy it
💸 pumpfun/trade/pumpfun_snipe_token_geyser.py The same snipe, detected over Geyser gRPC
💸 pumpfun/trade/pumpfun_collect_creator_fee_v2.py Sweep the creator fees your coins have accrued
💸 pumpfun/trade/pumpfun_claim_cashback_v2.py Pay out cashback accrued on an existing cashback coin

Start at pumpfun_buy_token_v2.py; the two snipers are that same trade behind a listener.

The buys differ in which side you pin down: buy_v2 fixes the tokens you receive and caps the spend, buy_exact_quote_in_v2 fixes the spend and floors the tokens. Pin the spend when the quote asset is a budget you hold, which is usually the case once a coin is priced in something other than SOL.

Graduation

A coin that fills its bonding curve graduates to the PumpSwap AMM and stops trading on the curve.

Script What it does
pumpfun/graduation/pumpfun_watch_graduating_programsubscribe.py Coins approaching graduation, over a filtered programSubscribe
pumpfun/graduation/pumpfun_watch_graduating_geyser.py The same watch over Geyser gRPC
pumpfun/graduation/pumpfun_listen_migrations_logsubscribe.py Migrations as the wrapper program emits them
pumpfun/graduation/pumpfun_listen_migrations_programsubscribe.py Migrations as new pool accounts appear — noisy

Decode

Each script decodes one kind of payload and falls back to the fixture beside it, so they all run with no arguments and no network.

Script What it does
pumpfun/decode/pumpfun_decode_transaction_gettransaction.py pump.fun instructions inside a getTransaction response
pumpfun/decode/pumpfun_decode_transaction_blocksubscribe.py The same, from a blockSubscribe frame
pumpfun/decode/pumpfun_decode_curve_getaccountinfo.py A bonding curve account's raw bytes

PumpSwap

Where a coin trades after it graduates.

Script What it does
pumpswap/pumpswap_find_pool.py Find a coin's pool and decode it
💸 pumpswap/pumpswap_buy_token.py Buy against the AMM
💸 pumpswap/pumpswap_sell_token.py Sell against the AMM

letsbonk.fun

Built on Raydium LaunchLab, which quotes in two directions: exact in fixes what you spend, exact out fixes what you receive.

Script What it does
💸 letsbonk/letsbonk_buy_token_exact_in.py Spend a fixed amount
💸 letsbonk/letsbonk_buy_token_exact_out.py Receive a fixed number of tokens
💸 letsbonk/letsbonk_sell_token_exact_in.py Sell a fixed number of tokens
💸 letsbonk/letsbonk_sell_token_exact_out.py Sell for a fixed amount received
letsbonk/letsbonk_idl_parser.py Loads the LaunchLab IDL for the four above

legacy

Instructions pump.fun has moved on from. They still land on chain and older coins were made with them, but don't copy these for new work.

Script What it does
💸 legacy/pumpfun_create_and_buy_token_v1.py Create a coin with the pre-Token-2022 create instruction

Not in here

  • tools/ — scripts that exercise the bot rather than teach it: mainnet simulations, live round trips, listener benchmarks, leftover-account cleanup.
  • tests/regression/ — one offline check per fixed bug, each importing the bot's own code. uv run tests/regression/run_all.py.