From 008446e253079658d8be8603d09e75044895762a Mon Sep 17 00:00:00 2001 From: smypmsa Date: Sat, 29 Mar 2025 21:31:46 +0000 Subject: [PATCH] feat: add script to get pumpswap market data --- learning-examples/get_pumpswap_pools.py | 86 +++++++++++++++++++++++++ learning-examples/manual_sell.py | 2 +- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 learning-examples/get_pumpswap_pools.py diff --git a/learning-examples/get_pumpswap_pools.py b/learning-examples/get_pumpswap_pools.py new file mode 100644 index 0000000..c8e9d00 --- /dev/null +++ b/learning-examples/get_pumpswap_pools.py @@ -0,0 +1,86 @@ +import asyncio +import os +import struct + +import base58 +from solana.rpc.async_api import AsyncClient +from solana.rpc.types import MemcmpOpts +from solders.pubkey import Pubkey + +RPC_ENDPOINT = os.environ.get("SOLANA_NODE_RPC_ENDPOINT") +PUMP_AMM_PROGRAM_ID = Pubkey.from_string("pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA") +TOKEN_MINT = Pubkey.from_string("35ySx7Rt3RqeTp75QB81FgRvPT5yDY2m5BupsUYDpump") + + +async def get_market_address_by_base_mint(base_mint_address: Pubkey, amm_program_id: Pubkey): + async with AsyncClient(RPC_ENDPOINT) as client: + base_mint_bytes = bytes(base_mint_address) + + # Define the offset for base_mint field + offset = 43 + + # Create the filter to match the base_mint + filters = [ + MemcmpOpts(offset=offset, bytes=base_mint_bytes) + ] + + # Retrieve the accounts that match the filter + response = await client.get_program_accounts( + amm_program_id, # AMM program ID + encoding="jsonParsed", + filters=filters + ) + + pool_addresses = [account.pubkey for account in response.value] + return pool_addresses[0] + +async def get_market_data(market_address: Pubkey): + async with AsyncClient(RPC_ENDPOINT) as client: + response = await client.get_account_info_json_parsed(market_address) + data = response.value.data + parsed_data = {} + + offset = 8 + fields = [ + ("pool_bump", "u8"), + ("index", "u16"), + ("creator", "pubkey"), + ("base_mint", "pubkey"), + ("quote_mint", "pubkey"), + ("lp_mint", "pubkey"), + ("pool_base_token_account", "pubkey"), + ("pool_quote_token_account", "pubkey"), + ("lp_supply", "u64"), + ] + + for field_name, field_type in fields: + if field_type == "pubkey": + value = data[offset:offset + 32] + parsed_data[field_name] = base58.b58encode(value).decode("utf-8") + offset += 32 + elif field_type in {"u64", "i64"}: + value = struct.unpack("