mirror of
https://github.com/chainstacklabs/pumpfun-bonkfun-bot.git
synced 2026-08-19 18:28:06 +00:00
docs(claude): add claude code rules
This commit is contained in:
@@ -20,8 +20,12 @@ load_dotenv()
|
||||
|
||||
# Constants
|
||||
RPC_ENDPOINT: Final[str] = os.environ.get("SOLANA_NODE_RPC_ENDPOINT")
|
||||
PUMP_PROGRAM_ID: Final[Pubkey] = Pubkey.from_string("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P")
|
||||
TOKEN_PROGRAM_ID: Final[Pubkey] = Pubkey.from_string("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
|
||||
PUMP_PROGRAM_ID: Final[Pubkey] = Pubkey.from_string(
|
||||
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"
|
||||
)
|
||||
TOKEN_PROGRAM_ID: Final[Pubkey] = Pubkey.from_string(
|
||||
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
||||
)
|
||||
|
||||
# The 8-byte discriminator for bonding curve accounts in Pump.fun
|
||||
BONDING_CURVE_DISCRIMINATOR_BYTES: Final[bytes] = bytes.fromhex("17b7f83760d8ac60")
|
||||
@@ -30,10 +34,10 @@ BONDING_CURVE_DISCRIMINATOR_BYTES: Final[bytes] = bytes.fromhex("17b7f83760d8ac6
|
||||
async def get_bonding_curves_by_reserves(client: AsyncClient | None = None) -> list:
|
||||
"""
|
||||
Fetch bonding curve accounts with real token reserves below a threshold.
|
||||
|
||||
|
||||
Args:
|
||||
client: Optional AsyncClient instance. If None, a new one will be created.
|
||||
|
||||
|
||||
Returns:
|
||||
List of bonding curve accounts matching the criteria
|
||||
"""
|
||||
@@ -47,19 +51,21 @@ async def get_bonding_curves_by_reserves(client: AsyncClient | None = None) -> l
|
||||
if should_close_client:
|
||||
client = AsyncClient(RPC_ENDPOINT, commitment="processed", timeout=180)
|
||||
await client.is_connected()
|
||||
|
||||
|
||||
# Define on-chain filters for getProgramAccounts
|
||||
filters = [
|
||||
MemcmpOpts(offset=0, bytes=BONDING_CURVE_DISCRIMINATOR_BYTES), # Match bonding curve accounts
|
||||
MemcmpOpts(offset=30, bytes=msb_prefix), # Pre-filter by real token reserves MSB
|
||||
MemcmpOpts(
|
||||
offset=0, bytes=BONDING_CURVE_DISCRIMINATOR_BYTES
|
||||
), # Match bonding curve accounts
|
||||
MemcmpOpts(
|
||||
offset=30, bytes=msb_prefix
|
||||
), # Pre-filter by real token reserves MSB
|
||||
MemcmpOpts(offset=48, bytes=b"\x00"), # Ensure complete flag is False
|
||||
]
|
||||
|
||||
# Query accounts matching filters
|
||||
response = await client.get_program_accounts(
|
||||
PUMP_PROGRAM_ID,
|
||||
encoding="base64",
|
||||
filters=filters
|
||||
PUMP_PROGRAM_ID, encoding="base64", filters=filters
|
||||
)
|
||||
|
||||
result = []
|
||||
@@ -68,7 +74,7 @@ async def get_bonding_curves_by_reserves(client: AsyncClient | None = None) -> l
|
||||
|
||||
# Extract real_token_reserves (u64 = 8 bytes, little-endian)
|
||||
offset: int = 24 # real_token_reserves field offset
|
||||
real_token_reserves: int = struct.unpack("<Q", raw[offset:offset + 8])[0]
|
||||
real_token_reserves: int = struct.unpack("<Q", raw[offset : offset + 8])[0]
|
||||
|
||||
# Post-filter: ensure value is below the threshold
|
||||
if real_token_reserves < threshold:
|
||||
@@ -88,11 +94,11 @@ async def find_associated_bonding_curve(
|
||||
) -> dict | None:
|
||||
"""
|
||||
Find the SPL token account owned by a bonding curve.
|
||||
|
||||
|
||||
Args:
|
||||
bonding_curve_address: The bonding curve public key (as a string)
|
||||
client: Optional AsyncClient instance. If None, a new one will be created.
|
||||
|
||||
|
||||
Returns:
|
||||
The associated SPL token account data or None if not found
|
||||
"""
|
||||
@@ -101,12 +107,12 @@ async def find_associated_bonding_curve(
|
||||
if should_close_client:
|
||||
client = AsyncClient(RPC_ENDPOINT)
|
||||
await client.is_connected()
|
||||
|
||||
|
||||
response = await client.get_token_accounts_by_owner(
|
||||
Pubkey.from_string(bonding_curve_address),
|
||||
TokenAccountOpts(program_id=TOKEN_PROGRAM_ID)
|
||||
TokenAccountOpts(program_id=TOKEN_PROGRAM_ID),
|
||||
)
|
||||
|
||||
|
||||
if response.value and len(response.value) > 0:
|
||||
return response.value[0].account
|
||||
else:
|
||||
@@ -123,10 +129,10 @@ async def find_associated_bonding_curve(
|
||||
def get_mint_address(data: bytes) -> str:
|
||||
"""
|
||||
Extract the mint address from SPL token account data.
|
||||
|
||||
|
||||
Args:
|
||||
data: The token account data as bytes
|
||||
|
||||
|
||||
Returns:
|
||||
The mint address as a base58-encoded string
|
||||
"""
|
||||
@@ -137,7 +143,7 @@ async def main() -> None:
|
||||
"""Main entry point for querying and processing bonding curves."""
|
||||
async with AsyncClient(RPC_ENDPOINT, commitment="processed", timeout=120) as client:
|
||||
await client.is_connected()
|
||||
|
||||
|
||||
bonding_curves = await get_bonding_curves_by_reserves(client)
|
||||
print(f"Total matches: {len(bonding_curves)}")
|
||||
print("=" * 50)
|
||||
@@ -147,13 +153,13 @@ async def main() -> None:
|
||||
associated_token_account = await find_associated_bonding_curve(
|
||||
str(bonding_curve.pubkey), client
|
||||
)
|
||||
|
||||
|
||||
if associated_token_account:
|
||||
mint_address = get_mint_address(associated_token_account.data)
|
||||
print(f"Bonding curve: {bonding_curve.pubkey}")
|
||||
print(f"Mint address: {mint_address}")
|
||||
print("=" * 50)
|
||||
|
||||
|
||||
# For demonstration, only process the first curve
|
||||
break
|
||||
|
||||
|
||||
Reference in New Issue
Block a user