Christopherus
Christopherus

Reputation: 85

Error when fetching pool keys from Raydium_py Solana

I’m working with a public GitHub repo (you can find it here: https://github.com/AL-THE-BOT-FATHER/raydium_py) that interacts with the Raydium decentralized exchange using Python. I’m trying to fetch liquidity pool keys but am encountering the following error:

Fetching pool keys...
Error fetching pool keys: a bytes-like object is required, not 'solders.account_decoder.ParsedAccount'
No pool keys found....

Here’s the relevant part of the code (utils.py in the repo) from the repo that is causing the issue:

def fetch_pool_keys(pair_address: str) -> Optional[PoolKeys]:
    try:
        amm_id = Pubkey.from_string(pair_address)
        amm_data = client.get_account_info_json_parsed(amm_id, commitment=Processed).value.data
        amm_data_decoded = LIQUIDITY_STATE_LAYOUT_V4.parse(amm_data)
        marketId = Pubkey.from_bytes(amm_data_decoded.serumMarket)
        marketInfo = client.get_account_info_json_parsed(marketId, commitment=Processed).value.data
        market_decoded = MARKET_STATE_LAYOUT_V3.parse(marketInfo)
        vault_signer_nonce = market_decoded.vault_signer_nonce

        pool_keys = PoolKeys(
            amm_id=amm_id,
            base_mint=Pubkey.from_bytes(market_decoded.base_mint),
            quote_mint=Pubkey.from_bytes(market_decoded.quote_mint),
            base_decimals=amm_data_decoded.coinDecimals,
            quote_decimals=amm_data_decoded.pcDecimals,
            open_orders=Pubkey.from_bytes(amm_data_decoded.ammOpenOrders),
            target_orders=Pubkey.from_bytes(amm_data_decoded.ammTargetOrders),
            base_vault=Pubkey.from_bytes(amm_data_decoded.poolCoinTokenAccount),
            quote_vault=Pubkey.from_bytes(amm_data_decoded.poolPcTokenAccount),
            market_id=marketId,
            market_authority=Pubkey.create_program_address( 
                [bytes(marketId), bytes_of(vault_signer_nonce)],
                OPEN_BOOK_PROGRAM,
            ),
            market_base_vault=Pubkey.from_bytes(market_decoded.base_vault),
            market_quote_vault=Pubkey.from_bytes(market_decoded.quote_vault),
            bids=Pubkey.from_bytes(market_decoded.bids),
            asks=Pubkey.from_bytes(market_decoded.asks),
            event_queue=Pubkey.from_bytes(market_decoded.event_queue),
        )

        return pool_keys
    except Exception as e:
        print(f"Error fetching pool keys: {e}")
        return None

The error suggests that there’s a problem with how I’m handling the ParsedAccount object, stating that a bytes-like object is required but a solders.account_decoder.ParsedAccount is being passed. Despite trying multiple approaches, I keep hitting the same error.

Additionally, the creator of the repo mentioned that Free-Tier RPCs might not work correctly, and recommended using Helius or Quicknode. I’ve tested both services, including the paid versions, but the error persists.

Has anyone encountered a similar issue or have any suggestions for resolving it? Any guidance would be greatly appreciated!

PS: The method is used for buying and selling. While buying works fine, when trying to sell there appears this error...

Upvotes: 0

Views: 91

Answers (0)

Related Questions