* feat(cookbook): cover every create_v2 coin parameter in the launch scripts Both create scripts now build create_v2 through pumpfun_instructions_v2 instead of each carrying their own copy of the discriminators, PDAs and account list. - A holder-reward coin's curve creator is derived rather than assumed, so the opening buy finds the matching creator vault instead of reverting. - create_v2's three trailing arguments are settable independently. None omits an argument, a value sends it, so all four wire forms are reachable and an explicit default is distinct from an omission. - create_v2 carries all four remaining accounts, quote_control included. Without them the program ignores creator_fee_bps. - --creator, --creator-fee-bps and --quote-mint added. A creator fee on a SOL-paired coin warns, because the program stores zero for it; the create-and-buy script refuses one outright before sending anything. - The opening buy is sized from Global's reserves and fee rates. - Mayhem mode is off by default. Removes the fee-recipient lookup whose result was discarded and the buy wrapper whose parameters were unused. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * test(regression): verify the launch path's create_v2 arguments Eight offline checks: the substituted creator on a holder-reward coin, every committed create_v2 fixture round-tripping through the trailing argument encoder, all four wire forms being reachable, --creator reaching the wire, the opening buy following Global rather than constants, the Global decoder stopping cleanly on a short buffer, and the four quote accounts being present with the ATA under the quote mint's own program. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * docs: correct create_v2's remaining accounts and the creator-fee rule create_v2 takes four remaining accounts, not three; the fourth is the QuoteControl PDA. Omitting them is accepted and yields a SOL-paired coin, which is also how a creator fee goes missing: the program applies creator_fee_bps only to a coin priced in something other than SOL, and otherwise stores zero without an error. Also records that solders documents TransactionConfig.priority_fee as micro-lamports while SIMD-0385 defines the field as total lamports. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * feat(cookbook): price a new coin in an asset other than SOL --quote-mint on both create scripts, checked against both registries that admit a quote asset. QuoteControl carries most of them with a per-mint opening reserve; Global.whitelisted_quote_mints carries USDC, which QuoteControl does not list, so consulting either alone refuses a mint the program accepts. A mint neither admits is refused rather than priced from a default, since the opening reserve spans orders of magnitude. The quote mint's token program and decimals are resolved from chain, and --amount is denominated in the quote asset rather than in SOL. A paused mint is refused before anything is sent, and a scaled-UI mint says so, because amounts here are raw units. A creator fee now works, since pump.fun applies one only to a coin priced in something other than SOL. On a SOL-paired coin it is refused instead of being accepted and stored as zero. The create-and-buy script requires the wallet to already hold the quote asset; it does not acquire one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * feat(cookbook): launch a coin in one v1 transaction Create, extend, the buyer's token account and the buy now travel under a single signature, so nobody can buy between the create and the opening buy. They were split because the two together are 1479 bytes against the 1232 a v0 transaction is held to; SIMD-0296 raised the limit to 4096 for v1 and the combined message uses about a third of it. v1 has no address lookup tables -- the larger limit exists so the whole account list goes inline -- and it carries the compute budget in the message header, so the script sends no ComputeBudget instructions. The priority fee is now one total in lamports rather than micro-lamports per compute unit; the constant is converted, not renamed. The two-transaction path is removed rather than kept behind a flag. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(cookbook): state the loaded-accounts data size limit on the v1 launch A v1 message carries this limit in its header, and left unset it is zero rather than the network default, so the runtime rejects the transaction for exceeding it. The launch skips preflight, so the rejection never reached the caller: send returned a signature that never landed. Measured against a forked mainnet, the launch is rejected at 128 KiB and lands at 256 KiB. The limit is set to 1 MiB, which leaves room for a quote mint whose accounts are larger, and the verifier fails if it is dropped or set at or below the measured failing size. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * feat(cookbook): offer the launch as a v0 or a v1 transaction The Solana transaction version changes what a launch can be, so it is the script that changes rather than a flag on one of them. _txv1 sends create and buy under a single signature, so the coin is bought by the transaction that creates it. _txv0 sends them as two transactions, because together they do not fit what a v0 transaction can carry, and anyone watching the create can buy in the gap. Use it when the endpoint will not take a v1 send. The coin is identical either way: quote asset, creator fee, holder rewards and mayhem mode all behave the same. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * refactor(cookbook): drop the instruction version from script names The cookbook ships one form of each pump.fun action, so `_v2` in a basename distinguished nothing — and it read as a Solana transaction version, which is a different thing and now appears in the same names. `pumpfun_buy_token_exact_sol_in.py` already went without it. Every trade script loses the suffix, the shared module becomes `pumpfun_instructions.py`, and the retired path is named for what it is rather than for the instruction set it uses. The instruction each script builds is named in its docstring, where it cannot be mistaken for a transaction version. `txv0`/`txv1` is now the only version marker in any filename, and it is the one the reader chooses between. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(cookbook): refuse mayhem mode paired with a non-SOL quote asset The program rejects the pairing with MayhemModeQuoteMintNotAllowed (6071), so a mayhem coin is always SOL-paired — and therefore can never carry a creator fee, which needs a non-SOL quote. Both create scripts now refuse the combination before sending, rather than letting it land as a reverted transaction that has already cost fees. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(cookbook): size the v1 loaded-accounts limit for what mainnet loads The limit counts the executable data of every program a transaction touches, not just the accounts it names, and the pump program's own code is the bulk of it. The previous figure was set against a local fork, which does not charge for executables; on mainnet the launch was rejected with MaxLoadedAccountsDataSizeExceeded. Set to the network default a v0 transaction gets when nothing narrows it, which is the behaviour being reproduced. The verifier now holds the mainnet figure as its floor. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(cookbook): a creator fee needs a QuoteControl quote mint, not just a non-SOL one Measured on mainnet: the fee is applied on a coin priced in a mint QuoteControl admits, whether that mint is SPL Token or Token-2022, and is not applied on wrapped SOL or on USDC — which the older Global whitelist carries and QuoteControl does not. The deciding property is registry membership, so the previous check let a USDC-priced coin through and the program stored zero without an error. Also stops the sell script calling a price "SOL" when the curve is priced in something else. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * feat(cookbook): offer the create-only script as a v0 or a v1 transaction Same split as the create-and-buy pair, for the same reason: the Solana transaction version is the reader's choice, so it is the script that changes rather than a flag. _txv1 carries the compute budget in the message header and sends no ComputeBudget instructions; _txv0 sends them. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(cookbook): refuse a paused quote mint on the create-and-buy path too The check only ran in the create-only scripts, so a launch that also buys could reach the chain with a quote mint whose transfers are paused. On the two-transaction path that leaves a created coin nobody bought, after the create has already cost rent. Also corrects the v1 script's run docstring, which still described two transactions and a spend denominated in SOL. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(cookbook): say --amount is in whole quote units, not raw ones The scaled-UI notice told the reader the opposite of what the scripts do: --amount is multiplied by the mint's decimals, so it is a whole-token figure. A reader who followed the notice would have overspent by a factor of the decimals. Reworded so the multiplier is described as what it is — a display scale a wallet applies — rather than as something the amount has to account for. The create-only scripts carried the same wording without even taking an amount. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
11 KiB
Agent guide
Solana trading bot for pump.fun and letsbonk.fun. Snipes newly created tokens and exits on a configured strategy. See README.md for setup and configuration.
AGENTS.md is a symlink to this file, so Claude Code, Codex, Cursor and Windsurf read the same guide.
Reference
Deeper notes, kept out of this file so they load only when needed:
| Doc | Read it before |
|---|---|
| docs/pumpfun-protocol.md | touching account layouts, instruction args, fee recipients or quote assets |
| docs/listeners-and-geyser.md | changing a listener, the geyser stubs or a decoder |
| docs/cookbook-conventions.md | adding or changing anything under cookbook/ |
| docs/regression-tests.md | picking which verifiers your change needs |
Ground rules
- Running a bot with real funds is how a change gets verified, with explicit
approval for that session and after stating what will run and what it costs.
cookbook/and the simulations move no funds but skipbot_runner, config loading, the trader loop, the exit strategy and cleanup, so they cannot close the question. A verification run covers every mode the change reaches — each listener,extreme_fast_modeon and off, eachexit_strategy— and ends with the wallet holding SOL only. - Never touch
.envor print its contents.SOLANA_PRIVATE_KEYis a live key. - Don't commit anything from
logs/; test with a cookbook script beforesrc/.
Layout
src/ bot source — this dir is the import root (see below)
cookbook/ standalone scripts; each runs on its own, no bot config
tests/regression/ one offline verifier per fixed bug; imports src/
tools/ dev harness — simulations, live round trips, benchmarks
bots/ one YAML per bot instance
idl/ vendored Anchor IDLs
logs/ {bot_name}_{timestamp}.log
Imports are rooted at src/, not at the repo. uv pip install -e . puts
src/ on sys.path, so it is from core.client import SolanaClient, not
from src.core.... Cookbook scripts don't import from src at all — don't
rewire one to; that is what tools/ is for.
Dependency layers, low to high — don't introduce an upward import:
interfaces → utils → core → platforms → monitoring → trading → bot_runner
interfaces is the leaf; geyser holds only generated stubs; cleanup sits on
core/utils and is pulled in by trading.
Platform differences resolve through interfaces/core.py abstractions
(AddressProvider, curve manager, event parser, instruction builder) and the
registry in platforms/__init__.py. Listeners and the trader are
platform-agnostic (Universal*); anything platform-shaped belongs under
platforms/<name>/.
Commands
uv sync # install runtime deps + the dev group (ruff)
uv pip install -e . # editable install (required for the imports above)
pump_bot # run all enabled bots
uv run src/bot_runner.py # same, without the console script
uv run tests/regression/run_all.py # every offline verifier; moves no funds
Lint and format the files you touched, not the whole tree:
uv run ruff check --fix <paths> && uv run ruff format <paths>
A bare uv run ruff check reports a large backlog of pre-existing errors — the
known baseline, not a failing build and not something your change caused. Ruff
config is in pyproject.toml: line length 88, double quotes, target py311,
E501 ignored. Type-hint public functions and use get_logger(__name__).
Docstrings and comments carry what the code cannot. A one-line summary, then
only what a reader could not get from the signature: units, ranges, what None
means, which errors a caller must handle, a constraint that stops the next
person breaking it. An Args: entry that restates the parameter name, or a
comment that restates the line under it, is noise and gets deleted. Leave out
rationale nobody acts on, hypotheticals about what might change, measurements,
dates and issue numbers.
Where the Solana libraries live
solana-py 0.40 moved most of them, and nothing in this class of break shows up offline — an import sweep passes and the call fails against mainnet.
TxOptsisTxOptsModel, and it,MemcmpOptsandTokenAccountOptslive insolana.rpc.core, notsolana.rpc.types.- spl-token's
*Params(BurnParams,CloseAccountParams, …) are inspl.token.models;spl.token.instructionsstill holds the builders. - Those are pydantic models: keyword-only and validating.
MemcmpOpts(bytes=...)wants the base58 str a Pubkey'sstr()gives; rawbytesraises. - A bare
commitment="processed"still works;Commitmentis a str enum.
Invariants
Rules that constrain code you might write next. The reasoning behind each lives in the verifier named in docs/regression-tests.md.
Listeners and RPC
maxSupportedTransactionVersionis a whole-frame setting. AskingblockSubscribefor0does not skip a block's v1 transactions, it nullsvalue.blockfor the whole notification — indistinguishable from a skipped slot, and a near-total outage of the blocks listener. Send1everywhere.- A listener routes on
meta.logMessages, never on the envelope decode. The RPC has already decoded the envelope by the time it emits the logs, and they read the same for every transaction version; the byte decode is the fallback. src/sends v0 transactions (MessageV0.try_compile, no lookup tables); nothing builds a legacyMessage. The cookbook launch sends v1 — 4096 bytes, budget inline, no tables — so scope this rule, don't apply it there.post_rpcmust catchasyncio.TimeoutErroralongsideaiohttp.ClientError: aiohttp raises the former on a request timeout, it is not aClientError, andstr()on it is empty, so the caller logs a blank reason.post_rpcbounds attempts;deadline_seconds(defaultNone) bounds wall time. Don't wrap a lookup inasyncio.timeoutinstead — cutting off an in-flightgetTransactionand returning None conflates "can't see it" with "it failed".build_and_send_transactionreturns a soldersSignature, not astr. Normalize at the boundary: aSignatureis neither JSON serializable nor sliceable, and solana-py'sconfirm_transactionrejects astr.- The endpoints carry their API key in the URL, so any log line holding one is
a leak.
install_secret_redaction(utils/logger.py) masks the value at log-record creation, and every entry point calls it before attaching a handler. Redact the rendered message, notrecord.msgplus the string arguments — httpx2 passes its URL as aURLobject, so a type check skips the one argument that matters.
Buying
- Resolve a coin's quote mint before pricing or sizing anything.
resolve_quote_token_programreturns the token program and caches the mint's decimals off the same read. Both unit helpers then raise rather than guess —quote_units_per_tokeninsrc/,quote_unitsincookbook/— because a wrong power of ten inflates the price and the slippage cap in the same direction, so they compound into an overspend instead of cancelling. Onlycached_quote_unitsanswersNoneinstead of raising, for the curve decoder, which runs against coins that are never traded; it leavesprice_per_tokenunset and the caller's quote gate refuses the coin. trade.curve_refresh_budget(seconds, default 2.0) bounds the pre-buy curve read inextreme_fast_mode; when it expires the token is skipped, because a buy built from listener-guessed defaults reverts withNotAuthorized(6000),ConstraintSeeds(2006) or, on letsbonk,AccountNotInitialized(3012). The sell path keeps the opposite fallback — proceed with cached values — since skipping a sell strands the position.- The refresh is skipped entirely when
TokenInfo.state_from_eventis set, i.e. the listener resolved creator/flags/quote_mint for itself. The CreateEvent parsers set it; instruction-parsedTokenInfodoes not, becauseargs.creatoris user-supplied and may differ from the canonicalBC.creator. Theshredslistener sets the flag itself, having no curve to read.trade.trust_create_event: falseforces the refresh back on.
Selling
PlatformAwareSeller.executedoes not read a price — thetoken_priceit is handed is the slippage floor (min_quote_output = amount * price * (1 - slippage)). The caller owns that floor, so an exit prices off the value that triggered it, never the entry price.- The seller's
max_retriescovers transaction submission only. An on-chain revert comes back assuccess=Falseand is retried in the monitor loop, where the price is re-read first, bounded bytrade.max_exit_sell_attempts(default 3, validated 1..100). - An exit sell is not idempotent, so "it failed" is not enough to act on.
confirm_transaction_detailed/verify_transaction_statusreturnConfirmationStatus(SUCCESS/REVERTED/UNCONFIRMED): aREVERTEDretries, anUNCONFIRMEDsignature is re-checked first. A missingfailure_reasonmeans "unknown", never "reverted". SUBMIT_FAILEDmeans "no transaction ever reached the chain" and nothing else — the one reason besidesREVERTEDthat retries without asking the chain. A post-submission throw reportsUNCONFIRMEDwith its signature.confirm_transactionandverify_transaction_succeededdeliberately stay bools. Returning the enum would be silent: every member is truthy, so everyif await client.confirm_transaction(sig):would start passing unconditionally.calculate_pricereturns0.0for a curve with no virtual token reserves — it does not raise, and the seller rejects it before its own error handling. Never store a non-positive read as the last known price or floor a sell against one;0.0also satisfies the stop-loss comparison.
Config notes
- Bot YAML supports
${VAR}interpolation from the file named byenv_file:SOLANA_NODE_RPC_ENDPOINT,SOLANA_NODE_WSS_ENDPOINT,SOLANA_PRIVATE_KEY,GEYSER_*. src/config_loader.py(package root, not undercore/) validates the platform/listener pairing before startup: pump.fun supportslogs,blocks,geyser,shreds; letsbonk.fun supportsblocksandgeyser— notlogs, and notshreds(issue #201). Adding a listener means updatingPLATFORM_LISTENER_COMPATIBILITYthere too.- Bots with
separate_process: truerun in their own process, one log file each. pump_botruns everybots/*.yaml, and three of the four committed configs shipenabled: false. With all of them disabled it prints nothing and exits 0, indistinguishable from a clean run — check thatlogs/<name>_<timestamp>.logappeared before reading anything into a run.