diff --git a/learning-examples/listen_to_logs_migration.py b/learning-examples/listen_to_logs_migration.py new file mode 100644 index 0000000..d02a2bc --- /dev/null +++ b/learning-examples/listen_to_logs_migration.py @@ -0,0 +1,158 @@ +import asyncio +import base64 +import json +import os +import struct + +import base58 +import websockets +from solders.pubkey import Pubkey + +WSS_ENDPOINT = os.environ.get("SOLANA_NODE_WSS_ENDPOINT") +MIGRATION_PROGRAM_ID = Pubkey.from_string("39azUYFWPz3VHgKCf3VChUwbpURdCHRxjWVowf5jUJjg") + + +def parse_migrate_instruction(data): + if len(data) < 8: + print(f"[ERROR] Data length too short: {len(data)} bytes") + return None + + offset = 8 + parsed_data = {} + + fields = [ + ("timestamp", "i64"), + ("index", "u16"), + ("creator", "publicKey"), + ("baseMint", "publicKey"), + ("quoteMint", "publicKey"), + ("baseMintDecimals", "u8"), + ("quoteMintDecimals", "u8"), + ("baseAmountIn", "u64"), + ("quoteAmountIn", "u64"), + ("poolBaseAmount", "u64"), + ("poolQuoteAmount", "u64"), + ("minimumLiquidity", "u64"), + ("initialLiquidity", "u64"), + ("lpTokenAmountOut", "u64"), + ("poolBump", "u8"), + ("pool", "publicKey"), + ("lpMint", "publicKey"), + ("userBaseTokenAccount", "publicKey"), + ("userQuoteTokenAccount", "publicKey"), + ] + + try: + for field_name, field_type in fields: + if field_type == "publicKey": + 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("