mirror of
https://github.com/chainstacklabs/pumpfun-bonkfun-bot.git
synced 2026-08-16 08:48:04 +00:00
Add bonding curve state check & Raydium migration event listening
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,96 @@
|
|||||||
|
import asyncio
|
||||||
|
import struct
|
||||||
|
from typing import Final
|
||||||
|
from construct import Struct, Int64ul, Flag
|
||||||
|
from solana.rpc.async_api import AsyncClient
|
||||||
|
from solders.pubkey import Pubkey
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||||
|
from config import RPC_ENDPOINT, PUMP_PROGRAM
|
||||||
|
|
||||||
|
# Constants
|
||||||
|
EXPECTED_DISCRIMINATOR: Final[bytes] = struct.pack("<Q", 6966180631402821399)
|
||||||
|
|
||||||
|
class BondingCurveState:
|
||||||
|
_STRUCT = Struct(
|
||||||
|
"virtual_token_reserves" / Int64ul,
|
||||||
|
"virtual_sol_reserves" / Int64ul,
|
||||||
|
"real_token_reserves" / Int64ul,
|
||||||
|
"real_sol_reserves" / Int64ul,
|
||||||
|
"token_total_supply" / Int64ul,
|
||||||
|
"complete" / Flag
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, data: bytes) -> None:
|
||||||
|
parsed = self._STRUCT.parse(data[8:])
|
||||||
|
self.__dict__.update(parsed)
|
||||||
|
|
||||||
|
def get_associated_bonding_curve_address(mint: Pubkey, program_id: Pubkey) -> tuple[Pubkey, int]:
|
||||||
|
"""
|
||||||
|
Derives the associated bonding curve address for a given mint
|
||||||
|
"""
|
||||||
|
return Pubkey.find_program_address(
|
||||||
|
[
|
||||||
|
b"bonding-curve",
|
||||||
|
bytes(mint)
|
||||||
|
],
|
||||||
|
program_id
|
||||||
|
)
|
||||||
|
|
||||||
|
async def get_bonding_curve_state(conn: AsyncClient, curve_address: Pubkey) -> BondingCurveState:
|
||||||
|
response = await conn.get_account_info(curve_address)
|
||||||
|
if not response.value or not response.value.data:
|
||||||
|
raise ValueError("Invalid curve state: No data")
|
||||||
|
|
||||||
|
data = response.value.data
|
||||||
|
if data[:8] != EXPECTED_DISCRIMINATOR:
|
||||||
|
raise ValueError("Invalid curve state discriminator")
|
||||||
|
|
||||||
|
return BondingCurveState(data)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
print("\nToken Status:")
|
||||||
|
print("-" * 50)
|
||||||
|
print(f"Token Mint: {mint}")
|
||||||
|
print(f"Associated Bonding Curve: {bonding_curve_address}")
|
||||||
|
print(f"Bump Seed: {bump}")
|
||||||
|
print("-" * 50)
|
||||||
|
|
||||||
|
# Check completion status
|
||||||
|
async with AsyncClient(RPC_ENDPOINT) as client:
|
||||||
|
try:
|
||||||
|
curve_state = await get_bonding_curve_state(client, bonding_curve_address)
|
||||||
|
|
||||||
|
print("\nBonding Curve Status:")
|
||||||
|
print("-" * 50)
|
||||||
|
print(f"Completion Status: {'Completed' if curve_state.complete else 'Not Completed'}")
|
||||||
|
if curve_state.complete:
|
||||||
|
print("\nNote: This bonding curve has completed and liquidity has been migrated to Raydium.")
|
||||||
|
print("-" * 50)
|
||||||
|
|
||||||
|
except ValueError as e:
|
||||||
|
print(f"\nError accessing bonding curve: {e}")
|
||||||
|
|
||||||
|
except ValueError as e:
|
||||||
|
print(f"\nError: Invalid address format - {e}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\nUnexpected error: {e}")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description='Check token bonding curve status')
|
||||||
|
parser.add_argument('mint_address', help='The token mint address')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
asyncio.run(check_token_status(args.mint_address))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import websockets
|
||||||
|
import asyncio
|
||||||
|
import json
|
||||||
|
import base64
|
||||||
|
from solders.pubkey import Pubkey
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||||
|
from config import WSS_ENDPOINT, PUMP_LIQUIDITY_MIGRATOR
|
||||||
|
|
||||||
|
def process_initialize2_transaction(data):
|
||||||
|
"""Process and decode an initialize2 transaction"""
|
||||||
|
try:
|
||||||
|
signature = data['transaction']['signatures'][0]
|
||||||
|
account_keys = data['transaction']['message']['accountKeys']
|
||||||
|
|
||||||
|
# Check raydium_amm_idl.json for the account keys
|
||||||
|
# The token address is typically the 19th account (index 18)
|
||||||
|
# The liquidity pool address is typically the 3rd account (index 2)
|
||||||
|
if len(account_keys) > 18:
|
||||||
|
token_address = account_keys[18]
|
||||||
|
liquidity_address = account_keys[2]
|
||||||
|
|
||||||
|
print(f"\nSignature: {signature}")
|
||||||
|
print(f"Token Address: {token_address}")
|
||||||
|
print(f"Liquidity Address: {liquidity_address}")
|
||||||
|
print("=" * 50)
|
||||||
|
else:
|
||||||
|
print(f"\nError: Not enough account keys (found {len(account_keys)})")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\nError: {str(e)}")
|
||||||
|
|
||||||
|
async def listen_for_events():
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
async with websockets.connect(WSS_ENDPOINT) as websocket:
|
||||||
|
subscription_message = json.dumps({
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"id": 1,
|
||||||
|
"method": "blockSubscribe",
|
||||||
|
"params": [
|
||||||
|
{"mentionsAccountOrProgram": str(PUMP_LIQUIDITY_MIGRATOR)},
|
||||||
|
{
|
||||||
|
"commitment": "confirmed",
|
||||||
|
"encoding": "json",
|
||||||
|
"showRewards": False,
|
||||||
|
"transactionDetails": "full",
|
||||||
|
"maxSupportedTransactionVersion": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
await websocket.send(subscription_message)
|
||||||
|
response = await websocket.recv()
|
||||||
|
print(f"Subscription response: {response}")
|
||||||
|
print("\nListening for Raydium pool initialization events...")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
response = await asyncio.wait_for(websocket.recv(), timeout=30)
|
||||||
|
data = json.loads(response)
|
||||||
|
|
||||||
|
if 'method' in data and data['method'] == 'blockNotification':
|
||||||
|
if 'params' in data and 'result' in data['params']:
|
||||||
|
block_data = data['params']['result']
|
||||||
|
if 'value' in block_data and 'block' in block_data['value']:
|
||||||
|
block = block_data['value']['block']
|
||||||
|
if 'transactions' in block:
|
||||||
|
for tx in block['transactions']:
|
||||||
|
logs = tx.get('meta', {}).get('logMessages', [])
|
||||||
|
|
||||||
|
# Check for initialize2 instruction
|
||||||
|
for log in logs:
|
||||||
|
if "Program log: initialize2: InitializeInstruction2" in log:
|
||||||
|
print("Found initialize2 instruction!")
|
||||||
|
process_initialize2_transaction(tx)
|
||||||
|
break
|
||||||
|
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
print("\nChecking connection...")
|
||||||
|
print("Connection alive")
|
||||||
|
continue
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\nConnection error: {str(e)}")
|
||||||
|
print("Retrying in 5 seconds...")
|
||||||
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(listen_for_events())
|
||||||
Reference in New Issue
Block a user