docs(claude): add claude code rules

This commit is contained in:
smypmsa
2025-08-11 05:35:25 +00:00
parent f2efd56f81
commit 8ab8932168
56 changed files with 4193 additions and 2605 deletions
@@ -25,14 +25,16 @@ RPC_ENDPOINT = os.environ.get("SOLANA_NODE_RPC_ENDPOINT")
TOKEN_MINT = "..."
# Constants
PUMP_PROGRAM_ID: Final[Pubkey] = Pubkey.from_string("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P")
PUMP_PROGRAM_ID: Final[Pubkey] = Pubkey.from_string(
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"
)
EXPECTED_DISCRIMINATOR: Final[bytes] = struct.pack("<Q", 6966180631402821399)
class BondingCurveState:
"""
Represents the state of a bonding curve account.
Attributes:
virtual_token_reserves: Virtual token reserves in the curve
virtual_sol_reserves: Virtual SOL reserves in the curve
@@ -41,6 +43,7 @@ class BondingCurveState:
token_total_supply: Total token supply in the curve
complete: Whether the curve has completed and liquidity migrated
"""
_STRUCT_1 = Struct(
"virtual_token_reserves" / Int64ul,
"virtual_sol_reserves" / Int64ul,
@@ -73,9 +76,9 @@ class BondingCurveState:
else:
parsed = self._STRUCT_2.parse(data[8:])
self.__dict__.update(parsed)
self.__dict__.update(parsed)
# Convert raw bytes to Pubkey for creator field
if hasattr(self, 'creator') and isinstance(self.creator, bytes):
if hasattr(self, "creator") and isinstance(self.creator, bytes):
self.creator = Pubkey.from_bytes(self.creator)
@@ -84,11 +87,11 @@ def get_associated_bonding_curve_address(
) -> tuple[Pubkey, int]:
"""
Derives the associated bonding curve address for a given mint.
Args:
mint: The token mint address
program_id: The program ID for the bonding curve
Returns:
Tuple of (bonding curve address, bump seed)
"""
@@ -100,14 +103,14 @@ async def get_bonding_curve_state(
) -> BondingCurveState:
"""
Fetches and validates the state of a bonding curve account.
Args:
conn: AsyncClient connection to Solana RPC
curve_address: Address of the bonding curve account
Returns:
BondingCurveState object containing parsed account data
Raises:
ValueError: If account data is invalid or missing
"""
@@ -125,7 +128,7 @@ async def get_bonding_curve_state(
async def check_token_status(mint_address: str) -> None:
"""
Checks and prints the status of a token and its bonding curve.
Args:
mint_address: The token mint address as a string
"""
@@ -174,9 +177,11 @@ async def check_token_status(mint_address: str) -> None:
def main() -> None:
"""Main entry point for the token status checker."""
parser = argparse.ArgumentParser(description="Check token bonding curve status")
parser.add_argument("mint_address", nargs='?', help="The token mint address", default=TOKEN_MINT)
parser.add_argument(
"mint_address", nargs="?", help="The token mint address", default=TOKEN_MINT
)
args = parser.parse_args()
asyncio.run(check_token_status(args.mint_address))
@@ -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
@@ -17,21 +17,25 @@ load_dotenv()
# Constants
RPC_URL: Final[str] = os.getenv("SOLANA_NODE_RPC_ENDPOINT")
TOKEN_MINT: Final[str] = "xWrzYY4c1LnbSkLrd2LDUg9vw7YtVyJhGmw7MABpump"
PUMP_PROGRAM_ID: Final[Pubkey] = Pubkey.from_string("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P")
PUMP_PROGRAM_ID: Final[Pubkey] = Pubkey.from_string(
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"
)
LAMPORTS_PER_SOL: Final[int] = 1_000_000_000
TOKEN_DECIMALS: Final[int] = 6
EXPECTED_DISCRIMINATOR: Final[bytes] = struct.pack("<Q", 6966180631402821399) # Pump.fun bonding curve discriminator
EXPECTED_DISCRIMINATOR: Final[bytes] = struct.pack(
"<Q", 6966180631402821399
) # Pump.fun bonding curve discriminator
POLL_INTERVAL: Final[int] = 10 # Seconds between each status check
def get_associated_bonding_curve_address(mint: Pubkey, program_id: Pubkey) -> Pubkey:
"""
Derive the bonding curve PDA address from a mint address.
Args:
mint: The token mint address
program_id: The program ID for the bonding curve
Returns:
The bonding curve address
"""
@@ -41,14 +45,14 @@ def get_associated_bonding_curve_address(mint: Pubkey, program_id: Pubkey) -> Pu
async def get_account_data(client: AsyncClient, pubkey: Pubkey) -> bytes:
"""
Fetch raw account data for a given public key.
Args:
client: AsyncClient connection to Solana RPC
pubkey: The public key of the account to fetch
Returns:
The raw account data as bytes
Raises:
ValueError: If the account is not found or has no data
"""
@@ -62,13 +66,13 @@ async def get_account_data(client: AsyncClient, pubkey: Pubkey) -> bytes:
def parse_curve_state(data: bytes) -> dict:
"""
Decode bonding curve account data into a readable format.
Args:
data: The raw bonding curve account data
Returns:
A dictionary containing parsed bonding curve fields
Raises:
ValueError: If the account discriminator is invalid
"""
@@ -89,7 +93,7 @@ def parse_curve_state(data: bytes) -> dict:
def print_curve_status(state: dict) -> None:
"""
Print the current status of the bonding curve in a readable format.
Args:
state: The parsed bonding curve state dictionary
"""
@@ -98,11 +102,11 @@ def print_curve_status(state: dict) -> None:
progress = 100.0
else:
# Pump.fun constants (already converted to human-readable format)
TOTAL_SUPPLY = 1_000_000_000 # 1B tokens
TOTAL_SUPPLY = 1_000_000_000 # 1B tokens
RESERVED_TOKENS = 206_900_000 # 206.9M tokens reserved for migration
initial_real_token_reserves = TOTAL_SUPPLY - RESERVED_TOKENS # 793.1M tokens
if initial_real_token_reserves > 0:
left_tokens = state["real_token_reserves"]
progress = 100 - (left_tokens * 100) / initial_real_token_reserves
@@ -124,7 +128,9 @@ 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_associated_bonding_curve_address(
mint_pubkey, PUMP_PROGRAM_ID
)
print("Tracking bonding curve for:", mint_pubkey)
print("Curve address:", curve_pubkey, "\n")