From 68c8251ccf2a1ae64c2cff6b925059608c73ff11 Mon Sep 17 00:00:00 2001 From: smypmsa Date: Wed, 2 Apr 2025 15:36:58 +0000 Subject: [PATCH] feat: add track bonding curve progress script --- .../track_bonding_curve_progress.py | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 learning-examples/track_bonding_curve_progress.py diff --git a/learning-examples/track_bonding_curve_progress.py b/learning-examples/track_bonding_curve_progress.py new file mode 100644 index 0000000..11933c1 --- /dev/null +++ b/learning-examples/track_bonding_curve_progress.py @@ -0,0 +1,96 @@ +""" +Track bonding curve progress for a pump.fun token by mint address. +""" + +import asyncio +import os +import struct + +from dotenv import load_dotenv +from solana.rpc.async_api import AsyncClient +from solders.pubkey import Pubkey + +# Import pump.fun program address +from core.pubkeys import PumpAddresses + +load_dotenv() + +RPC_URL = os.getenv("SOLANA_NODE_RPC_ENDPOINT") +TOKEN_MINT = "xWrzYY4c1LnbSkLrd2LDUg9vw7YtVyJhGmw7MABpump" + +LAMPORTS_PER_SOL = 1_000_000_000 +TOKEN_DECIMALS = 6 +EXPECTED_DISCRIMINATOR = struct.pack(" Pubkey: + """Derive the bonding curve PDA address from mint.""" + return Pubkey.find_program_address([b"bonding-curve", bytes(mint)], program_id)[0] + + +async def get_account_data(client: AsyncClient, pubkey: Pubkey) -> bytes: + """Fetch raw account data for a given public key.""" + resp = await client.get_account_info(pubkey, encoding="base64") + if not resp.value or not resp.value.data: + raise ValueError(f"Account {pubkey} not found or has no data") + + return resp.value.data + + +def parse_curve_state(data: bytes) -> dict: + """Decode bonding curve account data.""" + if data[:8] != EXPECTED_DISCRIMINATOR: + raise ValueError("Invalid discriminator for bonding curve") + + fields = struct.unpack_from("