mirror of
https://github.com/chainstacklabs/pumpfun-bonkfun-bot.git
synced 2026-08-07 12:37:47 +00:00
Add mayhem mode support and Token2022 integration (#149)
* feat: mayhem update in idl * feat(examples): update bonding curve scripts * feat(example): update listen_blocksubscribe * feat(examples): update geyser listener * feat(examples): update all new token listeners * feat(examples): add comments, fix printing, formatting * feat(examples): pumpswap buy and sell update with mayhem mode * fix(examples): sell pump amm fee recipient * feat(examples): update decode scripts * feat(examples): update fetch price * feat(examples): buy and sell bonding curve scripts * feat(examples): add mint with mayhem mode enabled * feat(examples): improve listening to wallet txs * feat(examples): migration listener improvements * feat(examples): global vol accumulator is not writable * feat(examples): support token/token2022 programs in buy instructions * feat(examples): token/token2022 for pumpswap buy * feat(examples): token/token2022 supprot for sell instructions * feat(bot): support create_v2 with token2022, mayhem mode, other fixes * fix(bot): support only token2022 in logs and pumportal listeners * feat(bot): token2022 support in cleanup flow * fix(bot): update token program handling and improve price validation in trading logic * feat(bot): enhance token program handling for LetsBonk integration
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
"""
|
||||
Module for checking the status of a token's bonding curve on the Solana network using
|
||||
the Pump.fun program. It allows querying the bonding curve state and completion status.
|
||||
|
||||
Note: creator fee upgrade introduced updates in bonding curve structure.
|
||||
https://github.com/pump-fun/pump-public-docs/blob/main/docs/PUMP_CREATOR_FEE_README.md
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -42,20 +39,11 @@ class BondingCurveState:
|
||||
real_sol_reserves: Real SOL reserves in the curve
|
||||
token_total_supply: Total token supply in the curve
|
||||
complete: Whether the curve has completed and liquidity migrated
|
||||
is_mayhem_mode: Whether the curve is in mayhem mode
|
||||
"""
|
||||
|
||||
_STRUCT_1 = Struct(
|
||||
"virtual_token_reserves" / Int64ul,
|
||||
"virtual_sol_reserves" / Int64ul,
|
||||
"real_token_reserves" / Int64ul,
|
||||
"real_sol_reserves" / Int64ul,
|
||||
"token_total_supply" / Int64ul,
|
||||
"complete" / Flag,
|
||||
)
|
||||
|
||||
# Struct after creator fee update has been introduced
|
||||
# https://github.com/pump-fun/pump-public-docs/blob/main/docs/PUMP_CREATOR_FEE_README.md
|
||||
_STRUCT_2 = Struct(
|
||||
# V2: Struct with creator field (81 bytes total: 8 discriminator + 73 data)
|
||||
_STRUCT_V2 = Struct(
|
||||
"virtual_token_reserves" / Int64ul,
|
||||
"virtual_sol_reserves" / Int64ul,
|
||||
"real_token_reserves" / Int64ul,
|
||||
@@ -65,26 +53,43 @@ class BondingCurveState:
|
||||
"creator" / Bytes(32), # Added new creator field - 32 bytes for Pubkey
|
||||
)
|
||||
|
||||
# V3: Struct with creator + mayhem mode (82 bytes total: 8 discriminator + 74 data)
|
||||
_STRUCT_V3 = Struct(
|
||||
"virtual_token_reserves" / Int64ul,
|
||||
"virtual_sol_reserves" / Int64ul,
|
||||
"real_token_reserves" / Int64ul,
|
||||
"real_sol_reserves" / Int64ul,
|
||||
"token_total_supply" / Int64ul,
|
||||
"complete" / Flag,
|
||||
"creator" / Bytes(32),
|
||||
"is_mayhem_mode" / Flag, # Added mayhem mode flag - 1 byte
|
||||
)
|
||||
|
||||
def __init__(self, data: bytes) -> None:
|
||||
"""Parse bonding curve data."""
|
||||
if data[:8] != EXPECTED_DISCRIMINATOR:
|
||||
raise ValueError("Invalid curve state discriminator")
|
||||
|
||||
if len(data) < 150:
|
||||
parsed = self._STRUCT_1.parse(data[8:])
|
||||
self.__dict__.update(parsed)
|
||||
total_length = len(data)
|
||||
|
||||
else:
|
||||
parsed = self._STRUCT_2.parse(data[8:])
|
||||
if total_length == 81: # V2: Creator only
|
||||
parsed = self._STRUCT_V2.parse(data[8:])
|
||||
self.__dict__.update(parsed)
|
||||
# Convert raw bytes to Pubkey for creator field
|
||||
if hasattr(self, "creator") and isinstance(self.creator, bytes):
|
||||
self.creator = Pubkey.from_bytes(self.creator)
|
||||
self.creator = Pubkey.from_bytes(self.creator)
|
||||
self.is_mayhem_mode = False
|
||||
|
||||
elif total_length >= 82: # V3: Creator + mayhem mode
|
||||
parsed = self._STRUCT_V3.parse(data[8:])
|
||||
self.__dict__.update(parsed)
|
||||
# Convert raw bytes to Pubkey for creator field
|
||||
self.creator = Pubkey.from_bytes(self.creator)
|
||||
|
||||
else:
|
||||
raise ValueError(f"Unexpected bonding curve size: {total_length} bytes")
|
||||
|
||||
|
||||
def get_associated_bonding_curve_address(
|
||||
mint: Pubkey, program_id: Pubkey
|
||||
) -> tuple[Pubkey, int]:
|
||||
def get_bonding_curve_address(mint: Pubkey, program_id: Pubkey) -> tuple[Pubkey, int]:
|
||||
"""
|
||||
Derives the associated bonding curve address for a given mint.
|
||||
|
||||
@@ -134,17 +139,14 @@ async def check_token_status(mint_address: str) -> None:
|
||||
"""
|
||||
try:
|
||||
mint = Pubkey.from_string(mint_address)
|
||||
|
||||
# Get the associated bonding curve address
|
||||
bonding_curve_address, bump = get_associated_bonding_curve_address(
|
||||
mint, PUMP_PROGRAM_ID
|
||||
)
|
||||
bonding_curve_address, bump = get_bonding_curve_address(mint, PUMP_PROGRAM_ID)
|
||||
|
||||
print("\nToken status:")
|
||||
print("-" * 50)
|
||||
print(f"Token mint: {mint}")
|
||||
print(f"Associated bonding curve: {bonding_curve_address}")
|
||||
print(f"Bump seed: {bump}")
|
||||
print(f"Bonding curve: {bonding_curve_address}")
|
||||
if bump is not None:
|
||||
print(f"Bump seed: {bump}")
|
||||
print("-" * 50)
|
||||
|
||||
# Check completion status
|
||||
@@ -156,9 +158,25 @@ async def check_token_status(mint_address: str) -> None:
|
||||
|
||||
print("\nBonding curve status:")
|
||||
print("-" * 50)
|
||||
print(f"Creator: {curve_state.creator}")
|
||||
print(
|
||||
f"Completion status: {'Completed' if curve_state.complete else 'Not completed'}"
|
||||
f"Mayhem Mode: {'✅ Enabled' if curve_state.is_mayhem_mode else '❌ Disabled'}"
|
||||
)
|
||||
print(
|
||||
f"Completed: {'✅ Migrated' if curve_state.complete else '❌ Bonding curve'}"
|
||||
)
|
||||
|
||||
print("\nBonding curve reserves:")
|
||||
print(f"Virtual Token: {curve_state.virtual_token_reserves:,}")
|
||||
print(
|
||||
f"Virtual SOL: {curve_state.virtual_sol_reserves:,} lamports"
|
||||
)
|
||||
print(f"Real Token: {curve_state.real_token_reserves:,}")
|
||||
print(
|
||||
f"Real SOL: {curve_state.real_sol_reserves:,} lamports"
|
||||
)
|
||||
print(f"Total Supply: {curve_state.token_total_supply:,}")
|
||||
|
||||
if curve_state.complete:
|
||||
print(
|
||||
"\nNote: This bonding curve has completed and liquidity has been migrated to PumpSwap."
|
||||
|
||||
@@ -17,7 +17,7 @@ load_dotenv()
|
||||
# Constants
|
||||
RPC_URL: Final[str] = os.getenv("SOLANA_NODE_RPC_ENDPOINT")
|
||||
TOKEN_MINT: Final[str] = (
|
||||
"YOUR_TOKEN_MINT_ADDRESS_HERE" # Replace with actual token mint address
|
||||
"5ZHx2GGGj87xpidVJpBqadMUutqBirhL2TqUR9T9taKc" # Replace with actual token mint address
|
||||
)
|
||||
PUMP_PROGRAM_ID: Final[Pubkey] = Pubkey.from_string(
|
||||
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"
|
||||
@@ -30,7 +30,7 @@ EXPECTED_DISCRIMINATOR: Final[bytes] = struct.pack(
|
||||
POLL_INTERVAL: Final[int] = 10 # Seconds between each status check
|
||||
|
||||
|
||||
def get_associated_bonding_curve_address(mint: Pubkey, program_id: Pubkey) -> Pubkey:
|
||||
def get_bonding_curve_address(mint: Pubkey, program_id: Pubkey) -> Pubkey:
|
||||
"""
|
||||
Derive the bonding curve PDA address from a mint address.
|
||||
|
||||
@@ -81,8 +81,9 @@ def parse_curve_state(data: bytes) -> dict:
|
||||
if data[:8] != EXPECTED_DISCRIMINATOR:
|
||||
raise ValueError("Invalid discriminator for bonding curve")
|
||||
|
||||
# Parse common fields (present in all versions)
|
||||
fields = struct.unpack_from("<QQQQQ?", data, 8)
|
||||
return {
|
||||
result = {
|
||||
"virtual_token_reserves": fields[0] / 10**TOKEN_DECIMALS,
|
||||
"virtual_sol_reserves": fields[1] / LAMPORTS_PER_SOL,
|
||||
"real_token_reserves": fields[2] / 10**TOKEN_DECIMALS,
|
||||
@@ -91,6 +92,20 @@ def parse_curve_state(data: bytes) -> dict:
|
||||
"complete": fields[5],
|
||||
}
|
||||
|
||||
# Parse creator field if present
|
||||
data_length = len(data) - 8
|
||||
if data_length >= 73: # Has creator field
|
||||
creator_bytes = data[49:81] # 8 (discriminator) + 41 (base fields) = 49
|
||||
result["creator"] = Pubkey.from_bytes(creator_bytes)
|
||||
|
||||
# Parse is_mayhem_mode if present
|
||||
if data_length >= 74: # Has mayhem mode field
|
||||
result["is_mayhem_mode"] = bool(data[81])
|
||||
else:
|
||||
result["is_mayhem_mode"] = False
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def print_curve_status(state: dict) -> None:
|
||||
"""
|
||||
@@ -130,9 +145,7 @@ async def track_curve() -> None:
|
||||
return
|
||||
|
||||
mint_pubkey: Pubkey = Pubkey.from_string(TOKEN_MINT)
|
||||
curve_pubkey: Pubkey = get_associated_bonding_curve_address(
|
||||
mint_pubkey, PUMP_PROGRAM_ID
|
||||
)
|
||||
curve_pubkey: Pubkey = get_bonding_curve_address(mint_pubkey, PUMP_PROGRAM_ID)
|
||||
|
||||
print("Tracking bonding curve for:", mint_pubkey)
|
||||
print("Curve address:", curve_pubkey, "\n")
|
||||
|
||||
Reference in New Issue
Block a user