Commit Graph
7 Commits
Author SHA1 Message Date
b7aae5e333 chore(monitoring,platforms,tools): retire the pumpportal listener (#232)
* chore(monitoring,platforms,tools): retire the pumpportal listener

Remove the third-party feed from the bot, the cookbook and the listener
race. It sampled rather than covered the chain, and was the one listener
that could never set state_from_event, so every buy paid the pre-buy
curve read.

Rescope the two buy-path verifiers that used it as a stand-in for a
TokenInfo without state_from_event.

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

* style(trading): rewrap a docstring paragraph

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

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-26 08:47:31 +02:00
ca1f8919e6 fix(platforms,tools,cookbook): match the create marker whole, race pump.fun coins only (#231)
The logs create gate tested the marker as a substring. Anchor writes
`Instruction: <Name>` for every program, so it also accepted
CreateTokenAccount, CreatePool and the rest from whichever programs shared the
transaction. The CreateEvent check downstream rejected them, but a
CreateTokenAccount veto had been added to suppress them and, being a
whole-transaction test, it also dropped genuine creates whose transaction
opened a token account. Matching the marker lines whole retires the veto.

compare_listeners' PumpPortal lane ignored the payload's `pool` field, so
letsbonk creates raced as pump.fun coins against lanes that subscribe to the
pump.fun program alone. The lane now reports `pool: "pump"` only.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-25 22:07:26 +02:00
978946f8ed fix(trading,monitoring,cookbook): keep clean shutdowns clean, guard the migration decoder (#228)
* fix(trading): balance task_done against get in the token queue processor

`_process_token_queue` called `task_done()` from a `finally` that also runs
when `queue.get()` itself is cancelled, at which point no item was taken, so
the call was unbalanced and raised:

    ValueError: task_done() called too many times

Cancelling that task is how `start()` shuts yolo mode down, and the
cancellation almost always lands while parked on `get()`. `start()` catches
only `CancelledError` around the await, so the ValueError reached the outer
handler and every clean yolo-mode shutdown was logged as `Trading stopped due
to error` with a traceback. Nothing was lost, since `_cleanup_resources()`
still ran, but the log said a good run had failed.

Track whether an item was taken and call `task_done()` only then. The
stale-token `continue` path did take one and still calls it, or `join()` would
never return.

Closes #210

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

* fix(monitoring): stop logging a normal WebSocket close as a ping error

Every WebSocket listener runs a `_ping_loop` that caught `CancelledError` and
then fell through to a broad `except Exception: logger.exception("Ping error")`.
When the connection closes normally, `websocket.ping()` raises
`ConnectionClosedOK` or `ConnectionClosedError` — neither is a `CancelledError`,
so both landed in the broad handler and printed a traceback at ERROR:

    ERROR:monitoring.universal_logs_listener:Ping error
    websockets.exceptions.ConnectionClosedError: sent 1000 (OK); no close frame received

Close code 1000 is a normal closure. Nothing was wrong, but a completed run
reported a failure to anyone reading the logs or alerting on ERROR.

Catch `ConnectionClosed` before the broad handler and exit the loop at debug.
The broad handler stays for anything genuinely unexpected.

#206 had narrowed the race by cancelling the ping task in a `finally` on the
read loop, but the ping can still fire between the connection closing and the
cancellation landing, and a server-initiated close always reached the loop this
way. The pumpportal listener has the same loop and is fixed here too.

Closes #203

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

* fix(cookbook,tools): reject payloads that are not the migration event

`parse_migrate_instruction` skipped the first 8 bytes as a discriminator but
never checked them, so every `Program data:` line in a migration transaction
was decoded against the migration schema whatever event it actually was. The
schema needs 301 bytes; any payload at least that long came back as a fully
populated dict of meaningless values rather than as a failure — a
`baseMintDecimals` of 176 where the field can only legitimately be 0-9. Shorter
payloads happened to fail inside `struct.unpack`, which is why the underrun was
never the visible symptom.

The event is the wrapper program's `CreatePoolEvent`, not the
`CompletePumpAmmMigrationEvent` in `idl/pump_fun_idl.json` — confirmed against
mainnet, where every payload the program emits carries discriminator
`b1310cd2a076a774`, which is `sha256("event:CreatePoolEvent")[:8]`. Assert it
before reading any field. The field layout itself was already correct.

Both copies of the decoder are fixed. In the cookbook script, `parsed_data` was
also reassigned on every `Program data:` line, so a later non-matching line
would wipe a good parse now that the guard returns None; keep the first match.

Closes #198

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

* refactor(cookbook): declare BondingCurveState fields instead of __dict__.update

The class assigned its parsed fields through `self.__dict__.update(...)`. The
fields were correct at runtime, but nothing declared them, so type checkers and
editors could not see them: reading `state.virtual_token_reserves` in any
consumer produced an "attribute is unknown" warning, with no autocomplete and
no go-to-definition for any reserve field.

Declare the fields and assign them from the parse result. Where several struct
versions share the leading fields, pick the struct in the branch and assign
once after it, so the optional trailing fields resolve through one `.get` each
rather than through a pre-set default that a later update may or may not
overwrite. This also drops construct's `_io` from the instance dict.

No behaviour change: parsed state for a live curve is identical field for field
before and after, across all three classes. `src/` is unaffected — its curve
manager works on plain dicts and never used this class.

Closes #204

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

* fix(trading): finish shutdown cleanup through the cancellation that triggered it

`start()` reclaims account rent from a `finally` that awaited
`_cleanup_resources`. Shutdown reaches that coroutine as a cancellation, and
cleanup awaits once per account — a settle wait, then an RPC read — so the first
of those re-raised `CancelledError` and every account after it kept its rent.
The run then ended without even logging that it shut down, so nothing in the log
said cleanup had been cut short.

Seen on a live run interrupted during the settle wait: it stopped after two of
its accounts. Three other runs interrupted a moment earlier finished cleanly, so
this is a race rather than a certainty.

Run cleanup as its own task and wait through the cancellation with
`asyncio.wait`, which neither cancels the task on timeout nor re-raises what it
failed with. Bounded by `_CLEANUP_SHUTDOWN_BUDGET` so a stuck RPC cannot hold
the process open; rent left behind is recoverable, so the warning names
`tools/cleanup_accounts.py` rather than retrying here.

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

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-25 14:28:43 +02:00
c00cd608e3 fix(trading): label quote-denominated output by its actual quote mint (#224)
Prices, exit targets and PnL printed "SOL" for every coin. They now use the
quote mint's symbol, promoted to `core.pubkeys.quote_symbol`, and `get_pnl`
returns `unrealized_pnl_quote`.

Also deletes seven uncalled methods that converted with `LAMPORTS_PER_SOL` or
a hardcoded base unit, and adds a verifier to stop them returning. It covers
`core/`, `trading/` and `platforms/pumpfun/`; letsbonk still scales prices by
a SOL literal, and the verifier records which sites and why it stops there.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-24 14:51:15 +02:00
01edbbf8c4 fix(core): raise on unresolved quote decimals instead of defaulting to 9 (#223)
Only the buy path's quote gate kept a guessed power of ten off the chain.
`quote_decimals` now raises, `cached_quote_units` returns None for the curve
decoder, and `resolve_quote_token_program` no longer short-circuits before
reading decimals. The buy validates its price after the gate.

verify_quote_decimals_resolved gains four checks and now covers src/.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-24 14:43:54 +02:00
b04a375506 fix(cookbook): resolve quote-mint decimals instead of assuming 9 (#222)
QuoteControl admits mints from 4 to 12 decimals, so the default was wrong
for most quote assets and silently so. Parsers return raw quote reserves;
callers scale off the mint account.

Same class elsewhere: pumpswap refuses non-SOL-quoted pools instead of
capping in the wrong unit, letsbonk exact_out/exact_in scale by
base_decimals, wallet_trades decodes through to quote_mint (fixing an
ix_name offset that left later fields three bytes short), balances read at
confirmed, cleanup_accounts takes a required mint.

Verified on mainnet with real funds; wallet left holding SOL only.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-24 11:24:28 +02:00
Anton SauchykandGitHub de7fd2aa90 docs: compact docs and docstrings, split CLAUDE.md per Anthropic guidance (#221) 2026-09-23 19:00:03 +02:00