Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 8180

Error: 'dict' object has no attribute 'offset'

$
0
0

when im trying to execute the code its getting error from offset , in mem filter , need to get pool keys from this

from solana.rpc.types import MemcmpOpts, DataSliceOptsfrom solders.pubkey import Pubkeyimport constructimport asynciofrom solders.rpc.requests import GetProgramAccountsfrom borsh_construct import CStruct, U64, Bytes, U128from construct import Bytes, Int8ul, Int32ul, Int64ul, Pass, Switchfrom base58  import b58decode, b58encodePUBLIC_KEY_LAYOUT = Bytes(32)# Define constants and initialize Solana clientRPC_URL = "https://mainnet.helius-rpc.com/?api-key"connection = AsyncClient(RPC_URL, "confirmed")# Public keys for base and quote tokensWSOL_MINT = "So11111111111111111111111111111111111111112"  # WSOL mint addressQUOTE_MINT = "CJduScRXPGpkT3oKuu2mNny5Do9vzL46guxXwAP4pump"base = Pubkey.from_string(WSOL_MINT)quote = Pubkey.from_string(QUOTE_MINT)print(f"sad{base} fdf{quote}")# Constants for RaydiumAMM_PROGRAM_ID = Pubkey.from_string("AMM5p5yAx2m9T8p7K8v8SYJGtZo2PYJ9yya9CZKyUiSv")  # Raydium AMM V4 Program IDLIQUIDITY_STATE_LAYOUT_V4_SPAN = 752  # Size of the liquidity state layout V4 in bytes# Function to fetch market accountsasync def fetch_market_accounts(connection: AsyncClient, base: Pubkey, quote: Pubkey, commitment: str) -> dict[str, any]:    try:        # Create memory comparison filters using MemcmpOpts        base_mint_filter = MemcmpOpts(            offset=LIQUIDITY_STATE_LAYOUT_V4.baseMint,            bytes=str(base)        )        quote_mint_filter = MemcmpOpts(            offset=LIQUIDITY_STATE_LAYOUT_V4.quoteMint,            bytes=str(quote)        )        # Create the config object for fetching program accounts        data_size_filter = {"dataSize": LIQUIDITY_STATE_LAYOUT_V4_SPAN}        # Fetching program accounts        accounts = await connection.get_program_accounts(            pubkey=AMM_PROGRAM_ID,            filters=[data_size_filter, base_mint_filter, quote_mint_filter],            encoding="base64",            commitment=commitment        )        print(accounts)        # Decode the data and format it        raw_data = [{"id": str(pubkey),"data": LIQUIDITY_STATE_LAYOUT_V4.decode(account.data)        } for pubkey, account in zip(accounts.keys(), accounts.values())]        # Assuming only one relevant account is found, return the first object        obj = raw_data[0] if raw_data else None        print(f'fetch_market_accounts', obj)        return obj    except Exception as error:        print(f'fetch_market_accounts', error)# Running the functionasyncio.run(fetch_market_accounts(connection, base, quote, "confirmed"))

Viewing all articles
Browse latest Browse all 8180

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>