mirror of
https://github.com/chainstacklabs/pumpfun-bonkfun-bot.git
synced 2026-08-16 08:48:04 +00:00
fix(learning-examples): repair crashing listeners and decoders, prune obsolete paths, unify naming (#181)
Audited every script in learning-examples/ against mainnet. Broken — found by running them, all invisible offline: - listen_geyser.py crashed with IndexError after ~11 coins: it never resolved v0 address-lookup-table accounts, which geyser reports in meta.loaded_writable_addresses / loaded_readonly_addresses. Resolving them removes the crash and brings detections level with the WebSocket listeners, 35 coins each per 150 s. - compare_listeners.py logged 13,090,862 error lines / 888 MB in 150 s and never printed its own 30-second report: the inner recv() loop caught ConnectionClosed in a broad handler that only logged, so every following recv() raised at once and the outer reconnect handler was unreachable. Now 12 KB and exit 0. Same shape fixed in compare_migration_listeners.py, listen_blocksubscribe.py and extract_blocksubscribe_transactions.py; the last two also gained the reconnect loop their siblings already had. - decode_from_gettransaction.py matched instructions on account count instead of discriminator, reporting a real 19-account create_v2 as claim_cashback with every account under the wrong name. It also walked only top-level instructions, and in 40 consecutive pump.fun transactions there was 1 top-level pump instruction against 8 inner ones. - decode_from_blocksubscribe.py crashed on every real create_v2: on chain the trailing args are variable length, 0001 in one tx and 00 in another, so is_cashback_enabled can be absent entirely. - poll_bonding_curve_progress.py polled a hardcoded dead mint and took no argv. Obsolete: - Delete listen_blocksubscribe_old_raydium.py. Seven minutes on mainnet produced 0 initialize2 events while the wrapper listener caught 3 real migrations. - Delete the duplicate geyser stubs and protos under listen-new-tokens/. The protos were byte-identical to src/geyser/proto and the stubs had drifted; both geyser examples now import src.geyser.generated. - Recapture all four fixtures. The old ones were from Aug 2024 and included a 49-byte pre-creator bonding curve. Behind the protocol: - fetch_price.py, get_bonding_curve_status.py, poll_bonding_curve_progress.py and decode_from_getaccountinfo.py never read quote_mint and scaled by a hardcoded 1e9. Against a live USDC-paired curve the price was off by 1000x. - get_pumpswap_pools.py stopped parsing at coin_creator and missed the i128 virtual_quote_reserves. Live pools carry 17.5845 SOL of them, which under-prices by 3.5-23.9% when ignored. Duplication and naming: - Merge manual_buy_cu_optimized.py into manual_buy.py --cu-optimized. The deleted file's docstring said 512 KB while its code used 16 MB; simulation confirms 512 KB and 4 MB both fail MaxLoadedAccountsDataSizeExceeded on Token-2022 mints, so 16 MB is the correct value. - Merge listen_logsubscribe_abc.py into listen_logsubscribe.py. Its ATA derivation hardcoded the legacy token program, so every Associated BC it printed for a Token2022 coin was an address that does not exist on chain. Fixed on merge and cross-checked 59/59 against on-chain accounts. - Remove 19 dead symbols. BREAKING_FEE_RECIPIENTS is still live in the PumpSwap scripts and stays there. - Normalize naming: kebab-case directories, RPC method names as one lowercase token, scripts verb-first. Rules documented in CLAUDE.md. get_graduating_tokens.py is knowingly left broken: getProgramAccounts over the whole pump program is now rejected by providers and it needs a getProgramAccountsV2 rewrite, which belongs in its own PR. Verified: both offline gates pass, all 41 examples parse, every read-only script exercised on mainnet against SOL- and USDC-paired coins, no new ruff findings (427 -> 413). No script that spends real funds was run. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
5c1fb7eb28
commit
a33f4fd035
@@ -1,9 +1,31 @@
|
||||
"""Buy the next pump.fun coin to be created, using buy_v2.
|
||||
|
||||
WARNING: this submits a real transaction and spends real funds.
|
||||
|
||||
Usage:
|
||||
uv run learning-examples/manual_buy.py
|
||||
uv run learning-examples/manual_buy.py --cu-optimized
|
||||
|
||||
`--cu-optimized` adds a SetLoadedAccountsDataSizeLimit instruction. A transaction
|
||||
may load up to 64 MB of account data by default, which is billed at 16k CU toward
|
||||
the fee and priority calculation. Declaring a smaller ceiling lowers that share.
|
||||
The saving does not show up in a transaction's reported `unitsConsumed`, which
|
||||
only covers execution, so it is hard to measure directly from a receipt.
|
||||
|
||||
Do not lower the limit too far: 16 MB is still 4x smaller than the default and
|
||||
leaves room for Token-2022 mints with extensions, while 512 KB is rejected with
|
||||
MaxLoadedAccountsDataSizeExceeded on exactly those coins.
|
||||
|
||||
Reference: https://www.anza.xyz/blog/cu-optimization-with-setloadedaccountsdatasizelimit
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import base64
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
||||
import base58
|
||||
import pump_v2
|
||||
@@ -14,6 +36,7 @@ from solana.rpc.async_api import AsyncClient
|
||||
from solana.rpc.commitment import Confirmed
|
||||
from solana.rpc.types import TxOpts
|
||||
from solders.compute_budget import set_compute_unit_price
|
||||
from solders.instruction import Instruction
|
||||
from solders.keypair import Keypair
|
||||
from solders.message import Message
|
||||
from solders.pubkey import Pubkey
|
||||
@@ -26,6 +49,13 @@ from spl.token.instructions import (
|
||||
EXPECTED_DISCRIMINATOR = pump_v2.BONDING_CURVE_DISCRIMINATOR
|
||||
TOKEN_DECIMALS = 6
|
||||
|
||||
COMPUTE_BUDGET_PROGRAM = Pubkey.from_string(
|
||||
"ComputeBudget111111111111111111111111111111"
|
||||
)
|
||||
# 16 MB. Enough for Token-2022 mints carrying extensions, and still 4x below the
|
||||
# 64 MB default; 4-8 MB is rejected with MaxLoadedAccountsDataSizeExceeded.
|
||||
LOADED_ACCOUNTS_DATA_SIZE_LIMIT = 16_384_000
|
||||
|
||||
# Global constants
|
||||
PUMP_PROGRAM = Pubkey.from_string("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P")
|
||||
PUMP_GLOBAL = Pubkey.from_string("4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf")
|
||||
@@ -100,6 +130,22 @@ def calculate_pump_curve_price(curve_state: pump_v2.BondingCurveState) -> float:
|
||||
return price
|
||||
|
||||
|
||||
def set_loaded_accounts_data_size_limit(bytes_limit: int) -> Instruction:
|
||||
"""Build a SetLoadedAccountsDataSizeLimit compute-budget instruction.
|
||||
|
||||
solders does not ship a helper for this one, so encode it by hand: the
|
||||
compute-budget program takes a 1-byte discriminator (4) and a u32 limit.
|
||||
|
||||
Args:
|
||||
bytes_limit: Max account data the transaction may load, in bytes
|
||||
|
||||
Returns:
|
||||
The compute-budget instruction
|
||||
"""
|
||||
data = struct.pack("<BI", 4, bytes_limit)
|
||||
return Instruction(COMPUTE_BUDGET_PROGRAM, data, [])
|
||||
|
||||
|
||||
async def buy_token(
|
||||
mint: Pubkey,
|
||||
bonding_curve: Pubkey,
|
||||
@@ -109,6 +155,8 @@ async def buy_token(
|
||||
amount: float,
|
||||
slippage: float = 0.25,
|
||||
max_retries=5,
|
||||
*,
|
||||
cu_optimized: bool = False,
|
||||
):
|
||||
private_key = base58.b58decode(os.environ.get("SOLANA_PRIVATE_KEY"))
|
||||
payer = Keypair.from_bytes(private_key)
|
||||
@@ -142,7 +190,13 @@ async def buy_token(
|
||||
is_mayhem_mode=curve_state.is_mayhem_mode,
|
||||
)
|
||||
|
||||
instructions = [
|
||||
instructions = []
|
||||
if cu_optimized:
|
||||
# Must come first, before the instructions it applies to.
|
||||
instructions.append(
|
||||
set_loaded_accounts_data_size_limit(LOADED_ACCOUNTS_DATA_SIZE_LIMIT)
|
||||
)
|
||||
instructions += [
|
||||
set_compute_unit_price(1_000),
|
||||
create_idempotent_associated_token_account(
|
||||
payer.pubkey(), payer.pubkey(), mint, token_program_id=token_program
|
||||
@@ -350,7 +404,9 @@ async def listen_for_create_transaction():
|
||||
return decoded_args
|
||||
|
||||
|
||||
async def main():
|
||||
async def main(*, cu_optimized: bool = False):
|
||||
if cu_optimized:
|
||||
print("Compute-unit optimization enabled (SetLoadedAccountsDataSizeLimit)")
|
||||
print("Waiting for a new token creation...")
|
||||
token_data = await listen_for_create_transaction()
|
||||
print("New token created:")
|
||||
@@ -393,8 +449,9 @@ async def main():
|
||||
token_program,
|
||||
amount,
|
||||
slippage,
|
||||
cu_optimized=cu_optimized,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
asyncio.run(main(cu_optimized="--cu-optimized" in sys.argv))
|
||||
|
||||
Reference in New Issue
Block a user